使用Tinkerpop / bluebrints将三元组导入OrientDB

时间:2013-11-12 10:02:04

标签: jena tinkerpop openrdf

我试图在OrientDB的帮助下将RDF-Triples导入tinkerpop/blueprints。 我找到了基本用法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创建类型并将Statement添加到我的SailConnection。 不幸的是我无法找到一个如何使用它的例子。

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

1 个答案:

答案 0 :(得分:0)

我想你需要从Jena对象类型转换为芝麻对象类型并使用

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

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