1

i'm reading RDF documents from an InputStream, as follows (scala syntax):

def foo(rdfData: InputStream, dialect: String = null) = {
  require(List("RDF/XML", "N-TRIPLE", "TURTLE", "TTL", "N3", "RDF/XML-ABBREV").contains(dialect) || dialect == null)
  val model: Model = ModelFactory.createDefaultModel
  model.read(rdfData, null, dialect)
  doSomethingWithTriplesIterator(model.listStatements())
}

now, some triples has typed literals, so i do something like:

val it = model.listStatements()
it.next.getObject.toString 

i get (sometimes) something like: "13"^^<http://www.w3.org/2001/XMLSchema#int> or "Hello world"@en_US when i'm only intrested at the value as strings, i.e. 13 & Hello world in the given example.

is there a way to get the "naked" values staight out of jena's statements? if so, how? thanks.

EDIT:

trying AndyS solution, using a triple taken from yago, i got:

scala> val model = ModelFactory.createDefaultModel
model: com.hp.hpl.jena.rdf.model.Model = <ModelCom   {} | >

scala> val is = new java.io.ByteArrayInputStream("""<http://yago-knowledge.org/resource/Mount_Cramer> <http://yago-knowledge.org/resource/hasLatitude> "44.01102^^http://yago-knowledge.org/resource/degrees" .""".getBytes("UTF-8"))
is: java.io.ByteArrayInputStream = java.io.ByteArrayInputStream@2b3c4f10

scala> model.read(is, null, "N-TRIPLE")
res0: com.hp.hpl.jena.rdf.model.Model = <ModelCom   {http://yago-knowledge.org/resource/Mount_Cramer @http://yago-knowledge.org/resource/hasLatitude "44.01102^^http://yago-knowledge.org/resource/degrees"} |  [http://yago-knowledge.org/resource/Mount_Cramer, http://yago-knowledge.org/resource/hasLatitude, "44.01102^^http://yago-knowledge.org/resource/degrees"]>

scala> val it = model.listStatements
it: com.hp.hpl.jena.rdf.model.StmtIterator = com.hp.hpl.jena.rdf.model.impl.StmtIteratorImpl@55ef662c

scala> val stmt = it.next
stmt: com.hp.hpl.jena.rdf.model.Statement = [http://yago-knowledge.org/resource/Mount_Cramer, http://yago-knowledge.org/resource/hasLatitude, "44.01102^^http://yago-knowledge.org/resource/degrees"]

scala> val obj = stmt.getObject
obj: com.hp.hpl.jena.rdf.model.RDFNode = 44.01102^^http://yago-knowledge.org/resource/degrees

scala> val ltrl = obj.asLiteral
ltrl: com.hp.hpl.jena.rdf.model.Literal = 44.01102^^http://yago-knowledge.org/resource/degrees

scala> ltrl.getLexicalForm
res1: String = 44.01102^^http://yago-knowledge.org/resource/degrees

so as you see, i'm not getting the desired output. what am i doing wrong?

gilad hoch
  • 2,846
  • 2
  • 33
  • 57
  • 1
    The RDF string that you parsed isn't right. It has a triple pattern `<...Mount_Cramer> <../hasLatitude> "44.01102^^http://yago-knowledge.org/resource/degrees"`, but that should be `<...Mount_Cramer> <../hasLatitude> "44.01102"^^`. The syntax is `"literal-form"^^`, not `"literal-form^^datatype-IRI"`. – Joshua Taylor Nov 11 '13 at 14:55

1 Answers1

4

What you want is the lexical form. See Literal.getLexicalForm.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
AndyS
  • 16,345
  • 17
  • 21
  • I tried it, and as you can see in the updated question, clearly, i did something wrong... so, what am i missing here? – gilad hoch Nov 11 '13 at 12:32
  • 1
    @giladhoch The code as shown in the update to your question is right, but your RDF data string is not. (See [my comment](http://stackoverflow.com/questions/19904412/jena-typed-literals-language-annotations-how-to-ommit-it-when-exporting#comment29621777_19904412) on the question.) – Joshua Taylor Nov 11 '13 at 14:55