protege v 3.4.8 does not recognize transitive property - sparql

I have created object property hasSibling where A hasSibling B, B hasSibling C.I have made this property as transitive and symmetric,
but in inferred instances it is not showing A hasSibling C.
This is showing correctly in protege v4.3 but I am using protege v3.4.8
in my project where i have to use transitive and symmetric object properties.
I have tried Sparql query also but it is showing result for symmetric not for transitive.
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX uni:<http://www.owl-ontologies.com/aa.owl#>
select * where {
?x uni:hasSibling ?y .
}
this is giving result as:
Where in inferred tab nothing came
Kindly suggest how to overcome this problem.

Given the query:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX uni:<http://www.owl-ontologies.com/aa.owl#>
select * where {
?x uni:hasSibling ?y .
}
You need to have a reasoning that understands the semantics of the uni:hasSibling relation which is more than likely described in the ontology identified by the URI: http://www.owl-ontologies.com/aa.owl# .
If you were using Virtuoso, this would require the following:
Derive and Inference Rule from
http://www.owl-ontologies.com/aa.owl#
Execute your query with a pragma for invoking the Inference Rule
created in the first step plus another pragma for loading your data
(collection of subject and objects connected by uni:hasSibling
relationship type)
I provide a similar example in my post that demonstrates Reasoning & Inference using British Royal Family relationship types. Also note a recent follow-on post that shows how you can create your own Custom Inference Rules.

Related

Unexpected behavior in Visual Graph, and when returning triples with SPARQL

How are you?
I 'm taking my first steps with GraphDb and I've found a couple of behaviors that I don't quite understand. Let me build the case.
I have the following Ontology, which I have loaded into GraphDb.
enter image description here
Let's only consider the tree under Persona.
When I go to Visual Graph and type :Persona in the search bar, this is what returns:
enter image description here
As you can see all the nodes corresponding to the ontology are there, but also some other nodes like Class (in different colors), and Thing and Nothing. (Ignore Paul which is an instance I added)
What are these other nodes? and how can I prevent them from appearing in this view?
Now, when I query with SPARQL, and I run
select * where {
?s ?p ?o .
}
If I have "Include inferred data in results" Off, I get this
enter image description here
Which is fine. It's what I would expect.
But ... when I turn inference On , which I believe is one of the true powers of working with rdf, I get around 800 records with all sort of triples with definitions for owl and rdf generic objects.
In order to get only my stuff and keep the inference capability on, I filtered as follows
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX pe: <http://www.semanticlab.com/ontologias/EmpresasYPersonas#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
select * where {
?s ?p ?o .
FILTER (REGEX(str(?s),"Persona*" )).
FILTER (!REGEX(str(?o),"owl*" )).
FILTER (!REGEX(str(?o),"rdf*" )).
}
order by ?s
Which returns
enter image description here
Here I see some inferencing, for example Paul classified as a Persona, which is not explicitly stated.
But on the other hand there are a bunch of new triples that I don't understand nor want, as they don't bring any value: for example the ones with owl:sameAs, owl:equivalentClass, or the ones stating that Persona is a subClassOf Persona (which in fact I believe is wrong).
Could you please explain why this is happening, and how to prevent this behavior?
I'm aware that I might be making some mistakes, so if you spot any, please let me know.

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 }

Use SPARQL property path on DBpedia

I'd like to find out if property paths exist between two entities on DBpedia. This is a sample query that I tried on snorql:
SELECT * WHERE {
:Braveheart (:|!:)* :Mel_Gibson
}
LIMIT 100
The queries runs into a memory error:
Virtuoso 42000 Error TN...: Exceeded 1000000000 bytes in transitive temp memory. use t_distinct, t_max or more T_MAX_memory options to limit the search or increase the pool SPARQL query: define sql:big-data-const 0 #output-format:application/sparql-results+json define input:default-graph-uri PREFIX owl: PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: SELECT * WHERE { :Braveheart (:|!:)* :Mel_Gibson } LIMIT 100
I suspect someone's going to suggest setting up a local dbpedia mirror. If that's the case, I'd love some detailed steps on how to do so.
I think your query is a bit wrong for what you're trying to answer... also as there are no variables in it select * can't project anything out (i'd consider it a bug to even compile this), so let me rephrase your query to
ASK { dbr:Braveheart (<>|!<>)+ dbr:Mel_Gibson }
Sadly that query errs with the same problem you described.
While i agree, that complicated should be executed against local endpoints, the above query isn't complicated at all, especially considering that there are several direct edges between the two nodes:
SELECT * { dbr:Braveheart ?p dbr:Mel_Gibson }
I consider this a bug in Virtuoso's query planner and reported it: https://github.com/openlink/virtuoso-opensource/issues/641
Having said all that, i'd like to point out that in real cases you're probably interested in paths that don't only point forward. The direction of edges greatly depends on modelling. So consider using queries like these instead:
ASK { dbr:Braveheart ((<>|!<>)|^(<>|!<>))+ dbr:Mel_Gibson }
The expression says follow any edge in their direction or against it (^) for at least one step. (Yes, i also wonder why property paths didn't a short syntax for arbitrary edges ;) )
Spinning off #JörnHees's answer, a couple of points:
<> is an invalid predicate identifier. For Virtuoso, <> identifies a document (Location of Content that returns 200 OK on HTTP GET) which is why <#> or <#this> work. This isn't a parsing issue since it has more to do with the semantics of an identifier.
The public DBpedia endpoint isn't configured to accept that kind of query, hence the error.
Using <#this> rather than <>, we have --
prefix dbpedia: <http://dbpedia.org/resource/>
ASK { dbpedia:Braveheart (<#this>|!<#this>)+ dbpedia:Mel_Gibson }
Two alternative instances, both hosted by OpenLink Software (my employer, and producer of Virtuoso), that produce solutions for that query:
DBpedia-Live instance
LOD Cloud Cache instance

PROTÉGÉ SPARQL QUERY TAB: cannot query for ontology-specific classes

I am using SPARQL Query tab in Protege 5 to query an OWL ontology I have been constructing. I succeded in many kinds of queries, but when I use some specific class of my ontology inside the very same queries (that are apparently well formed) they return no results. Following, two of the problematic queries - assuming "Event" as one of the concepts of the ontology (http://www.semanticweb.org/ontologies/2014/5/MyOnto#Event):
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX onto: <http://www.semanticweb.org/ontologies/2014/5/MyOnto#>
SELECT ?a WHERE { ?a rdfs:subClassOf onto:Event }
and, with the same prefixes
SELECT ?a WHERE { ?a rdfs:range onto:Event }
Both return no results. However, if I substitute "onto:Event" for, let's say, ?b, both return a long list of results - inclunding Event as a match for ?b.
Is it something I'm misusing or forgetting (although I've seen this pattern in several links on internet with people claiming to have got results) or is it a limitation of SPARQL or some issue of the Protege tab?
The problem is that, in fact, although the URI of the ontology is:
<http://www.semanticweb.org/ontologies/2014/5/MyOnto#>
in the OWL document, the prefix used before class names is the IRI:
<http://www.semanticweb.org/ontologies/2014/2/untitled-ontology-662#>
Thus, replacing the old onto: by
PREFIX onto: <http://www.semanticweb.org/ontologies/2014/2/untitled-ontology-662#>
solves the issue.
(Thanks to #Csongor from Protégé Project mail list, who found the answer.)
P.S.: It's also worthy to note that it can't be taken for granted that all the terms in the ontology will be <current_ontology_URI#term> - e.g. if one includes some terms in the ontology and then changes ontology URI, these terms will be identified as <previous_ontology_URI#term> and the new ones as <current_ontology_URI#term> (which was exactly the cause of the problem above).
I had the same problem, whenever using an ontology specific class there were no results although there should have been. My ontology (pizza.owl) was loaded from a local file.
I found that it is required to add the file name in the PREFIX.
PREFIX : <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
After that I got the information that I expected.

How write this SPARQL request?

I've the following Ontology built in Protege 4.
In this Ontology : The main class Frame has an datatypeProperty hasDuration with domain 'Frame' and range UnsignedShort. the ClassShortFrame and LongFrame are inferred from the class SizedFrame with the followiing restriction
Rectriction for ShortFrame class
SizedFrame that hasDuration some unsignedLong[<=20]
Rectriction for LongFrame class
SizedFrame that hasDuration some unsignedLong[>=200]
I've manually created an instance of the class frame named frame0, which has a property hasDuration set to 12.
What is the SPARQL query that I need to get the all shortFrame. I hope that frame0 will be inferred like a shortFrame ?
Thanks for any reply !
Edition: sample query
PREFIX frame: <http://www.semantic.org/sample.owl#>
SELECT ?y WHERE {?y rdf:type frame:Frame}
but It is not working ! maybe It is not correct !
I believe, You're going to write some queries for OWL restriction information in SPARQL language. SPARQL is a RDF query language and has no understanding the concepts of OWL. Instead of making a restriction, you can use a data property to define duration value and from that you can get all the shortFrames using SPARQL. Other option I would recommend is use SWRL rules instead of SPARQL. Hope this helps !!
The query you give asks for all instance of type frame:Frame. Since you want just the short frames, you should adapt it like so:
SELECT ?y WHERE {?y a frame:ShortFrame}
...but the above will only work if the reasoner understands your restriction and can correctly classify frame0 as an instance of ShortFrame. I am not overly familiar with Protege's syntax for owl restrictions, so I am not 100% sure your restriction expresses what you want it to express.
As an alternative, you can actually express the restriction you require in SPARQL. To query for all frames with a duration of less than 20:
SELECT ?y
WHERE {
?y a frame:Frame;
frame:hasDuration ?d .
FILTER (?d <= 20)
}