Viewing the go-plus ontology in a freshly installed, stock Protégé 5, I found a useful inference in the entities tab for http://purl.obolibrary.org/obo/GO_0003215:
'cardiac right ventricle morphogenesis' 'results in morphogenesis of' some 'cardiac ventricle'
'results in morphogenesis of' in this case is http://purl.obolibrary.org/obo/RO_0002298 and 'cardiac ventricle' is http://purl.obolibrary.org/obo/UBERON_0002082
If I load the same ontology into Virtuoso Open Source 07.20.3217 and describe http://purl.obolibrary.org/obo/GO_0003215, no relationship with 'cardiac ventricle' is listed. (Even after enabling OWL inference.)
However, http://purl.obolibrary.org/obo/GO_0003215 is linked to an anonymous node with
rdf:type owl:Restriction
owl:onProperty n3:RO_0002298
owl:someValuesFrom n3:UBERON_0002080
Where n3 is http://purl.obolibrary.org/obo/
Is there a Virtuoso configuration that would make this relationship clear in a describe view?
Is there some concise SPARQL syntax that would make the relationship clear? Currently, I'm using
select distinct ?goid (str(?goterm) as ?go_str)
?svf (str(?anatomy ) as ?anat_str)
where
{
?goid obo:hasOBONamespace 'biological_process'^^xsd:string .
?goid rdfs:label ?goterm .
?goid rdfs:subClassOf+ ?parent .
?parent owl:someValuesFrom* ?svf .
?svf rdfs:subClassOf+
<http://purl.obolibrary.org/obo/UBERON_0001062> .
?svf rdfs:label ?anatomy
}
There are many things in play here.
You can use Property Paths for transitivity, as described in comment by #ASKW.
If you want to leverage Virtuoso's built-in reasoning for relationship types described by RDF Schema (rdfs:subClassOf, rdfs:subPropertyOf, rdfs:subClassOf) or OWL (owl:equivalentProperty, owl:equivalentClass, owl:SymmetricProperty, owl:inverseOf, etc.), then you can leverage the inference rules pragma as described in #MarkMiller's comments (note reference to a blog post about that usage pattern).
If you want to write custom inference rules (i.e., use SPARQL as your Inference Rules language), then you will need Virtuoso 8.0 (coming soon) which delivers that capability. Note, this is the ultimate solution, as you can write your own algorithms using SPARQL.
How do you enable OWL reasoning in Virtuoso? You should know that it doesn't support OWL DL reasoning, but only some kind of rule-based reasoning which only covers a small part of OWL DL. Protege on the other hand supports OWL DL reasoning by means of reasoners like HermiT, Pellet, etc.
If you mean by "enable OWL inference" just using SPARQL 1.1 proeprty paths on the rdfs:subClassOf relation, then this is far away from OWL DL reasoning. It just means to consider the transitive closure of that relation from a start node in the graph, nothing more and no more magic behind.
Related
Note: My background is in sparql, and i'm learning Property Graph and Gremlin. Just started the journey
There is one particular type of traversal that so far i am not seeing how to express very well.
The type of traversal is selecting a set of matching start node, based on how they connect to a path or a set of node along a path of multiple node.
Simple example would be:
Finding all the person that like a message that has been twitted by an Organization.
In sparql it would be something akin to
?p a Person .
?p likes ?msg .
?msg a Message .
?msg twitted_by ?Org .
?Org a Organization .
Can someone show me how to express this is Gremlin. And as i keep learning, maybe point me some tutorial that would help me grasp how to write this kind of traversal.
I'm, not familiar with SPARQL syntax,
but from your description I think you looking for something like this:
g.V().hasLabel("Person").where(
out('likes').hasLabel('Message').
out('twitted_by').hasLabel('Organization')
)
example: https://gremlify.com/ywp5cd33un
I'd recommend you to learn Gremlin from Kevin Lawrence's book PRACTICAL GREMLIN
As far as I read from the grammar of SPARQL https://www.w3.org/TR/sparql11-query/#sparqlGrammar it is allowed to have literals as the subject in a triple:
[75] TriplesSameSubject ::= VarOrTerm PropertyListNotEmpty | TriplesNode PropertyList
[106] VarOrTerm ::= Var | GraphTerm
[109] GraphTerm ::= iri | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | NIL
So it would be possible to have a triple such as:
(3, rdfs:label, 'three')
I can handle such triples in Python's rdflib, but when I try to make a federated SPARQL query with SERVICE in Virtuoso version 06.01.3127, Virtuoso complains. Here is an error message from my execution at a local install at http://localhost:8890/sparql
Virtuoso 37000 Error SP031: SPARQL compiler: No one quad map pattern is suitable for GRAPH _:_::default_8_4 { 3 <http://www.w3.org/2000/01/rdf-schema#label> ?s } triple at line 8
SPARQL query:
define sql:big-data-const 0
#output-format:text/html
define sql:signal-void-variables 1 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?s WHERE {
SERVICE <http://127.0.0.1:5000/sparql> {
SELECT ?s WHERE {
3 rdfs:label ?s .
}
}
}
Is this a Virtuoso issue or is this a more general SPARQL/RDF issue, - or a programming error that I make?
Very few (I believe the current count is zero) enterprise-grade triple- or quad-stores handle "Generalized RDF", which is RDF that permits literals in the Subject position. As yet, this is generally understood not to scale well, though it can be useful or interesting at small scale, such as in CWM, TimBL's Python-based Closed World Machine.
Virtuoso is an enterprise-grade DBMS, handling tabular SQL data, graphical RDF data, and more. At present, and for the planned future, Virtuoso will not handle Generalized RDF.
All that said, it should be noted that you're running a rather old Virtuoso, from circa July 2012. Whether you're running Commercial or Open Source, updating to a more recent build (at least 7.2.4.2 as of April 2016) is strongly recommended for a wide variety of performance and functionality reasons.
ObDisclaimer: OpenLink Software produces Virtuoso, and employs me.
SPARQL has always include literals as subject in the grammar even at SPARQL 1.0 - variables from one position can used in another so via variables matching literals-as-subject happens anyway.
SPARQL 1.0:
https://www.w3.org/TR/rdf-sparql-query/#sparqlTriplePatterns
SPARQL 1.1:
https://www.w3.org/TR/sparql11-query/#sparqlTriplePatterns
Of course, they will not match RDF as stored.
The rules for CONSTRUCT say "reject such triples".
https://www.w3.org/TR/sparql11-query/#construct
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.
I've been testing Sesame 2.7.2 and I got a big surprise when faced to the fact that DESCRIBE queries do not include blank nodes closure [EDIT: the right term for this is CBD for concise bounded description]
If I correctly understand, the SPARQL spec is quite loose on that and says that what is returned is actually up to the provider, but I'm still surprised at the choice, since bnodes (in the results of the describe query) cannot be used in subsequent SPARQL queries.
So the question is: how can I get a closed description of a resource <uri1> without doing:
query DESCRIBE <uri1>
iterate over the result to determine which objects are blank nodes
then DESCRIBE ?b WHERE { <uri1> pred_relating_to_bnode_ ?b }
do it recursively and chaining over as long as bnodes are found
If I'm not mistaken, depth-2 bnodes would have to be described with
DESCRIBE ?b2 WHERE {<uri1> <p1&> ?b . ?b <p2> ?b2 }
unless there is a simpler way to do this?
Finally, would it not be better and simpler to let DESCRIBE return a closed description of a resource where you can still obtain the currently returned result with something like the following?
CONSTRUCT {<uri1> ?p ?o} WHERE {<uri1> ?p ?o}
EDIT: here is an example of a closed result I want to get back from Sesame
<urn:sites#1> a my:WebSite .
<urn:sites#1> my:domainName _:autos1 .
<urn:sites#1> my:online "true"^^xsd:boolean .
_:autos1 a rdf:Alt .
_:autos1 rdf:_1 _:autos2
_:autos2 my:url "192.168.2.111:15001"#fr
_:autos2 my:url "192.168.2.111:15002"#en
Currently: DESCRIBE <urn:sites#1> returns me the same result as the query CONSTRUCT WHERE {<urn:sites#1> ?p ?o}, so I get only that
<urn:sites#1> a my:WebSite .
<urn:sites#1> my:domainName _:autos1 .
<urn:sites#1> my:online "true"^^xsd:boolean .
Partial solutions using SPARQL
Based on your comments, this isn't an exact solution yet, but note that you can describe multiple things in a given describe query. For instance, given the data:
#prefix : <http://example.org/> .
:Alice :named "Alice" ;
:likes :Bill, [ :named "Carl" ;
:likes [ :named "Daphne" ]].
:Bill :likes :Elaine ;
:named "Bill" .
you can run the query:
PREFIX : <http://example.org/>
describe :Alice ?object where {
:Alice :likes* ?object .
FILTER( isBlank( ?object ) )
}
and get the results:
#prefix : <http://example.org/> .
:Alice
:likes :Bill ;
:likes [ :likes [ :named "Daphne"
] ;
:named "Carl"
] ;
:named "Alice" .
That's not a complete description of course, because it's only following :likes out from :Alice, not arbitrary predicates. But it does get the blank nodes named "Carl" and "Daphne", which is a start.
The larger issue in Sesame
It looks like you're going to have to do something like what's described above, and possibly with multiple searches, or you're going to have to modify Sesame. The alternative to writing some creative SPARQL is to change the way that Sesame implements describe queries. Some endpoints make this relatively easy, but Sesame doesn't seem to be one of them. There's a mailing list thread from 2011, Custom SPARQL DESCRIBE Implementation, that seems addressed at this same problem.
Roberto García asks:
I'm trying to customise the behaviour of SPARQL DESCRIBE queries.
I'm willing to get something similar to CBD (i.e. all properties and
values for the described resource plus all properties and values for
the blank nodes connected to it).
I have tried to reproduce a similar behaviour using a CONSTRUCT query
but the performance is not good and the query gets quite complex if I
try to consider long chains of properties pointing to blank nodes
starting from the described resource.
Jeen Broekstra replies:
The implementation of DESCRIBE in Sesame is hardcoded in the query
parser. It can only be changed by adapting the parser itself, and even
then it will be tricky, as the query model has no easy way to express it
either: it needs an extension of the algebra.
> If this is not possible, any advice about how to implement it using CONSTRUCT
queries?
I'm not sure it's technically possible to do this in a single query.
CBDs are recursive in nature, and while SPARQL does have some support
for recursivity (property chains), the problem is that you have to do an
intermediate check in every step of the property chain to see if the
bound value is a blank node or not. This is not something that SPARQL
supports out of the box: property chains are defined to have only length
of the path as the stop condition.
Perhaps something is possible using a convoluted combination of
subqueries, unions and optionals, but I doubt it.
I think the best workaround is instead to use the standard DESCRIBE
format that Sesame supports, and for each blank node value in that
result do a separate consecutive query. In other words: you solve it by
hand.
The only other option is to log a feature request for support of CBDs in
Sesame. I can't give any guarantees about if/when that will be followed
up on though.
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)
}