in owl "Dl query" how to use advanced valu query in protege - semantic-web

I am developing an ontology and I have a problem with my Dl query
there is a class called "flower"
and this class has subclasses which are some flowers names
and also there is another class called "flowersColor"
and it has these values ("red","green" and "blue") as individuals-not subclass-
every flower has one color or more
I want to search for a flower that has red color and only red
my DL Query is :
"flower and hasColor value red"
this query will give me all flowers that has the color red even if it has other colors
however I want all flowers that has ONLY the color red
I want to write something like this
"flower and hasColor only value red" <- this is not correct grammatically
I main if the color has a combination of "red" and "green" then I don't want to see it in my result
I hope you can help me in my query
Thanks

Remember that OWL uses the open world assumption, so you are somewhat limited in what can be inferred via description logic.
So your "query", as Kaarel mentions, could be:
flower and (hasColor only {red})
Yet this is unprovable in the open world assumption. There could be statement, somewhere in the universe, which asserts:
<RedRose> :hasColor :StackOverflow .
Which, when combined with your assertions (which you're trying to query):
<RedRose> :hasColor :Red .
<RedRose> a :Flower .
Will cause the DL query to return no results. So due to the open world assumption, and the theoretical existence of wild, inaccurate, and irrelevant assertions (at least from your perspective), the DL query will fail, since it can only infer statements it can prove are true.
However, your example query can be used in an OWL restriction to determine if something is not something else. As an example, if you have a class (:OnlyRedFlower) which must only have the color red, but it has the color blue (you've asserted this additional color), then you can infer that this new flower is not in the set of :OnlyRedFlower.
Update: For those that are interested in trying this themselves, here's the ontology I created based on this question:
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY owl2xml "http://www.w3.org/2006/12/owl2-xml#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<!ENTITY onto "http://www.elastra.com/onto/2009/5/30/onto.owl#" >
]>
<rdf:RDF xmlns="http://stackoverflow.com/users/64881/ontology_842588.rdf#"
xml:base="http://stackoverflow.com/users/64881/ontology_842588.rdf"
xmlns:owl2xml="http://www.w3.org/2006/12/owl2-xml#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:onto="http://www.elastra.com/onto/2009/5/30/onto.owl#">
<owl:Ontology rdf:about="">
<rdfs:comment xml:lang="en"
>Example for http://stackoverflow.com/questions/842588/in-owl-dl-query-how-to-use-advanced-valu-query-in-protege</rdfs:comment>
</owl:Ontology>
<owl:ObjectProperty rdf:about="&onto;hasColor"/>
<owl:Class rdf:about="&onto;Color"/>
<owl:Class rdf:about="&onto;ExampleFlower">
<rdfs:subClassOf rdf:resource="&onto;Flower"/>
</owl:Class>
<owl:Class rdf:about="&onto;Flower"/>
<owl:Class rdf:about="&onto;OnlyRedFlower">
<owl:equivalentClass>
<owl:Class>
<owl:intersectionOf rdf:parseType="Collection">
<rdf:Description rdf:about="&onto;Flower"/>
<owl:Restriction>
<owl:onProperty rdf:resource="&onto;hasColor"/>
<owl:allValuesFrom>
<owl:Class>
<owl:oneOf rdf:parseType="Collection">
<rdf:Description rdf:about="&onto;Red"/>
</owl:oneOf>
</owl:Class>
</owl:allValuesFrom>
</owl:Restriction>
</owl:intersectionOf>
</owl:Class>
</owl:equivalentClass>
<rdfs:subClassOf rdf:resource="&onto;Flower"/>
</owl:Class>
<owl:Class rdf:about="&onto;OtherFlower">
<rdfs:subClassOf rdf:resource="&onto;Flower"/>
</owl:Class>
<onto:Color rdf:about="&onto;Blue">
<rdf:type rdf:resource="&owl;Thing"/>
</onto:Color>
<onto:Flower rdf:about="&onto;BlueOrchid">
<rdf:type rdf:resource="&owl;Thing"/>
<onto:hasColor rdf:resource="&onto;Blue"/>
</onto:Flower>
<onto:Color rdf:about="&onto;Red">
<rdf:type rdf:resource="&owl;Thing"/>
</onto:Color>
<onto:Flower rdf:about="&onto;RedRose">
<rdf:type rdf:resource="&owl;Thing"/>
<onto:hasColor rdf:resource="&onto;Red"/>
</onto:Flower>
</rdf:RDF>

The query that you are after is:
flower and (hasColor only {red})
Note that the {.} constructor creates a class from an individual, or a list of individuals. So you can use it everywhere where a class is syntactically required, e.g.
(not {blue}) subClassOf
{red} and {green,blue} or (hasColor max 10 ({red} or {blue}))

Related

UPdate Data property Value based on SPARQL DELETE and INSERT

I have created an ontology, and I want to update some data property in it. I read SPARQL Update in enter link description here and I found that with SPARQL Update (Insert/Update) I can update RDF triple based on Pellet reasoner. but I'm in doubt that it is useful fo data property.
For example I have a person class with datapropery has-age "30" and has-age-category="child"
I create this SPARQL query and I don't have result.
"DELETE ?person nn:has-category-age 'child'\n"
"INSERT ?person nn:has-category-age 'adult'\n"
"WHERE {\n"
"?person rdf:type nn:person.\n"
"?person nn:has-age ?age.\n"
"?person nn:has-category-age ?category.\n"
"FILTER ((has-category-age='child') && (?has-age='30'))\n"
"} ";
Thanks a lot
my ontology is:
<?xml version="1.0"?>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Object Properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-class -->
<owl:ObjectProperty rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-class">
<rdfs:domain rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>
<rdfs:range rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Classroom"/>
</owl:ObjectProperty>
<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-time -->
<owl:ObjectProperty rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-time">
<rdfs:domain rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Courses"/>
<rdfs:range rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Time"/>
</owl:ObjectProperty>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Data properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-age -->
<owl:DatatypeProperty rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-age">
<rdfs:domain rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
</owl:DatatypeProperty>
<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-category-age -->
<owl:DatatypeProperty rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#has-category-age">
<rdfs:domain rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
</owl:DatatypeProperty>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Classroom -->
<owl:Class rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Classroom"/>
<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Courses -->
<owl:Class rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Courses"/>
<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person -->
<owl:Class rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>
<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Time -->
<owl:Class rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Time"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Individuals
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Jihed -->
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Jihed">
<rdf:type rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>
<has-age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">30</has-age>
<has-category-age rdf:datatype="http://www.w3.org/2001/XMLSchema#string">child</has-category-age>
</owl:NamedIndividual>
<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Joseph -->
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Joseph">
<rdf:type rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>
<has-age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">10</has-age>
<has-category-age rdf:datatype="http://www.w3.org/2001/XMLSchema#string">child</has-category-age>
</owl:NamedIndividual>
<!-- http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Ralph -->
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Ralph">
<rdf:type rdf:resource="http://www.semanticweb.org/hp/ontologies/2017/9/untitled-ontology-563#Person"/>
<has-age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">25</has-age>
<has-category-age rdf:datatype="http://www.w3.org/2001/XMLSchema#string">adult</has-category-age>
</owl:NamedIndividual>
Formatting of your question always helps other to read the question.
Which triple store /SPARQL engine do you use?
Without seeing the data, how can we check whether the WHERE part is correct and matches some data?
Debugging of SPARQL Update queries is obviously possible by first checking whether the WHERE part matches any result - this can indeed be done by using a SELECT query.
From your SPARQL query I can see obvious errors in the WHERE part:
WHERE {
?person rdf:type nn:person .
?person nn:has-age ?ag .
?person nn:has-category-age ?categry .
FILTER ((has-category-age='child') && (?has-age='30'))
}
Triple pattern ?person nn:has-category-age ?categry . and the FILTER is (has-category-age='child'). Why? You have to filter based on the variable value, not using the predicate again
Triple pattern ?person nn:has-age ?ag . and the FILTER is (?has-age='30'). The same problem as before...in addition, if the datatype of the age is xsd:integer, you can't use '30', because inside quotes it would be a string. Either use 30 or "30"^^xsd:integer
Please please check your variable names next time, it's horrible to see typos there. ?ag -> ?age and ?categry -> ?category
Fixed WHERE part (I'm assuming the age is an integer value):
WHERE {
?person rdf:type nn:person .
?person nn:has-age ?age .
?person nn:has-category-age ?category .
FILTER ((?category='child') && (?age=30))
}

How to list all elements of the selected enumerations with the use of SPARQL?

The following is a subquestion to my previous question: available here.
How to modify the following SPARQL query:
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?dt ?element ?elementType {
?dt a rdfs:Datatype ;
owl:oneOf/rdf:rest*/rdf:first ?element .
bind(datatype(?element) as ?elementType)
}
in order to to get a result of only A and C? I would like to obtain { "a1" "a2" "c1" "c2" }. The above query returns all enumeration values from the ontology, I mean: { "a1" "a2" "b1" "b2" "c1" "c2" }
We are given the ontology (A and B are equivalent but presented in different style syntax):
Variant A) in the functional style syntax:
Prefix(ont:=<http://www/ont.owl#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Ontology(<http://www/ont.owl>
DatatypeDefinition( ont:A DataOneOf( "a1" "a2" ) )
DatatypeDefinition( ont:B DataOneOf( "b1" "b2" ) )
DatatypeDefinition( ont:C DataOneOf( "c1" "c2" ) )
)
Variant B) in the RDF/XML style syntax:
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY ont "http://www/ont.owl#" >
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY xml "http://www.w3.org/XML/1998/namespace" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<rdf:RDF xmlns="http://www/ont.owl#"
xml:base="http://www/ont.owl"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:ont="http://www/ont.owl#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace">
<owl:Ontology rdf:about="http://www/ont.owl"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Datatypes
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www/ont.owl#A -->
<rdfs:Datatype rdf:about="&ont;A">
<owl:equivalentClass>
<rdfs:Datatype>
<owl:oneOf>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>a1</rdf:first>
<rdf:rest>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>a2</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</rdf:Description>
</rdf:rest>
</rdf:Description>
</owl:oneOf>
</rdfs:Datatype>
</owl:equivalentClass>
</rdfs:Datatype>
<!-- http://www/ont.owl#B -->
<rdfs:Datatype rdf:about="&ont;B">
<owl:equivalentClass>
<rdfs:Datatype>
<owl:oneOf>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>b1</rdf:first>
<rdf:rest>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>b2</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</rdf:Description>
</rdf:rest>
</rdf:Description>
</owl:oneOf>
</rdfs:Datatype>
</owl:equivalentClass>
</rdfs:Datatype>
<!-- http://www/ont.owl#C -->
<rdfs:Datatype rdf:about="&ont;C">
<owl:equivalentClass>
<rdfs:Datatype>
<owl:oneOf>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>c1</rdf:first>
<rdf:rest>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>c2</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</rdf:Description>
</rdf:rest>
</rdf:Description>
</owl:oneOf>
</rdfs:Datatype>
</owl:equivalentClass>
</rdfs:Datatype>
</rdf:RDF>
<!-- Generated by the OWL API (version 3.4.2) http://owlapi.sourceforge.net -->
As I said in the comments on the previous answer:
#Annabelle I was basing the retrieval methods on the ontology that I provided. There are certainly other ways to select the data types if they're identified by IRIs. In your case, it looks like it would be values ?dt {:A :B } if you only want ?dt to be A or B.
and
In this case, note that the axiom is encoded by saying that :A is owl:equivalentClass to the datatype class expression. That's the extra link you need between the class IRI and the expression.
That gives us:
select ?dt ?element ?elementType {
values ?dt { ont:A ont:B }
?dt owl:equivalentClass/a rdfs:Datatype ;
owl:oneOf/rdf:rest*/rdf:first ?element .
bind(datatype(?element) as ?elementType)
}
This really isn't much different from the previous answer. You just need to add on the specific values that you're looking for, and then add the equivalentClass link.

Executing a SPARQL query

I have created a small ontology. It has only one class called methods and a datatype property action_nb (integer).
Then I created two individuals :
AHP => action_nb = 20
electre => action_nb = 50
I want to execute a simple query . Select method where nb_action < 40 and the results should give me EL1.
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<!ENTITY untitled-ontology-77 "http://www.semanticweb.org/diabolico/ontologies/2016/3/untitled-ontology-77#" >
]>
<rdf:RDF xmlns="http://www.semanticweb.org/diabolico/ontologies/2016/3/untitled-ontology-77#"
xml:base="http://www.semanticweb.org/diabolico/ontologies/2016/3/untitled-ontology-77"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:untitled-ontology-77="http://www.semanticweb.org/diabolico/ontologies/2016/3/untitled-ontology-77#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<owl:Ontology rdf:about="http://www.semanticweb.org/diabolico/ontologies/2016/3/untitled-ontology-77"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Data properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/diabolico/ontologies/2016/3/untitled-ontology-77#action_nb -->
<owl:DatatypeProperty rdf:about="&untitled-ontology-77;action_nb">
<rdfs:domain rdf:resource="&untitled-ontology-77;methods"/>
<rdfs:range rdf:resource="&xsd;integer"/>
</owl:DatatypeProperty>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/diabolico/ontologies/2016/3/untitled-ontology-77#methods -->
<owl:Class rdf:about="&untitled-ontology-77;methods"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Individuals
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/diabolico/ontologies/2016/3/untitled-ontology-77#ahp -->
<owl:NamedIndividual rdf:about="&untitled-ontology-77;ahp">
<rdf:type rdf:resource="&untitled-ontology-77;methods"/>
<action_nb rdf:datatype="&xsd;integer">20</action_nb>
</owl:NamedIndividual>
<!-- http://www.semanticweb.org/diabolico/ontologies/2016/3/untitled-ontology-77#electre -->
<owl:NamedIndividual rdf:about="&untitled-ontology-77;electre">
<rdf:type rdf:resource="&untitled-ontology-77;methods"/>
<action_nb rdf:datatype="&xsd;integer">50</action_nb>
</owl:NamedIndividual>
</rdf:RDF>
<!-- Generated by the OWL API (version 3.4.2) http://owlapi.sourceforge.net -->
PREFIX ex: <http://example.org/so#>
SELECT ?methods
WHERE {
?inst rdf:type ex:methods .
?inst ex:action_nb ?value .
FILTER (?value < 40)
}
this is the code that I have been manipulating: but it gave me only an empty row when filtering with 40 & 2 rows when using 60
The key to understanding how to approach this is to understand how RDF triples are defined. You've stated that action_nb is the property whose values are integers that you want to compare. Therefore create your query using that property:
PREFIX untitled-ontology-77: <http://www.semanticweb.org/diabolico/ontologies/2016/3/untitled-ontology-77#>
SELECT ?inst
WHERE {
?inst untitled-ontology-77:action_nb ?value .
FILTER (?value < 40)
}
...where the FILTER clause allows only values of action_nb that are less than 40.
If the property is used in other classes, and you want to make sure that only members of methods are found, then you will also need to query for instances of that class:
PREFIX untitled-ontology-77: <http://www.semanticweb.org/diabolico/ontologies/2016/3/untitled-ontology-77#>
SELECT ?inst
WHERE {
?inst rdf:type untitled-ontology-77:methods .
?inst untitled-ontology-77:action_nb ?value .
FILTER (?value < 40)
}
I doubt you'll need DISTINCT in this case, and be aware that finding all distinct values is performed after the query, but is applied pairwise to all SELECTED values. I.e. it may not perform well with large result sets. Therefore, use DISTINCT only when necessary.

How to use "all xs with value v for property p" as an object property range?

I have a class , Person. There is a datatype property Profession whose value for a Person are {"Composer","Singer","Conductor"}. I have another class that is called Piece, and an object property composedBy. I want the range of composedBy to be all Persons whose Profession is "Composer"? How can I do this in OWL, and how can I express that OWL using Protégé?
Your first description isn't too hard to express as a DL axiom (although, I'll use the name hasProfession to be more consistent with the other property name, composedBy).
There is a datatype property Profession whose value for a Person are {"Composer","Singer","Conductor"}.
Person &sqsubseteq; Profession only {"Composer, "Singer", "Conductor"}
The second isn't too tricky either:
I have another class that is called Piece, and an object property composedBy. I want the range of composedBy to be all Persons whose Profession is "Composer"?
Now, you need to be clearer here. You might mean that the range of composedBy is "all Persons whose profession is ‘Composer’", i.e., that anything that is the value of a composedBy statement is a Peron whose profession is ‘Composer’. However, you mentioned another class, Piece, so I think what you're asking is how to say that if a Piece is composedBy something, then that something is a Person whose profession is ‘Composer’. That would be this axiom:
Piece &sqsubseteq; ∀composedBy.(Person &sqcap; hasProfession value "Composer")
If you want to copy and paste the ontology, here it is:
<rdf:RDF
xmlns="http://stackoverflow.com/q/20920232/1281433/composers#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://stackoverflow.com/q/20920232/1281433/composers"/>
<owl:Class rdf:about="http://stackoverflow.com/q/20920232/1281433/composers#Piece">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty>
<owl:ObjectProperty rdf:about="http://stackoverflow.com/q/20920232/1281433/composers#composedBy"/>
</owl:onProperty>
<owl:allValuesFrom>
<owl:Class>
<owl:intersectionOf rdf:parseType="Collection">
<owl:Class rdf:about="http://stackoverflow.com/q/20920232/1281433/composers#Person"/>
<owl:Restriction>
<owl:onProperty>
<owl:DatatypeProperty rdf:about="http://stackoverflow.com/q/20920232/1281433/composers#hasProfession"/>
</owl:onProperty>
<owl:hasValue>Composer</owl:hasValue>
</owl:Restriction>
</owl:intersectionOf>
</owl:Class>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
<owl:Class rdf:about="http://stackoverflow.com/q/20920232/1281433/composers#Person">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://stackoverflow.com/q/20920232/1281433/composers#hasProfession"/>
<owl:allValuesFrom>
<rdfs:Datatype>
<owl:oneOf>
<rdf:List>
<rdf:first>Composer</rdf:first>
<rdf:rest>
<rdf:List>
<rdf:first>Conductor</rdf:first>
<rdf:rest>
<rdf:List>
<rdf:first>Singer</rdf:first>
<rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
</rdf:List>
</rdf:rest>
</rdf:List>
</rdf:rest>
</rdf:List>
</owl:oneOf>
</rdfs:Datatype>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
</rdf:RDF>
Define the range for composedBy to be Person and some Profession {Composer}
What the range says is that the value of composedBy will be a Person and it will have a property Profession with possible values only Composer - it is a HasValue restriction.

Issues with Jena OWL reasoner

I am new to Jena but now encountered with some problems. I have a superclass Query Processing and its four subclasses:
Query Processing
— Query intent
— Query reformulation
— Query representation
— Query suggestion
When I use:
PREFIX Article: <http://www.semanticweb.org/aero/ontologies/computer-science#>
SELECT ?paper ?category
WHERE
{
?paper Article:inQueryIntent ?category .
}
Or with any the other 3 subclasses as the predicate like inQueryReformulation I can get the correct answer.
However when I used ?article Article:inQueryProcessing ?category which should return all the individuals related to the sub-classes QueryProcessing I got nothing. inQueryIntent (and the other 3) and inQueryProcessing are the object properties.
Here is my code:
Dataset dataset = TDBFactory.createDataset(directory);
Model model = dataset.getNamedModel(modelName);
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF, model);
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
InfModel infModel = ModelFactory.createInfModel(reasoner, ontModel);
Query query = QueryFactory.create(queryString);
QueryExecution queryExe = QueryExecutionFactory.create(query, infModel);
here is the ontology snippet :
object properties:
<!-- http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#inQueryIntent -->
<owl:ObjectProperty rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#inQueryIntent">
<rdf:type rdf:resource="&owl;FunctionalProperty"/>
<rdfs:range rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Query_intent"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#article"/>
<rdfs:subPropertyOf rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#inInformationRetrievalQueryProcessing"/>
</owl:ObjectProperty>
class:
<owl:Class rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Query_intent">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Information_retrieval_query_processing"/>
</owl:Class>
individual:
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Classifying_Web_Queries_by_Topic_and_User_Intent">
<rdf:type rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#article"/>
<hasAuthor rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Bernard_J._Jansen"/>
<inQueryIntent rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Query_intent"/>
</owl:NamedIndividual>
I just build a domain ontology in ComputerScience, all the classes are concepts (like query processing is a superclass and query intent/reformulation/… are subclasses) in hierarchy and, all the papers and their corresponding authors are the individuals