How the Triples for OWL Symmetric or Inverse object property is populated? - graphdb

Whether the Graph DB dataload engine creates additional Triples for the inserted Triples which have OWL Symmetric or Inverse object property in the RDFS model?
Let’s assume the model and individuals given below,
RDFS model:
I have the classes Male and Female, and an object property “hasMarried” with domain as Male and Range as Female. The characteristic of “hasMarried” is set as “Symmetric”.
Triples:
:Male1 rdf:type :Male
:Female1 rdf:type :Female
:Male1 :hasMarried :Female1
Question here is while Inserting the above Triples in Ontotext, would it generate additional triple as follows based on the Model definition for the “Symmetric” object property,
:Female1 :hasMarried :Male1
If the above is not happening, would SPARQL query answer for the following query by inferencing the “Symmetric” object property in the referenced RDFS model?
Select ?s ?o
WHERE {
:Female1 :hasMarried ?o
}
Expected answer:
:Female1 :Male1

Yes this is what you are going to get. Note that you will need the owl horst optimized ruleset when creating the repository(the rdfs ruleset will not be enough).

To the first question: Yes, :Female1 :hasMarried :Male1 would follow.
To the second question: The WHERE clause of your SPARQL query does not contain ?s.
For the SPARQL Query Select ?s ?o WHERE { ?s :hasMarried ?o } with enabled reasoning you should get two answers (:Female1, :Male1) and (:Male1, :Female1)
Two remarks:
RDFS does not support "symmetric properties", you'll need OWL for example.
Defining domain and range as you did will also entail the following two triples:
:Male1 rdf:type :Female . :Female1 rdf:type :Male
In general it doesn't make much sense to define two different (and possibly disjoint!) properties as domain and range of a symmetric property.

Related

Sparql Query to retrieve all the properties and classes belong to specific class

I have ontology URI and I need to know all the properties and classes belongs to this ontology.
the URI of the ontology Prefix Names: http://data.Ordanancesurvery.cor.uk/ontology/OpenName#.
It is hosted by ordnance survey and The API is:
https://data.ordnancesurvey.co.uk/datasets/os-linked-data/explorer/sparql
I need Sparql query which can retrieve all the classes and properties from the ontology.
PREFIX Names: <http://data.ordnancesurvey.co.uk/ontology/OpenNames/>
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl:<http://www.w3.org/2002/07/owl#>
SELECT ?s ?p ?o
WHERE {
?s ?p ?o
Filter (regex (?o,"OpenNames"))
}
I am trying to retrieve all the classes and properties, belong to the ontology OpenNames under the uri : http://data.ordnancesurvey.co.uk/ontology/OpenNames/
URIs are not strings. Conversion is not automatic. Use str(?o)
regex (str(?o),"OpenNames") or CONTAINS(str(?o),"OpenNames")
Better is
STRSTARTS(str(?o), str(Names:))
Prefixes are expanded during parsing so
str(Names:)
is the same as writing
str(<http://data.ordnancesurvey.co.uk/ontology/OpenNames/>)
then STRSTARTS does a leading string test.

How to retrieve and delete a JSON-LD tree from a triple store using SPARQL?

I need to save and delete JSON-LD trees in a triple store. These trees often have subtrees that are represented as blank nodes. It is easy to transform them into RDF and use SPARQL to save them. But, when I need to retrieve/delete them, it is impossible to get all blank nodes. I am using the following query to get all blank nodes (but only up to 3 levels deep):
CONSTRUCT {
<instanceURI> ?p ?o.
?o ?p1 ?o1.
?o1 ?p2 ?o2.
}
WHERE {
<instanceURI> ?p ?o.
OPTIONAL {
FILTER (isBlank(?o))
?o ?p1 ?o1.
OPTIONAL {
FILTER (isBlank(?o1))
?o1 ?p2 ?o2.
}
}
}
In another question (How to recursively expand blank nodes in SPARQL construct query?) they suggest the use of DESCRIBE. But DESCRIBE returns more things than I want. Can I make a subquery to the graph DESCRIBE returns? If so, how?
This use case (retrieve/delete JSON-LD instances with arbitrary blank nodes) seems to be very common for people working with JSON-LD. A solution for it shouldn't be hard to implement. Am I doing something wrong? Is there a standard way of doing this?

RDF + OWL reasoning

Let's suppose I have an RDF data about Socrates. The data is shown below
subject, predicate, object
man, being, mortal
Socrates, being, man
To check whether Socrates is mortal I have a request
SELECT *
FROM RDFData t1
JOIN RDFData t2
ON t1.subject = t2.object
Then I have a filter on "Socrates" and "mortal" and if result is not empty, then Socrates is mortal.
It works fine, but my teacher asks to add OWL information.
For example, if we have the next data
subject, predicate, object
man, being, mortal
Socrates, being, Greek
Greek, being, man
My approach does not work, because we have additional step in the chain.
I need to add an OWL static data here and implement a request for arbitrary number of steps in the chain.
What are my next steps?
If we turn your example data into actual RDF (using Turtle syntax), you'd get something like this:
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix : <http://example.org/> .
:socrates rdf:type :Greek .
:Man rdfs:subClassOf :Mortal .
:Greek rdfs:subClassOf :Man .
If you upload this data into an RDF database (such as RDF4J, Jena, GraphDB, Stardog, Blazegraph, or a host of other options), you can use the following SPARQL query:
ASK WHERE { :socrates rdf:type/rdfs:subClassOf* :Mortal }
This checks if :socrates is of a type that is either :Mortal, or a (direct or indirect) subclass of :Mortal. It returns true if Socrates is a mortal, false otherwise. You don't even need a reasoner for this, you can just use the expressivity of the query language.
If your RDF database supports basic RDFS reasoning, you can simplify your query even further:
ASK WHERE { :socrates rdf:type :Mortal }

Default RDFS inference in Virtuoso 7.x

This is a question about simple RDFS inference in Virtuoso 7.1 and DBpedia. I have a Virtuoso instance which was installed using this link as a reference. Now if I query the endpoint with the following query :
Select ?s
where { ?s a <http://dbpedia.org/ontology/Cricketer> . }
I get a list of Cricketers that are present in DBpedia. Suppose I want all the athletes (all sports and cricketers included, where Athlete is rdfs:superClassOf Cricketer), I just try the query
Select ?s
where { ?s a <http://dbpedia.org/ontology/Athlete> . }
For this I get all the correct answers. However I have an issue with rdfs:subPropertyOf. For example the property <http://dbpedia.org/ontology/capital> is the sub-property of <http://dbpedia.org/ontology/administrativeHeadCity>. So suppose I want all the capitals and the administrative head cities and I issue the query
Select ?s ?o
where { ?s <http://dbpedia.org/ontology/administrativeHeadCity> ?o . }
I get zero results. Why is it that subproperty inference isn't working in DBpedia? Is there something else that I have missed?
You've missed a couple of things.
First, Virtuoso is at 7.2.4 as of April 2016, and this version is strongly recommended over the old version from 2014, for many reasons.
#AKSW's advice about Property Paths will work much better with this later version, too.
Then, you can use inference on the DBpedia endpoint (including your local mirror), through the input:inference pragma, as shown on the live results of the query shown below --
DEFINE input:inference "http://dbpedia.org/resource/inference/rules/dbpedia#"
SELECT ?place ?HeadCity
WHERE
{
?place <http://dbpedia.org/ontology/administrativeHeadCity> ?HeadCity
}
ORDER BY ?place ?HeadCity
You can also see a list of predefined inference rule sets.
And... more of the relevant documentation.
(ObDisclaimer: I work for OpenLink Software, producer of Virtuoso.)
There is no automatic inference enabled in DBpedia. DBpedia itself is a dataset loaded into Virtuoso.
The reason that you get all instances with a superclass like dbo:Athlete is that subclass-inheritance is fully materialized in the current DBpedia dataset:
(s rdf:type c1), (c1 rdfs:subClassOf c2) -> (s rdf:type c2)
That means that for each individual x, the DBpedia dataset contains all the classes C it belongs to - in fact also the superclasses.
That procedure was not done for subproperty-inheritance, i.e.,
(s p1 o), (p1 rdfs:subPropertyOf p2) -> (s p2 o)
You can solve that problem with SPARQL 1.1 property paths:
SELECT ?s ?o WHERE {
?p rdfs:subPropertyOf* <http://dbpedia.org/ontology/administrativeHeadCity> .
?s ?p ?o .
}

SPARQL 1.1 entailment regimes and query with FROM clause (follow-up)

This is a follow-up question from SPARQL 1.1 entailment regimes and query with FROM clause
I'm currently documenting/testing about SPARQL 1.1 entailment regimes and the recommendation repeatedly states that
The scoping graph is graph-equivalent to the active graph...
So it would seems that the inference scoping graph depends on the query.
The question is: does the scoping graph stems from the query's dataset (FROM/FROM NAMED clauses) or does it refer to the real current active graph context for the triple pattern being evaluated ?
With the following graphs
# Named graph: <urn:rdfs-schema-graph>
#prefix ex:<http://www.example.org/> .
ex:Article rdfs:subClassOf ex:Publication .
ex:publishes rdfs:range ex:Publication .
# Named graph: <urn:data-graph>
#prefix ex:<http://www.example.org/> .
ex:book1 a ex:Publication .
ex:book2 a ex:Article .
ex:MITPress ex:publishes ex:book3 .
What should the following query return (here under RDFS-entailment regime, for instance) and according to the recommendation ?
PREFIX ex: <http://www.example.org/>
SELECT ?s
FROM <urn:rdfs-schema-graph>
FROM NAMED <urn:data-graph>
WHERE {
GRAPH <urn:data-graph> {
?s a ex:Publication .
}
}
should I get back all three resources:
<http://www.example.org/book1>
<http://www.example.org/book2>
<http://www.example.org/book3>
or just
<http://www.example.org/book1>
since the active graph on the triple pattern is scoped to the NAMED graph while inferencing axioms are "located" in the default graph ?
Thanks for your insight,
Max.