Skip to content

Demo: How to Create a Question Answering System capable of Analyzing the Question "What is the real name of Batman?"

Dennis Schiese edited this page Mar 11, 2024 · 7 revisions

This page illustrates step by step procedure of integrating a new component into Qanary architecture.

To illustrate rapid engineering of QA Systems using the Qanary architecture, we provide a demo of the creation of a component for answering the question “What is the real name of Batman?”, i.e., a component that identifies relation present in input question. For instance, in the mentioned question, the component identifies dbp:alterEgo as a relation, i.e., a DBpedia property. The component can be integrated into the Qanary ecosystem by wrapping the functionality into a Qanary component and to create a Qanary QA system following this step by step procedure:

  • Check out the Qanary project from GitHub:
git clone https://github.com/WDAqua/Qanary
  • In project sub-folder qanary-component-archetype build and install the Maven archetype qa.qanarycomponent-archetype for creating new Qanary components in our local Maven repository:
mvn install -Dgpg.skip

Note: To skip the Docker image creation you can use mvn -DskipDockerBuild install^1

  • To create a new Qanary component, execute the following command in the project root folder:
mvn archetype:generate \
       -DarchetypeGroupId=eu.wdaqua.qanary.component \
       -DarchetypeArtifactId=qa.qanarycomponent-archetype \
       -DarchetypeVersion=0.1.1 \
       -DgroupId=eu.wdaqua.qanary.commons \
       -DartifactId=qa.qanary_component-MyComponent \
       -Dversion=0.0.1 \
       -Dpackage=eu.wdaqua.qanary.realnamerelationidentifier \
       -Dclassname=RealNameRelationIdentifier \
       -DinteractiveMode=false
  • The previous step creates the component named qanary_component-realnamerelationidentifier.
  • Open the Maven project in your IDE. The new component automatically appears in the list of components displayed in your IDE. The screenshot shows the representation in Eclipse:

  • The component is already completely runnable. However, the component body is not implemented.
import java.net.URLEncoder;
import java.util.ArrayList;

@Component
publi class RealNameRelationIdentifier extends QanaryComponent {
	private static final Logger logger = LoggerFactory.getLogger(RealNameRelationIdentifier.class);

	/**
	 * implement this method encapsulating the functionality of your Qanary
	 * component
	 */
	@Override
	public QanaryMessage process(QanaryMessage QanaryMessage) {
		

		try
		{
			long startTime = System.currentTimeMillis();
            logger.info("process: {}", QanaryMessage);
  • Retrieve the textual question from the triplestore:
 QanaryUtils myQanaryUtils = this.getUtils(myQanaryMessage);
		QanaryQuestion<String> myQanaryQuestion = new QanaryQuestion(myQanaryMessage);
		String question = myQanaryQuestion.getTextualRepresentation();
  • Use a simple string matcher to identify the sub-string “real name of” in the textual question (mapped to dbp:alterEgo) and identify the start (START) and end (END) position of it.

  • Store this information within the triplestore using a SPARQL INSERT query. The text index of the matcher is used as well as the DBpedia property dbp:alterEgo.

                    sparql = "prefix qa: <http://www.wdaqua.eu/qa#> "
                            + "prefix oa: <http://www.w3.org/ns/openannotation/core/> "
                            + "prefix xsd: <http://www.w3.org/2001/XMLSchema#> "
                            + "prefix dbp: <http://dbpedia.org/property/> "
                            + "INSERT { "
                            + "GRAPH <" + namedGraph + "> { "
                            + "  ?a a qa:AnnotationOfRelation . "
                            + "  ?a oa:hasTarget [ "
                            + "           a    oa:SpecificResource; "
                            + "           oa:hasSource    <" + uriQuestion + ">; "
                            + "              oa:start \"" + START + "\"^^xsd:nonNegativeInteger ; " //
                            + "              oa:end  \"" + END + "\"^^xsd:nonNegativeInteger  " //
                            + "  ] ; "
                            + "     oa:hasBody dbp:alterEgo ;";
                            + "     oa:annotatedBy <http://relationidentifier.com> ; "
                            + "	    oa:AnnotatedAt ?time  "
                            + "}} "
                            + "WHERE { "
                            + "BIND (IRI(str(RAND())) AS ?a) ."
                            + "BIND (now() as ?time) "
                            + "}";
                    logger.info("Sparql query {}", sparql);
                    loadTripleStore(sparql, endpoint);
            }
  • Now the component is ready w.r.t. the demanded functionality.

  • Next the service composition is initialized: run the reference implementation (java -jar qa.pipeline-0.1.0.jar), start the new component (java -jar qanary_component-Realnamerelationidentifier-0.1.0.jar), start the Qanary component DBpedia Spotlight (java -jar qa.DBpedia.Spotlight-NED-0.1.0.jar). Call the AdminServer at http://localhost:8080 where three components are shown now.

  • Execute this three component sub-workflow of the whole process - using http://localhost:8080/startquestionansweringwithaudioquestion - to show that the data is stored in the triplestore (use Stardog web interface at http://localhost:5820/ to show the presence of the data in the triplestore).

  • Iteratively extend the workflow to a complete QA system by adding a SPARQL query generator and SPARQL query executor. Due to the characteristics of the approach not only the mentioned question can be answered, but at least 700 other (based on the DBpedia KB).

  • This concludes the integration of a newly developed component into Qanary following easy hassle-free integration steps.

Clone this wiki locally