You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by 锐光刘 <ti...@gmail.com> on 2012/02/25 14:20:12 UTC

How to create an instance with the given information ?

I am doing a project in which I have to create ontology with given
information parsed from another original OWL file.However, there is a
problem about the instance creation confusing me for a long time,so I list
the steps of my program here hoping the problems can be solved ,thanks
gracefully firstly.

Now ,it's the routine below,

1.get the information from an instance which belonging to an class
(OntClass)RawClass,
      Firstly,using API RawClass.listInstances() and get an
ExtendedIterator<OntResource>.If RawInstance is one element of this
iterator, I use API  RawInstance.listProperties() to get the detailed
information of the instance.Now I get a StmtIterator with statements in it
,which all belong to RawInstantce.
If I have the information parsed such as ,

   RawClass.toString()=http://www.geneontology.org/formats/oboInOwl#Subset
   (Data below is parsed from statements of instance,in the real process
the statements are more than one,just take one for example)
   Suject of RawInstance = http://purl.obolibrary.org/obo/IAO_0000224
   Predicate of RawInstance = http://purl.obolibrary.org/obo/IAO_0000117
   Object of RawInstance = PERSON: Alan Ruttenberg@en
   Type of Object is Literal

2.create an instance with the given information above and add it to the
OntModel RawModel(I think problems are in this step ,because I am not clear
how to achieve it)

     Individual NewSubject = RawModel.createIndividual("
http://purl.obolibrary.org/obo/IAO_0000224", RawModel.createResource("
http://www.geneontology.org/formats/oboInOwl#Subset"));
     Property NewProperty = RawModel.createProperty("
http://purl.obolibrary.org/obo/IAO_0000117");
     Literal NewObject = RawModel.createLiteral("PERSON: Alan Ruttenberg@en
");
     RawModel.add(NewSubject, NewProperty, NewObject);


My aim is to create an instance belonging to  (
http://www.geneontology.org/formats/oboInOwl#Subset  )  and than add it to
RawModel ,but it seems doesn't work ,since the RawModel haven't contain any
information about the new created instance . Could you tell me how to
achieve my aim?  Thanks !


Thanks sincerely.

Re: How to create an instance with the given information ?

Posted by Dave Reynolds <da...@gmail.com>.
On 25/02/12 13:20, 锐光刘 wrote:
> I am doing a project in which I have to create ontology with given
> information parsed from another original OWL file.However, there is a
> problem about the instance creation confusing me for a long time,so I list
> the steps of my program here hoping the problems can be solved ,thanks
> gracefully firstly.
>
> Now ,it's the routine below,
>
> 1.get the information from an instance which belonging to an class
> (OntClass)RawClass,
>        Firstly,using API RawClass.listInstances() and get an
> ExtendedIterator<OntResource>.If RawInstance is one element of this
> iterator, I use API  RawInstance.listProperties() to get the detailed
> information of the instance.Now I get a StmtIterator with statements in it
> ,which all belong to RawInstantce.
> If I have the information parsed such as ,
>
>     RawClass.toString()=http://www.geneontology.org/formats/oboInOwl#Subset
>     (Data below is parsed from statements of instance,in the real process
> the statements are more than one,just take one for example)
>     Suject of RawInstance = http://purl.obolibrary.org/obo/IAO_0000224
>     Predicate of RawInstance = http://purl.obolibrary.org/obo/IAO_0000117
>     Object of RawInstance = PERSON: Alan Ruttenberg@en
>     Type of Object is Literal
>
> 2.create an instance with the given information above and add it to the
> OntModel RawModel(I think problems are in this step ,because I am not clear
> how to achieve it)
>
>       Individual NewSubject = RawModel.createIndividual("
> http://purl.obolibrary.org/obo/IAO_0000224", RawModel.createResource("
> http://www.geneontology.org/formats/oboInOwl#Subset"));
>       Property NewProperty = RawModel.createProperty("
> http://purl.obolibrary.org/obo/IAO_0000117");
>       Literal NewObject = RawModel.createLiteral("PERSON: Alan Ruttenberg@en
> ");
>       RawModel.add(NewSubject, NewProperty, NewObject);

That is just putting in nearly the same information that's already in 
there so you won't see much change.

> My aim is to create an instance belonging to  (
> http://www.geneontology.org/formats/oboInOwl#Subset  )  and than add it to
> RawModel ,but it seems doesn't work ,since the RawModel haven't contain any
> information about the new created instance . Could you tell me how to
> achieve my aim?  Thanks !

Presumably you meant to create some different individual from the one 
that was already in there.

BTW addProperty/addLiteral is slightly easier, see the javadoc for 
Resource (Individual is a subclass of Resource):

    Property p = 
RawModel.createProperty("http://purl.obolibrary.org/obo/IAO_0000117");
    Individual subject
       = RawModel.createIndividual("http://mynamespace/newsubject")
                 .appProperty(p, "my new information");

Dave