SPARQL query on Protege 4.3 - sparql

The following query (preceded by relevant prefixes of course)
posed on an ontology (.owl file) gives the object properties or data properties?
SELECT DISTINCT ?predicate
WHERE { ?subject ?predicate ?object }
Thank you,

It wholly depends on what the data in the triple store or file contains. Variable ?predicate will match the predicate of the triple, and that predicate might be a datatype property or an object property in OWL, or neither of those if you're not querying an OWL ontology. Likewise, ?object will match an RDF resource or a literal, again depending on what the data says.

Related

Do all ontologies that import 'owl' or 'rdf', implement 'domain', 'range' and other related predicates?

Sorry if this is a noob's and simple question, but it will help me resolve a conceptual confusion of mine! I have some guesses, but want to make sure.
I got the location of a part of brain via NeuroFMA ontology and the query below:
PREFIX fma: <http://sig.uw.edu/fma#>
select ?loc{
fma:Superior_temporal_gyrus fma:location ?loc}
The result was: fma:live_incus_fm_14056
I thought I might be able to get some more information on this item.
Question 1: Was there a difference if the result was a literal?
So, I used optional {?loc ?p ?o} and got some results.
However, I thought since this ontology also imported RDF and OWL, the following queries should work too, but it was not the case (hopefully these codes are correct)!
optional {?value rdfs:range ?loc}
optional {?loc rdfs:domain ?value}
optional {?loc rdf:type ?value}
Question 2 If the above queries are correct, are RDFS and OWL just a suggestion? Or do ontologies that import/ follow them have to use all their resources or at least expand on them?
Thanks!
An import declaration in OWL is, for the most part, just informative. It is typically used to signal that this ontology re-uses some of the concepts defined in the target (for example, it could define some additional subclasses of classes defined in the target data).
Whether the import results in any additional data being loaded into your dataset depends on what database/API/reasoner you use to process the ontology. Most tools don't automatically load the targets of import declarations, by default, so the presence or absence of the import-declaration will have no influence on what your queries return.
I thought since this ontology also imported RDF and OWL, the following queries should work too, but it was not the case (hopefully
these codes are correct)!
optional {?value rdfs:range ?loc}
optional {?loc rdfs:domain ?value}
optional {?loc rdfs:type ?value}
It's rdf:type, not rdfs:type. Apart from that, each of these individually look fine. However, judging from your broader query, ?loc is usually not a property, but a property value. Property values don't have domains and ranges. You could query for something like this, possibly:
optional { fma:location rdfs:domain ?value}
This asks "if the property fma:location has a domain declaration, return that declaration and bind it to the ?value variable".
More generally, whether these queries return any results has little or nothing to do with what import declaration are present in your ontology. If your ontology contains a range declaration for a property, the first pattern will return a result. If it contains a domain declaration, the second one will return a result.
And finally, if your ontology contains an instance of some class, the third pattern (corrected) will return a result. It's as simple as that.
There is no magic here: the query only returns what is present in your dataset. What is present in your dataset is determined by how you have loaded the data into your database, and (optionally) what form of reasoner you have enabled on top of your database.

PROTEGE: Using length path

is it possible to use Arbitrary Length Path Matching in protege SPARQL query tab?
You are using the Snap SPARQL Query Plugin, not the SPARQL Query plugin.
Unlike the SPARQL Query plugin, the Snap SPARQL Query plugin supports querying over inferred knowledge, but does not support property paths.
From Snap-SPARQL: A Java Framework for working
with SPARQL and OWL (section 4):
SPARQL 1.1 contains property path expressions that allow
regular-expression-like paths of properties to be matched. However,
these are not supported by the Snap-SPARQL framework. While this
would be a significant limitation under simple entailment, it is
not clear how much of a limitation it actually is under the OWL
entailment regime. This is because, one of motivations for property
path expressions is that they enable queries to be written whose
answers involve some kind of “transitivity” such as { ?x rdfs:subClassOf+ ?y } or { ?x :partOf+ ?y }.
In these cases, under the OWL entailment regime, transitivity comes
“for free” according to the semantics of the language, for example if
A is a subclass of B and B is a subclass of C, then A is
also a subclass of C. For more complex cases that involve choices
e.g. the lack of property path expressions imposes some inconvenience
and queries such as { ?x rdfs:label | dce:title ?y }, will need to
be written by the user, if possible.
Let us suppose that i ∈ sub ⊆ sup. Both plugins allow to "infer" that i ∈ sup:
with the SPARQL Query Plugin, you need to use property paths;
with the Snap SPARQL Query Plugin, you don't need to use property paths, and in fact you can't.
Choose Window > Reset selected tab to default state, if you need the "SPARQL Query" view to be the only view on the "SPARQL Query" tab.

How to get specific datatype property using SPARQL in Protege

This is my ontology:
I have an individual and I set two different datatype properties: "code" and "EnglishName". In SPARQL, I can get all datatype properties of individual:
Query:
SELECT ?x ?y WHERE { uni:舌苔厚度厚 ?x ?y. ?x a owl:DatatypeProperty}
The question:
Why every datatype property appears twice in the result?
If I want to get value of one datatype property (not of all datatype properties), what do I suppose to do?
Thanks.

Using a skos vocabulary in an owl ontology

I would like to refer to external skos vocabularies in an ontology.
More precisely i would like, if possible, to state that the range of a property is one of the skos:concept defined in an existing skos vocabulary.
I think one of the problem is that in owl, a skos:concept is an individual and not a class.
I tried something like this but it is not convincing:
myproperty
a owl:ObjectProperty ;
rdfs:range _:x0 .
_:x0 rdf:type owl:Restriction ;
owl:onProperty skos:inScheme ;
owl:hasValue theskosconceptscheme .
If it is possible, how could I do this properly ?
Thanks
Indeed, the object property range axiom in OWL is used to infer class membership for individuals which are objects of object properties with declared rdfs:range. As such it relates an object property to a class. SKOS concepts and schemes are individuals. So it is not possible to specify a concrete SKOS concept, scheme or collection as rdfs:range of an owl:ObjectProperty in OWL1. However, this is possible in OWL2, as one of the few cases where punning is allowed.

Strings in Sparql

I'm playing around with DBPedia.
With this query I get all people who were born in London:
SELECT ?person
WHERE {
?person dbo:birthPlace :London
}
But why I get an empty result when I execute this query?
SELECT ?person
WHERE {
?person dbo:birthPlace "London"
}
I just changed London to a String.
This is because the object of this relation is an entity, and not a string, hence the absence of result with the second query.
To know if a property (i.e dbo:birthPlace) relates an entity to a literal or not, one approach is to have a look at the "About" page of the property, for example, birthPlace's one.
What can be seen there is that the type of birthPlace is owl:ObjectProperty, meaning that the object of the relation will have to be an entity, defined with a URI.
The other possibility would be DatatypeProperty, as for the "abstract" property for example, where the object of the relation will be a literal.
The fact that the birth place is an entity allows a lot of things, such as retrieving specific information about that place in the same query, for example.
Hope that helps !