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)
}
Related
I am unsure of the SPARQL query needed to replicate the results of DL Query "has part some benzamide".
That query should return all entities that have some part that is a benzamide or a subclass of benzamide.
My SPARQL attempt:
PREFIX opioid: <https://mac389.github.io/ontology#>
SELECT ?substance ?substance_label
{ ?substance rdfs:subClassOf* opioid:chemical_entity.
?substance rdfs:subClassOf* / opioid:has_part / owl:someValuesFrom opioid:benzamide.
?substance rdfs:label ?substance_label }
Link to OWL as RDF/XML
In this code the 1st and 3rd lines work as intended, retrieving a list of all chemical entities and their labels. When I add the second line, the query returns no answers (there should be 21 items which is what the DL Query in Protege returns).
How does one query for anonymous subclasses like this?
I have looked at this question but I am looking for a subclass that only fulfills one of the property restrictions. I don't fully understand the answer to this question, but mine seems very 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
I'm quite new to sparql.
I founded this query to get all country in the UN
select distinct ?s
where { ?s a <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> }
So I tried to adapt it to Geonames with:
select distinct ?s
where { ?s a <http://dbpedia.org/page/GeoNames> }
But it doesn't work. How can I get every place's name in geonames?
I hope someone can help me with that!
Every publisher uses its own namespace and method to generate URIs of the published entities. The nice thing about Linked Open Data is that it allows such independence while URIs can still be linked using agreed open standards. When different URI represent the same thing, this is declared by linking them with owl:sameAs.
Your query attempt assumes that DPpedia and Geonames use the same URIs, if I understood correctly the intention (I'm not sure qhat you mean by "to adapt"). What you need to do is use two separate variables, and then specify that from the owl:sameAs mappings, you want only those from Geonames.
select distinct *
where { ?cuntryDBpedia a <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> ;
owl:sameAs ?countryGeonames .
FILTER REGEX (?countryGeonames,"geonames.org")
}
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.