[protege-owl] help on owl property creation needed

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

[protege-owl] help on owl property creation needed

Julia Dmitrieva
Hello,

I try to convert thesaurus.owl file in other smaller variant,
with only needed information.
For the conversion I use the ProptegeOWL API.
I just parse the owl file with SAX parser and
if I see something  interesting the new class/property
is created.
But I dont know how can I implement the creation of the following
property:

<owl:DatatypeProperty rdf:ID="code">
<code>AHC0</code>
<protege:readOnly
rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>
</owl:DatatypeProperty>

First I do

OWLDatatypeProperty property =owlFactory.CreateDataTypeProperty("code");
Stirng uri = "http://www.w3.org/2001/XMLSchema#string";
RDFSDatatype dataType = owlModel.getRDFSDatatypeByURI(uri);
property.setRange(dataType);

But I don't know how to handle the
<code>AHC0</code>
<protege:readOnly
rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>

Can somebody help me.

Julia
-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Nikolaj Berntsen
Julia Dmitrieva wrote:

> Hello,
>
> I try to convert thesaurus.owl file in other smaller variant,
> with only needed information.
> For the conversion I use the ProptegeOWL API.
> I just parse the owl file with SAX parser and
> if I see something  interesting the new class/property
> is created.
> But I dont know how can I implement the creation of the following
> property:
>
> <owl:DatatypeProperty rdf:ID="code">
> <code>AHC0</code>
> <protege:readOnly
> rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>
> <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
> <rdf:type
> rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>
> </owl:DatatypeProperty>
>
> First I do
>
> OWLDatatypeProperty property =owlFactory.CreateDataTypeProperty("code");
> Stirng uri = "http://www.w3.org/2001/XMLSchema#string";
> RDFSDatatype dataType = owlModel.getRDFSDatatypeByURI(uri);
> property.setRange(dataType);
>
> But I don't know how to handle the
> <code>AHC0</code>
> <protege:readOnly
> rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>
> <rdf:type
> rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>
>
> Can somebody help me.


I think I can help you with the <code></code> part. I do

        JenaOWLModel spModel = ProtegeOWL.createJenaOWLModel();        
        RDFProperty gender = spModel.createRDFProperty("gender");
        RDFProperty name = spModel.createRDFProperty("name");
        OWLNamedClass profileDataClass =
spModel.createOWLNamedClass("ProfileData");
        OWLIndividual knbProfileDataIndividual =
profileDataClass.createOWLIndividual("knbProfileData");
        knbProfileDataIndividual.addPropertyValue(gender, "male");
        knbProfileDataIndividual.addPropertyValue(name,
spModel.createRDFSLiteral("nikolaj"));

I think the code-value solution is to do something like the two last lines?

If you manage I would be interested to see you solution. Also, if you
manage to write that RDF and parse it again and dig out the code-value
using the protege-owl API (I can do it using Jena), you would have
answered a yet unanswered question of mine on the list.

Cheers,
/\/

-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Julia Dmitrieva
Hello, Nikolaj,
Thank you for you answer,

The propblem is that I have to create
Datatype property "code"
whith the property "code"
***********************************************************
<owl:DatatypeProperty rdf:ID="code">
<code>AHC0</code>
<protege:readOnly
<rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
        <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>
</owl:DatatypeProperty>
But can not get the
<code>AHCO<code>
inside
<owl:DatatypeProperty rdf:ID="code">
****************************************************************
I am doing the following

OWLDatatypeProperty codeProp = owlModel.createOWLDatatypeProperty("code");
      dataType =
owlModel.getRDFSDatatypeByURI("http://www.w3.org/2001/XMLSchema#strintg");
      codeProp.setRange(dataType);
      RDFProperty codeSubProp = owlModel.createRDFProperty("code");
      codeProp.addPropertyValue(codeSubProp, "AHC0");

And becouse the name not unique name I get the error:
Exception in thread "main" java.lang.IllegalArgumentException: code not
unique: Slot(code)

Probably Proptege OWL don't support this kind of structures.
<code>
        <code>

But I am not shure whether I create the <code>AHCO<code>
correctly
The  developers of the Thesaurus.owl from NCI have it down by one
or another manner. I don't know how???

Julia

Nikolaj Berntsen wrote:

> Julia Dmitrieva wrote:
>
>
>>Hello,
>>
>>I try to convert thesaurus.owl file in other smaller variant,
>>with only needed information.
>>For the conversion I use the ProptegeOWL API.
>>I just parse the owl file with SAX parser and
>>if I see something  interesting the new class/property
>>is created.
>>But I dont know how can I implement the creation of the following
>>property:
>>
>><owl:DatatypeProperty rdf:ID="code">
>><code>AHC0</code>
>><protege:readOnly
>>rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>>
>><rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
>><rdf:type
>>rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>
>></owl:DatatypeProperty>
>>
>>First I do
>>
>>OWLDatatypeProperty property =owlFactory.CreateDataTypeProperty("code");
>>Stirng uri = "http://www.w3.org/2001/XMLSchema#string";
>>RDFSDatatype dataType = owlModel.getRDFSDatatypeByURI(uri);
>>property.setRange(dataType);
>>
>>But I don't know how to handle the
>><code>AHC0</code>
>><protege:readOnly
>>rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>>
>><rdf:type
>>rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>
>>
>>Can somebody help me.
>
>
>
> I think I can help you with the <code></code> part. I do
>
>         JenaOWLModel spModel = ProtegeOWL.createJenaOWLModel();        
>         RDFProperty gender = spModel.createRDFProperty("gender");
>         RDFProperty name = spModel.createRDFProperty("name");
>         OWLNamedClass profileDataClass =
> spModel.createOWLNamedClass("ProfileData");
>         OWLIndividual knbProfileDataIndividual =
> profileDataClass.createOWLIndividual("knbProfileData");
>         knbProfileDataIndividual.addPropertyValue(gender, "male");
>         knbProfileDataIndividual.addPropertyValue(name,
> spModel.createRDFSLiteral("nikolaj"));
>
> I think the code-value solution is to do something like the two last lines?
>
> If you manage I would be interested to see you solution. Also, if you
> manage to write that RDF and parse it again and dig out the code-value
> using the protege-owl API (I can do it using Jena), you would have
> answered a yet unanswered question of mine on the list.
>
> Cheers,
> /\/
>
> -------------------------------------------------------------------------
> To unsubscribe go to http://protege.stanford.edu/community/subscribe.html


--
Julia Dmitrieva

LIACS Office:  124
Phone:  +31 (0)71 – 5275777
E-Mail:  [hidden email]

Member of:  Imaging
Scientific Personnel

-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Nikolaj Berntsen
Julia Dmitrieva wrote:

> Hello, Nikolaj,
> Thank you for you answer,
>
> The propblem is that I have to create
> Datatype property "code"
> whith the property "code"

I did not read your RDF properly. My guess is that data-type properties
are "primitive" in some sens and does not allow children. The XML might
be able to express it, but RDF does not allow it.

Just my best guess.

/\/

> ***********************************************************
> <owl:DatatypeProperty rdf:ID="code">
> <code>AHC0</code>
> <protege:readOnly
> <rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>
>     <rdfs:range                    
> rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
> <rdf:type
> rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>
> </owl:DatatypeProperty>
> But can not get the
> <code>AHCO<code>
> inside
> <owl:DatatypeProperty rdf:ID="code">
> ****************************************************************
> I am doing the following
>
> OWLDatatypeProperty codeProp =
> owlModel.createOWLDatatypeProperty("code");
>         dataType =
> owlModel.getRDFSDatatypeByURI("http://www.w3.org/2001/XMLSchema#strintg");
>
>         codeProp.setRange(dataType);
>         RDFProperty codeSubProp = owlModel.createRDFProperty("code");
>         codeProp.addPropertyValue(codeSubProp, "AHC0");
>
> And becouse the name not unique name I get the error:
> Exception in thread "main" java.lang.IllegalArgumentException: code
> not unique: Slot(code)
>
> Probably Proptege OWL don't support this kind of structures.
> <code>
>     <code>
>
> But I am not shure whether I create the <code>AHCO<code>
> correctly
> The  developers of the Thesaurus.owl from NCI have it down by one
> or another manner. I don't know how???
>
> Julia
>
> Nikolaj Berntsen wrote:
>
>> Julia Dmitrieva wrote:
>>
>>
>>> Hello,
>>>
>>> I try to convert thesaurus.owl file in other smaller variant,
>>> with only needed information.
>>> For the conversion I use the ProptegeOWL API.
>>> I just parse the owl file with SAX parser and
>>> if I see something  interesting the new class/property
>>> is created.
>>> But I dont know how can I implement the creation of the following
>>> property:
>>>
>>> <owl:DatatypeProperty rdf:ID="code">
>>> <code>AHC0</code>
>>> <protege:readOnly
>>> rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>>>
>>>
>>> <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
>>> <rdf:type
>>> rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>
>>> </owl:DatatypeProperty>
>>>
>>> First I do
>>>
>>> OWLDatatypeProperty property
>>> =owlFactory.CreateDataTypeProperty("code");
>>> Stirng uri = "http://www.w3.org/2001/XMLSchema#string";
>>> RDFSDatatype dataType = owlModel.getRDFSDatatypeByURI(uri);
>>> property.setRange(dataType);
>>>
>>> But I don't know how to handle the
>>> <code>AHC0</code>
>>> <protege:readOnly
>>> rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>>>
>>>
>>> <rdf:type
>>> rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>
>>>
>>> Can somebody help me.
>>
>>
>>
>>
>> I think I can help you with the <code></code> part. I do
>>
>>         JenaOWLModel spModel =
>> ProtegeOWL.createJenaOWLModel();                RDFProperty gender =
>> spModel.createRDFProperty("gender");
>>         RDFProperty name = spModel.createRDFProperty("name");
>>         OWLNamedClass profileDataClass =
>> spModel.createOWLNamedClass("ProfileData");
>>         OWLIndividual knbProfileDataIndividual =
>> profileDataClass.createOWLIndividual("knbProfileData");
>>         knbProfileDataIndividual.addPropertyValue(gender, "male");
>>         knbProfileDataIndividual.addPropertyValue(name,
>> spModel.createRDFSLiteral("nikolaj"));
>>
>> I think the code-value solution is to do something like the two last
>> lines?
>>
>> If you manage I would be interested to see you solution. Also, if you
>> manage to write that RDF and parse it again and dig out the code-value
>> using the protege-owl API (I can do it using Jena), you would have
>> answered a yet unanswered question of mine on the list.
>>
>> Cheers,
>> /\/
>>
>> -------------------------------------------------------------------------
>>
>> To unsubscribe go to
>> http://protege.stanford.edu/community/subscribe.html
>
>
>


--
Cheers,
/\/ikolaj Berntsen
--
Mobile People A/S
Toldbodgade 31, 2 sal, DK-1253 Copenhagen K
T: +45 7025 2722 F: 70 25 27 23 M: +45 3054 2207

-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Julia Dmitrieva
Hi,
you meen that it is impossible ?

Julia

Nikolaj Berntsen wrote:

>
> I did not read your RDF properly. My guess is that data-type properties
> are "primitive" in some sens and does not allow children. The XML might
> be able to express it, but RDF does not allow it.
>
> Just my best guess.
>
> /\/
>
>

--
Julia Dmitrieva

LIACS Office:  124
Phone:  +31 (0)71 – 5275777
E-Mail:  [hidden email]

Member of:  Imaging
Scientific Personnel

-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Nikolaj Berntsen
Julia Dmitrieva wrote:

> Hi,
> you meen that it is impossible ?

just a guess, but yes that is my guess.

just like a java primitive int cannot have methods on it.

/\/
-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Fragoso, Gilberto (NIH/NCI) [E]
In reply to this post by Julia Dmitrieva
Julia,

I can't give you any tips with the protege/owl API, but in your sample/test owl file you may have an error (or maybe it happened during copy-and-paste into the e-mail), the portion that reads

<protege:readOnly
<rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>

should be

<protege:readOnly
rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>

the rdf:datatype attribute is not preceeded by a '<' character.

On another note, the annotation of the "code" datatype property with a "code" is acceptable OWL; we include it only because it's required for comparisons that we are performing with the Prompt plugin, otherwise we would have omitted it.  Of course, Protege doesn't have problems loading the file, but I'm afraid I can't tell you what API methods to use to process this section.  If it's any help, you could disregard the code of the "code" in your extracted subset.

Regards,
Gilberto

-----Original Message-----
From: Julia Dmitrieva [mailto:[hidden email]]
Sent: Wednesday, June 28, 2006 9:09 AM
To: [hidden email]
Subject: [protege-owl] Re: help on owl property creation needed


Hello, Nikolaj,
Thank you for you answer,

The propblem is that I have to create
Datatype property "code"
whith the property "code"
***********************************************************
<owl:DatatypeProperty rdf:ID="code">
<code>AHC0</code>
<protege:readOnly
<rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
        <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>
</owl:DatatypeProperty>
But can not get the
<code>AHCO<code>
inside
<owl:DatatypeProperty rdf:ID="code">
****************************************************************
I am doing the following

OWLDatatypeProperty codeProp = owlModel.createOWLDatatypeProperty("code");
      dataType =
owlModel.getRDFSDatatypeByURI("http://www.w3.org/2001/XMLSchema#strintg");
      codeProp.setRange(dataType);
      RDFProperty codeSubProp = owlModel.createRDFProperty("code");
      codeProp.addPropertyValue(codeSubProp, "AHC0");

And becouse the name not unique name I get the error:
Exception in thread "main" java.lang.IllegalArgumentException: code not
unique: Slot(code)

Probably Proptege OWL don't support this kind of structures.
<code>
        <code>

But I am not shure whether I create the <code>AHCO<code>
correctly
The  developers of the Thesaurus.owl from NCI have it down by one
or another manner. I don't know how???

Julia

Nikolaj Berntsen wrote:

> Julia Dmitrieva wrote:
>
>
>>Hello,
>>
>>I try to convert thesaurus.owl file in other smaller variant,
>>with only needed information.
>>For the conversion I use the ProptegeOWL API.
>>I just parse the owl file with SAX parser and
>>if I see something  interesting the new class/property
>>is created.
>>But I dont know how can I implement the creation of the following
>>property:
>>
>><owl:DatatypeProperty rdf:ID="code">
>><code>AHC0</code>
>><protege:readOnly
>>rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>>
>><rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
>><rdf:type
>>rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>
>></owl:DatatypeProperty>
>>
>>First I do
>>
>>OWLDatatypeProperty property =owlFactory.CreateDataTypeProperty("code");
>>Stirng uri = "http://www.w3.org/2001/XMLSchema#string";
>>RDFSDatatype dataType = owlModel.getRDFSDatatypeByURI(uri);
>>property.setRange(dataType);
>>
>>But I don't know how to handle the
>><code>AHC0</code>
>><protege:readOnly
>>rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>>
>><rdf:type
>>rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>
>>
>>Can somebody help me.
>
>
>
> I think I can help you with the <code></code> part. I do
>
>         JenaOWLModel spModel = ProtegeOWL.createJenaOWLModel();        
>         RDFProperty gender = spModel.createRDFProperty("gender");
>         RDFProperty name = spModel.createRDFProperty("name");
>         OWLNamedClass profileDataClass =
> spModel.createOWLNamedClass("ProfileData");
>         OWLIndividual knbProfileDataIndividual =
> profileDataClass.createOWLIndividual("knbProfileData");
>         knbProfileDataIndividual.addPropertyValue(gender, "male");
>         knbProfileDataIndividual.addPropertyValue(name,
> spModel.createRDFSLiteral("nikolaj"));
>
> I think the code-value solution is to do something like the two last lines?
>
> If you manage I would be interested to see you solution. Also, if you
> manage to write that RDF and parse it again and dig out the code-value
> using the protege-owl API (I can do it using Jena), you would have
> answered a yet unanswered question of mine on the list.
>
> Cheers,
> /\/
>
> -------------------------------------------------------------------------
> To unsubscribe go to http://protege.stanford.edu/community/subscribe.html


--
Julia Dmitrieva

LIACS Office:  124
Phone:  +31 (0)71 – 5275777
E-Mail:  [hidden email]

Member of:  Imaging
Scientific Personnel

-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html
-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Julia Dmitrieva
Thanks Gilberto.

May be I am doing to difficult and
in place of creation of a new owl file
with ProtegeAPI I have to think about
writing an text processing tool.

Only what I want, is extract some part
of Thesaurus.owl, because the whole Thesaurus is to big
for my computer memory.
Indeed <code>IOOIOIO</code>
is not important for me.

The property has to be as you say
<protege:readOnly
rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
But I don't know how to create it.

I will just scip it.

Julia

Fragoso, Gilberto (NIH/NCI) [E] wrote:

> Julia,
>
> I can't give you any tips with the protege/owl API, but in your sample/test owl file you may have an error (or maybe it happened during copy-and-paste into the e-mail), the portion that reads
>
> <protege:readOnly
> <rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>
> should be
>
> <protege:readOnly
> rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>
> the rdf:datatype attribute is not preceeded by a '<' character.
>
> On another note, the annotation of the "code" datatype property with a "code" is acceptable OWL; we include it only because it's required for comparisons that we are performing with the Prompt plugin, otherwise we would have omitted it.  Of course, Protege doesn't have problems loading the file, but I'm afraid I can't tell you what API methods to use to process this section.  If it's any help, you could disregard the code of the "code" in your extracted subset.
>
> Regards,
> Gilberto
>

--
Julia Dmitrieva

LIACS Office:  124
Phone:  +31 (0)71 – 5275777
E-Mail:  [hidden email]

Member of:  Imaging
Scientific Personnel

-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Tania Tudorache
Julia,

the "protege:readOnly" property is a Datatype Annotation property that
can be attached to rdf properties (for example on "code"). In order to
get/set its value for a certain property, you must call the
get/setPropertyValue method. Below, is a code snippet showing you how
you can do that:

OWLModel owlModel = (OWLModel) kb;

//get the readOnly property
OWLDatatypeProperty readOnlyProp =
owlModel.getOWLDatatypeProperty("protege:readOnly");

//get the code property
OWLDatatypeProperty codeProp = owlModel.getOWLDatatypeProperty("code");

//get the value of  readOnly for property "code"
Object value = codeProp.getPropertyValue(readOnlyProp);

//set the value of "readOnly" for property "code" to true
codeProp.setPropertyValue(readOnlyProp, Boolean.TRUE);

You can find further documentation on how to use the ProtegeOWL API
here: http://protege.stanford.edu/plugins/owl/api/guide.html

Tania
     


Julia Dmitrieva wrote:

> Thanks Gilberto.
>
> May be I am doing to difficult and
> in place of creation of a new owl file
> with ProtegeAPI I have to think about
> writing an text processing tool.
>
> Only what I want, is extract some part
> of Thesaurus.owl, because the whole Thesaurus is to big
> for my computer memory.
> Indeed <code>IOOIOIO</code>
> is not important for me.
>
> The property has to be as you say
> <protege:readOnly
> rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>
> But I don't know how to create it.
>
> I will just scip it.
>
> Julia
>
> Fragoso, Gilberto (NIH/NCI) [E] wrote:
>
>> Julia,
>>
>> I can't give you any tips with the protege/owl API, but in your
>> sample/test owl file you may have an error (or maybe it happened
>> during copy-and-paste into the e-mail), the portion that reads
>>
>> <protege:readOnly
>> <rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>>
>>
>> should be
>>
>> <protege:readOnly
>> rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>>
>>
>> the rdf:datatype attribute is not preceeded by a '<' character.
>>
>> On another note, the annotation of the "code" datatype property with
>> a "code" is acceptable OWL; we include it only because it's required
>> for comparisons that we are performing with the Prompt plugin,
>> otherwise we would have omitted it.  Of course, Protege doesn't have
>> problems loading the file, but I'm afraid I can't tell you what API
>> methods to use to process this section.  If it's any help, you could
>> disregard the code of the "code" in your extracted subset.
>>
>> Regards,
>> Gilberto
>
>

-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Nikolaj Berntsen
Dear group,

I have a similar problem, perhaps I thoroughly misunderstand something,
any help would be greatly appreciated? The problem is reading a property
value when parsing RDF.

Simply stated I have a property value, 36, in the generated RDF below
which I would like to access. How can I do that?

I have created little java app to illustrate my problem:

/////////////// BEGIN JAVA APP
//////////////////////////////////////////////////////////////////
package com.mobilepeople.socialportal.domain.tests;

import java.io.ByteArrayOutputStream;
import java.io.StringReader;

import com.hp.hpl.jena.ontology.OntModel;

import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.jena.Jena;
import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;
import edu.stanford.smi.protegex.owl.model.OWLDatatypeProperty;
import edu.stanford.smi.protegex.owl.model.OWLIndividual;
import edu.stanford.smi.protegex.owl.model.OWLNamedClass;
import edu.stanford.smi.protegex.owl.model.RDFProperty;

public class GenericProtegeOwlTest {

    private static String rdf;
   
    public static void main(String[] args) throws Exception {
        GenericProtegeOwlTest test = new GenericProtegeOwlTest();
        test.testProtegeOwlGenericRDF();
        test.testJenaParseRDF();
    }

    public void testProtegeOwlGenericRDF() {
        JenaOWLModel spModel = ProtegeOWL.createJenaOWLModel();
       
        RDFProperty gender = spModel.createRDFProperty("gender");
        RDFProperty name = spModel.createRDFProperty("name");

        OWLDatatypeProperty age = spModel.createOWLDatatypeProperty("age");
        age.setPropertyValue(age, new Integer(35));

        OWLNamedClass profileDataClass =
spModel.createOWLNamedClass("ProfileData");
        OWLIndividual knbProfileDataIndividual =
profileDataClass.createOWLIndividual("knbProfileData");
       
        knbProfileDataIndividual.addPropertyValue(gender, "male");
        knbProfileDataIndividual.addPropertyValue(name,
spModel.createRDFSLiteral("nikolaj"));
        knbProfileDataIndividual.addPropertyValue(age, new Integer(36));
       
        rdf = rdfAsString(spModel.getOntModel());
        System.out.println( rdf );

    }

    public void testJenaParseRDF() throws Exception {
        JenaOWLModel model = ProtegeOWL.createJenaOWLModelFromReader(new
StringReader(rdf));
        for (Object cls : model.getUserDefinedRDFIndividuals(false)) {
            OWLIndividual owlClass = (OWLIndividual) cls;
            System.out.println("individual name: " + owlClass.getName());
            for (Object prop : owlClass.getRDFProperties()) {
                RDFProperty property = (RDFProperty) prop;
                System.out.println("property name: " + property.getName());
                System.out.println(property.getRDFType());
                System.out.println(property.getBrowserText());
                System.out.println(property.getPropertyValue(property));
               
System.out.println(property.getPropertyValueLiteral(property));
            }
        }
    }


    protected String rdfAsString(OntModel spModel) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Jena.dumpRDF(spModel,bos);
        return new String(bos.toByteArray());
    }

}

//////////////////////// END JAVA APP
///////////////////////////////////////////////////

which produces the following output:

<?xml version="1.0"?>
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns="http://www.owl-ontologies.com/unnamed.owl#"
  xml:base="http://www.owl-ontologies.com/unnamed.owl">
  <owl:Ontology rdf:about=""/>
  <owl:Class rdf:ID="ProfileData"/>
  <rdf:Property rdf:ID="gender"/>
  <rdf:Property rdf:ID="name"/>
  <owl:DatatypeProperty rdf:ID="age">
    <age rdf:datatype="http://www.w3.org/2001/XMLSchema#int">35</age>
  </owl:DatatypeProperty>
  <ProfileData rdf:ID="knbProfileData">
    <gender rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >male</gender>
    <age rdf:datatype="http://www.w3.org/2001/XMLSchema#int">36</age>
    <name rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >nikolaj</name>
  </ProfileData>
</rdf:RDF>

Loading triples
[ProtegeOWLParser] Completed triple loading after 40 ms
[TripleChangePostProcessor] Completed lists after 0 ms
[TripleChangePostProcessor] Completed anonymous classes after 10 ms
[TripleChangePostProcessor] Completed deprecated classes after 0 ms
[TripleChangePostProcessor] Completed properties after 30 ms
[TripleChangePostProcessor] Completed named classes after 0 ms
... Loading completed after 90 ms
individual name: knbProfileData
property name: rdf:type
null
rdf:type
null
null
property name: gender
Cls(rdf:Property, FrameID(0:9007 0))
gender
null
null
property name: name
Cls(rdf:Property, FrameID(0:9007 0))
name
null
null
property name: age
Cls(owl:DatatypeProperty, FrameID(0:9008 0))
age
35
35

Thanks,
/\/ikolaj

> Julia,
>
> the "protege:readOnly" property is a Datatype Annotation property that
> can be attached to rdf properties (for example on "code"). In order to
> get/set its value for a certain property, you must call the
> get/setPropertyValue method. Below, is a code snippet showing you how
> you can do that:
>
> OWLModel owlModel = (OWLModel) kb;
>
> //get the readOnly property
> OWLDatatypeProperty readOnlyProp =
> owlModel.getOWLDatatypeProperty("protege:readOnly");
>
> //get the code property
> OWLDatatypeProperty codeProp = owlModel.getOWLDatatypeProperty("code");
>
> //get the value of  readOnly for property "code"
> Object value = codeProp.getPropertyValue(readOnlyProp);
>
> //set the value of "readOnly" for property "code" to true
> codeProp.setPropertyValue(readOnlyProp, Boolean.TRUE);
>
> You can find further documentation on how to use the ProtegeOWL API
> here: http://protege.stanford.edu/plugins/owl/api/guide.html
>
> Tania
>    
>
> Julia Dmitrieva wrote:
>
>> Thanks Gilberto.
>>
>> May be I am doing to difficult and
>> in place of creation of a new owl file
>> with ProtegeAPI I have to think about
>> writing an text processing tool.
>>
>> Only what I want, is extract some part
>> of Thesaurus.owl, because the whole Thesaurus is to big
>> for my computer memory.
>> Indeed <code>IOOIOIO</code>
>> is not important for me.
>>
>> The property has to be as you say
>> <protege:readOnly
>> rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>>
>> But I don't know how to create it.
>>
>> I will just scip it.
>>
>> Julia
>>
>> Fragoso, Gilberto (NIH/NCI) [E] wrote:
>>
>>> Julia,
>>>
>>> I can't give you any tips with the protege/owl API, but in your
>>> sample/test owl file you may have an error (or maybe it happened
>>> during copy-and-paste into the e-mail), the portion that reads
>>>
>>> <protege:readOnly
>>> <rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>>>
>>>
>>> should be
>>>
>>> <protege:readOnly
>>> rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</protege:readOnly>
>>>
>>>
>>> the rdf:datatype attribute is not preceeded by a '<' character.
>>>
>>> On another note, the annotation of the "code" datatype property with
>>> a "code" is acceptable OWL; we include it only because it's required
>>> for comparisons that we are performing with the Prompt plugin,
>>> otherwise we would have omitted it.  Of course, Protege doesn't have
>>> problems loading the file, but I'm afraid I can't tell you what API
>>> methods to use to process this section.  If it's any help, you could
>>> disregard the code of the "code" in your extracted subset.
>>>
>>> Regards,
>>> Gilberto
>>

-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Julia Dmitrieva
Hello Nicolaj,
May be I have not good enough understood you question,
but I see that the file you get is also what you want?

May be you would like to add the properties to the definition of the
class, because I see that you add the properties only to the individual,
you can do it at the same manner as you add the properties
to the individuals:

OWLNamedClass personClass = owlModel.createOWLNamedClass("Person");
         personClass.addLabel("NicePerson",null);
         OWLDatatypeProperty codeProp =
owlModel.createOWLDatatypeProperty("code");
         RDFSDatatype dataType;
      dataType =
owlModel.getRDFSDatatypeByURI("http://www.w3.org/2001/XMLSchema#strintg");
      codeProp.setRange(dataType);
/***********add code property to the person class******************/
      personClass.setPropertyValue(codeProp, "hahahahaha");
  OWLDatatypeProperty ageProperty =
owlModel.createOWLDatatypeProperty("age");

        // another manner to create range type for dataype property
         dataType =
owlModel.getRDFSDatatypeByURI("http://www.w3.org/2001/XMLSchema#int");
      ageProperty.setRange(dataType);
         ageProperty.setDomain(personClass);
         ageProperty.setRDFType( owlModel.getOWLAnnotationPropertyClass());
         OWLObjectProperty childrenProperty =
owlModel.createOWLObjectProperty("children");
         childrenProperty.setRange(personClass);
         childrenProperty.setDomain(personClass);

         RDFProperty name = owlModel.createRDFProperty("name");
         childrenProperty.addPropertyValue(name, "tralala");
/****************Now add the children propertu to the person class*****/
         personClass.addPropertyValue(childrenProperty, childrenProperty);

         RDFIndividual darwin = personClass.createRDFIndividual("Darwin");
         darwin.setPropertyValue(ageProperty, new Integer(0));
         RDFIndividual holgi = personClass.createRDFIndividual("Holger");
         holgi.setPropertyValue(childrenProperty, darwin);
         holgi.setPropertyValue(ageProperty, new Integer(33));


         saveOWLModel();
Nikolaj Berntsen wrote:

> Dear group,
>
> I have a similar problem, perhaps I thoroughly misunderstand something,
> any help would be greatly appreciated? The problem is reading a property
> value when parsing RDF.
>
> Simply stated I have a property value, 36, in the generated RDF below
> which I would like to access. How can I do that?
>
> I have created little java app to illustrate my problem:
>
> /////////////// BEGIN JAVA APP
> //////////////////////////////////////////////////////////////////
> package com.mobilepeople.socialportal.domain.tests;
>
> import java.io.ByteArrayOutputStream;
> import java.io.StringReader;
>
> import com.hp.hpl.jena.ontology.OntModel;
>
> import edu.stanford.smi.protegex.owl.ProtegeOWL;
> import edu.stanford.smi.protegex.owl.jena.Jena;
> import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;
> import edu.stanford.smi.protegex.owl.model.OWLDatatypeProperty;
> import edu.stanford.smi.protegex.owl.model.OWLIndividual;
> import edu.stanford.smi.protegex.owl.model.OWLNamedClass;
> import edu.stanford.smi.protegex.owl.model.RDFProperty;
>
> public class GenericProtegeOwlTest {
>
>     private static String rdf;
>    
>     public static void main(String[] args) throws Exception {
>         GenericProtegeOwlTest test = new GenericProtegeOwlTest();
>         test.testProtegeOwlGenericRDF();
>         test.testJenaParseRDF();
>     }
>
>     public void testProtegeOwlGenericRDF() {
>         JenaOWLModel spModel = ProtegeOWL.createJenaOWLModel();
>        
>         RDFProperty gender = spModel.createRDFProperty("gender");
>         RDFProperty name = spModel.createRDFProperty("name");
>
>         OWLDatatypeProperty age = spModel.createOWLDatatypeProperty("age");
>         age.setPropertyValue(age, new Integer(35));
>
>         OWLNamedClass profileDataClass =
> spModel.createOWLNamedClass("ProfileData");
>         OWLIndividual knbProfileDataIndividual =
> profileDataClass.createOWLIndividual("knbProfileData");
>        
>         knbProfileDataIndividual.addPropertyValue(gender, "male");
>         knbProfileDataIndividual.addPropertyValue(name,
> spModel.createRDFSLiteral("nikolaj"));
>         knbProfileDataIndividual.addPropertyValue(age, new Integer(36));
>        
>         rdf = rdfAsString(spModel.getOntModel());
>         System.out.println( rdf );
>
>     }
>
>     public void testJenaParseRDF() throws Exception {
>         JenaOWLModel model = ProtegeOWL.createJenaOWLModelFromReader(new
> StringReader(rdf));
>         for (Object cls : model.getUserDefinedRDFIndividuals(false)) {
>             OWLIndividual owlClass = (OWLIndividual) cls;
>             System.out.println("individual name: " + owlClass.getName());
>             for (Object prop : owlClass.getRDFProperties()) {
>                 RDFProperty property = (RDFProperty) prop;
>                 System.out.println("property name: " + property.getName());
>                 System.out.println(property.getRDFType());
>                 System.out.println(property.getBrowserText());
>                 System.out.println(property.getPropertyValue(property));
>                
> System.out.println(property.getPropertyValueLiteral(property));
>             }
>         }
>     }
>
>
>     protected String rdfAsString(OntModel spModel) {
>         ByteArrayOutputStream bos = new ByteArrayOutputStream();
>         Jena.dumpRDF(spModel,bos);
>         return new String(bos.toByteArray());
>     }
>
> }
>
> //////////////////////// END JAVA APP
> ///////////////////////////////////////////////////
>
> which produces the following output:
>
> <?xml version="1.0"?>
> <rdf:RDF
>     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
>     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
>     xmlns:owl="http://www.w3.org/2002/07/owl#"
>     xmlns="http://www.owl-ontologies.com/unnamed.owl#"
>   xml:base="http://www.owl-ontologies.com/unnamed.owl">
>   <owl:Ontology rdf:about=""/>
>   <owl:Class rdf:ID="ProfileData"/>
>   <rdf:Property rdf:ID="gender"/>
>   <rdf:Property rdf:ID="name"/>
>   <owl:DatatypeProperty rdf:ID="age">
>     <age rdf:datatype="http://www.w3.org/2001/XMLSchema#int">35</age>
>   </owl:DatatypeProperty>
>   <ProfileData rdf:ID="knbProfileData">
>     <gender rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>     >male</gender>
>     <age rdf:datatype="http://www.w3.org/2001/XMLSchema#int">36</age>
>     <name rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>     >nikolaj</name>
>   </ProfileData>
> </rdf:RDF>
>
> Loading triples
> [ProtegeOWLParser] Completed triple loading after 40 ms
> [TripleChangePostProcessor] Completed lists after 0 ms
> [TripleChangePostProcessor] Completed anonymous classes after 10 ms
> [TripleChangePostProcessor] Completed deprecated classes after 0 ms
> [TripleChangePostProcessor] Completed properties after 30 ms
> [TripleChangePostProcessor] Completed named classes after 0 ms
> ... Loading completed after 90 ms
> individual name: knbProfileData
> property name: rdf:type
> null
> rdf:type
> null
> null
> property name: gender
> Cls(rdf:Property, FrameID(0:9007 0))
> gender
> null
> null
> property name: name
> Cls(rdf:Property, FrameID(0:9007 0))
> name
> null
> null
> property name: age
> Cls(owl:DatatypeProperty, FrameID(0:9008 0))
> age
> 35
> 35
>
> Thanks,
> /\/ikolaj

Julia Dmitrieva

LIACS Office:  124
Phone:  +31 (0)71 – 5275777
E-Mail:  [hidden email]

Member of:  Imaging
Scientific Personnel

-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Julia Dmitrieva
In reply to this post by Tania Tudorache
Thanks Tania,

but I am not completely rid of my propblem:
I have created the protege namespace and then
I ask to give me the needed property (protege:readOnly), but
somewhere I do it wrong and get the error.

Here is my code:

// first set the proptege namespace
owlModel.getNamespaceManager().setPrefix("http://protege.stanford.edu/plugins/owl/protege#","protege");
// now, I ask for the property
OWLDatatypeProperty readOnlyProp =
owlModel.getOWLDatatypeProperty("protege:readOnly");
// And now I try to add this value to this property
codeProp.setPropertyValue(readOnlyProp, Boolean.TRUE);

and here it goes wrong with the following error:

Exception in thread "main" java.lang.NullPointerException
        at
edu.stanford.smi.protege.model.DefaultKnowledgeBase.setDirectOwnSlotValues(Unknown
Source)
        at
edu.stanford.smi.protege.model.DefaultKnowledgeBase.setOwnSlotValues(Unknown
Source)
        at
edu.stanford.smi.protegex.owl.model.impl.OWLUtil.setPropertyValue(Unknown
Source)
        at
edu.stanford.smi.protegex.owl.model.impl.DefaultRDFProperty.setPropertyValue(Unknown
Source)
        at testCreator.OWLCreator.main(OWLCreator.java:29)

Tania Tudorache wrote:

> Julia,
>
> the "protege:readOnly" property is a Datatype Annotation property that
> can be attached to rdf properties (for example on "code"). In order to
> get/set its value for a certain property, you must call the
> get/setPropertyValue method. Below, is a code snippet showing you how
> you can do that:
>
> OWLModel owlModel = (OWLModel) kb;
>
> //get the readOnly property
> OWLDatatypeProperty readOnlyProp =
> owlModel.getOWLDatatypeProperty("protege:readOnly");
>
> //get the code property
> OWLDatatypeProperty codeProp = owlModel.getOWLDatatypeProperty("code");
>
> //get the value of  readOnly for property "code"
> Object value = codeProp.getPropertyValue(readOnlyProp);
>
> //set the value of "readOnly" for property "code" to true
> codeProp.setPropertyValue(readOnlyProp, Boolean.TRUE);
>
> You can find further documentation on how to use the ProtegeOWL API
> here: http://protege.stanford.edu/plugins/owl/api/guide.html
>
> Tania


--
Julia Dmitrieva

LIACS Office:  124
Phone:  +31 (0)71 – 5275777
E-Mail:  [hidden email]

Member of:  Imaging
Scientific Personnel

-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Nikolaj Berntsen
In reply to this post by Julia Dmitrieva

> May be I have not good enough understood you question,
> but I see that the file you get is also what you want?

The file I generate is OK with me. My problem is in parsing it [ see the
method testJenaParseRDF() ]. If you look in the generated RDF there is a
value "36" for my age. I cannot get that value using the jena api. THAT
is my problem. Do you have a clue for that?

> May be you would like to add the properties to the definition of the
> class, because I see that you add the properties only to the individual,
> you can do it at the same manner as you add the properties
> to the individuals:

That might be a valid point, but since I cannot extract the data from
RDF yet, I am not pursuing refining way I write RDF yet.

What I would prefer would be to generate java classes from my owl
ontology, but the generated code does not work for me, I get a
NullPointerException. I have tried to ask about it but no answer
hitherto. I may try and repost that question with a small example later.

Thanks,
/\/

>
> OWLNamedClass personClass = owlModel.createOWLNamedClass("Person");
>         personClass.addLabel("NicePerson",null);
>         OWLDatatypeProperty codeProp =
> owlModel.createOWLDatatypeProperty("code");
>         RDFSDatatype dataType;
>         dataType =
> owlModel.getRDFSDatatypeByURI("http://www.w3.org/2001/XMLSchema#strintg");
>
>         codeProp.setRange(dataType);
> /***********add code property to the person class******************/
>         personClass.setPropertyValue(codeProp, "hahahahaha");
>  OWLDatatypeProperty ageProperty =
> owlModel.createOWLDatatypeProperty("age");
>
>        // another manner to create range type for dataype property
>         dataType =
> owlModel.getRDFSDatatypeByURI("http://www.w3.org/2001/XMLSchema#int");
>         ageProperty.setRange(dataType);
>         ageProperty.setDomain(personClass);
>         ageProperty.setRDFType(
> owlModel.getOWLAnnotationPropertyClass());
>         OWLObjectProperty childrenProperty =
> owlModel.createOWLObjectProperty("children");
>         childrenProperty.setRange(personClass);
>         childrenProperty.setDomain(personClass);
>
>         RDFProperty name = owlModel.createRDFProperty("name");
>         childrenProperty.addPropertyValue(name, "tralala");
> /****************Now add the children propertu to the person class*****/
>         personClass.addPropertyValue(childrenProperty, childrenProperty);
>
>         RDFIndividual darwin = personClass.createRDFIndividual("Darwin");
>         darwin.setPropertyValue(ageProperty, new Integer(0));
>         RDFIndividual holgi = personClass.createRDFIndividual("Holger");
>         holgi.setPropertyValue(childrenProperty, darwin);
>         holgi.setPropertyValue(ageProperty, new Integer(33));
>
>
>         saveOWLModel();
> Nikolaj Berntsen wrote:
>
>> Dear group,
>>
>> I have a similar problem, perhaps I thoroughly misunderstand something,
>> any help would be greatly appreciated? The problem is reading a property
>> value when parsing RDF.
>>
>> Simply stated I have a property value, 36, in the generated RDF below
>> which I would like to access. How can I do that?
>>
>> I have created little java app to illustrate my problem:
>>
>> /////////////// BEGIN JAVA APP
>> //////////////////////////////////////////////////////////////////
>> package com.mobilepeople.socialportal.domain.tests;
>>
>> import java.io.ByteArrayOutputStream;
>> import java.io.StringReader;
>>
>> import com.hp.hpl.jena.ontology.OntModel;
>>
>> import edu.stanford.smi.protegex.owl.ProtegeOWL;
>> import edu.stanford.smi.protegex.owl.jena.Jena;
>> import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;
>> import edu.stanford.smi.protegex.owl.model.OWLDatatypeProperty;
>> import edu.stanford.smi.protegex.owl.model.OWLIndividual;
>> import edu.stanford.smi.protegex.owl.model.OWLNamedClass;
>> import edu.stanford.smi.protegex.owl.model.RDFProperty;
>>
>> public class GenericProtegeOwlTest {
>>
>>     private static String rdf;
>>        public static void main(String[] args) throws Exception {
>>         GenericProtegeOwlTest test = new GenericProtegeOwlTest();
>>         test.testProtegeOwlGenericRDF();
>>         test.testJenaParseRDF();
>>     }
>>
>>     public void testProtegeOwlGenericRDF() {
>>         JenaOWLModel spModel = ProtegeOWL.createJenaOWLModel();
>>                RDFProperty gender = spModel.createRDFProperty("gender");
>>         RDFProperty name = spModel.createRDFProperty("name");
>>
>>         OWLDatatypeProperty age =
>> spModel.createOWLDatatypeProperty("age");
>>         age.setPropertyValue(age, new Integer(35));
>>
>>         OWLNamedClass profileDataClass =
>> spModel.createOWLNamedClass("ProfileData");
>>         OWLIndividual knbProfileDataIndividual =
>> profileDataClass.createOWLIndividual("knbProfileData");
>>                knbProfileDataIndividual.addPropertyValue(gender,
>> "male");
>>         knbProfileDataIndividual.addPropertyValue(name,
>> spModel.createRDFSLiteral("nikolaj"));
>>         knbProfileDataIndividual.addPropertyValue(age, new Integer(36));
>>                rdf = rdfAsString(spModel.getOntModel());
>>         System.out.println( rdf );
>>
>>     }
>>
>>     public void testJenaParseRDF() throws Exception {
>>         JenaOWLModel model = ProtegeOWL.createJenaOWLModelFromReader(new
>> StringReader(rdf));
>>         for (Object cls : model.getUserDefinedRDFIndividuals(false)) {
>>             OWLIndividual owlClass = (OWLIndividual) cls;
>>             System.out.println("individual name: " +
>> owlClass.getName());
>>             for (Object prop : owlClass.getRDFProperties()) {
>>                 RDFProperty property = (RDFProperty) prop;
>>                 System.out.println("property name: " +
>> property.getName());
>>                 System.out.println(property.getRDFType());
>>                 System.out.println(property.getBrowserText());
>>                 System.out.println(property.getPropertyValue(property));
>>              
>> System.out.println(property.getPropertyValueLiteral(property));
>>             }
>>         }
>>     }
>>
>>
>>     protected String rdfAsString(OntModel spModel) {
>>         ByteArrayOutputStream bos = new ByteArrayOutputStream();
>>         Jena.dumpRDF(spModel,bos);
>>         return new String(bos.toByteArray());
>>     }
>>
>> }
>>
>> //////////////////////// END JAVA APP
>> ///////////////////////////////////////////////////
>>
>> which produces the following output:
>>
>> <?xml version="1.0"?>
>> <rdf:RDF
>>     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>>     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
>>     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
>>     xmlns:owl="http://www.w3.org/2002/07/owl#"
>>     xmlns="http://www.owl-ontologies.com/unnamed.owl#"
>>   xml:base="http://www.owl-ontologies.com/unnamed.owl">
>>   <owl:Ontology rdf:about=""/>
>>   <owl:Class rdf:ID="ProfileData"/>
>>   <rdf:Property rdf:ID="gender"/>
>>   <rdf:Property rdf:ID="name"/>
>>   <owl:DatatypeProperty rdf:ID="age">
>>     <age rdf:datatype="http://www.w3.org/2001/XMLSchema#int">35</age>
>>   </owl:DatatypeProperty>
>>   <ProfileData rdf:ID="knbProfileData">
>>     <gender rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>>     >male</gender>
>>     <age rdf:datatype="http://www.w3.org/2001/XMLSchema#int">36</age>
>>     <name rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>>     >nikolaj</name>
>>   </ProfileData>
>> </rdf:RDF>
>>
>> Loading triples
>> [ProtegeOWLParser] Completed triple loading after 40 ms
>> [TripleChangePostProcessor] Completed lists after 0 ms
>> [TripleChangePostProcessor] Completed anonymous classes after 10 ms
>> [TripleChangePostProcessor] Completed deprecated classes after 0 ms
>> [TripleChangePostProcessor] Completed properties after 30 ms
>> [TripleChangePostProcessor] Completed named classes after 0 ms
>> ... Loading completed after 90 ms
>> individual name: knbProfileData
>> property name: rdf:type
>> null
>> rdf:type
>> null
>> null
>> property name: gender
>> Cls(rdf:Property, FrameID(0:9007 0))
>> gender
>> null
>> null
>> property name: name
>> Cls(rdf:Property, FrameID(0:9007 0))
>> name
>> null
>> null
>> property name: age
>> Cls(owl:DatatypeProperty, FrameID(0:9008 0))
>> age
>> 35
>> 35
>>
>>
>
-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Julia Dmitrieva
Hi, Nikolaj
I have changed you code and you can get now the needed properties:

/**********************************/
package testCreator;


import java.io.ByteArrayOutputStream;
import java.io.StringReader;

  import com.hp.hpl.jena.ontology.OntModel;
  import java.util.Collection;
  import java.util.Iterator;
  import edu.stanford.smi.protegex.owl.ProtegeOWL;
  import edu.stanford.smi.protegex.owl.jena.Jena;
  import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;
  import edu.stanford.smi.protegex.owl.model.OWLDatatypeProperty;
  import edu.stanford.smi.protegex.owl.model.OWLIndividual;
  import edu.stanford.smi.protegex.owl.model.OWLNamedClass;
  import edu.stanford.smi.protegex.owl.model.RDFProperty;
  import edu.stanford.smi.protegex.owl.model.OWLProperty;
  public class GenericProtegeOwlTest {

      private static String rdf;
         public static void main(String[] args) throws Exception {
          GenericProtegeOwlTest test = new GenericProtegeOwlTest();
          test.testProtegeOwlGenericRDF();
          test.testJenaParseRDF();
      }

      public void testProtegeOwlGenericRDF() {
          JenaOWLModel spModel = ProtegeOWL.createJenaOWLModel();
                 RDFProperty gender = spModel.createRDFProperty("gender");
          RDFProperty name = spModel.createRDFProperty("name");

          OWLDatatypeProperty age =
  spModel.createOWLDatatypeProperty("age");
         age.setPropertyValue(age, new Integer(35));

          OWLNamedClass profileDataClass =
  spModel.createOWLNamedClass("ProfileData");

          OWLIndividual knbProfileDataIndividual =
  profileDataClass.createOWLIndividual("knbProfileData");
                 knbProfileDataIndividual.addPropertyValue(gender,
  "male");
          knbProfileDataIndividual.addPropertyValue(name,
  spModel.createRDFSLiteral("nikolaj"));
          knbProfileDataIndividual.addPropertyValue(age, new Integer(36));
                 rdf = rdfAsString(spModel.getOntModel());
          System.out.println( rdf );

      }

      public void testJenaParseRDF() throws Exception {
          JenaOWLModel model = ProtegeOWL.createJenaOWLModelFromReader(new
  StringReader(rdf));
          for (Object cls : model.getUserDefinedRDFIndividuals(false)) {
              OWLIndividual owlClass = (OWLIndividual) cls;
              System.out.println("individual name: " + owlClass.getName());



              for (Object prop : owlClass.getRDFProperties()) {
                  RDFProperty property = (RDFProperty) prop;
                  Collection propValues =
owlClass.getPropertyValues(property);
                  System.out.println("property name: " +
property.getName());
                  for(Iterator iter = propValues.iterator();
iter.hasNext() ;){
                 
                  System.out.println(iter.next());
                 
                  }

                  //System.out.println(property.getRDFType());
              //System.out.println(property.getBrowserText());
              //System.out.println(property.getPropertyValue(property));
             
//System.out.println(property.getPropertyValueLiteral(property));

              }

          }
      }


      protected String rdfAsString(OntModel spModel) {
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          Jena.dumpRDF(spModel,bos);
          return new String(bos.toByteArray());
      }

  }

/**********************************/

output:

<?xml version="1.0"?>
<rdf:RDF
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns="http://www.owl-ontologies.com/unnamed.owl#"
   xml:base="http://www.owl-ontologies.com/unnamed.owl">
   <owl:Ontology rdf:about=""/>
   <owl:Class rdf:ID="ProfileData"/>
   <rdf:Property rdf:ID="gender"/>
   <rdf:Property rdf:ID="name"/>
   <owl:DatatypeProperty rdf:ID="age">
     <age rdf:datatype="http://www.w3.org/2001/XMLSchema#int">35</age>
   </owl:DatatypeProperty>
   <ProfileData rdf:ID="knbProfileData">
     <gender rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
     >male</gender>
     <age rdf:datatype="http://www.w3.org/2001/XMLSchema#int">36</age>
     <name rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
     >nikolaj</name>
   </ProfileData>
</rdf:RDF>

[ProtegeOWLParser] Completed triple loading after 32 ms
[TripleChangePostProcessor] Completed lists after 0 ms
[TripleChangePostProcessor] Completed anonymous classes after 15 ms
[TripleChangePostProcessor] Completed deprecated classes after 0 ms
[TripleChangePostProcessor] Completed properties after 0 ms
[TripleChangePostProcessor] Completed named classes after 0 ms
... Loading completed after 47 ms
individual name: knbProfileData
property name: rdf:type
Cls(ProfileData, FrameID(1:29921 1))
property name: gender
male
property name: name
nikolaj
property name: age
36

--
Julia Dmitrieva

LIACS Office:  124
Phone:  +31 (0)71 – 5275777
E-Mail:  [hidden email]

Member of:  Imaging
Scientific Personnel

-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

[protege-owl] Re: help on owl property creation needed

Tania Tudorache
In reply to this post by Julia Dmitrieva
Julia,

Did you  import the protege ontology in your ontology? If not, then you
will not have the "protege:readOnly" property defined in your ontology,
since it is only defined in the protege ontology.

After the second call (OWLDatatypeProperty readOnlyProp = ...), test
whether the readOnlyProp is null and call the third line of code, only
if the property if not null.

Another equivalent way of getting the protege:readonly property is with
the following call:

OWLDatatypeProperty readOnlyProp = owlModel.getProtegeReadOnlyProperty();

But! this will also return null, if you did not import the protege ontology.

And, the first call
(owlModel.getNamespaceManager().setPrefix("http://protege.stanford.edu/plugins/owl/protege#","protege");
) is not necessary, actually it may even be harmfull :) So, it is better
not to do it.

Tania


Julia Dmitrieva wrote:

> Thanks Tania,
>
> but I am not completely rid of my propblem:
> I have created the protege namespace and then
> I ask to give me the needed property (protege:readOnly), but
> somewhere I do it wrong and get the error.
>
> Here is my code:
>
> // first set the proptege namespace
> owlModel.getNamespaceManager().setPrefix("http://protege.stanford.edu/plugins/owl/protege#","protege");
>
> // now, I ask for the property
> OWLDatatypeProperty readOnlyProp =
> owlModel.getOWLDatatypeProperty("protege:readOnly");
> // And now I try to add this value to this property
> codeProp.setPropertyValue(readOnlyProp, Boolean.TRUE);
>
> and here it goes wrong with the following error:
>
> Exception in thread "main" java.lang.NullPointerException
>     at
> edu.stanford.smi.protege.model.DefaultKnowledgeBase.setDirectOwnSlotValues(Unknown
> Source)
>     at
> edu.stanford.smi.protege.model.DefaultKnowledgeBase.setOwnSlotValues(Unknown
> Source)
>     at
> edu.stanford.smi.protegex.owl.model.impl.OWLUtil.setPropertyValue(Unknown
> Source)
>     at
> edu.stanford.smi.protegex.owl.model.impl.DefaultRDFProperty.setPropertyValue(Unknown
> Source)
>     at testCreator.OWLCreator.main(OWLCreator.java:29)
>
> Tania Tudorache wrote:
>
>> Julia,
>>
>> the "protege:readOnly" property is a Datatype Annotation property
>> that can be attached to rdf properties (for example on "code"). In
>> order to get/set its value for a certain property, you must call the
>> get/setPropertyValue method. Below, is a code snippet showing you how
>> you can do that:
>>
>> OWLModel owlModel = (OWLModel) kb;
>>
>> //get the readOnly property
>> OWLDatatypeProperty readOnlyProp =
>> owlModel.getOWLDatatypeProperty("protege:readOnly");
>>
>> //get the code property
>> OWLDatatypeProperty codeProp = owlModel.getOWLDatatypeProperty("code");
>>
>> //get the value of  readOnly for property "code"
>> Object value = codeProp.getPropertyValue(readOnlyProp);
>>
>> //set the value of "readOnly" for property "code" to true
>> codeProp.setPropertyValue(readOnlyProp, Boolean.TRUE);
>>
>> You can find further documentation on how to use the ProtegeOWL API
>> here: http://protege.stanford.edu/plugins/owl/api/guide.html
>>
>> Tania
>
>
>

-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html