我正在从InputStream读取RDF文档,如下所示(scala语法):

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())
}


现在,一些三元组已经键入文字,所以我做类似的事情:

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


当我只以字符串的值(即给定示例中的"13"^^<http://www.w3.org/2001/XMLSchema#int>"Hello world"@en_US)表示兴趣时,我得到(有时)类似的内容:13Hello world

有没有办法让耶拿的话语中的“裸”值保持稳定?如果是这样,怎么办?
谢谢。

编辑:

尝试使用来自yago的三元组的AndyS解决方案,我得到了:

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


如您所见,我没有得到所需的输出。我究竟做错了什么?

最佳答案

您想要的是lexical form。请参见Literal.getLexicalForm

关于java - 耶拿键入文字和语言注释-导出时如何省略?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19904412/

10-10 01:25