I am new to using ONTOP in protege and I have a question about its use.
I have a small ontology that contains a class called OnConnectedState and an individual of that type "on_connected_state_1". With the following axiom: "satisfies some OnConnectedPrecondition".
When I use a Hermit reasoner, and create a DL query, I can query "satisfies some OnConnectedPrecondition" and the query will return my individual "on_connected_state_1".
Using ontop, I want to be able to query this information. So I run the ONTOP reasoner with no errors and have written the following sparql query:
PREFIX proc: http://www.semanticweb.org/procedure-ontology#
SELECT ?s ?y
WHERE {
?s proc:satisfies ?y
}
However, the result comes up blank and there is no SQL translation.
What am I missing here? I am unclear why my "on_connected_state_1" individual does not appear.
Related
I'm trying to extract buildings from Wikidata using a recursive SPARQL query but I keep getting query timeouts. Is there a way to circumvent this?
This is my current query, selecting all buildings with either a Freebase ID or a Google Knowledge Graph ID, and a Dutch label:
SELECT DISTINCT ?building ?buildingLabel
WHERE {
?building p:P2671|p:P646 ?id;
p:P31/ps:P31/wdt:P279* wd:Q41176;
rdfs:label ?buildingLabel .
FILTER(LANG(?buildingLabel) = 'nl') .
FILTER (?building != ?buildingLabel) .
}
I've tried manually looking a few layers deep instead but, for some reason, I get no results for three or more layers deep even though those definitely exist. I've tried this using:
SELECT ?building
WHERE {
?building p:P31/ps:P31/wdt:P279 [p:P31/ps:P31/wdt:P279 [p:P31/ps:P31/wdt:P279 wd:Q41176]].
}
and using
SELECT ?building
WHERE {
?parent2 p:P31/ps:P31/wdt:P279 wd:Q41176.
?parent1 p:P31/ps:P31/wdt:P279 ?parent2.
?building p:P31/ps:P31/wdt:P279 ?parent1.
}
There are about 2.24 million buildings and about 18 million entities with either a Freebase ID or a Google Knowledge Graph ID on Wikidata. I've looked at this guide but couldn't quite figure out how to apply it to my query. I've also read the answer to this question but, unfortunately, using multiple queries isn't really an option for me.
If your intention is to use the "recursive" property path to find things of type building and also types that are subclasses of buildings, your first query using wdt:P279* is right, while the later attempts at repeating the full p:P31/ps:P31/wdt:P279 pattern won't match any data.
By simplifying the first query a bit I was able to get this to run (returning 96,297 results in 39s):
SELECT DISTINCT ?building ?buildingLabel
WHERE {
?building p:P2671|p:P646 ?id;
wdt:P31/wdt:P279* wd:Q41176 .
?building rdfs:label ?buildingLabel .
FILTER(LANGMATCHES(LANG(?buildingLabel), "nl"))
}
Two notable changes:
p:P31/ps:P31 is replaced by wdt:P31, removing one join from the query.
The second FILTER is unnecessary, as ?building (a URI) and ?buildingLabel (a string) are necessarily going to be unequal
I am attempting to do a SPARQL query in MarkLogic by concating my subject, predicate and object to use as a new "subject" node. I have attempted to do so with the query below
SELECT *
WHERE {
?subject </in/relationship/with> ?object .
BIND(concat(?subject, "/in/relationship/with", ?object) AS ?relationship
?relationship </current/status> ?status
}
However, this query does not work as ?relationship now contains a string for each row resulting in the output of the query to be completely empty. Therefore, I am wondering if this can be done and whether it is possible to convert a string into a object that SPARQL can query with.
Stanislav is correct, you need to wrap the string in IRI(). Here a code snippet that runs directly in QC. Run it against an empty database to not pollute your other data:
xdmp:document-insert('/triples.xml', <triples>{
sem:triple(sem:iri("http://my/subject1"), sem:iri("/in/relationship/with"), sem:iri("http://my/subject2")),
sem:triple(sem:iri("http://my/subject1/in/relationship/with/http://my/subject2"), sem:iri("/current/status"), "My status")
}</triples>)
;
sem:sparql('
SELECT *
WHERE {
?subject </in/relationship/with> ?object.
BIND(IRI(CONCAT(?subject, "/in/relationship/with/", ?object)) AS ?relationship)
?relationship </current/status> ?status.
}
')
Whether this is a sensible approach might depend. Keep in mind that MarkLogic is particularly strong in keeping associated data together in documents, and you can embed triples, or use TDE to project triples out of them as well, allowing you to combine strength from document search, and keeping related data together, while still allowing to reason over facts with SPARQL.
HTH!
I've been learning about sparql lately and confuse about blank nodes. Is blank nodes can be used to linked data from multiple dataset ? Or it is just used for one dataset? then what is the specific usage of this blank nodes?
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0-1/>
SELECT DISTINCT ?class
WHERE {[] a ?class}
does query above already using different dataset or multiple datasets?
Blank nodes are basically pronouns.
They're used when you know an entity exists, and you can say some things about it, but you don't know its absolute identifier, its URI, its name, so you use a pronoun to reference it.
In your example query, you're not really using a blank node, as the [] is just taking the place of the common ?s or any other variable. A better example of a blank node would be here --
:Fred :hasThing [ :hasColor :Blue ]
We don't know anything else about the "Thing", so we refer to it obliquely.
Added --
Also note that in your query, the PREFIX declarations are pointless, as the declared prefixes appear nowhere in your query. They do not cause inclusion of listed datasets (because they're not lists of datasets, in this context; they're just syntactic sugar to make other URIs in the query easier to write as prefixed-URIs, like foaf:Person, rather than fully-qualified URIs, like <http://xmlns.com/foaf/0.1/Person>), nor exclusion of others.
(Tangentially -- your foaf: prefix is incorrect, as it has a hyphen, "-", where it should have a dot, ".".)
This query is identical to yours --
SELECT DISTINCT ?class
WHERE { ?s a ?class }
I have MultiPetsOwner class in my ontology, and with the current set up I expect 2 Instances to be detected for it (Harry and Alex).
But when I run the DL Query "hasPet min 2 Animal" for it, there are no corresponding instances.
At the same time, the DL Query "hasPet some Animal" seems to work - it gives me the PetOwner class instances I expected.
What am I doing wrong? If the "hasPet min 2 Animal" query is incorrect, what should I use instead to get all the MultiPetsOwners?
The contents of my .owl file can be found here: http://pastebin.com/5xcriLRE
In OWL there is no Unique Names Assumption (UNA), which means two individuals with a different URI are not necessarily different from each other. This means, a standard OWL reasoner, which is what's used for DL queries can't answer your query without having the information in your ontology that e.g. two animals a and b are not the same individuals (via owl:differentFrom):
Your ontology:
hasPet(x, a), Animal(a)
hasPet(x, b), Animal(b)
-> Q: hasPet min 2 Animal?
-> A: NO RESULT
With the additional OWL axiom
hasPet(x, a), Animal(a)
hasPet(x, b), Animal(b)
a ≠ b
-> Q: hasPet min 2 Animal?
-> A: x
Alternative way: Use SPARQL as query language
SELECT ?x WHERE {
?x :hasPet ?pet .
?pet a :Animal
} GROUP BY ?x
HAVING(COUNT(?pet) >= 2)
Note, this query might probably not take needed inferences into account.
OWL is working in Open World Assumption. In your case, that means than it is not assumed the individuals are different. You have to assert it explicitly. In Protégé, this is done when all individuals are selected, in your case all animals, and then Edit -> "Make all individuals different".
If you run the hasPet min 2 Animal it will give you the expected results, but you can see them already after running the reasoner in the inferred instances of the class MultiPetsOwner.
In OWL, is it possible to query a class that does not have a property?
Suppose I have an object property R and I want to retrieve all classes that do not have the property R. Also, suppose that I have already closed all classes with closures.
I was trying this:
suppose the propety in question is hasProperty, my query was this
hasProperty only Nothing
But it doesn't work
What do you mean by "class that does not have a property"?
Semantically, a class is a set of individuals and a property is a set of pairs of individuals. Given these two sets, what do you mean by "class has / has not a property"?
Regarding your example query
hasProperty only Nothing
lets rewrite it a bit so that we can think about it in natural language. This gives better intuition about the meaning of this query.
First lets rename hasProperty to follows (or whatever English verb), then we have:
follows only Nothing
This is semantically equivalent to
follows only (not Thing)
which is semantically equivalent to
not (follows some Thing)
Now we have gotten rid of the only which is a confusing part of OWL and is better avoided. So now we can verbalize the query in English as:
those who do not follow anything
or
who does not follow anything?
or more formally
which individuals of the ontology are known
not to have a follow relationship to any other individual
E.g. if your ontology states that
John does not follow Mary.
John does not follow himself.
Every individual in the ontology is either John or is Mary.
then John will be the answer to the above query.
You can also get a named class as the query answer if the asked restriction holds for a (named) group of individuals. In any case, the following must hold: if you asserted that the answer (or a member of it) does have a follow-relation to some individual then it would render the ontology inconsistent.
OWL does not have any means for querying the data. SPARQL is used for that. So the SPARQL query to find all class definitions that do not have the property :R would be:
SELECT ?cls
WHERE {
?cls a owl:Class .
FILTER NOT EXISTS {?cls :R ?o}
}