Skip to main content

Contextual information

Up to now the result was always given by the "rdfs:label". But in an RDF dataset there are potentially many contextual information that can be shown like descriptions, images, maps and videos.

To allow QAnswer to display this contextual information your ontology vocabulary has to be aligned by the one used by QAnswer. This is necessary since there are different proposed vocabulary to express this type of information in the Semantic Web Community and no one became a standard. QAnswer is using some common properties. So let's start.

In the case of the cocktail KG you can add the following properties:

  1. Description: http://www.w3.org/2004/02/skos/core#definition
  2. Image: http://vocabulary.semantic-web.at/cocktail-ontology/image
  3. DBpedia: http://www.w3.org/2004/02/skos/core#exactMatch

Let's align the vocabulary using the mapping API.

Get existing mapping

To start we need to get the existing mapping using the following API:

curl -X GET \
'https://app.qanswer.ai/api/dataset/mappings?dataset=cocktails' \
-H 'Authorization: Bearer eyJhbGciOiJIUzUx....' \

the result is:

{
"dataset": "cocktails",
"label": [
"http://www.w3.org/2000/01/rdf-schema#label",
"http://www.w3.org/2004/02/skos/core#prefLabel",
"http://purl.org/dc/terms/title",
"http://xmlns.com/foaf/0.1/givenName",
"http://purl.org/dc/elements/1.1/title"
],
"description": [
"http://www.w3.org/2000/01/rdf-schema#description"
],
"image": [
"http://www.wikidata.org/prop/direct/P18"
],
"coordinate": [
"http://www.wikidata.org/prop/direct/P625"
],
"osmRelation": [
"http://www.wikidata.org/prop/direct/P402"
],
"youtube": [
"http://www.wikidata.org/prop/direct/P165"
],
"github": [
"http://www.wikidata.org/prop/direct/P2037"
],
"twitter": [
"http://www.wikidata.org/prop/direct/P2002"
],
"facebook": [
"http://www.wikidata.org/prop/direct/P2013"
],
"instagram": [
"http://www.wikidata.org/prop/direct/P2003"
],
"homepage": [
"http://www.wikidata.org/prop/direct/P856"
],
"orcid": [
"http://www.wikidata.org/prop/direct/P496"
],
"doi": [
"http://www.wikidata.org/prop/direct/P356"
],
"geometry": [
"http://www.opengis.net/ont/geosparql#hasGeometry"
]
}

Update the mappings

Now let's update the mappings with the above changes you can POST on the same API:

curl -X POST \
'https://app.qanswer.ai/api/dataset/mappings?dataset=cocktails' \
-H 'Authorization: Bearer eyJhbGciOiJIUzUx.....' \
-d '{
"dataset": "cocktails",
"label": [
"http://www.w3.org/2000/01/rdf-schema#label",
"http://www.w3.org/2004/02/skos/core#prefLabel",
"http://purl.org/dc/terms/title",
"http://xmlns.com/foaf/0.1/givenName",
"http://purl.org/dc/elements/1.1/title"
],
"description": [
"http://www.w3.org/2000/01/rdf-schema#description",
"http://www.w3.org/2004/02/skos/core#definition"
],
"image": [
"http://www.wikidata.org/prop/direct/P18",
"http://vocabulary.semantic-web.at/cocktail-ontology/image"
],
"coordinate": [
"http://www.wikidata.org/prop/direct/P625"
],
"osmRelation": [
"http://www.wikidata.org/prop/direct/P402"
],
"youtube": [
"http://www.wikidata.org/prop/direct/P165"
],
"github": [
"http://www.wikidata.org/prop/direct/P2037"
],
"twitter": [
"http://www.wikidata.org/prop/direct/P2002"
],
"facebook": [
"http://www.wikidata.org/prop/direct/P2013"
],
"instagram": [
"http://www.wikidata.org/prop/direct/P2003"
],
"homepage": [
"http://www.wikidata.org/prop/direct/P856"
],
"orcid": [
"http://www.wikidata.org/prop/direct/P496"
],
"doi": [
"http://www.wikidata.org/prop/direct/P356"
],
"dbpedia": [
"http://www.w3.org/2004/02/skos/core#exactMatch"
],
"geometry": [
"http://www.opengis.net/ont/geosparql#hasGeometry"
]
}'

With these substitutions we get the following result:

{
"question": "give me all cocktails",
"queries": [
{
"query": "SELECT DISTINCT ?s1 where { ?s1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://vocabulary.semantic-web.at/cocktail-ontology/Cocktail> . } limit 1000",
"confidence": 0.999998823957124,
"kb": "cocktails"
}
.
.
.



],
"qaContexts": [
{
"kb": "cocktails",
"literal": null,
"uri": "http://vocabulary.semantic-web.at/cocktails/099726a2-ec4b-4b0f-b4e4-e6f25cdfd685",
"description": "A stinger is a Duo cocktail made by adding crème de menthe to a spirit. The classic recipe is based on brandy and white crème de menthe, shaken and served in a cocktail glass. The origins of this drink are unclear, but it is mentioned in bartender's recipe books as far back as Tom Bullock's Ideal Bartender, published in 1917. Mixing brandy with green crème de menthe, in place of white, yields a Green Hornet.@en",
"links": {
"cocktails": "http://vocabulary.semantic-web.at/cocktails/099726a2-ec4b-4b0f-b4e4-e6f25cdfd685"
},
"label": "Stinger",
"time": null,
"images": [
"http://www.iba-world.com/images/cocktail_drinks/stinger.jpg"
],
"audio": [],
"geo": [],
"video": [],
"geoJson": null,
"pageRank": 0.2528768
},
{
"kb": "cocktails",
"literal": null,
"uri": "http://vocabulary.semantic-web.at/cocktails/0bbdca98-077b-48d1-99d6-47eca59c442c",
"description": "The Aviation is a classic cocktail made with gin, maraschino liqueur, crème de violette, and lemon juice. Some recipes omit the crème de violette. It is served straight up, in a cocktail glass.@en",
"links": {
"cocktails": "http://vocabulary.semantic-web.at/cocktails/0bbdca98-077b-48d1-99d6-47eca59c442c"
},
"label": "Aviation",
"time": null,
"images": [
"https://upload.wikimedia.org/wikipedia/commons/4/4f/Aviation_Cocktail.jpg"
],
"audio": [],
"geo": [],
"video": [],
"geoJson": null,
"pageRank": 0.27815425
},
{
"kb": "cocktails",
"literal": null,
"uri": "http://vocabulary.semantic-web.at/cocktails/0f8cc862-9056-49be-b636-cd22f8d7282d",
"description": "The Harvey Wallbanger is a cocktail made with vodka, Galliano, and orange juice.@en",
"links": {
"cocktails": "http://vocabulary.semantic-web.at/cocktails/0f8cc862-9056-49be-b636-cd22f8d7282d"
},
"label": "Harvey Wallbanger",
"time": null,
"images": [
"http://upload.wikimedia.org/wikipedia/commons/4/44/Harvey_Wallbanger.jpg"
],
"audio": [],
"geo": [],
"video": [],
"geoJson": null,
"pageRank": 0.27841586
},
{
"kb": "cocktails",
"literal": null,
"uri": "http://vocabulary.semantic-web.at/cocktails/117bd4d2-6da3-4d69-8c79-bc1d873b5010",
"description": "A grasshopper is a sweet, mint-flavored, after-dinner drink. The name of the drink is derived from its green color, which is provided by the crème de menthe. The drink reputedly originated at Tujague's, a landmark bar in the French Quarter of New Orleans, Louisiana, and gained popularity during the 1950s and 1960s throughout the American South.@en",
"links": {
"cocktails": "http://vocabulary.semantic-web.at/cocktails/117bd4d2-6da3-4d69-8c79-bc1d873b5010"
},
"label": "Grasshopper",
"time": null,
"images": [
"http://upload.wikimedia.org/wikipedia/commons/thumb/7/7b/Grasshopper_cocktail.jpg/440px-Grasshopper_cocktail.jpg"
],
"audio": [],
"geo": [],
"video": [],
"geoJson": null,
"pageRank": 0.24938273
},
.
.
.


]
}

Note that now the contextual information contains descriptions, images and links to DBpedia.