3.3.3. WS Invocations in the QueryGenerator

Invoking the QueryGenerator may feel like talking to a black box – just like invoking the QAPlanner. In the previous sections we have seen how other WSs are invoked inside the QAPlanner and therewith maybe even “demystified” the planner component a bit. We’d now like to attempt something similar for the QueryGenerator. To show its full internal workflow would be out of scope, though, for this tutorial; rather we would like to quickly show how the two internally used WSs are invoked: the EntailmenTester and the Timex2SparqlConverter. If you are interested in the concrete functioning of the QueryGenerator, then you may have a look at the explanations in sections 4.2.3.3: “QueryGenerator” and 2.1.5: “Recognizing Textual Entailment for QA”.

At some point the QueryGenerator has to find out how to map the given analyzed question to a SPARQL answer query. This “finding out” is achieved by comparing the given question to predefined question patterns using an implementation of the EntailmentTester WS for the question language.

Let’s again take the German sample question from section 3.3.1: “Wo kann ich heute Abend in Alicante den Film Saw 5 sehen?” (“Where can I see the movie Saw 5 in Alicante tonight?”). When reaching the QueryGenerator, temporal expressions, named entities and domain-relevant terms are already annotated. Based on the set of annotations in the question, there may be several predefined question patterns that could match the question. So the QueryGenerator takes these question patterns and – together with copies of the original question – enters them as pairs into the EntailmentTester; the first element of every pair is the original question, the second element of every pair is one of the possibly matching question patterns. So a sample request (SOAP body) to the getEntailmentProbability web method could look like this:[7]

<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
	<ent:getEntailmentProbability xmlns:ent="http://qallme.sf.net/wsdl/entailmenttest.wsdl"
	                              xmlns:ent1="http://qallme.sf.net/xsd/entailmenttest.xsd"
                                  xmlns:ns2="http://qallme.sf.net/xsd/qallmeshared.xsd"
                                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
		<pairs>
			<ent1:AnnotatedSentence id="no1" xsi:type="ent1:AnnotatedSentenceId"
				>Wo in <ns2:annotation canonicalForm="Alicante" type="DESTINATION"
				>Alicante</ns2:annotation> kann ich <ns2:annotation canonicalForm="&lt;TIMEX2 VAL=&quot;2008-12-11TEV&quot;>heute Abend&lt;/TIMEX2>" type="TIMEX2"
				>heute Abend</ns2:annotation> <ns2:annotation canonicalForm="Saw 5" type="MOVIE"
				>Saw 5</ns2:annotation> sehen?</ent1:AnnotatedSentence>
			<ent1:AnnotatedSentence id="no2" xsi:type="ent1:AnnotatedSentenceId"
				>In welchen Ortsteilen von <ns2:annotation canonicalForm="Alicante" type="DESTINATION"
				>Alicante</ns2:annotation> wird <ns2:annotation canonicalForm="&lt;TIMEX2 VAL=&quot;2008-12-11TEV&quot;>heute Abend&lt;/TIMEX2>" type="TIMEX2"
				>heute Abend</ns2:annotation> der Film <ns2:annotation canonicalForm="Saw 5" type="MOVIE"
				>Saw 5</ns2:annotation> gezeigt?</ent1:AnnotatedSentence>
			<ent1:AnnotatedSentence ref="no1" xsi:type="ent1:AnnotatedSentenceRef" />
			<ent1:AnnotatedSentence id="no3" xsi:type="ent1:AnnotatedSentenceId"
				>In welchem Kino in <ns2:annotation canonicalForm="Alicante" type="DESTINATION"
				>Alicante</ns2:annotation> kann ich <ns2:annotation canonicalForm="&lt;TIMEX2 VAL=&quot;2008-12-11TEV&quot;>heute Abend&lt;/TIMEX2>" type="TIMEX2"
				>heute Abend</ns2:annotation> <ns2:annotation canonicalForm="Saw 5" type="MOVIE"
				>Saw 5</ns2:annotation> sehen?</ent1:AnnotatedSentence>
			<ent1:AnnotatedSentence ref="no1" xsi:type="ent1:AnnotatedSentenceRef" />
			<ent1:AnnotatedSentence id="no4" xsi:type="ent1:AnnotatedSentenceId"
				>Welche Filme laufen <ns2:annotation canonicalForm="&lt;TIMEX2 VAL=&quot;2008-12-11TEV&quot;>heute Abend&lt;/TIMEX2>" type="TIMEX2"
				>heute Abend</ns2:annotation> zur selben Zeit wie <ns2:annotation canonicalForm="Saw 5" type="MOVIE"
				>Saw 5</ns2:annotation> in <ns2:annotation canonicalForm="Alicante" type="DESTINATION"
				>Alicante</ns2:annotation>?</ent1:AnnotatedSentence>
		</pairs>
	</ent:getEntailmentProbability>
</soapenv:Body>
In the request the original question is only given once in full; the other times where it is used in a pair, it is just referenced by its ID in order to minimize the network overhead for the WS invocation. Please note that the <AnnotatedSentence> elements in this request are spezialized subtypes of the <AnnotatedSentence> elements which are used elsewhere. So simple copying and pasting is not possible here. However, the changes for a copied element are manageable: just have a close look at the above examples and compare the relevant XML namespaces.

As we would expect, the response (SOAP body) for the above request yields the highest entailment probability for the second question pair:

<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
	<ns3:getEntailmentProbabilityResponse xmlns:ns3="http://qallme.sf.net/wsdl/entailmenttest.wsdl">
		<probabilities xmlns:ns2="http://qallme.sf.net/xsd/entailmenttest.xsd">
			<ns2:probability>0.47395766</ns2:probability>
			<ns2:probability>0.79949445</ns2:probability>
			<ns2:probability>0.53195786</ns2:probability>
		</probabilities>
	</ns3:getEntailmentProbabilityResponse>
</soapenv:Body>

By finding a matching predefined question pattern for the input question using textual entailment, the QueryGenerator also has a SPARQL query pattern which it can already almost return (cf. 2.1.5: “Recognizing Textual Entailment for QA”). What is still missing here, though, is the filling of the placeholder slots in the query pattern with the information from the annotations of the input question. In the case of entity and term annotations this is straightforward. However, for temporal expression annotations the TIMEX2 value of the annotation still needs to be converted to a format that can be used in a SPARQL query. This is the task of the Timex2SparqlConverter WS; the WS is internally called by the QueryGenerator for every TIMEX2 value in the input question.

All relevant information for a temporal expression annotation in the input is stored in the canonicalForm attribute value of the annotation. This value is actually an XML string which basically just needs to be parsed and put into a SOAP request to the convert web method of the Timex2SparqlConverter; additionally the temporal context of the expression is needed. Here is an example SOAP request body for the temporal expression “tonight”:

<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
	<tim:ConversionRequest xmlns:tim="http://qallme.sf.net/wsdl/timex2sparqlconversion.wsdl">
		<tim:TIMEX2AnnotatedText xmlns:tim1="http://qallme.sf.net/xsd/timex2.xsd">
			<tim1:TIMEX2 VAL="2008-12-11TEV">tonight</tim1:TIMEX2>
		</tim:TIMEX2AnnotatedText>
		<tim:temporalContext>2008-12-11T10:51:26</tim:temporalContext>
	</tim:ConversionRequest>
</soapenv:Body>

Please note that in the current implementation of the QALL-ME Framework we are using “extended” TIMEX2 annotations (cf. 4.2.1). So there is also another possible form of the SOAP request, e.g., for the temporal expression “from 3 till 4 pm today”:

<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
	<tim:ConversionRequest xmlns:tim="http://qallme.sf.net/wsdl/timex2sparqlconversion.wsdl">
		<tim:TIMEX2AnnotatedText>
			<tim:TIMEX2 VAL="2008-12-11T15:00" function="FROM">from 3</tim:TIMEX2>
			<tim:TIMEX2 VAL="2008-12-11T16:00" function="TO">till 4 pm today</tim:TIMEX2>
		</tim:TIMEX2AnnotatedText>
		<tim:temporalContext>2008-12-11T10:51:26</tim:temporalContext>
	</tim:ConversionRequest>
</soapenv:Body>
Note the different <TIMEX2> elements in this request compared to the previous one: the elements have the same name but different XML namespaces.



[7] English translations for the other sentences:

  • In which part of Alicante can I see the movie Saw 5 tonight?
  • In which cinema in Alicante can I see the movie Saw 5 tonight?
  • Which movies are running at the same time as Saw 5 in Alicante tonight?