On 07/02/13 09:37, Darko Androcec wrote:
How can I get values for the OWL individual by using Jena API? I created
the OWL ontology using Java and Jena, and I now want to retrieve values
for each individual, e.g. I have one individual Customer_1
<rdf:Description
rdf:about="http://hr.org.foi.ontology/AzureDataModel#Customer_1">
<j.0:phoneNumber
rdf:datatype="http://www.w3.org/2001/XMLSchema#string">123-456</j.0:phoneNumber>
<j.0:address
rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Adresa
12</j.0:address>
<j.0:name
rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Darko</j.0:name>
<j.0:CustomerID
rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1</j.0:CustomerID>
<rdf:type
rdf:resource="http://hr.org.foi.ontology/AzureDataModel#Customer"/>
</rdf:Description>
and I want to print that his phoneNumber is 123-456, address is Adresa
12 etc. I tried with the following code, but I got only the types of
properties:
ExtendedIterator<? extends OntResource> it =
MyClass.listInstances(true);
if (it.hasNext()) {
Individual ins = (Individual) it.next();
RDFNode iValue = ins.getPropertyValue(property);
String value = iValue.toString();
}
Do you really mean you got *only* the types or do you mean you got the
types as well, e.g.
"12"^^http://www.w3.org/2001/XMLSchema#string
Assuming the latter then what you want is to extract the lexical form
from those typed literals:
iValue.asLiteral().getLexicalForm();
Note that you should test that the value *is* a literal before calling
asLiteral.
[It so happens that for strings the java representation is the lexical
form so asLiteral().getValue() will also work.]
Dave