Here is a part of the ttl file.
#prefix rr: <http://www.w3.org/ns/r2rml#> .
#prefix drugbank: <http://wifo5-04.informatik.uni-mannheim.de/drugbank/resource/drugbank/> .
#prefix ns5: <http://wifo5-04.informatik.uni-mannheim.de/drugbank/resource/drugs/> .
#prefix ns8: <http://linkeddata.finki.ukim.mk/lod/data/hifm#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix hifm-ont: <http://purl.org/net/hifm/ontology#> .
<http://purl.org/net/hifm/data#976423>
a hifm-ont:Drug , drugbank:drugs ;
rdfs:label "Amlodipine" ;
rdfs:seeAlso ns5:DB00381 ;
hifm-ont:dosageForm "Таблети" ;
hifm-ont:id 976423 ;
hifm-ont:manufacturer "REPLEKFARM" ;
hifm-ont:packaging 20 ;
hifm-ont:refPriceNoVAT 18.1 ;
hifm-ont:refPriceWithVAT 19.0 ;
hifm-ont:similarTo <http://purl.org/net/hifm/data#989088> , <http://purl.org/net/hifm/data#989096> , <http://purl.org/net/hifm/data#983756> , <http://purl.org/net/hifm/data#989118> , <http://purl.org/net/hifm/data#973424> , <http://purl.org/net/hifm/data#967483> , <http://purl.org/net/hifm/data#985759> , <http://purl.org/net/hifm/data#976385> , <http://purl.org/net/hifm/data#983691> , <http://purl.org/net/hifm/data#973432> , <http://purl.org/net/hifm/data#962392> , <http://purl.org/net/hifm/data#989061> , <http://purl.org/net/hifm/data#983721> , <http://purl.org/net/hifm/data#983713> , <http://purl.org/net/hifm/data#976393> , <http://purl.org/net/hifm/data#985732> , <http://purl.org/net/hifm/data#962384> ;
hifm-ont:strength "5 mg" ;
drugbank:atcCode "C08CA01" ;
drugbank:brandName "AMLODIPIN табл.20 x 5mg" ;
drugbank:genericName "Amlodipine" .
<http://purl.org/net/hifm/data#994995>
a drugbank:drugs , hifm-ont:Drug ;
rdfs:label "Paroxetine" ;
rdfs:seeAlso ns5:DB00715 ;
hifm-ont:dosageForm "Таблети/Филм обложени таблети" ;
hifm-ont:id 994995 ;
hifm-ont:manufacturer "PharmaS" ;
hifm-ont:packaging 30 ;
hifm-ont:refPriceNoVAT 443.81 ;
hifm-ont:refPriceWithVAT 466.0 ;
hifm-ont:similarTo <http://purl.org/net/hifm/data#989401> , <http://purl.org/net/hifm/data#989266> , <http://purl.org/net/hifm/data#984639> , <http://purl.org/net/hifm/data#994987> , <http://purl.org/net/hifm/data#993603> , <http://purl.org/net/hifm/data#976938> , <http://purl.org/net/hifm/data#978124> , <http://purl.org/net/hifm/data#993581> , <http://purl.org/net/hifm/data#976911> , <http://purl.org/net/hifm/data#989274> ;
hifm-ont:strength "30 mg" ;
drugbank:atcCode "N06AB05" ;
drugbank:brandName "PAROKSETIN PharmaS филм обл.табл. 30 x 30mg" ;
drugbank:genericName "Paroxetine" .
I need to get the brandName property of each medicine.
First I read the file:
Model model = ModelFactory.createDefaultModel();
InputStream in = FileManager.get().open(inputFile);
model.read(in, "", "TTL");
Then I form iterator with the statements:
StmtIterator iter = model.listStatements();
and then:
while(iter.hasNext()){
iter.nextStatement().getProperty(DRUGBANK.brandName));
}
So I get an error saying that the symbol DRUGBANK cannot be found.
How do I get the and print the brandName property?
Related
I have the following Turtle syntax file (see end of question), and I would like to be able to infer :hasSibling, but only full siblings, not half. i.e. I only want those children that share the same mother and father.
I have reviewed How to infer isBrotherOf property between two individuals, which solves half of the problem. The following SPARQL query:
PREFIX : <http://example.com/Test#>
SELECT DISTINCT *
WHERE {
?child :isSiblingOf ?sibling .
FILTER ( ?child = :jennySmith )
}
returns:
:jimJones - half-sibling, don't want
:joeSmith
:jennySmith - self, not ideal, but I can live with it
I've tried to use owl:intersectionOf and provide 2 sets, one using :hasFather in an owl:propertyChainAxiom and the other using :hasMother but that intersection is empty (it's possible -- likely -- I've got the syntax wrong, or that the 2 property chains are in fact returning different "things" -- I don't have a strong grasp of OWL yet):
:x1
a owl:Restriction ;
owl:intersectionOf (
[
owl:propertyChainAxiom(
:hasFather
:isParentOf
) ] [
owl:propertyChainAxiom(
:hasMother
:isParentOf
)
]
)
.
Another possibility is that such a thing is just not possible with OWL.
I have the repository in GraphDB set up with OWL2-RL. Please ignore that there are existing ontologies to define family trees, and that OWL might not be the best way to represent them. My goal is not to create a family tree, but to learn OWL restrictions and inferences. This was the MVCE I came up with to illustrate my problem.
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix owl2: <http://www.w3.org/2006/12/owl2#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix xml: <http://www.w3.org/XML/1998/namespace> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix : <http://example.com/Test#> .
<file:test.ttl>
a owl:Ontology ;
.
:Person
a owl:Class ;
rdfs:subClassOf owl:Thing ;
.
:hasGender
a owl:ObjectProperty ;
rdfs:domain :Person ;
.
:Man
a owl:Class ;
rdfs:subClassOf :Person ;
owl:equivalentClass [
a owl:Restriction ;
owl:onProperty :hasGender ;
owl:hasValue :male ;
]
.
:Woman
a owl:Class ;
rdfs:subClassOf :Person ;
owl:equivalentClass [
a owl:Restriction ;
owl:onProperty :hasGender ;
owl:hasValue :female ;
]
.
:Parent
a owl:Restriction ;
rdfs:subClassOf :Person ;
owl:onProperty :isParentOf ;
owl:someValuesFrom :Person ;
.
:Child
a owl:Restriction ;
rdfs:subClassOf :Person ;
owl:onProperty :hasParent ;
owl:someValuesFrom :Person ;
.
:Father
a owl:Class ;
rdfs:subClassOf :Parent ;
owl:equivalentClass [
a owl:Restriction ;
owl:intersectionOf ( :Parent :Man ) ;
] ;
.
:Mother
a owl:Class ;
rdfs:subClassOf :Parent ;
owl:equivalentClass [
a owl:Restriction ;
owl:intersectionOf ( :Parent :Woman ) ;
] ;
owl2:disjointObjectProperties :Father ;
.
:hasFather
owl:inverseOf :isFatherOf ;
.
:hasMother
owl:inverseOf :isMotherOf ;
.
:hasParent
a owl:ObjectProperty ;
.
:isMotherOf
a owl:ObjectProperty ;
rdfs:domain :Woman ;
rdfs:range: :Child ;
rdfs:subPropertyOf :isParentOf ;
.
:isFatherOf
a owl:ObjectProperty ;
rdfs:domain :Man ;
rdfs:range: :Child ;
rdfs:subPropertyOf :isParentOf ;
.
:isParentOf
a owl:ObjectProperty ;
rdfs:domain :Person ;
rdfs:range :Person ;
owl:inverseOf :hasParent ;
.
:isSiblingOf
a owl:ObjectProperty ;
owl:propertyChainAxiom(
:hasParent
:isParentOf
)
.
:janeSmith
a :Person ;
:hasGender :female ;
:isMotherOf :jimJones ;
:isMotherOf :joeSmith ;
:isMotherOf :jennySmith ;
.
:johnSmith
a :Person ;
:hasGender :male ;
:isFatherOf :joeSmith ;
:isFatherOf :jennySmith ;
.
:tomJones
a :Person ;
:hasGender :male ;
:isFatherOf :jimJones ;
.
:jimJones
a :Person ;
:hasGender :male ;
.
:joeSmith
a :Person ;
:hasGender :male ;
.
:jennySmith
a :Person ;
:hasGender :female ;
:isMotherOf :harrySmith ;
.
:harrySmith
a :Person ;
:hasGender :male ;
.
You can define :isFullSiblingOf with a custom rule like this. Read about Constraints and Cut at http://graphdb.ontotext.com/documentation/enterprise/reasoning.html
id: isFullSiblingOf
x <:hasFather> f
x <:hasMother> m
y <:hasFather> f [Constraint x != y] [Cut]
y <:hasMother> m
----------------
x <:isSiblingOf> y
PS1: I assume you already have inverse reasoning. The best is to pick the axioms you need, then add your own: eg you don't have to include all RL axioms if you don't need them. See more advice: http://graphdb.ontotext.com/documentation/standard/rules-optimisations.html
PS2: You should also declare isFullSiblingOf as owl:SymmetricProperty. BTW I would use hasFullSibling since the inverse name is harder to grasp
PS3: owl2:disjointObjectProperties :Father above is a mistake, you can't use that on classes.
PS4: <file:test.ttl> uses a relative URL without base, which is not very good.
I try to add a bit of ontology to a (public) RDF dataset (wordnet), specifically I need to differentiate between LexicalEntries for Verbs and Nouns, separated as two subclasses. Following examples on the web and in the OWL standard, I assumed that
:LexicalEntryNoun a owl:Class ;
rdfs:subClassOf
[ a owl:Restriction ;
owl:onProperty wn:part_of_speech ;
owl:hasValue wn:noun
] .
should build a class LexicalEntryNoun, but the query (in jena fuseki)
prefix : <http://gerastree.at/2017/litonto#>
SELECT *
WHERE {
?s a :LexicalEntryNoun.
}
gives an empty result. The two URI which should be returned are included in the class represented by a blank node, which stands for the restriction, but are not reported as LexicalEntryNoun as reported in other queries.
i am new to OWL and do not find many examples of OWL in turtle syntax. Where is my error?
Thank you for help!
I constructed a very small subset of data which is loaded together with the OWL reasoner http://jena.hpl.hp.com/2003/OWLFBRuleReasoner:
#prefix wn31: <http://wordnet-rdf.princeton.edu/wn31> .
#prefix lemon: <http://lemon-model.net/lemon#> .
#prefix nlp: <http://gerastree.at/nlp_2015#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix lit: <http://gerastree.at/lit_2014#> .
#prefix wn: <http://wordnet-rdf.princeton.edu/ontology#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix ns: <http://www.example.org/ns#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix : <http://gerastree.at/2017/litonto#> .
<http://wordnet-rdf.princeton.edu/wn31/%27s+Gravenhage-n>
a _:b0 , owl:Thing , rdfs:Resource , lemon:LexicalEntry ;
lemon:canonicalForm <http://wordnet-rdf.princeton.edu/wn31/%27s+Gravenhage-n#CanonicalForm> ;
lemon:sense <http://www.lexvo.org/page/wordnet/30/noun/%27s_gravenhage_1_15_00> , <http://wordnet-rdf.princeton.edu/wn31/%27s+Gravenhage-n#1-n> ;
wn:part_of_speech wn:noun ;
owl:sameAs <http://wordnet-rdf.princeton.edu/wn31/%27s+Gravenhage-n> .
<http://wordnet-rdf.princeton.edu/wn31/%27hood-n>
a _:b0 , owl:Thing , rdfs:Resource , lemon:LexicalEntry ;
lemon:canonicalForm <http://wordnet-rdf.princeton.edu/wn31/%27hood-n#CanonicalForm> ;
lemon:sense <http://www.lexvo.org/page/wordnet/30/noun/%27hood_1_15_00> , <http://wordnet-rdf.princeton.edu/wn31/%27hood-n#1-n> ;
wn:part_of_speech wn:noun ;
owl:sameAs <http://wordnet-rdf.princeton.edu/wn31/%27hood-n> .
:LexicalEntryNoun a owl:Class ;
rdfs:subClassOf
[ a owl:Restriction ;
owl:onProperty wn:part_of_speech ;
owl:hasValue wn:noun
] .
as already posted on the Apache Jena Users mailing list, the answer is:
Change the subclassof to an equivalence. Since both resources:
http://wordnet-rdf.princeton.edu/wn31/%27s+Gravenhage-n
http://wordnet-rdf.princeton.edu/wn31/%27hood-n
would fall inside the :LexicalEntryNoun class and show up in his SPARQL query.
Regards, Barry
I'm learning about reasoning and knowledge engineering and I made up the following example:
#prefix : <http://example.org#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix xml: <http://www.w3.org/XML/1998/namespace> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#base <http://www.w3.org/2002/07/owl> .
[ rdf:type owl:Ontology
] .
:value rdf:type owl:DatatypeProperty ;
rdfs:range xsd:string .
:humiditySensor rdf:type owl:Class ;
rdfs:subClassOf :sensor .
:location rdf:type owl:Class .
:room rdf:type owl:Class ;
rdfs:subClassOf :location .
:sensor rdf:type owl:Class.
:temperatureSensor rdf:type owl:Class ;
rdfs:subClassOf :sensor .
:temp1 rdf:type owl:NamedIndividual ,
:temperatureSensor ;
:room 201 ;
:value 29 .
I'm trying to infer that temp1 is of type sensor. When I pose the following query to Eye reasoner (backward chaining) I get nothing, i.e. the fact that temp1 is of type sensor is not inferred, even though subClassOf is transitive:
#prefix : <http://example.org#>.
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
{
?x a :sensor.
?x :value ?y.
}
=>
{
?x :value ?y.
}.
If I write a couple of rules manually to express this transitivity property of subClassOf, it will work. However, CWM reasoner (forward chaining) in the proof states correctly that temp1 is of type sensor, without the additional rules.
Is this because of the difference between forward and backward chaining?
I hope I'm making sense.
I have developed an ontology and I want to add the following SWRL in protege:
Divider_intersection(?node), is_extent_of(?node, ?s), builds(?s, ?l),Segment(?s),Lane(?l),detailed_partition(?d), builds(?l, ?d)-> is_divided_at(?d, ?node)
with this I wish to add an object property, is_divided_at, between an individual from detailed_partition (?d) and a node that is classified as a divider_intersection if it is the extent of a segment (?s) that build a lane (?l) which then build the detailed?partition (?d). As noted here, I am looking for NamedIndividuals, hence I presume the SWRL should do the job.
Further research, I found Rolification (1, 2, 3) as a possible answer however I have never used it before, but I made the following chain:
r_Divider_intersection o is_extent_of o r_Segment o builds o r_Lane o builds o r_detailed_partition
still I do not get the answer. Any idea what is wrong?
Your approach works, and without seeing your ontology (your link requires permissions, and offsite links aren't very helpful anyhow) we can't see why your particular construction of it works. One thing that jumps out from your question is that the it looks like your is_divided_at property has its arguments (?d,?node) in the opposite order from what the property chain axiom would produce. Anyhow, here's a working example.
#prefix : <urn:ex:#> .
#prefix ex: <urn:ex:#> .
#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#> .
ex:isDividedAt a owl:ObjectProperty ;
owl:propertyChainAxiom ( ex:_DividerIntersection ex:isExtentOf ex:_Segment ex:builds ex:_Lane ex:builds ex:_DetailedPartition ) .
ex:Segment a owl:Class ;
owl:equivalentClass [ a owl:Restriction ;
owl:hasSelf true ;
owl:onProperty ex:_Segment
] .
ex:_DetailedPartition
a owl:ObjectProperty .
ex:DividerIntersection
a owl:Class ;
owl:equivalentClass [ a owl:Restriction ;
owl:hasSelf true ;
owl:onProperty ex:_DividerIntersection
] .
ex:_Segment a owl:ObjectProperty .
ex:_Lane a owl:ObjectProperty .
ex:builds a owl:ObjectProperty .
ex:dividerIntersection0
a owl:NamedIndividual , ex:DividerIntersection ;
ex:isExtentOf ex:segment0 .
<urn:ex:> a owl:Ontology .
ex:detailedPartition0
a owl:NamedIndividual , ex:DetailedPartition .
ex:_DividerIntersection
a owl:ObjectProperty .
ex:segment0 a owl:NamedIndividual , ex:Segment ;
ex:builds ex:lane0 .
ex:DetailedPartition a owl:Class ;
owl:equivalentClass [ a owl:Restriction ;
owl:hasSelf true ;
owl:onProperty ex:_DetailedPartition
] .
ex:isExtentOf a owl:ObjectProperty .
ex:lane0 a owl:NamedIndividual , ex:Lane ;
ex:builds ex:detailedPartition0 .
ex:Lane a owl:Class ;
owl:equivalentClass [ a owl:Restriction ;
owl:hasSelf true ;
owl:onProperty ex:_Lane
] .
I want to write a nested DL query in Protege. I can run a simple query like:
Person and hasFather value PersonA
It retrieves the name of all the Persons whose Father is PersonA. But I want that PersonA value should also be retrieved from some query like
Person and hasFather value (Person and hasSon value PersonB)
It is showing syntax error in Protege. Please help me with the correct format.
The reason that
Person and hasFather value (Person and hasSon value PersonB)
is a syntax error is not that it's “nested”, but that value requires an individual, but (Person and hasSon value PersonB) is a class. If you use
Person and hasFather some (Person and hasSon value PersonB)
instead, you should be all set. This query asks for individuals that are people that have a father that is a person and has person B as a son. That is, it's asking for siblings of person B, i.e., other children of person B's father.
For instance, here's a query about the Simpson family where Bart and Lisa each have Homer as their father, and Homer has each of them as a child:
The data is:
#prefix : <http://www.example.org/families#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix families: <http://www.example.org/families#> .
<http://www.example.org/families>
a owl:Ontology .
families:Person a owl:Class .
families:hasFather a owl:ObjectProperty .
families:hasChild a owl:ObjectProperty .
families:Bart a owl:NamedIndividual , families:Person ;
families:hasFather families:Homer .
families:Lisa a owl:NamedIndividual , families:Person ;
families:hasFather families:Homer .
families:Homer a owl:NamedIndividual , families:Person ;
families:hasChild families:Bart , families:Lisa .
families:Milhouse a owl:NamedIndividual , families:Person .