The limit of Sparql - sparql

I would like to know how to express the following question in sparql:
"Give me the parents whose every child goes to MIT"
More generally, I would like to know what are the limits of query sparql please? What kinds of questions with answers in database cannot be formulated as sparql, please?
Thank you for your help

You can express this using a negated existential quantification. Like this:
SELECT ?parent
WHERE { ?parent a :Parent .
FILTER NOT EXISTS {
?c :childOf ?parent .
?c :enrolledIn ?school .
FILTER (str(?school) != "MIT")
}
}
This query asks for all parents who do not havy any child that is enrolled in a school different from MIT.

Your question involves quantification, and is one example of things that cannot be expressed as one query in regular SPARQL 1.0. (It may be expressed in SPARQL 1.1 as shown in Jeen Broekstra's answer, or as an OWL class.)
Many SPARQL 1.0 implementations, though, have developped extensions to handle quantification. A commercial example is Intellidimension Semantics Platform, which would give you something like:
SELECT ?parent
WHERE { ?child :hasParent ?parent FORALL(?child){ ?child :hasSchool "MIT" } }
An academic example is SPARQLog from Oxford University Computing Lab. I am not aware that this system is available as an easy download, but the paper is freely available and provides insight into the difficulties of implementing quantification for SPARQL.
As for your question about the limits of SPARQL, it is too general to answer in a few words, but here is a link to a relevant paper, again as far as SPARQL 1.0 is concerned: Semantics and Complexity of SPARQL

For the specific question you can read up on relational division. Alternatively, you can find all the children who do not go to MIT, find their parents, and remove those parents from the list of all parents.
Sorry, can't help with SPARQL's limits.

Related

Display all fields in Wikidata Query Service

Wikidata provides query browser at https://query.wikidata.org
I want to display films all fields. I tried with using * but its not working. Does anybody know how to display all fields of the data for Films?
To work with SPARQL is necessary to understand some concepts, as #AKSW said in the comments of the question. If you don't understand the meaning of ?film ?p ?o. This is called triple¹ and is composed by subject-predicate-object. E. g., in the case of the films, it could be: x is a film. This is what you are querying in the Wikidata Query Service (WDQS) when you use ?film wdt:P31 wd:Q11424.
I think it isn't possible to display all the property-values of an item. In addition it probably could cause a timeout because there is many statements of many items.
If you want to check the property-values of all the films in Wikidata I think an option might be you write or find a script to extract the items with P31-Q11424 (instance of films). For that, the accessing data section could be useful (e. g. with pywikibot you could query and extract what you want).
If you are interested in SPARQL and WDQS I recommend you to read some help resources:
Wikidata Query Service Help, specifically the SPARQL tutorial.
Query examples (read another queries is how I began to learn).
SPARQL 1.1 Query Language specification.
RDF Dump Format (because read about the ontology of Wikidata could help to understand the concepts).
Edit
When I answer it I wrote triplestore and linked it to its respective page in the Wikipedia in English, but after the comment of #AKSW I consider I was wrong because the triplestore is the concept which is used to refer to the storage and retrieval of triple or semantic triple, "a set of three entities that codifies a statement about semantic data in the form of subject–predicate–object expressions" (from Semantic triple page in Wikipedia in English).

SPARQL Query of FOAF doesn't return any result

I want to get some information from the FOAF ontology. I tried the following SPARQL query, but it returns no results. I tried this query to get familiar with FOAF, but what I really want to do is to find all the people that a particular person ?x knows (using the property foaf:knows). How do I do this?
PREFIX foaf:<http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox
WHERE { ?x foaf:name ?name .
?x foaf:mbox ?mbox .
}
Semantic web is made of different components.
Knowledge is represented as RDF triples. These triples describes Resources based on a Subject - Predicate - Object syntax. For example, "John is a Male" may be represented as a RDF triple.
On top of RDF, we may use RDFS and OWL to specify restrictions and other information on these data. Thanks to RDFS, I can specify that "Male is a subclass of Person" and it is therefore possible to infer that "John is a Person". RDFS and OWL helps to define ontologies. An ontology is a vocabulary (that can be general or specific to a domain) to represents data. For example, I may want to create an ontology CAT to represent data on cats.
In that case, I would create my CAT vocabulary defining that "Cat is a subclass of Animal" and "hasOwner is a property that links a cat to a Person" and some other properties. Then, I am able to instantiate some individuals to create data on cats. For example by saying that "Baccara is a Cat" and "Baccara hasOwner John".
FOAF is basically a vocabulary to represent data on people and especially links between these people. FOAF vocabulary gives some properties and classes to handle easily information on people. But it doesn't provide any piece of information, only the "structure"/"model"/"schema" to organize information.
There are no individuals in the FOAF dataset. That is why your query returns no result. Since there's no people in the FOAF dataset, it is normal that the query returns nothing.
You may want to build your own RDF dataset based on FOAF vocabulary. To do so, you can try a tool like Protégé, or more easily with a text editor if you're familiar with RDF/XML or Turtle.
Otherwise, if you only need to get familiar with FOAF, you can query the model. For example, you may want to get all the subclasses of Agent :
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT distinct ?c
WHERE { ?c rdfs:subClassOf foaf:Agent }
I recommend you to read a bit on the semantic web components (especially RDF and RDFS, and differences between them) before going any further in FOAF. Plus, a nice exercise to learn SPARQL consists in querying DBpedia: http://dbpedia.org/sparql.

Retrieve smallest subgraph for given subjects from RDF graph via SPARQL

As you might see from the formulation of my question title, I am new to SPARQL and RDF in general, so please excuse me for not being able to formulate the question more precisely.
I am looking for a SPARQL query which returns a list of triples that describe a connected subgraph (assuming that the queried graph is completly connected). I found a solution at SPARQL query to construct sub-graph with select paths (paths have different lengths) but it only works if the passed nodes are directly connected. If for example I have a scenario where I pass nodes that are not connected directly I don't get a result. I would like to get a subgraph (as triples) that is allowed to include additional nodes but has to be connected.
Example: Given Graph G=(V,E), with V={A,B,C,D,E,F,G,H} and E as described in the following picture (predicates are not displayed as they are not important). I would like to find a query which when given {C,E,H} (see picture 1) returns the triples that describe the connected subgraph given in picture 2, that is {(C,E),(E,G),(G,H)}.
Obviously there might be multiple ways in which this can be achieved in an arbitrary graph, so in this case there are two possibilities: 1. A structure should be returned that is the minimum spanning tree of those vertices ({C,E,G,H}) or 2. If this is not possible, a structure should be returned from which a minimum spanning tree can be calculated afterwards
Thanks for any help.
The primary misunderstanding, wrt SPARQL, seems to be in the second paragraph. The predicates ARE important. They are the driving force behind RDF and SPARQL - i.e. naming the "relationships", which are the names of edges. As you'll see below, it's not possible to answer the question without knowing something about the predicate names.
But let me try anyway. Assuming all predicates are named :p1, I think what you may want is something like the following:
CONSTRUCT {
:C :p1 :E .
:E :p1 ?G .
?G :p1 :H .
}
WHERE {
:C :p1 :E .
:E :p1 ?G .
?G :p1 :H .
}
The WHERE clause will find the graph pattern, in your specific example finding a solution for ?G. The CONSTRUCT statement then creates your minimal spanning tree.
Another tip for going from graph theory to RDF and SPARQL is the use of URI's to uniquely name nodes and edges. The above takes a specific XML-based shortcut that assumes a default prefix has been defined. For example, if the default prefix were <http://example.com/graphTheory/>, then replace the : in the above with the prefix, e.g. <http://example.com/graphTheory/p1>.

How to build simple SPARQL query in the right way

I am novice with SPARQL and DBpedia.
I would like to get knowledge of building simple SPARQL queries.
Could you please help me to build answer for such questions as:
Hometown of footballer (any one), List of Artists, List of Oscar winners (any year)
I think this question is probably too broad, but in case it's useful, it might make sense to describe how to approach this type of problem. For one of the problems, here's what I did.
List of Oscar winners (any year)
In this case, I started by visting the DBpedia entry for an Academy Award winner, Brad Pitt. There you'll see the property dcterms:subject category:Producers_who_won_the_Best_Picture_Academy_Award.
That category has property
skos:broader
category:Best_Picture_Academy_Award_winners which, in turn, has
skos:broader
category:Academy_Award_winners. So you could look for things that have a dcterms:subject value of some category that's connected by a path of skos:broader links to the Academy_Award_winners category. That will actually turn up some things that aren't persons, because those categories are categories of articles, not classes of entities, so you'll also want to filter down to those things which are Persons. That's probably going to give you a list of Academy Award winners, though it's possible that some are just in that category because they have some other relationship to the category:
select ?person where {
?person a dbpedia-owl:Person ;
dcterms:subject/skos:broader* category:Academy_Award_winners .
}
SPARQL results

How to list all different properties in DBPedia

I have a burning question concerning DBpedia. Namely, I was wondering how I could search for all the properties in DBpedia per page. The URI http://nl.dbpedia.org/property/einde concerns the property "einde". I would like to get all existing property/ pages. This does not seem too hard, but I don't know anything about SPARQL, so that's why I want to ask for some help. Perhaps there is some kind of dump of it, but I honestly don't know.
Rather than asking for pages whose URLs begin with, e.g., http://nl.dbpedia.org/property/, we can express the query by asking “for which values of ?x is there a triple ?x rdf:type rdf:Property in DBpedia?” This is a pretty simple SPARQL query to write. Because I expected that there would be lots of properties in DBPedia, I first wrote a query to count how many there are, and afterward wrote a query to actually list them.
There are 48292 things in DBpedia declared to be of rdf:type rdf:Property, as reported by this SPARQL query, run against one of DBpedia's SPARQL endpoints:
select COUNT( ?property ) where {
?property a rdf:Property
}
SPARQL Results
You can get the list by selecting ?property instead of COUNT( ?property ):
select ?property where {
?property a rdf:Property
}
SPARQL Results
I second Joshua Taylor's answer, however if you want to limit the properties to the Dutch DBpedia, you need to change the default-graph-uri query parameter to nl.dbpedia.org and set the SPARQL endpoint to nl.dbpedia.org/sparql, as in the following query. You will get a result-set of just above 8000 elements.
SELECT DISTINCT ?pred WHERE {
?pred a rdf:Property
}
ORDER BY ?pred
run query
These are the Dutch translations of the properties that have been mapped from Wikipedia so far. The full English list is also available. According to mappings.dbpedia.org, there are ~1700 properties with missing Dutch translations.