Sequence with conditional nodes in OWL - sequence

I want to represent a sequence of action in OWL using protege. What I want to be able to represent is statement like : "if this action is true, then the next action is X. If it's false, then the next action is Y". Also I can have several condition in the same sequence of action.
For the moment I can represent simple sequence of action but I can't manage to add those conditionnal nodes.
Example of what I'm doing now :
:seq1step1 :hasAction :SayHello ;
:hasNextStep :seq1step2 .
:seq1step2 :hasAction :GiveYourName ;
:hasNextStep :seq1step3 .
:seq1step3 :hasAction :SayGoodbye ;
I tried to add a property "hasNextStepIfTrue" but then I can't manage to make a Sparql query to get the full sequence because an individual can have the property hasNextStep or also hasNextStepIfTrue so I always end with only a part of the total sequence.
Maybe it is possible to query the full sequence in SPARQL but I can't find how.
Here is a screen of OntoGraf in protege to show what I want to represent.
Thank you !

Related

Sequence in OWL using protege

I'm trying to define a sequence of action in OWL using protege. I have read the following topics:
Modelling sequence order in OWL-DL ontology
Assigning sequence in OWL using Protege
The problem I have is that an individual can be in different course of action. I hope the following example helps:
I have the class "Action" and class "Course of Action".
For Action I have the following individuals: "Say Hello", "Give Your Name", "Ask a question", "Say Good Bye"
For Course of Action I want to have 2 different sequences:
Say Hello - Give your Name - Say Good Bye
Say Hello - Ask a question - Say Good Bye
"Say Hello" will be linked to two individual by the property hasNext and I will not be able to find the exact course of action. Is it possible to do what I want in OWL?
This is something you can model, but you'll need to distinguish between the actual sequences and the steps within them. This is typically modeled by a linked list. RDFS defines a list vocabulary with rdf:first, rdf:rest and rdf:nil, but you probably don't want to co-opt that terminology in your OWL ontology. Instead, you'd do something like this
:seq1step1 :hasAction :SayHello ;
:hasNextStep :seq1step2 .
:seq1step2 :hasAction :GiveYourName ;
:hasNextStep :seq1step3 .
:seq1step3 :hasAction :SayGoodbye ;
:hasNextStep :emptySeq .
:seq2step1 :hasAction :SayHello ;
:hasNextStep :seq2step2 .
:seq2step2 :hasAction :AskAQuestion ;
:hasNextStep :seq2step3 .
:seq2step3 :hasAction :SayGoodbye ;
:hasNextStep :emptySeq .
This does mean your queries need to be in terms of steps rather than the specific actions, but that's actually necessary because otherwise:
"Say Hello" will be linked to two individual by the property hasNext and I will not be able to find the exact course of action.

Elasticsearch connector and owl:sameAs on graphdb

im using ruleset OWL-RL optimized and using elasticsearch connector for search.
All i want is to recoginize the entity has same value and merge all values into one document in es.
Im doing this by:
Person - hasPhone - Phone and have InverseFunctionalProperty on relation hasPhone
Example:
http://example.com#1 http://example.com#hasPhone http://example.com#111.
http://example.com#2 http://example.com#hasPhone http://example.com#111.
=> #1 owl:sameAs #2
when i search by ES, i receive two result both #1, #2 . But when i repair connector i get only one result (that what i want).
1./ I want to ask is there a way that ES connector auto merge doc and delete previous doc ?, because i dont want to repair connector all the time. When i set manageIndex:false, it always get two results when searching.
2./ How to receive only one record, exculding the others have owl:sameAs with this record by SPARQL.
3./ Is there a better ruleset for owl:sameAs and InverseFunctionalProperty for reference ?
The connector watches for changes to property paths (as specified by the index definition) but I don't think it can detect the merging (smushing) caused by sameAs, that's why you need the rebuilding. If this is an important case, I can post an improvement issue for you, but please email graphdb-support and vladimir.alexiev at ontotext with a description of your business case (and link to this question)
If you have "sameAs optimization" enabled for the repo (which it is by default) and do NOT have "expand sameAs URLs" in the query, you should get only 1 result for queries like ?x <http://example.com#hasPhone> <http://example.com#111>
OWL-RL-Optimized is good for your case. (The rulesets supporting InverseFunctionalProperty are OWL-RL, OWL-QL, rdfsPlus and their optimized variants.)

How to Sparql INSERT in TopBraid Composer?

I'm trying to insert new classes by using Sparql in TopBraid Composer (ME 5.5.2). My simple ontology looks like this:
Then I wrote a Sparql query to insert Berry as a subclass of Fruit:
PREFIX ft: <http://www.semanticweb.org/ontologies/2018/7/fruit#>
PREFIX rdfs: <ttp://www.w3.org/2000/01/rdf-schema#>
INSERT
{ft:Berry rdfs:subClassOf ft:Fruit}
But an error message appeared, saying Encountered "insert". Was expecting one of: "base, "select", ...
A similar post: Sparql insert data not working says that Sparql Query is a different language from Sparql Update. Some other post says that Sparql Update is not supported in Protege but is supported in Composer (for which reason I downloaded Composer). I also checked the Composer manual: https://www.topquadrant.com/docs/TBC-Getting-Started-Guide52.pdf, which mentions Sparql Update but doesn't say much.
My question then is, is it possible to insert classes and axioms in TopBraid? If so, how? My end goal is that the inserted classes will appear in the hierarchical view, and their inserted class definitions can be seen on the side as well. If Composer can't do this, what other tools/workflows can I use?
Sorry for such a newbie question. Any help is appreciated.
There are two forms of INSERT in SPARQL 1.1 Update:
INSERT DATA
INSERT
You are mixing them up.
The following works for me in TBC 5.5.2 Free Edition against the kennedys.ttl example:
INSERT DATA
{ kennedys:UralStateUniversity a kennedys:College }
Being an unknown URI, the subject is underlined in query editor, but just press the "Execute SPARQL" button.
Update
In your particular case, you should say something like
INSERT DATA
{ ft:Berry rdfs:subClassOf ft:Fruit; a owl:Class }
Please note that owl:Class is used. TBC considers instances of rdfs:Class as "system classes", their icons are brown, not yellow.

How to assign parameter values in a SparqlParameterizedString

I'm playing around some with Dotnetrdf's sparql engine and I'm trying to create parametered queries with no success yet.
Say I'm working on a graph g with a blank node identified as _:1690 with the code
Dim queryString As SparqlParameterizedString = New SparqlParameterizedString()
queryString.Namespaces.AddNamespace("rdfs", UriFactory.Create("http://www.w3.org/2000/01/rdf-schema#"))
queryString.CommandText = "SELECT ?label { #context rdfs:label ?label } "
queryString.SetParameter("context", g.GetBlankNode("1690"))
Dim result As VDS.RDF.Query.SparqlResultSet = g.ExecuteQuery(New SparqlQueryParser().ParseFromString(queryString))
Whenever I run this, I get all nodes having a rdfs:label property instead of filtering the result on my blank node only.
Please, how to set the parameter's value properly so I get only one item in the result ?
Thanks in advance,
Max.
Blank Nodes in a SPARQL query differ from Blank Nodes in a RDF Graph
In a SPARQL Query a blank node is treated as a temporary variable which has limited scope, it does not match a specific blank node so you cannot write a SPARQL query to select by blank node identifier.
So your code creating your query is giving a result the same as if you replaced #context with a variable e.g. ?s
If you need to find the value associated with a specific blank node then you need to formulate a query that uniquely selects that blank node based on the triples it participates in. If you can't do that then you need to re-think your data modelling since if this is the case then you should likely be using URIs instead of blank nodes.
As a workaround since you are using dotNetRDF and have the original graph you are querying you can use the IGraph API instead e.g.
INode label = g.GetTriplesWithSubjectPredicate(g.GetBlankNode("1690"), g.CreateUriNode("rdfs:label")).Select(t => t.Object).FirstOrDefault();
Just remember that label could always be null if the triple you are looking for doesn't exist

SPARQL prefix wildcard

I'm attempting to write a SPARQL query which would allow me to find all nodes which are reachable from a given node. At the moment every edge has the prefix http://www.foo.com/edge# and there are 3 possible edges (uses, extends, implements). While I can get the correct result from "?start (edge:uses | edge:implements | edge:extends)* ?reached " I would like to reduce that down to one statement, some kind of wildcard after edge:, so that if I add more edge types then I wouldn't need to extend the query. Is this possible?
see this SPARQL - Restricting Result Resource to Certain Namespace(s)
If you know it's always going to be in the same namespace, you could have something looking like:
?start ?edge ?reached
FILTER(REGEX(STR(?var), "^http://www.foo.com/edge#"))