sparql

“or” in a SPARQL query

非 Y 不嫁゛ 提交于 2020-05-09 20:34:08
问题 I don't quite understand why in SPARQL they haven't implemented the basic logic operators. However in most of the cases is possible to obtain the same result in a number of way. The purpose of this question is to have a quick reference for the possible way troughs that can substitute an "or" statement. Here's what I can think of: 1) UNION e.g: SELECT * WHERE { { ?s :propA ?o } UNION { ?s :propB ?o } } -not often suitable because it can became very verbose because SELECT * WHERE { { GRAPH ?g {

get wikipedia id-page using wikidata id

为君一笑 提交于 2020-04-17 21:13:40
问题 Using the sparql query below, I successfully got some of soccer players informations, then I tried to retrieve wikipedia page-id with wikidata Item-id, but it returns an error (java.util.concurrent.TimeoutException): PREFIX wd: <http://www.wikidata.org/entity/> PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?Wikidata_id ?SoccerPlayerLabel ?Team ?TeamLabel ?numMatches ?numGoals ?startTime ?article ?wikipedia_id WHERE { ?Wikidata_id wdt:P106 wd

variable 'x' in projection not present in GROUP BY

∥☆過路亽.° 提交于 2020-04-16 02:23:09
问题 I want to count municipalities and what I have in parentheses work. However, I want to get another variable too, but when I am adding it to SELECT, I am getting: org.openrdf.query.MalformedQueryException: variable 'region_name' in projection not present in GROUP BY. In my query I have: "SELECT ?region_name (COUNT(?municipality) AS ?count) " + What am I missing? Notice that I do not have anything like GROUP anywhere in my project, I think it is happening internally of Sesame. I just saw that

variable 'x' in projection not present in GROUP BY

▼魔方 西西 提交于 2020-04-16 02:21:48
问题 I want to count municipalities and what I have in parentheses work. However, I want to get another variable too, but when I am adding it to SELECT, I am getting: org.openrdf.query.MalformedQueryException: variable 'region_name' in projection not present in GROUP BY. In my query I have: "SELECT ?region_name (COUNT(?municipality) AS ?count) " + What am I missing? Notice that I do not have anything like GROUP anywhere in my project, I think it is happening internally of Sesame. I just saw that

Grouping by blank nodes

拥有回忆 提交于 2020-03-03 05:41:21
问题 I have the following data: @prefix f: <http://example.org#> . _:a f:trait "Rude"@en . _:a f:name "John" . _:a f:surname "Roy" . _:b f:trait "Crude"@en . _:b f:name "Mary" . _:b f:surname "Lestern" . However, if I execute the following query in Blazegraph : PREFIX f: <http://example.org#> SELECT ?s ?o WHERE { ?s f:trait ?o . } I get six results: s o t32 Crude t37 Crude t39 Crude t31 Rude t36 Rude t38 Rude If blank nodes _:a and _:b are distinct nodes, how should I write a SPARQL query to

FROM clause in SPARQL queries

拈花ヽ惹草 提交于 2020-02-25 02:53:45
问题 Good morning. If we consider this query SPARQL, for example: PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT DISTINCT ?name WHERE { ?x rdf:type foaf:Person . ?x foaf:name ?name } ORDER BY ?name The query is taken from this link My question is: it does not have any FROM CLAUSE. So how can it query the dataset? Finally, must I set a FROM CLAUSE when I have to do a SPARQL query? 回答1: When you send a SPARQL query to an endpoint, it's

Fuzzy entity query in Wikidata with Sparql times out

眉间皱痕 提交于 2020-02-02 15:14:48
问题 I'm trying to do a fuzzy (ie.. partial or case-insensitive) entity label lookup in Wikidata with Sparql (via the online endpoint). Unfortunately these return a " QueryTimeoutException: Query deadline is expired. " I'm assuming this is because the query is returning too many results to run through the filter in Wikidata's 1 minute timeout. Here's the specific query: def findByFuzzyLabel(self, item_label): qstring = ''' SELECT ?item WHERE { ?item rdfs:label ?label . FILTER( lcase(str(?label)) =

SPARQL select optional with language

末鹿安然 提交于 2020-01-31 04:13:47
问题 I have some triples that look like this: test:thing rdfs:label "Non-Language Label" test:thing rdfs:label "English Label"@en test:thing rdfs:label "French Label"@fr I'd like to form a sparql query that gives me the "Non-Language Label" AND the "French Label", if any exists. I tried this and it's not working: PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?label ?preferredLabel WHERE { test:thing rdfs:label ?label OPTIONAL { test:thing rdfs:label ?preferredLabel . FILTER (regex

select value that occurs most frequently by group

久未见 提交于 2020-01-24 23:11:12
问题 I have RDF data about hospital patients, including their date of birth. There are frequently multiple triples abut their date of birth , and some of those triples may be wrong . My group has decided to use this rule: whatever date occurs most frequently will provisionally be considered correct . It's clear how to do this in any programming language of our choice, external to SPARQL. Is an aggregation of aggregations possible in SPARQL? I have read the similar question SPARQL selecting MAX

How to get individuals data property value in sparql

爱⌒轻易说出口 提交于 2020-01-24 20:08:26
问题 Hi i am in new to ontologies. I have developed a restaurant ontology by Protege software. But I badly need a SPARQL query that finds property values for all individuals of a class. I want to get a result like: Angels_n_Gypsies House #30, Rd No. 19/A, Dhaka 1213, Bangladesh 回答1: Just follow the property values... SELECT ?rname ?lname WHERE { ?inst a :Popular_restaurant . ?inst :restaurant_name ?rname . ?inst :Location_name ?lname . } But that's just the end result. A way to understand SPARQL