Topology query in geosparql - sparql

I have inspired this articles and created an ontology with using geosparql ontology. Two classes named Area and Park were created as subclasses of the Feature class of geosparql. 3 Area instances and 1 Park instance were added to the ontology. Then, geometry instances were created (asWKT) as a subclass of Polygon class of geosparql. And the geometry instances were related with the Park and Area instances via hasGeometry object property (The created ontology and instances).
I have tried to make a topology query to find out which Area instances are within the Park instance. So, I have run the below query with using the sparql query plugin of Protégé 4.3.
PREFIX geosparql: http://www.opengis.net/ont/geosparql#
PREFIX su: http://www.example.org/su#
SELECT ?x ?y
WHERE {
?x a su:Area ;
geosparql:hasGeometry ?xgeo .
?y a su:Park ;
geosparql:hasGeometry ?ygeo .
?xgeo geosparql:sfWithin ?ygeo .
}
No results return but I know that there are two Area instances within the Park instance. I did not find out the problem. Do not I query topological relations with using geosparql and protégé?

The problem is you don't import the "good" use of sfWithin entity.
There is a difference between
http://www.opengis.net/ont/geosparql#sfWithin and http://www.opengis.net/def/function/geosparql/sfWithin.
Actually, I don't understand yet how to proceed in Protégé with this statement, I'm sorry about that.
If you really need to use such a topology query, you can use GraphDB instead, which implements a good working plugin for GeoSPARQL.

Related

How to retrieve anonymous subclass from OWL in SPARQL

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.

A type of traversal (pattern match) in gremlin

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

incomplete output in reading N-Triples (.nt) files in Fuseki and SPARQL

I am loading a N-triple(.nt) file in Fuseki and then using SPARQL query to query the data. The N-triple file I am using is - linkedct-dump-2010-02-10.zip at this link.
When I view the same file in Protege ontology editor (link here) I see following:
As can be seen there are Classes within Entities. I am currently working with trials class. When I click on any of the Instances of trials class I see following:
So it can be seen that there are Classes within the data and each class has instances. Now when in Fuseki I try to get all the classes through following SPARQL query:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?type
WHERE {
?s a ?type.
}
The output I see is just a list of urls something like this:
How do I get the Classes within the data and then get instances within a specific class(in my case trials class) and then select any Individual Annotations (in pic 2 you can see individual annotation for a specific instance in trials class as viewed in protege editor) within a specific instance?
Update: Following is a sample data i see when I open the .nt file in wordpad:
<http://data.linkedct.org/resource/trials/NCT00000102> <http://data.linkedct.org/resource/linkedct/condition> <http://data.linkedct.org/resource/condition/3196> .
<http://data.linkedct.org/resource/trials/NCT00000104> <http://data.linkedct.org/resource/linkedct/condition> <http://data.linkedct.org/resource/condition/7149> .
<http://data.linkedct.org/resource/trials/NCT00000105> <http://data.linkedct.org/resource/linkedct/condition> <http://data.linkedct.org/resource/condition/2080> .

protege v 3.4.8 does not recognize transitive property

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.

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)
}