The TextVerstehen REST API
Various navigation modes, knowledge graph creation, and much more!
For the sake of immediate usabillity, this API is documented in the form of curl commands with example parameters. Our knowledge graphs come as software containers and can be deployed easily whereever you want to run them. As for any REST API, the endpoints can be called very flexibly, be it from a smartphone app, a web frontend, or just from your local system.
1 Setting up a Knowledge Graph Project
1.1 Initialization
curl -i -H "Content-Type: application/json" -X PUT \ -d '{"token": 2604251, "kg_name": "ShowcaseKG", "project_type": "KG_QAKR"|"KG_QAPL", "persistence":"binary", "persist_file":"products_1000.pkl", "data_path": "/home/kguser/data/"}' \ 10.247.70.8:5000/initialize
Initializes a Knowledge Graph project with parameters such as token, name, type, persistence, and data path.
1.2 Get Project Definition
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251}' \ 10.247.70.8:5000/kgproject
Returns the current project definition.
1.3 Set Data Path
curl -i -H "Content-Type: application/json" -X PUT \ -d '{"token": 2604251, "data_path": "/home/kguser/data/"}' \ 10.247.70.8:5000/kgpath
Sets a new data path for the project.
1.4 Define Logic-Based KG
curl -i -H "Content-Type: application/json" -X PUT \ -d '{"token": 23571113, "ontofile":"showcase_logic2.qlf", "accessfile":"KG_Access_And_Querying.qlf"}' \ 10.247.70.8:5000/deflogic
Additional endpoint for logic-based projects of type KG_QAPL.
2 Navigating the Knowledge Graph
2.1 Label-Based Navigation
2.1.1 Query Labels
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251, "query": "Do you have a chopping board made of spruce"}' \ 10.247.70.8:5000/querylabels
Labels are simplified domain-specific terms and refer to entities.
2.1.2 Get All Labels
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251}' \ 10.247.70.8:5000/alllabels
Returns a list of all labels in the Knowledge Graph.
2.1.3 Get Triples by Labels
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251, "labels": ["chopping board", "spruce"], "support":1}' \ 10.247.70.8:5000/triplesbylabel
Triples are the basic statements of the Knowledge Graph. This endpoint returns all triples referenced by the given labels.
2.1.4 Get Triples by Label Pair
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251, "pair": ["chopping board", "spruce"]}' \ 10.247.70.8:5000/triplesbypair
The triple must match both labels.
2.1.5 Get Objects by Labels
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251, "labels": ["materials", "lampshade"]}' \ 10.247.70.8:5000/objectsbylabels
Returns all objects referenced by any of the given labels.
2.1.6 Get Labels for an Object
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251, "object":{"object":"clothing", "type":"KGType.Entity"}}' \ 10.247.70.8:5000/labelsforobjects
Returns all labels for a given object.
2.2 Triple-Based Navigation
2.2.1 Get Triples for a List of Objects
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251, "objects":[{"object":"gardening tools", "type":"KGType.Entity"}], "support":1}' \ 10.247.70.8:5000/triplesbyobjects
The support parameter specifies how many objects from the list must match a triple.
2.2.2 Get Reifications
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251, "triple":{"subj":{"object": "dragon", "type": "mythical_creature"},"prop": {"object": "quality", "type": "KGType.Property"}, "obj":{"object": "manager", "type": "KGType.Entity"}}, "withTypes":0}' \ 10.247.70.8:5000/reifications
A reification is a statement that refers to another statement. For example, it can indicate where a statement occurs in product records or descriptive texts.
2.2.3 Get Statements
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251, "number":1237, "type":"KGType.Statement"}' \ 10.247.70.8:5000/stmtortext
Returns the typed triple corresponding to the given statement number.
2.2.4 Get Text Pieces
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251, "number":"t212", "type":"KGType.Text"}' \ 10.247.70.8:5000/stmtortext
Returns the full text segment corresponding to the given number as a string.
2.3 Object-Based Navigation
2.3.1 Navigate from a Subject
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251, "subj":{"object":"effort", "type":"KGType.Entity"}, "depth":1, "link_names":[]}' \ 10.247.70.8:5000/objectsbysubj
Returns all typed entities in the object role that are reachable from the given subject within the specified depth. Link names can restrict the traversal.
2.3.2 Get Subjects for an Object
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251, "obj":{"object":"solution", "type":"KGType.Entity"}, "link_name":""}' \ 10.247.70.8:5000/objectsbyobjs
Returns subject entities for the given object.
2.3.3 Get Key Object
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251, "object":{"object":"bread bag", "type":"KGType.Entity"}}' \ 10.247.70.8:5000/keyobjects
A key is the root of a subgraph, such as a product number from which all specifications depend. This endpoint returns all keys for a given object.
3 Persistence, Statistics and Printing
3.1 Save Knowledge Graph
curl -i -H "Content-Type: application/json" -X PUT \ -d '{"token": 2604251, "persist_file":"products_1000.pkl"}' \ 10.247.70.8:5000/persistfile
Saves the Knowledge Graph according to the defined persistence.
3.2 Print Knowledge Graph
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251}' \ 10.247.70.8:5000/printkg
Prints the Knowledge Graph as ASCII text and stores it in a container file. The filename is returned.
3.3 Retrieve Print File
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251, "kg_file_name": "/home/kguser/data/ShowcaseKG.txt", "max_length":0, "start_point":0}' \ 10.247.70.8:5000/kgprintfile
Retrieves a print file in full or in parts.
3.4 Get Statistics
curl -i -H "Content-Type: application/json" -X GET \ -d '{"token": 2604251}' \ 10.247.70.8:5000/kgstatistics
Generates a set of descriptive statistics for the Knowledge Graph.