-
Notifications
You must be signed in to change notification settings - Fork 25
How to Implement a Qanary Component using Python
Qanary is a methodology following the idea of a lean architecture of Question Answering systems and easy reuse of Question Answering services (c.f., see our publication for details). We call these services Qanary components.
To implement a Qanary component there is just a trivial requirement: The service needs to provide a restful Web service endpoint named /annotatequestion
. This endpoint receives a JSON message of the following structure:
{
"values":{
"urn:qanary#endpoint": URI,
"urn:qanary#inGraph": URI,
"urn:qanary#outGraph": URI
}
}
Where the attribute urn:qanary#endpoint
identifies the Qanary triplestore (the global memory of the Qanary question processing), and the attribute urn:qanary#inGraph
identifies the graph containing the data that might be used by the current service while to urn:qanary#outGraph
new knowledge about the currently analyzed question (i.e., the question of the user) is stored. Mostly urn:qanary#inGraph
is equal to urn:qanary#outGraph
. The endpoint needs to return a JSON message following the same structure. Typically, the exact same object is returned.
In general, you might establish a Qanary component in any programming language following this simple Web service design.
The Qanary reference implementation provides several features to ease the implementation of Qanary-driven Question Answering systems. In particular, Spring Boot Admin is integrated to provide a service registration and easy access to all currently available components, s.t., Question Answering systems might easily be composed of existing (but independently deployed) Qanary components (e.g., the ones available here).
If the Python Qanary component has to be compatible with the Qanary reference implementation, then the requirements of Spring Boot Admin instances need to be supported.
An exemplary implementation is available at: github.com/anbo-de/PythonClientForSpringBootAdmin/
There, a general service implementation written in Python/Flask is provided that is compatible with Spring Boot Admin. Using this implementation just the file myservice.py
needs to be extended with the following statement. It defines the endpoint /annotatequestion
and provides access to the JSON data:
@myservice.route("/annotatequestion", methods=['POST'])
def qanaryService():
"""the POST endpoint required for a Qanary service"""
triplestore_endpoint = request.json["values"]["urn:qanary#endpoint"]
triplestore_ingraph = request.json["values"]["urn:qanary#inGraph"]
triplestore_outgraph = request.json["values"]["urn:qanary#outGraph"]
print("endpoint: %s, ingraph: %s, outGraph: %s" % (triplestore_endpoint, triplestore_ingraph, triplestore_outgraph))
# add your functionality here
return jsonify(request.get_json())
After having the Python Qanary component started, the Qanary component will register itself to the configured Qanary question answering system.
See "How do I integrate a new component in Qanary?" for a description of how to (automatically) create a Java Qanary component using a provided Maven archetype.
-
How to establish a Docker-based Qanary Question Answering system
-
How to implement a new Qanary component
... using Java?
... using Python (Qanary Helpers)?
... using Python (plain Flask service)?