本文介绍了如何加载N-Triples模型并从RDF文件获取名称空间?(新手)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an RDF/XML file like this:

<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-Triples格式,并且已经使用耶拿(Jena)自动完成了此操作:

Then I have to convert this RDF/XML into the N-Triples format, and I have done this automatically with Jena:

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

但是接下来我需要用前缀来缩短每个谓词.我必须获得这样的东西:

But then I need to shorten each predicate with a prefix. I have to obtain something like this:

<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()的信息,并进行了一些尝试,例如:

I have read about getNSPrefix() and have made some attempts, such as:

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()?我应该使用其他方法吗?

How do I use getNsPrefixURI() in this case? Should I use another method?

推荐答案

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

Try writing your RDF data with RDFDataMgr and RDFFormat.TURTLE_FLAT.https://jena.apache.org/documentation/io/rdf-output.html

这篇关于如何加载N-Triples模型并从RDF文件获取名称空间?(新手)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 18:57