You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Bojan Milić <bo...@gmail.com> on 2013/03/04 11:25:56 UTC
Modeling relationships of classes with ObjectProperty
Dear friends,
I am developing ontology for supply chain management and I am
encountering some problems regarding Jena API. In my ontology I have
following structure:
classA
classA1
classA2
classA3
classA4
classB
classC
classD
Classes are representing some documents for example (classA = planning
doc, classB = execution doc, etc.). Now I would like to connect
(relationship) these classes with same ObjectProperty. In Jena
Ontology API it sais: In an ontology, a property denotes the name of a
relationship between resources, or between a resource and a data
value. I followed jena api and did the relationship like this
(OntologyPrintscreen.jpg in attachment):
//let's start some JENA code -- simple default RDF model
String baseURI = InitInfo.getInstance().getDefaultBaseURI();
//create ontology model
OntModel processModel =
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_TRANS_INF);
//createResource
Resource r = processModel.createResource(baseURI + "r");
OntClass classA = processModel.createClass(baseURI + "classA");
OntClass classB = processModel.createClass(baseURI + "classB");
OntClass classC = processModel.createClass(baseURI + "classC");
OntClass classD = processModel.createClass(baseURI + "classD");
classA.addSubClass(processModel.createClass(baseURI +
"classA1"));
classA.addSubClass(processModel.createClass(baseURI +
"classA2"));
classA.addSubClass(processModel.createClass(baseURI +
"classA3"));
classA.addSubClass(processModel.createClass(baseURI +
"classA4"));
OntClass classA1 = processModel.getOntClass(baseURI +
"classA1");
OntClass classA2 = processModel.getOntClass(baseURI +
"classA2");
OntClass classA3 = processModel.getOntClass(baseURI +
"classA3");
OntClass classA4 = processModel.getOntClass(baseURI +
"classA4");
ObjectProperty uses =
processModel.createObjectProperty(baseURI + "uses");
ObjectProperty creates =
processModel.createObjectProperty(baseURI +
"creates");
creates.addDomain(classA1);
creates.addRange(classA2);
uses.addDomain(classA1);
uses.addRange(classB);
My problem: I would like to use same objectProperty (uses and creates)
to model relationship between my classes. For example:
classA1 uses classB
classA1 creates classA2
classA2 creates classA3
classA3 uses classD
classA4 creates classC
There is a desired look (what I would like to achieve) with jena api
(OntologyDesired.jpg). I've already tried:
creates.addDomain(classA2);
creates.addRange(classA3);
uses.addDomain(classA3);
uses.addRange(classD);
But statements get disregarded.
Can you please help me model relationships between these classes with
same ObjectProperty, is this even possible? With protege API you can
do this:
OWLObjectProperty childrenProperty =
owlModel.createOWLObjectProperty("children");
childrenProperty.addUnionRangeClass(personClass);
childrenProperty.addUnionRangeClass(animalClass);
Is something like that possible with Jena, I haven't found anything on
the web, so you are my final chance :)
Looking forward for your answer.
Thank you and my best regards,
Bojan Milic
--
Lep pozdrav,
Bojan Milić
Re: Modeling relationships of classes with ObjectProperty
Posted by Bojan Milić <bo...@gmail.com>.
Hi Dave,
thanks a lot, your queries are working perfectly - now that I know the
principle I will try to implement other queries.
Best regards,
Bojan
On Wed, Mar 6, 2013 at 9:57 AM, Dave Reynolds <da...@gmail.com>wrote:
> Hi Bojan,
>
>
> On 06/03/13 06:30, Bojan Milić wrote:
>
> What I would like to achieve is to build some kind of document library,
>> where some documents use and create other documents.
>>
>
> OK, so in fact it seems like you mostly want to create and query data.
> That's fine, that's what many people use Jena for.
>
> The ontology could be used to declare some of the shape of your data
> (domain, ranges) but given the wackiness of OWL semantics it probably isn't
> going to help you that much.
>
> [Example data snipped.]
>
> *What would I like to achieve:*
>>
>> 1. Select * from model where hasLevel = 1 (I would like to get all
>> individuals that are on level 1, level2, etc)
>>
>
> Easy. The programmatic way to do queries like this looks something like:
>
> String prefixes = "PREFIX ns: <" + baseURI + "> ";
> String query = prefixes + "SELECT * WHERE {?i ns:hasLevel 3}";
> QueryExecution qe
> = QueryExecutionFactory.create(**query, processModel);
> try {
> ResultSetFormatter.out(System.**out, qe.execSelect());
> } finally {
> qe.close();
> }
>
> Though I normally have various helper classes to cut down on the verbosity
> and typically centralize prefix management.
>
> For me, on your data, this produces:
> ------------------------------**------------------------------**
> ------------------------------**-----
> | i |
> ==============================**==============================**
> ==============================**=====
> | <http://jena.hpl.hp.com/**example#P1_4_**EstablishAndCommunicateSupplyC*
> *hainPlans<http://jena.hpl.hp.com/example#P1_4_EstablishAndCommunicateSupplyChainPlans>>
> |
> | <http://jena.hpl.hp.com/**example#P1_3_**BalanceSupplyChainResourcesWit*
> *hSCRequirements<http://jena.hpl.hp.com/example#P1_3_BalanceSupplyChainResourcesWithSCRequirements>>
> |
> | <http://jena.hpl.hp.com/**example#P1_2_**IdentifyPrioritizeAndAggregate*
> *SupplyChainResources<http://jena.hpl.hp.com/example#P1_2_IdentifyPrioritizeAndAggregateSupplyChainResources>>
> |
> | <http://jena.hpl.hp.com/**example#P1_1_**IdentifyPrioritizeAndAggregate*
> *SupplyChainRequirements<http://jena.hpl.hp.com/example#P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements>>
> |
> ------------------------------**------------------------------**
> ------------------------------**-----
>
>
> 2. All individuals have some meta data, like: title, description, metric,
>> etc. I am still not sure how to achieve that. So i have 4 classes that
>> have
>> all my individuals inside. These have to share same metadata. How would
>> you
>> do this?
>>
>
> Where suitable vocabularies exist then just use them. For example:
>
> P1_PlanSupplyChain
> .addProperty(RDFS.label, "Plan supply chain")
> .addProperty(DCTerms.title, "A plan supply chain")
> .addProperty(DCTerms.**description, "I am a supply chain plan");
>
> Where they don't (metric) then create additional properties in your
> ontology or in another ontology.
>
> If you want to say that everything in each of your classes should have all
> of these then you could group them under some common Document class and use
> OWL to provide the cardinality constraints on the properties.
>
> However, the whole "open world" thing means that such declarations are not
> necessary. You can always just add properties to things. When you want to
> validate then OWL semantics are less that useful so validation is often
> done using queries instead.
>
>
> 3. I would like to select specific document (individual) and know what is
>> its input / output (uses / creates). So something like this: select * from
>> model where hasLevel = 1 and name='nameOfIndividual' and uses='uses'
>>
>
> Since each individual may or may not have links to others then when search
> use optionals, for example:
>
> SELECT * WHERE {
> ?i ns:hasLevel 3.
> OPTIONAL {?i ns:uses ?uses}
> OPTIONAL {?i ns:creates ?creates}
> }
>
> You can also use
>
> DESCRIBE <uri-for-individual>
>
> to see all the properties for a specific resource.
>
>
> 4. Each individual can consist of some other individual (document) and can
>> create some other individual (document)
>>
>
> Fine.
>
> *Now my question :)*
>>
>> 1. Is this way right at all? As I said I am pretty new to semantic so I
>> am struggling with it, it is totally different concept of what I am used
>> to
>>
>
> Seems OK.
>
> The main advice I'd give would be to separate your ontology (declaration
> of classes and properties, together with any associated constraints) from
> your data.
>
> A common pattern is:
> - create the ontology once, could be in code but equally just using an
> editor, this documents your domain model so you and others can understand it
> - ideally publish the ontology at the URI you have given it, but this is
> not necessary in order to work with it
> - use schemagen (see Jena documentation) to create a java vocabulary
> file to make it easy to refer to the ontology terms in code
> - write code to create instance data (can use OntModel or plain Model)
> referring to that vocab and to store, query etc data as needed
> - if you want to validate your data as being consistent with your
> ontology and *if* the semantics of OWL are useful for this (that's a big
> *if*) then you can create an OntModel which imports your ontology and your
> instance data and use validate() on that with a suitable reasoner
> if you want closed world checking (e.g. you want to say every document
> should have a title and would like checker that tells you when titles are
> missing) then validate() won't help you, instead do this in queries or code
> - those queries can be auto-created from your ontology declarations though
> Jena doesn't have a packaged utility to do that. The Eyeball checker can do
> some forms of validation which may more may not be useful for you.
>
> Dave
>
>
>
>
--
Lep pozdrav,
Bojan Milić
Re: Modeling relationships of classes with ObjectProperty
Posted by Dave Reynolds <da...@gmail.com>.
Hi Bojan,
On 06/03/13 06:30, Bojan Milić wrote:
> What I would like to achieve is to build some kind of document library,
> where some documents use and create other documents.
OK, so in fact it seems like you mostly want to create and query data.
That's fine, that's what many people use Jena for.
The ontology could be used to declare some of the shape of your data
(domain, ranges) but given the wackiness of OWL semantics it probably
isn't going to help you that much.
[Example data snipped.]
> *What would I like to achieve:*
> 1. Select * from model where hasLevel = 1 (I would like to get all
> individuals that are on level 1, level2, etc)
Easy. The programmatic way to do queries like this looks something like:
String prefixes = "PREFIX ns: <" + baseURI + "> ";
String query = prefixes + "SELECT * WHERE {?i ns:hasLevel 3}";
QueryExecution qe
= QueryExecutionFactory.create(query, processModel);
try {
ResultSetFormatter.out(System.out, qe.execSelect());
} finally {
qe.close();
}
Though I normally have various helper classes to cut down on the
verbosity and typically centralize prefix management.
For me, on your data, this produces:
-----------------------------------------------------------------------------------------------
| i
|
===============================================================================================
|
<http://jena.hpl.hp.com/example#P1_4_EstablishAndCommunicateSupplyChainPlans>
|
|
<http://jena.hpl.hp.com/example#P1_3_BalanceSupplyChainResourcesWithSCRequirements>
|
|
<http://jena.hpl.hp.com/example#P1_2_IdentifyPrioritizeAndAggregateSupplyChainResources>
|
|
<http://jena.hpl.hp.com/example#P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements>
|
-----------------------------------------------------------------------------------------------
> 2. All individuals have some meta data, like: title, description, metric,
> etc. I am still not sure how to achieve that. So i have 4 classes that have
> all my individuals inside. These have to share same metadata. How would you
> do this?
Where suitable vocabularies exist then just use them. For example:
P1_PlanSupplyChain
.addProperty(RDFS.label, "Plan supply chain")
.addProperty(DCTerms.title, "A plan supply chain")
.addProperty(DCTerms.description, "I am a supply chain plan");
Where they don't (metric) then create additional properties in your
ontology or in another ontology.
If you want to say that everything in each of your classes should have
all of these then you could group them under some common Document class
and use OWL to provide the cardinality constraints on the properties.
However, the whole "open world" thing means that such declarations are
not necessary. You can always just add properties to things. When you
want to validate then OWL semantics are less that useful so validation
is often done using queries instead.
> 3. I would like to select specific document (individual) and know what is
> its input / output (uses / creates). So something like this: select * from
> model where hasLevel = 1 and name='nameOfIndividual' and uses='uses'
Since each individual may or may not have links to others then when
search use optionals, for example:
SELECT * WHERE {
?i ns:hasLevel 3.
OPTIONAL {?i ns:uses ?uses}
OPTIONAL {?i ns:creates ?creates}
}
You can also use
DESCRIBE <uri-for-individual>
to see all the properties for a specific resource.
> 4. Each individual can consist of some other individual (document) and can
> create some other individual (document)
Fine.
> *Now my question :)*
> 1. Is this way right at all? As I said I am pretty new to semantic so I
> am struggling with it, it is totally different concept of what I am used to
Seems OK.
The main advice I'd give would be to separate your ontology (declaration
of classes and properties, together with any associated constraints)
from your data.
A common pattern is:
- create the ontology once, could be in code but equally just using
an editor, this documents your domain model so you and others can
understand it
- ideally publish the ontology at the URI you have given it, but this
is not necessary in order to work with it
- use schemagen (see Jena documentation) to create a java vocabulary
file to make it easy to refer to the ontology terms in code
- write code to create instance data (can use OntModel or plain
Model) referring to that vocab and to store, query etc data as needed
- if you want to validate your data as being consistent with your
ontology and *if* the semantics of OWL are useful for this (that's a
big *if*) then you can create an OntModel which imports your ontology
and your instance data and use validate() on that with a suitable reasoner
if you want closed world checking (e.g. you want to say every
document should have a title and would like checker that tells you when
titles are missing) then validate() won't help you, instead do this in
queries or code - those queries can be auto-created from your ontology
declarations though Jena doesn't have a packaged utility to do that. The
Eyeball checker can do some forms of validation which may more may not
be useful for you.
Dave
Modeling relationships of classes with ObjectProperty
Posted by Bojan Milić <bo...@gmail.com>.
Hey Dave,
tnx for your reply. Yes I did describe my case poorly. I am not even sure
if I need to use domain and range property, I am new to semantic and Jena.
What I would like to achieve is to build some kind of document library,
where some documents use and create other documents. Thanks to feedback
from Joshua I created 4 classes to group my documents:
OntClass Plan = processModel.getOntClass(baseURI + "Plan");
OntClass Source = processModel.getOntClass(baseURI + "Source");
OntClass Make = processModel.getOntClass(baseURI + "Make");
OntClass Deliver = processModel.getOntClass(baseURI + "Deliver");
*Then I added some properties: *
OntProperty creates = processModel.createOntProperty(baseURI + "creates");
OntProperty uses = processModel.createOntProperty(baseURI + "uses");
OntProperty hasLevel = processModel.createOntProperty(baseURI + "hasLevel");
*And some individuals (here are just few listed):*
Individual P_Plan = processModel.createIndividual(baseURI + "P_Plan",
Plan);
Individual P1_PlanSupplyChain = processModel.createIndividual(baseURI +
"P1_PlanSupplyChain", Plan);
Individual P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements =
processModel.createIndividual(baseURI +
"P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements", Plan);
Individual P1_2_IdentifyPrioritizeAndAggregateSupplyChainResources =
processModel.createIndividual(baseURI +
"P1_2_IdentifyPrioritizeAndAggregateSupplyChainResources", Plan);
Individual P1_3_BalanceSupplyChainResourcesWithSCRequirements =
processModel.createIndividual(baseURI +
"P1_3_BalanceSupplyChainResourcesWithSCRequirements", Plan);
Individual P1_4_EstablishAndCommunicateSupplyChainPlans =
processModel.createIndividual(baseURI +
"P1_4_EstablishAndCommunicateSupplyChainPlans", Plan);
*Now these individuals = documents exist on different level within my
model, so I did the following:*
P_Plan.addLiteral(hasLevel, 1);
P1_PlanSupplyChain.addLiteral(hasLevel, 2);
P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements.addLiteral(hasLevel,
3);
P1_2_IdentifyPrioritizeAndAggregateSupplyChainResources.addLiteral(hasLevel,
3);
P1_3_BalanceSupplyChainResourcesWithSCRequirements.addLiteral(hasLevel, 3);
P1_4_EstablishAndCommunicateSupplyChainPlans.addLiteral(hasLevel, 3);
*Then I created relationships between individuals via addProperty() method:*
P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements.addProperty(creates,
P1_3_BalanceSupplyChainResourcesWithSCRequirements);
P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements.addProperty(uses,
EP10_AlignSupplyChainUnitPlanWithFinancialPlan);
P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements.addProperty(uses,
EP5_ManageIntegratedSupplyChainCapitalAssets);
P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements.addProperty(uses,
D1_11_LoadVehicleAndGenerateShippingDoc);
P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements.addProperty(uses,
D1_3_ReserveInventoryAndDetermineDeliveryDate);
P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements.addProperty(uses,
EP3_ManagePlanDataCollection);
P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements.addProperty(uses,
D1_11_LoadVehicleAndGenerateShippingDoc);
P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements.addProperty(uses,
D1_3_ReserveInventoryAndDetermineDeliveryDate);
P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements.addProperty(uses,
D2_3_ReserveInventoryAndDetermineDeliveryDate);
P1_1_IdentifyPrioritizeAndAggregateSupplyChainRequirements.addProperty(uses,
D3_3_EnterOrderCommitResourcesAndLaunchProgram);
*What would I like to achieve:*
1. Select * from model where hasLevel = 1 (I would like to get all
individuals that are on level 1, level2, etc)
2. All individuals have some meta data, like: title, description, metric,
etc. I am still not sure how to achieve that. So i have 4 classes that have
all my individuals inside. These have to share same metadata. How would you
do this?
3. I would like to select specific document (individual) and know what is
its input / output (uses / creates). So something like this: select * from
model where hasLevel = 1 and name='nameOfIndividual' and uses='uses'
4. Each individual can consist of some other individual (document) and can
create some other individual (document)
*Now my question :)*
1. Is this way right at all? As I said I am pretty new to semantic so I
am struggling with it, it is totally different concept of what I am used to
I really appreciate all your help.
Thanks and my best regards,
Bojan Milic
On Tue, Mar 5, 2013 at 5:12 PM, Dave Reynolds <da...@gmail.com>wrote:
> I don't follow what you are trying to achieve but it sounds like at least
> part of it is to be able to state that the domain or range of a property is
> a union of classes, rather than a single class. At least that's what your
> OWL API example seems to do.
>
> This is perfectly possible in Jena. For example:
>
> UnionClass range = ont.createUnionClass(null, ont.createList());
> range.addOperand(animalClass);
> range.addOperand(personClass);
> children.addRange(range);
>
> There are various ways to construct the RDFList for the union class, the
> above is just one example.
>
> If you want to later add more to the range then just do so:
>
> range.addOperand(plantClass);
>
> Dave
>
>
>
> On 04/03/13 10:25, Bojan Milić wrote:
>
>> Dear friends,
>>
>> I am developing ontology for supply chain management and I am
>> encountering some problems regarding Jena API. In my ontology I have
>> following structure:
>>
>> classA
>> classA1
>> classA2
>> classA3
>> classA4
>> classB
>> classC
>> classD
>>
>> Classes are representing some documents for example (classA = planning
>> doc, classB = execution doc, etc.). Now I would like to connect
>> (relationship) these classes with same ObjectProperty. In Jena
>> Ontology API it sais: In an ontology, a property denotes the name of a
>> relationship between resources, or between a resource and a data
>> value. I followed jena api and did the relationship like this
>> (OntologyPrintscreen.jpg in attachment):
>>
>> //let's start some JENA code -- simple default RDF model
>> String baseURI = InitInfo.getInstance().**
>> getDefaultBaseURI();
>>
>> //create ontology model
>> OntModel processModel =
>> ModelFactory.**createOntologyModel(**OntModelSpec.OWL_MEM_TRANS_**INF);
>>
>> //createResource
>> Resource r = processModel.createResource(**baseURI +
>> "r");
>>
>>
>> OntClass classA = processModel.createClass(**baseURI +
>> "classA");
>> OntClass classB = processModel.createClass(**baseURI +
>> "classB");
>> OntClass classC = processModel.createClass(**baseURI +
>> "classC");
>> OntClass classD = processModel.createClass(**baseURI +
>> "classD");
>>
>> classA.addSubClass(**processModel.createClass(**baseURI
>> +
>> "classA1"));
>> classA.addSubClass(**processModel.createClass(**baseURI
>> +
>> "classA2"));
>> classA.addSubClass(**processModel.createClass(**baseURI
>> +
>> "classA3"));
>> classA.addSubClass(**processModel.createClass(**baseURI
>> +
>> "classA4"));
>>
>> OntClass classA1 = processModel.getOntClass(**baseURI +
>> "classA1");
>> OntClass classA2 = processModel.getOntClass(**baseURI +
>> "classA2");
>> OntClass classA3 = processModel.getOntClass(**baseURI +
>> "classA3");
>> OntClass classA4 = processModel.getOntClass(**baseURI +
>> "classA4");
>>
>> ObjectProperty uses =
>> processModel.**createObjectProperty(baseURI + "uses");
>> ObjectProperty creates =
>> processModel.**createObjectProperty(baseURI +
>> "creates");
>>
>> creates.addDomain(classA1);
>> creates.addRange(classA2);
>>
>> uses.addDomain(classA1);
>> uses.addRange(classB);
>>
>> My problem: I would like to use same objectProperty (uses and creates)
>> to model relationship between my classes. For example:
>> classA1 uses classB
>> classA1 creates classA2
>> classA2 creates classA3
>> classA3 uses classD
>> classA4 creates classC
>>
>> There is a desired look (what I would like to achieve) with jena api
>> (OntologyDesired.jpg). I've already tried:
>> creates.addDomain(classA2);
>> creates.addRange(classA3);
>>
>> uses.addDomain(classA3);
>> uses.addRange(classD);
>> But statements get disregarded.
>>
>> Can you please help me model relationships between these classes with
>> same ObjectProperty, is this even possible? With protege API you can
>> do this:
>> OWLObjectProperty childrenProperty =
>> owlModel.**createOWLObjectProperty("**children");
>> childrenProperty.**addUnionRangeClass(**personClass);
>> childrenProperty.**addUnionRangeClass(**animalClass);
>>
>> Is something like that possible with Jena, I haven't found anything on
>> the web, so you are my final chance :)
>>
>> Looking forward for your answer.
>>
>> Thank you and my best regards,
>>
>> Bojan Milic
>>
>>
>>
>
--
Lep pozdrav,
Bojan Milić
--
Lep pozdrav,
Bojan Milić
Re: Modeling relationships of classes with ObjectProperty
Posted by Dave Reynolds <da...@gmail.com>.
I don't follow what you are trying to achieve but it sounds like at
least part of it is to be able to state that the domain or range of a
property is a union of classes, rather than a single class. At least
that's what your OWL API example seems to do.
This is perfectly possible in Jena. For example:
UnionClass range = ont.createUnionClass(null, ont.createList());
range.addOperand(animalClass);
range.addOperand(personClass);
children.addRange(range);
There are various ways to construct the RDFList for the union class, the
above is just one example.
If you want to later add more to the range then just do so:
range.addOperand(plantClass);
Dave
On 04/03/13 10:25, Bojan Milić wrote:
> Dear friends,
>
> I am developing ontology for supply chain management and I am
> encountering some problems regarding Jena API. In my ontology I have
> following structure:
>
> classA
> classA1
> classA2
> classA3
> classA4
> classB
> classC
> classD
>
> Classes are representing some documents for example (classA = planning
> doc, classB = execution doc, etc.). Now I would like to connect
> (relationship) these classes with same ObjectProperty. In Jena
> Ontology API it sais: In an ontology, a property denotes the name of a
> relationship between resources, or between a resource and a data
> value. I followed jena api and did the relationship like this
> (OntologyPrintscreen.jpg in attachment):
>
> //let's start some JENA code -- simple default RDF model
> String baseURI = InitInfo.getInstance().getDefaultBaseURI();
>
> //create ontology model
> OntModel processModel =
> ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_TRANS_INF);
>
> //createResource
> Resource r = processModel.createResource(baseURI + "r");
>
>
> OntClass classA = processModel.createClass(baseURI + "classA");
> OntClass classB = processModel.createClass(baseURI + "classB");
> OntClass classC = processModel.createClass(baseURI + "classC");
> OntClass classD = processModel.createClass(baseURI + "classD");
>
> classA.addSubClass(processModel.createClass(baseURI +
> "classA1"));
> classA.addSubClass(processModel.createClass(baseURI +
> "classA2"));
> classA.addSubClass(processModel.createClass(baseURI +
> "classA3"));
> classA.addSubClass(processModel.createClass(baseURI +
> "classA4"));
>
> OntClass classA1 = processModel.getOntClass(baseURI +
> "classA1");
> OntClass classA2 = processModel.getOntClass(baseURI +
> "classA2");
> OntClass classA3 = processModel.getOntClass(baseURI +
> "classA3");
> OntClass classA4 = processModel.getOntClass(baseURI +
> "classA4");
>
> ObjectProperty uses =
> processModel.createObjectProperty(baseURI + "uses");
> ObjectProperty creates =
> processModel.createObjectProperty(baseURI +
> "creates");
>
> creates.addDomain(classA1);
> creates.addRange(classA2);
>
> uses.addDomain(classA1);
> uses.addRange(classB);
>
> My problem: I would like to use same objectProperty (uses and creates)
> to model relationship between my classes. For example:
> classA1 uses classB
> classA1 creates classA2
> classA2 creates classA3
> classA3 uses classD
> classA4 creates classC
>
> There is a desired look (what I would like to achieve) with jena api
> (OntologyDesired.jpg). I've already tried:
> creates.addDomain(classA2);
> creates.addRange(classA3);
>
> uses.addDomain(classA3);
> uses.addRange(classD);
> But statements get disregarded.
>
> Can you please help me model relationships between these classes with
> same ObjectProperty, is this even possible? With protege API you can
> do this:
> OWLObjectProperty childrenProperty =
> owlModel.createOWLObjectProperty("children");
> childrenProperty.addUnionRangeClass(personClass);
> childrenProperty.addUnionRangeClass(animalClass);
>
> Is something like that possible with Jena, I haven't found anything on
> the web, so you are my final chance :)
>
> Looking forward for your answer.
>
> Thank you and my best regards,
>
> Bojan Milic
>
>
Re: Modeling relationships of classes with ObjectProperty
Posted by Bojan Milić <bo...@gmail.com>.
Hi Joshua,
thank you for your answer, it helps a lot. I couldn't attach my file when I
posted this issue to jena.apache.org, so I am attaching one now - there is
a desired functionality of what I would like to achieve. OK I understand
now, that you cannot add something as a domain property because that means
that classes are same.
But in your example bellow I do not understand why do you have to add
individauls at all? If you can see my attachment, classes: classA, classB,
classD, etc. are representing some various documents (classA = execution
plan, classB = production plan, etc) that need (use) some other documents
(in example: classA1 uses classB) and make (create) output documents (in
example: classA4 creates classC) in my domain.
In my case class equals individual, because each class (document) is
unique. So my domain is document database, where some document uses and
creates some other documents, but all the documents (classes) are unique.
Each document will have some metadata, for example: title, description,
etc. What would be your approach to resolve this issue?
1. Create classes like I did now
2. Create individuals for the classes - assign one individual to each class
(do I have to do this?)
3. Then addSuperClass restriction to each class that has some output or
input document
4. Assign each property between individuals that represent documents
Would be this the way to go?
Thank you so much for your help.
Best regards, Bojan Milic
On Mon, Mar 4, 2013 at 4:21 PM, Joshua TAYLOR <jo...@gmail.com> wrote:
> On Mon, Mar 4, 2013 at 5:25 AM, Bojan Milić <bo...@gmail.com> wrote:
> > Dear friends,
> >
> > I am developing ontology for supply chain management and I am
> > encountering some problems regarding Jena API. In my ontology I have
> > following structure:
> >
> > classA
> > classA1
> > classA2
> > classA3
> > classA4
> > classB
> > classC
> > classD
> >
> > Classes are representing some documents for example (classA = planning
> > doc, classB = execution doc, etc.). Now I would like to connect
> > (relationship) these classes with same ObjectProperty. In Jena
> > Ontology API it sais: In an ontology, a property denotes the name of a
> > relationship between resources, or between a resource and a data
> > value. I followed jena api and did the relationship like this
> > (OntologyPrintscreen.jpg in attachment):
> >
> > //let's start some JENA code -- simple default RDF model
> > String baseURI =
> InitInfo.getInstance().getDefaultBaseURI();
> >
> > //create ontology model
> > OntModel processModel =
> > ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_TRANS_INF);
> >
> > //createResource
> > Resource r = processModel.createResource(baseURI + "r");
> >
> >
> > OntClass classA = processModel.createClass(baseURI +
> "classA");
> > OntClass classB = processModel.createClass(baseURI +
> "classB");
> > OntClass classC = processModel.createClass(baseURI +
> "classC");
> > OntClass classD = processModel.createClass(baseURI +
> "classD");
> >
> > classA.addSubClass(processModel.createClass(baseURI +
> > "classA1"));
> > classA.addSubClass(processModel.createClass(baseURI +
> > "classA2"));
> > classA.addSubClass(processModel.createClass(baseURI +
> > "classA3"));
> > classA.addSubClass(processModel.createClass(baseURI +
> > "classA4"));
> >
> > OntClass classA1 = processModel.getOntClass(baseURI +
> > "classA1");
> > OntClass classA2 = processModel.getOntClass(baseURI +
> > "classA2");
> > OntClass classA3 = processModel.getOntClass(baseURI +
> > "classA3");
> > OntClass classA4 = processModel.getOntClass(baseURI +
> > "classA4");
> >
> > ObjectProperty uses =
> > processModel.createObjectProperty(baseURI + "uses");
> > ObjectProperty creates =
> > processModel.createObjectProperty(baseURI +
> > "creates");
> >
> > creates.addDomain(classA1);
> > creates.addRange(classA2);
> >
> > uses.addDomain(classA1);
> > uses.addRange(classB);
> >
> > My problem: I would like to use same objectProperty (uses and creates)
> > to model relationship between my classes. For example:
> > classA1 uses classB
> > classA1 creates classA2
> > classA2 creates classA3
> > classA3 uses classD
> > classA4 creates classC
> >
> > There is a desired look (what I would like to achieve) with jena api
> > (OntologyDesired.jpg). I've already tried:
> > creates.addDomain(classA2);
> > creates.addRange(classA3);
> >
> > uses.addDomain(classA3);
> > uses.addRange(classD);
> > But statements get disregarded.
> >
> > Can you please help me model relationships between these classes with
> > same ObjectProperty, is this even possible? With protege API you can
> > do this:
> > OWLObjectProperty childrenProperty =
> > owlModel.createOWLObjectProperty("children");
> > childrenProperty.addUnionRangeClass(personClass);
> > childrenProperty.addUnionRangeClass(animalClass);
> >
> > Is something like that possible with Jena, I haven't found anything on
> > the web, so you are my final chance :)
>
> If I understand you correctly, the problem you're having is like the
> following:
>
> Classes
> Car
> CarFactory
> Boat
> BoatFactor
>
> Properties
> creates
>
> and what you'd like to enforce is that whenever you have a statement
>
> [x, creates, y]
>
> either
>
> x is a CarFactory and y is a Car, or
> x is a BoatFactory and y is a Boat .
>
> The way to do this is *not* adding CarFactory and BoatFactory as
> domains of creates, as this means that any x such that [x creates y]
> is *both* a CarFactory and a BoatFactory.
>
> The way to do this is *not* to set (CarFactory OR BoatFactory) as the
> domain of creates, as this means that any x such that [x creates y] is
> *either* a CarFactory or a BoatFactory, without any regard to whether
> y is a Car or a Boat.
>
> The way to do this is to add some restriction superclasses to
> CarFactory and BoatFactory that restrict the way that the property
> creates will be used for them:
>
> CarFactory isSubClassOf (creates only Car)
> BoatFactory isSubClassOf (creates only Boat)
>
> This will ensure that whenever [x creates y]:
> if x is a CarFactory then y is a Car; and
> if x is a BoatFactory then y is a Boat.
>
> Here's some code that illustrates this:
>
> public class JenaTest {
> public static void main(String[] args) {
> String NS = "http://example.com/factories#";
>
> OntModel model = ModelFactory.createOntologyModel(
> OntModelSpec.OWL_DL_MEM_RULE_INF );
>
> OntClass Car = model.createClass( NS+"Car" );
> OntClass Boat = model.createClass( NS+"Boat");
> OntClass BoatFactory = model.createClass( NS+"BoatFactory"
> );
> OntClass CarFactory = model.createClass( NS+"CarFactory" );
>
> OntProperty creates = model.createOntProperty(
> NS+"creates" );
>
> BoatFactory.addSuperClass(
> model.createAllValuesFromRestriction(
> null, creates, Boat ));
> CarFactory.addSuperClass(
> model.createAllValuesFromRestriction(
> null, creates, Car ));
>
> Individual bf = model.createIndividual(
> NS+"someBoatFactory", BoatFactory );
> Individual cf = model.createIndividual(
> NS+"someCarFactory", CarFactory );
>
> Individual x = model.createIndividual( NS+"creature1",
> OWL.Thing );
> Individual y = model.createIndividual( NS+"creature2",
> OWL.Thing );
>
> bf.addProperty( creates, x );
> cf.addProperty( creates, y );
>
> for ( Individual i : new Individual[] { x, y } ) {
> ExtendedIterator<Resource> it = i.listRDFTypes(
> false );
> while( it.hasNext() ) {
> System.out.println( i+" has type
> "+it.next() );
> }
> }
> }
> }
>
> The output is:
>
> http://example.com/factories#creature1 has type
> http://www.w3.org/2002/07/owl#Thing
> http://example.com/factories#creature1 has type
> http://example.com/factories#Boat
> http://example.com/factories#creature1 has type
> http://www.w3.org/2000/01/rdf-schema#Resource
> http://example.com/factories#creature2 has type
> http://www.w3.org/2002/07/owl#Thing
> http://example.com/factories#creature2 has type
> http://example.com/factories#Car
> http://example.com/factories#creature2 has type
> http://www.w3.org/2000/01/rdf-schema#Resource
>
> Hope this helps!
>
> //JT
>
>
> --
> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
>
--
Lep pozdrav,
Bojan Milić
Re: Modeling relationships of classes with ObjectProperty
Posted by Joshua TAYLOR <jo...@gmail.com>.
On Mon, Mar 4, 2013 at 5:25 AM, Bojan Milić <bo...@gmail.com> wrote:
> Dear friends,
>
> I am developing ontology for supply chain management and I am
> encountering some problems regarding Jena API. In my ontology I have
> following structure:
>
> classA
> classA1
> classA2
> classA3
> classA4
> classB
> classC
> classD
>
> Classes are representing some documents for example (classA = planning
> doc, classB = execution doc, etc.). Now I would like to connect
> (relationship) these classes with same ObjectProperty. In Jena
> Ontology API it sais: In an ontology, a property denotes the name of a
> relationship between resources, or between a resource and a data
> value. I followed jena api and did the relationship like this
> (OntologyPrintscreen.jpg in attachment):
>
> //let's start some JENA code -- simple default RDF model
> String baseURI = InitInfo.getInstance().getDefaultBaseURI();
>
> //create ontology model
> OntModel processModel =
> ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_TRANS_INF);
>
> //createResource
> Resource r = processModel.createResource(baseURI + "r");
>
>
> OntClass classA = processModel.createClass(baseURI + "classA");
> OntClass classB = processModel.createClass(baseURI + "classB");
> OntClass classC = processModel.createClass(baseURI + "classC");
> OntClass classD = processModel.createClass(baseURI + "classD");
>
> classA.addSubClass(processModel.createClass(baseURI +
> "classA1"));
> classA.addSubClass(processModel.createClass(baseURI +
> "classA2"));
> classA.addSubClass(processModel.createClass(baseURI +
> "classA3"));
> classA.addSubClass(processModel.createClass(baseURI +
> "classA4"));
>
> OntClass classA1 = processModel.getOntClass(baseURI +
> "classA1");
> OntClass classA2 = processModel.getOntClass(baseURI +
> "classA2");
> OntClass classA3 = processModel.getOntClass(baseURI +
> "classA3");
> OntClass classA4 = processModel.getOntClass(baseURI +
> "classA4");
>
> ObjectProperty uses =
> processModel.createObjectProperty(baseURI + "uses");
> ObjectProperty creates =
> processModel.createObjectProperty(baseURI +
> "creates");
>
> creates.addDomain(classA1);
> creates.addRange(classA2);
>
> uses.addDomain(classA1);
> uses.addRange(classB);
>
> My problem: I would like to use same objectProperty (uses and creates)
> to model relationship between my classes. For example:
> classA1 uses classB
> classA1 creates classA2
> classA2 creates classA3
> classA3 uses classD
> classA4 creates classC
>
> There is a desired look (what I would like to achieve) with jena api
> (OntologyDesired.jpg). I've already tried:
> creates.addDomain(classA2);
> creates.addRange(classA3);
>
> uses.addDomain(classA3);
> uses.addRange(classD);
> But statements get disregarded.
>
> Can you please help me model relationships between these classes with
> same ObjectProperty, is this even possible? With protege API you can
> do this:
> OWLObjectProperty childrenProperty =
> owlModel.createOWLObjectProperty("children");
> childrenProperty.addUnionRangeClass(personClass);
> childrenProperty.addUnionRangeClass(animalClass);
>
> Is something like that possible with Jena, I haven't found anything on
> the web, so you are my final chance :)
If I understand you correctly, the problem you're having is like the following:
Classes
Car
CarFactory
Boat
BoatFactor
Properties
creates
and what you'd like to enforce is that whenever you have a statement
[x, creates, y]
either
x is a CarFactory and y is a Car, or
x is a BoatFactory and y is a Boat .
The way to do this is *not* adding CarFactory and BoatFactory as
domains of creates, as this means that any x such that [x creates y]
is *both* a CarFactory and a BoatFactory.
The way to do this is *not* to set (CarFactory OR BoatFactory) as the
domain of creates, as this means that any x such that [x creates y] is
*either* a CarFactory or a BoatFactory, without any regard to whether
y is a Car or a Boat.
The way to do this is to add some restriction superclasses to
CarFactory and BoatFactory that restrict the way that the property
creates will be used for them:
CarFactory isSubClassOf (creates only Car)
BoatFactory isSubClassOf (creates only Boat)
This will ensure that whenever [x creates y]:
if x is a CarFactory then y is a Car; and
if x is a BoatFactory then y is a Boat.
Here's some code that illustrates this:
public class JenaTest {
public static void main(String[] args) {
String NS = "http://example.com/factories#";
OntModel model = ModelFactory.createOntologyModel(
OntModelSpec.OWL_DL_MEM_RULE_INF );
OntClass Car = model.createClass( NS+"Car" );
OntClass Boat = model.createClass( NS+"Boat");
OntClass BoatFactory = model.createClass( NS+"BoatFactory" );
OntClass CarFactory = model.createClass( NS+"CarFactory" );
OntProperty creates = model.createOntProperty( NS+"creates" );
BoatFactory.addSuperClass( model.createAllValuesFromRestriction(
null, creates, Boat ));
CarFactory.addSuperClass( model.createAllValuesFromRestriction(
null, creates, Car ));
Individual bf = model.createIndividual( NS+"someBoatFactory", BoatFactory );
Individual cf = model.createIndividual( NS+"someCarFactory", CarFactory );
Individual x = model.createIndividual( NS+"creature1", OWL.Thing );
Individual y = model.createIndividual( NS+"creature2", OWL.Thing );
bf.addProperty( creates, x );
cf.addProperty( creates, y );
for ( Individual i : new Individual[] { x, y } ) {
ExtendedIterator<Resource> it = i.listRDFTypes( false );
while( it.hasNext() ) {
System.out.println( i+" has type "+it.next() );
}
}
}
}
The output is:
http://example.com/factories#creature1 has type
http://www.w3.org/2002/07/owl#Thing
http://example.com/factories#creature1 has type
http://example.com/factories#Boat
http://example.com/factories#creature1 has type
http://www.w3.org/2000/01/rdf-schema#Resource
http://example.com/factories#creature2 has type
http://www.w3.org/2002/07/owl#Thing
http://example.com/factories#creature2 has type http://example.com/factories#Car
http://example.com/factories#creature2 has type
http://www.w3.org/2000/01/rdf-schema#Resource
Hope this helps!
//JT
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/