首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何加载N-三元组模型并从RDF文件中获取名称空间?(新手)

如何加载N-三元组模型并从RDF文件中获取名称空间?(新手)
EN

Stack Overflow用户
提问于 2014-11-16 14:56:01
回答 1查看 702关注 0票数 1

我有一个如下所示的RDF/XML文件:

代码语言:javascript
复制
<rdf:RDF
xmlns:go="http://www.geneontology.org/dtds/go.dtd#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
        <go:term rdf:about="http://www.geneontology.org/go#GO:0000001">
            <go:accession>GO:0000001</go:accession>
            <go:name>mitochondrion inheritance</go:name>
            <go:synonym>mitochondrial inheritance</go:synonym>
            <go:definition>The distribution of mitochondria, including the mitochondrial genome, into daughter cells after mitosis or meiosis, mediated by interactions between mitochondria and the cytoskeleton.</go:definition>
            <go:is_a rdf:resource="http://www.geneontology.org/go#GO:0048308" />
            <go:is_a rdf:resource="http://www.geneontology.org/go#GO:0048311" />
        </go:term>
</rdf:RDF>

然后,我必须将这个RDF/XML转换成N格式,并且我已经在Jena中自动完成了这一点:

代码语言:javascript
复制
FileManager.get().addLocatorClassLoader(Converter.class.getClassLoader());
    Model model = FileManager.get().loadModel("smallfacts.rdf");
    try {

          File file= new File("outputsmall.txt");
          model.write(new FileOutputStream(file), "N-Triples");
        } catch (IOException e) {
          e.printStackTrace();

但是,我需要用前缀缩短每个谓词。我必须得到这样的东西:

代码语言:javascript
复制
<http://www.geneontology.org/go#GO:2000391> is_a <http://www.geneontology.org/go#GO:2000389>.
<http://www.geneontology.org/go#GO:2000391> accession "GO:2000391".

我读过关于getNSPrefix()的文章,并做了一些尝试,例如:

代码语言:javascript
复制
FileManager.get().addLocatorClassLoader(Converter.class.getClassLoader());
    Model model = FileManager.get().loadModel("smallfacts.rdf");
    try {

          File file= new File("outputsmall.txt");
          model.getNsPrefixURI("http://www.geneontology.org/dtds/go.dtd#");
          model.write(new FileOutputStream(file), "N-Triples", "http://www.geneontology.org/dtds/go.dtd#");
        } catch (IOException e) {
          e.printStackTrace();

在这种情况下,如何使用getNsPrefixURI()?我应该用另一种方法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-16 21:34:03

尝试使用RDFDataMgr和RDFFormat.TURTLE_FLAT编写RDF数据。https://jena.apache.org/documentation/io/rdf-output.html

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26958270

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档