将大型RDF / XML文件转换或转换为JSON-LD格式 - 如何?

时间:2013-09-05 08:38:32

标签: json rdf json-ld

我需要将此40MB file of RDF/XML转换为JSON-LD格式,而我只找到this web tool,这根本不起作用。当您粘贴40MB的文本时,它会崩溃,当您为其提供文件的URL时,它会说该服务不可用。

理论上,Jena API或芝麻应该能够做到这一点,但我错过了一个起点和关于这些系统的知识。有人可以给我一个路径,一个示例或链接到有用的文档,以便将大型RDF / XML转换为JSON-LD吗?

(我很高兴使用Java,C#或一个工作解决方案,我不需要在另一种语言/框架中有太多的编程知识)。

3 个答案:

答案 0 :(得分:11)

您可以使用RDFLib以RDF / XML格式读取RDF,并使用json-ld序列化程序将其序列化为JSON-LD

graph.parse(my_url, format='application/rdf+xml')


graph.serialize(my_url, format='application/json-ld')

答案 1 :(得分:5)

我是使用此工具完成的:http://rdf-translator.appspot.com/

可悲的是,上传/下载尺寸过大,因此我从here获取了代码,并在here端口8999上从本地Google App Engine上运行。然后我转到目录使用owl文件'ds.owl'并使用以下命令将其放入ds.json文件中:

curl --data-urlencode content@eclass_514en.owl http://localhost:8999/convert/detect/json-ld/content > ds.json

这是唯一有效的方法,我尝试了大约4个更大的本体文件。

答案 2 :(得分:2)

我不知道Jena API支持JSON-LD,但supports RDF/JSON是RDF三元组的直接编码。您可以使用Jena API,但使用Jena更方便的方法是使用Jena命令行rdfcat工具。 --help选项生成的帮助菜单有点过时,但看起来像这样:

$ rdfcat --help
Usage: java jena.rdfcat (option|input)*
Concatenates the contents of zero or more input RDF documents.
Options: -out N3 | N-TRIPLE | RDF/XML | RDF/XML-ABBREV
         -n  expect subsequent inputs in N3 syntax
         -x  expect subsequent inputs in RDF/XML syntax
         -t  expect subsequent inputs in N-TRIPLE syntax
         -[no]include  include rdfs:seeAlso and owl:imports
input can be filename, URL, or - for stdin
Recognised aliases for -n are: -n3 -ttl or -N3
Recognised aliases for -x are: -xml -rdf or -rdfxml
Recognised aliases for -t are: -ntriple
Output format aliases: x, xml or rdf for RDF/XML, n, n3 or ttl for N3, t or ntriple for N-TRIPLE
See the Javadoc for jena.rdfcat for additional details.

除此之外,您还想知道的是您可以传递输出格式RDF/JSON。例如,使用众所周知的比萨本体,我们得到:

$ rdfcat -out RDF/JSON ../sparql-pizza2/pizza.owl  | head -25
{ 
  "_:-b8ef06:140ee02a0b1:-7ff7" : { 
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest" : [ { 
      "type" : "uri" ,
      "value" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
    }
     ] ,
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#first" : [ { 
      "type" : "uri" ,
      "value" : "http://www.co-ode.org/ontologies/pizza/pizza.owl#TomatoTopping"
    }
     ]
  }
   ,
  "http://www.co-ode.org/ontologies/pizza/pizza.owl#Food" : { 
    "http://www.w3.org/2000/01/rdf-schema#subClassOf" : [ { 
      "type" : "uri" ,
      "value" : "http://www.co-ode.org/ontologies/pizza/pizza.owl#DomainConcept"
    }
     ] ,
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : [ { 
      "type" : "uri" ,
      "value" : "http://www.w3.org/2002/07/owl#Class"
    }
     ]
...and so on...
相关问题