【问题标题】:Importing Triples with Tinkerpop/bluebrints into OrientDB使用 Tinkerpop/bluebrints 将三元组导入 OrientDB
【发布时间】:2013-11-12 10:02:04
【问题描述】:

我试图在tinkerpop/blueprints 的帮助下将 RDF-Triples 导入OrientDB。 我找到了here的基本用法。

我现在那么远:

import info.aduna.iteration.CloseableIteration;

import org.openrdf.model.Statement;
import org.openrdf.model.ValueFactory;
import org.openrdf.sail.Sail;
import org.openrdf.sail.SailConnection;
import org.openrdf.sail.SailException;

import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Triple;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.oupls.sail.GraphSail;

import de.hof.iisys.relationExtraction.jena.parser.impl.ParserStreamIterator;
import de.hof.iisys.relationExtraction.neo4j.importer.Importer;


public class ImporterJenaTriples extends Importer {
    private OrientGraph graph = null;
    private Sail sail = null;
    private SailConnection sailConnection = null;
    private ValueFactory valueFactory = null;
    private Thread parserThread = null;

    public ImporterJenaTriples(ParserStreamIterator parser, String databasePath) throws SailException {
        this.parser = parser;
        this.databasePath = databasePath;

        this.initialize();
    }

    private void initialize() throws SailException {
        this.graph = new OrientGraph(this.databasePath);
        this.sail = new GraphSail<OrientGraph>(graph);

        sail.initialize();

        this.sailConnection = sail.getConnection();
        this.valueFactory = sail.getValueFactory();
    }

    public void startImport() {
        this.parserThread = new Thread(this.parser);
        this.parserThread.start();

        try {
            Triple next = (Triple) this.parser.getIterator().next();

            Node subject = next.getSubject();
            Node predicate = next.getPredicate();
            Node object = next.getObject();


        } catch (SailException e) {
            e.printStackTrace();
        }

        try {
            CloseableIteration<? extends Statement, SailException> results = this.sailConnection.getStatements(null, null, null, false);

            while(results.hasNext()) {
                System.out.println(results.next());
            }
        } catch (SailException e) {
            e.printStackTrace();
        }
    }

    public void stopImport() throws InterruptedException {
        this.parser.terminate();
        this.parserThread.join();
    }
}

我现在需要做的是区分主语、谓语和宾语的类型 但问题是我不知道它们是哪些类型以及我必须如何使用 valuefactory 创建类型并将语句添加到我的 SailConnection。 不幸的是,我找不到如何使用它的示例。

也许有人以前做过并且知道如何继续。

【问题讨论】:

    标签: jena tinkerpop openrdf


    【解决方案1】:

    我猜你需要将 Jena 对象类型转换为 Sesame 对象类型并使用

    不受支持的项目https://github.com/afs/JenaSesame 可能有一些代码。

    但是混合 Jena 和 Sesame 似乎会使事情变得更复杂 - 您是否考虑使用 Sesame 解析器并获取可以进入 SailConnection 的 Sesame 对象?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多