RDFazer show no results ( syntax error in the query ) - sparql

it's my first time working on ontology.
I downloaded Virtuoso, also the RDFazer which helps me to find the matches terms with ESCO ontology ..
this is the default sitting JSON file ( including the query statment), i did not change it at all:
{
"sparql": "http://localhost:8890/sparql",
"fileURI": "",
"profile": "ESCO (virtuoso)",
"profiles": {
"ESCO (virtuoso)": {
"query": "select ?target ?label (group_concat(distinct(?labels); separator=\"| \") as ?altLabels) (group_concat(distinct(?types); separator=\"| \") as ?types)\n where { \n{ ?target a <http://ec.europa.eu/esco/model#Occupation> . } \nUNION\n { ?target a <http://ec.europa.eu/esco/model#Skill> . } \n?target <http://www.w3.org/2008/05/skos-xl#prefLabel> ?thing3. ?thing3 <http://www.w3.org/2008/05/skos-xl#literalForm> ?label .\n ?target <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?types .\n{ ?target <http://www.w3.org/2008/05/skos-xl#prefLabel> ?thing1. \n?thing1 <http://www.w3.org/2008/05/skos-xl#literalForm> ?plabels . \nFILTER (bif:contains(?plabels,\"'$searchTerm*'\")) . \nFILTER (lang(?plabels) = \"en\") . } \nUNION\n { ?target <http://www.w3.org/2008/05/skos-xl#altLabel> ?thing2.\n ?thing2 <http://www.w3.org/2008/05/skos-xl#literalForm> ?plabels .\n FILTER (bif:contains(?plabels,\"'$searchTerm*'\")) . \nFILTER (lang(?plabels)= \"en\") . \n} \nOPTIONAL {?target <http://www.w3.org/2008/05/skos-xl#altLabel> ?thing4\n. ?thing4 <http://www.w3.org/2008/05/skos-xl#literalForm> ?labels\n. FILTER (lang (?labels) = \"en\") \n}\nFILTER (lang (?label) = \"en\") \n} GROUP BY ?target ?label",
"uriToUrl": "'https://ec.europa.eu/esco/web/guest/concept/-/concept/thing/en/' +uri",
"labelProperty": "label",
"labelPredicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"storedInfo": {
"label": {
"predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"type": "property",
"decorate": {
"xml:lang": "en"
}
},
"altLabels": {
"predicate": "http://www.w3.org/2004/02/skos/core#altLabel",
"type": "property",
"csv": "|",
"decorate": {
"xml:lang": "en"
}
},
"types": {
"predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"type": "relation",
"csv": "|"
}
}
},
"default (skos)": {
"query": "select ?target ?label (group_concat(distinct(?labels); separator=\"| \") as ?altLabels)\n (group_concat(distinct(?types); separator=\"| \") as ?types) where {\n ?target <http://www.w3.org/2004/02/skos/core##prefLabel> ?label .\n ?target <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?types .\n{ ?target <http://www.w3.org/2004/02/skos/core#prefLabel> ?plabels .\n FILTER (bif:contains(?plabels,\"'$searchTerm*'\")) . }\n UNION {\n ?target <http://www.w3.org/2004/02/skos/core#altLabel> ?plabels .\n FILTER (bif:contains(?plabels,\"'$searchTerm*'\")) .\n } OPTIONAL {\n?target <http://www.w3.org/2004/02/skos/core#altLabel> ?labels.\n FILTER (lang (?labels) = \"en\") }\nFILTER (lang (?label) = \"en\") \n} GROUP BY ?target ?label",
"uriToUrl": "uri",
"labelProperty": "label",
"labelPredicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"storedInfo": {
"label": {
"predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"type": "property",
"decorate": {
"xml:lang": "en"
}
},
"altLabels": {
"predicate": "http://www.w3.org/2004/02/skos/core#altLabel",
"type": "property",
"csv": "|",
"decorate": {
"xml:lang": "en"
}
},
"types": {
"predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"type": "relation",
"csv": "|"
}
}
},
"ESCO (pure SPARQL 1.1)": {
"query": "select ?target ?label (group_concat(distinct(?labels); separator=\"| \") as ?altLabels) (group_concat(distinct(?ttypes); separator=\"| \") as ?types)\nwhere { \n{ ?target a <http://ec.europa.eu/esco/model#Occupation> . } \nUNION\n{ ?target a <http://ec.europa.eu/esco/model#Skill> . } \n?target <http://www.w3.org/2008/05/skos-xl#prefLabel> ?thing3. ?thing3 <http://www.w3.org/2008/05/skos-xl#literalForm> ?label .\n?target <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?ttypes .\n{ ?target <http://www.w3.org/2008/05/skos-xl#prefLabel> ?thing1. \n?thing1 <http://www.w3.org/2008/05/skos-xl#literalForm> ?plabels . \n} UNION\n{ ?target <http://www.w3.org/2008/05/skos-xl#altLabel> ?thing2.\n?thing2 <http://www.w3.org/2008/05/skos-xl#literalForm> ?plabels .\n} \nFILTER (regex(?plabels,\".*$searchTerm.*\",\"i\")) . \nFILTER (lang(?plabels) = \"en\") . \nOPTIONAL {?target <http://www.w3.org/2008/05/skos-xl#altLabel> ?thing4\n. ?thing4 <http://www.w3.org/2008/05/skos-xl#literalForm> ?labels\n. FILTER (lang (?labels) = \"en\") \n}\nFILTER (lang (?label) = \"en\") \n} GROUP BY ?target ?label",
"uriToUrl": "'https://ec.europa.eu/esco/web/guest/concept/-/concept/thing/en/' +uri",
"labelProperty": "label",
"labelPredicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"storedInfo": {
"label": {
"predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"type": "property",
"decorate": {
"xml:lang": "en"
}
},
"altLabels": {
"predicate": "http://www.w3.org/2004/02/skos/core#altLabel",
"type": "property",
"csv": "|",
"decorate": {
"xml:lang": "en"
}
},
"types": {
"predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"type": "relation",
"csv": "|"
}
}
},
"ESCO (fuseki, text index)": {
"query": "select ?target ?label (group_concat(distinct(?labels); separator=\"| \") as ?altLabels) (group_concat(distinct(?ttypes); separator=\"| \") as ?types)\nwhere { \n{ ?target a <http://ec.europa.eu/esco/model#Occupation> . } \nUNION\n{ ?target a <http://ec.europa.eu/esco/model#Skill> . } \n?target <http://www.w3.org/2008/05/skos-xl#prefLabel> ?thing3. ?thing3 <http://www.w3.org/2008/05/skos-xl#literalForm> ?label .\n?target <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?ttypes .\n?target <http://jena.apache.org/text#query> \"$searchTerm\". \nOPTIONAL {?target <http://www.w3.org/2008/05/skos-xl#altLabel> ?thing4\n. ?thing4 <http://www.w3.org/2008/05/skos-xl#literalForm> ?labels\n. FILTER (lang (?labels) = \"en\") \n}\nFILTER (lang (?label) = \"en\") \n} GROUP BY ?target ?label",
"uriToUrl": "'https://ec.europa.eu/esco/web/guest/concept/-/concept/thing/en/' +uri",
"labelProperty": "label",
"labelPredicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"storedInfo": {
"label": {
"predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"type": "property",
"decorate": {
"xml:lang": "en"
}
},
"altLabels": {
"predicate": "http://www.w3.org/2004/02/skos/core#altLabel",
"type": "property",
"csv": "|",
"decorate": {
"xml:lang": "en"
}
},
"types": {
"predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"type": "relation",
"csv": "|"
}
}
}
}
}
I tried to query many times. I did not now it says syntax error as shown in this image ( sorry I could not copy the error, i was only able to take a screenshot)
is there any way that I can fix this error ?
Many thanks in advance.

Solution was to update apparently old Virtuoso to a current version.

Related

SPARQL Wikidata Query to retrieve url for multiple languages

I wrote this Sparql query to retrieve item labels in multiple language
SELECT ?item ?en ?es ?it WHERE {
{ ?item wdt:P31 wd:Q6256. }
UNION
{ ?item wdt:P31 wd:Q1250464. }
UNION
{ ?item wdt:P31 wd:Q3624078. }
UNION
{ ?item wdt:P31 wd:Q619610. }
UNION
{ ?item wdt:P31 wd:Q179164. }
UNION
{ ?item wdt:P31 wd:Q7270. }
?item rdfs:label ?en filter (lang(?en) = "en").
?item rdfs:label ?es filter (lang(?es) = "es").
?item rdfs:label ?it filter (lang(?it) = "it").
} LIMIT 2
that gives
{
"item": {
"type": "uri",
"value": "http://www.wikidata.org/entity/Q43"
},
"en": {
"xml:lang": "en",
"type": "literal",
"value": "Turkey"
},
"es": {
"xml:lang": "es",
"type": "literal",
"value": "Turquía"
},
"it": {
"xml:lang": "it",
"type": "literal",
"value": "Turchia"
}
}
I would like now to retrieve item url for each language. An approach could be the following
SELECT ?cid ?country ?article_en ?article_de WHERE {
?cid wdt:P31 wd:Q3624078 .
OPTIONAL {
?cid rdfs:label ?country filter (lang(?country) = "en") .
}
OPTIONAL {
?cid rdfs:label ?country filter (lang(?country) = "de") .
}
OPTIONAL {
?article_en schema:about ?cid .
?article_en schema:inLanguage "en" .
FILTER (SUBSTR(str(?article_en), 1, 25) = "https://en.wikipedia.org/")
}
OPTIONAL {
?article_de schema:about ?cid .
?article_de schema:inLanguage "de" .
FILTER (SUBSTR(str(?article_de), 1, 25) = "https://de.wikipedia.org/")
}
}
that gives
{
"cid": {
"type": "uri",
"value": "http://www.wikidata.org/entity/Q236"
},
"article_de": {
"type": "uri",
"value": "https://de.wikipedia.org/wiki/Montenegro"
},
"article_en": {
"type": "uri",
"value": "https://en.wikipedia.org/wiki/Montenegro"
},
"country": {
"xml:lang": "en",
"type": "literal",
"value": "Montenegro"
}
}
Try it here.
This will require to have a separate property article_* for each language.
Putting all together:
SELECT ?item ?en ?es ?url_en ?url_es WHERE {
{ ?item wdt:P31 wd:Q43229. }
UNION { ?item wdt:P31 wd:Q4830453. }
OPTIONAL { ?item rdfs:label ?en filter (lang(?en) = "en"). }
OPTIONAL { ?item rdfs:label ?es filter (lang(?es) = "es"). }
OPTIONAL {
?url_en schema:about ?item .
?url_en schema:inLanguage "en" .
FILTER (SUBSTR(str(?url_en), 1, 25) = "https://en.wikipedia.org/")
}
OPTIONAL {
?url_es schema:about ?item .
?url_es schema:inLanguage "es" .
FILTER (SUBSTR(str(?url_es), 1, 25) = "https://es.wikipedia.org/")
}
} LIMIT 10
Try it here.
that gives
{
"item": {
"type": "uri",
"value": "http://www.wikidata.org/entity/Q130178"
},
"en": {
"xml:lang": "en",
"type": "literal",
"value": "Arcadie"
},
"es": {
"xml:lang": "es",
"type": "literal",
"value": "Arcadie"
},
"url_en": {
"type": "uri",
"value": "https://en.wikipedia.org/wiki/Arcadie"
},
"url_es": {
"type": "uri",
"value": "https://es.wikipedia.org/wiki/Arcadie_(grupo)"
}
}
Is there a way to group the url and the label property result like
{
"en": {
"url": {
"xml:lang": "es",
"type": "literal",
"value": "Arcadie"
},
"label": {
"type": "uri",
"value": "https://es.wikipedia.org/wiki/Arcadie_(grupo)"
}
}
}

Elasticsearch match combos of two fields

How can I get this simple SQL query running on Elasticsearch?
SELECT * FROM [mytype] where (id=123 and cid = classroomIdA) or
(id=234 and cid = classroomIdB) or (id=345 and cid = classroomIdC)
I'm really having troubles with its syntax, multi-match queries doesn't work in my case. What type of query should I use?
The right way to do it is to combine bool/should (for the outer OR conditions) and bool/filter (for the inner AND conditions) together.
POST mytype/_search
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"filter": [
{
"term": {
"id": 123
}
},
{
"term": {
"cid": "classroomIdA"
}
}
]
}
},
{
"bool": {
"filter": [
{
"term": {
"id": 234
}
},
{
"term": {
"cid": "classroomIdB"
}
}
]
}
},
{
"bool": {
"filter": [
{
"term": {
"id": 345
}
},
{
"term": {
"cid": "classroomIdC"
}
}
]
}
}
]
}
}
}
UPDATE
The equivalent ES 1.7 query would be (just replace bool/filter by bool/must):
POST mytype/_search
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"must": [
{
"term": {
"id": 123
}
},
{
"term": {
"cid": "classroomIdA"
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"id": 234
}
},
{
"term": {
"cid": "classroomIdB"
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"id": 345
}
},
{
"term": {
"cid": "classroomIdC"
}
}
]
}
}
]
}
}
}

Function score inside the Post filter query.(elasticsearch)

I ran these following queries.
This query gives me proper score as expected.
{
"query": {
"filtered": {
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"match": {
"categorytags_snow": "gyms"
}
},
{
"match": {
"locationtags_snow": "gyms"
}
},
{
"match": {
"offerings_snow": ""
}
},
{
"match": {
"title_snow": "gyms"
}
},
{
"match": {
"locationcluster_snow": "gyms"
}
},
{
"match": {
"facilities_snow": "gyms in bandra"
}
},
{
"match": {
"info_service_snow": "gyms"
}
}
]
}
},
"functions": [
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"categorytags_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 8
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"locationtags_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 10
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"offerings_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 4
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"title_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 12
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"locationcluster_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 2
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"facilities_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 2
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"info_service_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 6
}
],
"boost_mode": "max",
"score_mode": "sum"
}
},
"filter": {
"bool": {
"must": [
{
"term": {
"city": "bankok"
}
}
]
}
}
}
}
}
While this query where i am using post_filter to wrap my query is not computing desired score(score is always 1)
{
"post_filter": {
"query": {
"filtered": {
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"match": {
"categorytags_snow": "gyms"
}
},
{
"match": {
"locationtags_snow": "gyms"
}
},
{
"match": {
"offerings_snow": "gyms"
}
},
{
"match": {
"title_snow": "gyms "
}
},
{
"match": {
"locationcluster_snow": "gyms"
}
},
{
"match": {
"facilities_snow": "gyms"
}
},
{
"match": {
"info_service_snow": "gyms"
}
}
]
}
},
"functions": [
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"categorytags_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 8
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"locationtags_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 10
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"offerings_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 4
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"title_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 12
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"locationcluster_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 2
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"facilities_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 2
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"info_service_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 6
}
],
"score_mode": "sum"
}
},
"filter": {"bool": {
"must": [
{
"term": {
"city": "bankok"
}
}
]
}}
}
}
}
}
Is it like query inside post_filter don't support function_score.
Thanks in advance
This is expected, as stated in the official doc and the definitive guide, anything in post_filter will run after the query has executed and will not affect the query scope, hence will not affect the score either.
Besides post_filter is a basically a filter and filters do not affect scoring, score 1 is always returned.

elastic search query parsing exception when adding term filter

I'm not quite sure why the term filter "term": {"language": "Austrian"} is causing an elastic search parse exception.
The surprising thing is it works if I remove the query_string query.
Where would I put "term": {"language": "Austrian"} filter if it doesn't go there?
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"terms": {
"status_type": [
"1",
"2",
"7"
]
}
}
]
}
},
"filter": {
"query": {
"query_string": {
"fields": [
[
"name",
"message"
]
],
"query": "Arnold AND Schwarz"
}
},
"term": { <-- Causes parse exception
"language": "Austrian"
}
}
}
},
"sort": [
{
"total": {
"order": "desc"
}
}
]
}
Inside your filter, you need a bool filter if you have more than one constraints, which is your case, since you have a query filter and a term filter. So the correct way of doing it is like this:
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"terms": {
"status_type": [
"1",
"2",
"7"
]
}
}
]
}
},
"filter": {
"bool": { <---- add this
"must": [ <---- and this
{
"query": {
"query_string": {
"fields": [
[
"name",
"message"
]
],
"query": "Arnold AND Schwarz"
}
}
},
{
"term": {
"language": "Austrian"
}
}
]
}
}
}
},
"sort": [
{
"total": {
"order": "desc"
}
}
]
}
However, if I may add something, I would rewrite your query a bit differently and move the query_string over to the query part and the status_type term over to the filter part, it would feel more "natural". Also, in your query part you don't need a bool/must if you have only one constraint.
{
"query": {
"filtered": {
"query": {
"query_string": {
"fields": [
[
"name",
"message"
]
],
"query": "Arnold AND Schwarz"
}
},
"filter": {
"bool": {
"must": [
{
"terms": {
"status_type": [
"1",
"2",
"7"
]
}
},
{
"term": {
"language": "Austrian"
}
}
]
}
}
}
},
"sort": [
{
"total": {
"order": "desc"
}
}
]
}

Elasticsearch function_score not in explain result

I"m trying to get a function_score working, but it appears to be ignored. Here's my query:
{
"explain" : true,
"query": {
"function_score": {
"functions": [
{
"script_score": {
"script": "_score * 999 * doc['total_digital_items_sold'].value"
}
}
],
"query": {
"filtered": {
"query": {
"query_string": {
"query": "photo",
"fields": [ "title^3" ],
"use_dis_max": true,
"analyzer": "snowball"
}
},
"filter": { "and": [ { } ] }
}
}
}
}
}
}
It appears to not affect the results, nor show up in the explain. Any ideas on what I'm doing wrong?