Retrieving String of Data Property for an Individual

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

Retrieving String of Data Property for an Individual

tmm1012
I have, what I think should be, a rather easy question, but I am stumped.

I have followed the examples given on the OWL API website (http://owlapi.sourceforge.net/documentation.html), particular the example of interacting with a reasoner (http://owlapi.svn.sourceforge.net/viewvc/owlapi/v3/trunk/examples/src/main/java/org/coode/owlapi/examples/Example8.java?view=markup).  I have essentially followed the Example8.java for my situation, but I need to retrieve a data property from an individual.

I simply need to get the value and store it in a String so I can work with it.  My code is essentially the same as that Example, where the individuals in question are being stored in a NodeSet<OWLNamedIndividual> individualsNodeSet, which is then flattened into Set<OWLNamedIndividual> individuals.

The example gives a for loop to print out each individual, which works for me, but I want to extract a particular data property (hasDoseVolume) from the individual.  Could someone please help me with this?  I feel like it should be ind.getDataPropertyValues, but this returns an OWLLiteral.  Is there a way to just extract the value into a string?

_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving String of Data Property for an Individual

Timothy Redmond

I think I see two questions here.  First you are asking about the relationship between the OWL Literals and the strings that you really want.  Second there is an implied question about when to use a reasoner and when to look at the asserted statements.

I feel like it should be ind.getDataPropertyValues, but this returns an OWLLiteral.  Is there a way to just extract the value into a string?

A quick answer is that I suspect that the OWLLiteral.getLiteral() method will return the right thing when it is the appropriate thing to do.  It is interesting that this class doesn't have a parseString() method. 

But there is a bit more to this.  For example, it might be worth checking that the OWLLiteral returned represents a string rather than something else like a float.

The OWLLiteral class is a combination of a datatype and a string representing the lexical representation of a data value.  The datatype defines a map from strings to data values.  So for instance the OWLLiteral with a lexical string of "123" and a datatype xsd:int represents the integer 123.

So the obvious thing to do would be to check that the OWLLiteral is supposed to represent a string value and then - if so - grab the string.  The obvious check to see if the OWLLiteral is supposed to represent a string would be to only accept OWLLiteral objects that are either
  1. PlainLiterals whose language is null or
  2. OWLLiterals with a datatype of xsd:string.
This is easy but you should be aware that such a check is incomplete.  For example the xsd:token, xsd:Name and xsd:NCName datatypes also have a value space of strings.  But these and other such data types are considerably rarer and for the purposes of your code the above might be sufficient.

You should be warned that if you look at datatypes closer the PlainLiteral datatype is weird.  There are several conflicting specifications about it - depending on what layer of specification you are looking at.   Indeed the OWLLiteralImpl implementation doesn't cleanly map to the specifications.  I think that this happened because the PlainLiteral was grafted into the data type specifications after it had been around for a while and used in a particular way.

I feel like it should be ind.getDataPropertyValues

You started by giving an example involving a reasoner but this call only retrieves the asserted values.  You use a reasoner to get all the values that can be deduced.  The reasoner call in this case is

OWLReasoner.getDataPropertyValues(OWLNamedIndividual, OWLDataProperty)

Now I did say that the using a reasoner will get all the values that can be deduced.  Unfortunately this example doesn't meet that criteria because the specification of this method says "Note that the results are not guaranteed to be complete for this method".  So the reasoner does as much deduction as it can and then returns those values.  It turns out that calculating all the possible data values that can be deduced is hard.  This is an exception though - usually the reasoner calls return everything that can be deduced.

The other method (ind.getDataPropertyValues) will only return those values that are explicitly stated in the ontology.

-Timothy



On 05/11/2011 02:46 PM, Tommy Minta wrote:
I have, what I think should be, a rather easy question, but I am stumped.

I have followed the examples given on the OWL API website (http://owlapi.sourceforge.net/documentation.html), particular the example of interacting with a reasoner (http://owlapi.svn.sourceforge.net/viewvc/owlapi/v3/trunk/examples/src/main/java/org/coode/owlapi/examples/Example8.java?view=markup).  I have essentially followed the Example8.java for my situation, but I need to retrieve a data property from an individual.

I simply need to get the value and store it in a String so I can work with it.  My code is essentially the same as that Example, where the individuals in question are being stored in a NodeSet<OWLNamedIndividual> individualsNodeSet, which is then flattened into Set<OWLNamedIndividual> individuals.

The example gives a for loop to print out each individual, which works for me, but I want to extract a particular data property (hasDoseVolume) from the individual.  Could someone please help me with this?  I feel like it should be ind.getDataPropertyValues, but this returns an OWLLiteral.  Is there a way to just extract the value into a string?

_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03


_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving String of Data Property for an Individual

tmm1012
In reply to this post by tmm1012
Timothy,

Thank you very much for your quick response.  I do understand the considerations - in this case, I do know for sure that the data being stored in the data property will be a string.  For now, I am just trying to make sure I am accessing the OWLLiteral correctly by outputting the literal that was obtained (i.e. the I have tried the following code:

   OWLNamedIndividual theDVInd = factory.getOWLNamedIndividual(IRI.create(baseURL + "#sampleIndividual"));


   PrefixManager pm = new DefaultPrefixManager("http://www.semanticweb.org/ontologies/2011/1/RTGO.owl#");

   OWLDataProperty hasDoseVolume = factory.getOWLDataProperty(":hasDoseVolume", pm);

    

   Set<OWLLiteral> literals = theDVInd.getDataPropertyValues(hasDoseVolume, rtgoOntology);

    

   for(OWLLiteral lit : literals)
   {
    String theDataProperty = lit.getLiteral();
System.out.println("LITERAL:   " + theDataProperty);
   }


But unfortunately, I do not get any output.  I know that sampleIndividual exists (this is hard coded for now), and I know that that individual has the Data Property I am looking for (hasDoseVolume).  Did I define the OWLDataProperty (hasDoseVolume) correctly for use in the getDataPropertyValues call?


_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving String of Data Property for an Individual

Thomas Russ
In reply to this post by Timothy Redmond

On May 11, 2011, at 3:27 PM, Timothy Redmond wrote:

> A quick answer is that I suspect that the OWLLiteral.getLiteral()  
> method will return the right thing when it is the appropriate thing  
> to do.  It is interesting that this class doesn't have a  
> parseString() method.
>
>
> But there is a bit more to this.  For example, it might be worth  
> checking that the OWLLiteral returned represents a string rather  
> than something else like a float.

Oddly enough, the OWLLiteral class doesn't have an isString() test,  
either.

But OWLDatatype does have that method, so one could test this with  
OWLLiteral.getDatatype.isString()



_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving String of Data Property for an Individual

Timothy Redmond

> But OWLDatatype does have that method, so one could test this with
> OWLLiteral.getDatatype.isString()

So that is cool!  I had to go look.  At first I thought that maybe it
figured out whether the values of the datatype would be string values.  
But actually what it does is to determine if the data type is the
xsd:string datatype.  There are sub-datatypes of string that also have
only string data values and isString() would return false for these.

-Timothy


On 05/11/2011 04:01 PM, Thomas Russ wrote:

>
> On May 11, 2011, at 3:27 PM, Timothy Redmond wrote:
>
>> A quick answer is that I suspect that the OWLLiteral.getLiteral()
>> method will return the right thing when it is the appropriate thing
>> to do.  It is interesting that this class doesn't have a
>> parseString() method.
>>
>>
>> But there is a bit more to this.  For example, it might be worth
>> checking that the OWLLiteral returned represents a string rather than
>> something else like a float.
>
> Oddly enough, the OWLLiteral class doesn't have an isString() test,
> either.
>
> But OWLDatatype does have that method, so one could test this with
> OWLLiteral.getDatatype.isString()
>
>
>
> _______________________________________________
> protege-owl mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing:
> http://protege.stanford.edu/doc/faq.html#01a.03

_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving String of Data Property for an Individual

Thomas Russ

On May 11, 2011, at 5:19 PM, Timothy Redmond wrote:

>
>> But OWLDatatype does have that method, so one could test this with  
>> OWLLiteral.getDatatype.isString()
>
> So that is cool!  I had to go look.  At first I thought that maybe  
> it figured out whether the values of the datatype would be string  
> values.  But actually what it does is to determine if the data type  
> is the xsd:string datatype.  There are sub-datatypes of string that  
> also have only string data values and isString() would return false  
> for these.
> -Timothy

Boy does that make robust programming hard.  I just looked at the  
javadoc and not the code.  But the javadoc also says that it just  
looks for the datatype xsd:string, so it didn't really matter.

I don't know how much it helps but there is also the even more  
involved path of

  OWLLiteral.getDatatype.getBuiltInDatatype().getCategory()

and looking for either

  OWL2Datatype.Category.STRING_WITH_LANGUAGE_TAG
  OWL2Datatype.Category.STRING_WITHOUT_LANGUAGE_TAG

now whether these work over string subtypes or not, I don't know.  
 From the constant list in OWL2Datatype, I can't really make a  
prediction.

>
>
> On 05/11/2011 04:01 PM, Thomas Russ wrote:
>>
>> On May 11, 2011, at 3:27 PM, Timothy Redmond wrote:
>>
>>> A quick answer is that I suspect that the OWLLiteral.getLiteral()  
>>> method will return the right thing when it is the appropriate  
>>> thing to do.  It is interesting that this class doesn't have a  
>>> parseString() method.
>>>
>>>
>>> But there is a bit more to this.  For example, it might be worth  
>>> checking that the OWLLiteral returned represents a string rather  
>>> than something else like a float.
>>
>> Oddly enough, the OWLLiteral class doesn't have an isString() test,  
>> either.
>>
>> But OWLDatatype does have that method, so one could test this with  
>> OWLLiteral.getDatatype.isString()
>>
>>
>>
>> _______________________________________________
>> protege-owl mailing list
>> [hidden email]
>> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>>
>> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
>
> _______________________________________________
> protege-owl mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03

_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving String of Data Property for an Individual

Timothy Redmond

> Boy does that make robust programming hard.

Yes.  So this might be regarded as a misuse of power.   I recently wrote
some code where I created a reasoner purely to answer questions about
subsumption of datatypes.  I gave it an ontology with one data property
and nothing else and made the reasoner answer entailment questions about
class expressions.  Somebody had to figure these datatypes out so why
not use their work :)?

-Timothy


On 05/11/2011 05:45 PM, Thomas Russ wrote:

>
> On May 11, 2011, at 5:19 PM, Timothy Redmond wrote:
>
>>
>>> But OWLDatatype does have that method, so one could test this with
>>> OWLLiteral.getDatatype.isString()
>>
>> So that is cool!  I had to go look.  At first I thought that maybe it
>> figured out whether the values of the datatype would be string
>> values.  But actually what it does is to determine if the data type
>> is the xsd:string datatype.  There are sub-datatypes of string that
>> also have only string data values and isString() would return false
>> for these.
>> -Timothy
>
> Boy does that make robust programming hard.  I just looked at the
> javadoc and not the code.  But the javadoc also says that it just
> looks for the datatype xsd:string, so it didn't really matter.
>
> I don't know how much it helps but there is also the even more
> involved path of
>
>  OWLLiteral.getDatatype.getBuiltInDatatype().getCategory()
>
> and looking for either
>
>  OWL2Datatype.Category.STRING_WITH_LANGUAGE_TAG
>  OWL2Datatype.Category.STRING_WITHOUT_LANGUAGE_TAG
>
> now whether these work over string subtypes or not, I don't know.  
> From the constant list in OWL2Datatype, I can't really make a prediction.
>
>>
>>
>> On 05/11/2011 04:01 PM, Thomas Russ wrote:
>>>
>>> On May 11, 2011, at 3:27 PM, Timothy Redmond wrote:
>>>
>>>> A quick answer is that I suspect that the OWLLiteral.getLiteral()
>>>> method will return the right thing when it is the appropriate thing
>>>> to do.  It is interesting that this class doesn't have a
>>>> parseString() method.
>>>>
>>>>
>>>> But there is a bit more to this.  For example, it might be worth
>>>> checking that the OWLLiteral returned represents a string rather
>>>> than something else like a float.
>>>
>>> Oddly enough, the OWLLiteral class doesn't have an isString() test,
>>> either.
>>>
>>> But OWLDatatype does have that method, so one could test this with
>>> OWLLiteral.getDatatype.isString()
>>>
>>>
>>>
>>> _______________________________________________
>>> protege-owl mailing list
>>> [hidden email]
>>> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>>>
>>> Instructions for unsubscribing:
>>> http://protege.stanford.edu/doc/faq.html#01a.03
>>
>> _______________________________________________
>> protege-owl mailing list
>> [hidden email]
>> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>>
>> Instructions for unsubscribing:
>> http://protege.stanford.edu/doc/faq.html#01a.03
>
> _______________________________________________
> protege-owl mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing:
> http://protege.stanford.edu/doc/faq.html#01a.03

_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03