如何在GraphDB中创建具名图?

huangapple go评论64阅读模式
英文:

how create named graphs in GraphDB?

问题

如何在GraphDB中创建命名图?

需要通过工具(如RDFLib或Apache Jena)将RDF文件的格式从三元组更改为N-Quads吗?或者有更简单的方法吗?

英文:

how create named graphs in GraphDB?

Is it necessary to change the format de rdf file from triples to n-quads through tools (like RDFLib or Apache Jena) or is there an easier way?

答案1

得分: 1

不一定。当你在GraphDB中使用GraphDB工作台进行导入时,它允许你指定一个命名图,如下所示。

如何在GraphDB中创建具名图?

在编程方面,你可以使用RDF4J来实现,需要注意的是,在RDF4J中,命名图被称为上下文。

String address = "http://localhost/"
String repositoryName = "myRepo"
File rdfFile = new File("some triples")

HTTPRepository repository = new HTTPRepository(address, repositoryName)
try (RepositoryConnection connection = repository.getConnection()) {
    connection.begin()
    connection.add(rdfFile, RDFFormat.TURTLE, "http://MyGraph,com")
    connection.commit()
} catch (RepositoryException re){
    re.printStackTrace()
}

要使用RDF4J,你需要添加以下依赖项:

<dependency>
    <groupId>org.eclipse.rdf4j</groupId>
    <artifactId>rdf4j-client</artifactId>
    <version>4.2.3</version>
    <type>pom</type>
</dependency>
英文:

Not necessarily. When you do the import into GraphDB using the GraphDB workbench, it allows you to specify a named graph, as shown below.

如何在GraphDB中创建具名图?

Programmatically you can do it as follows using RDF4J. Note that in RDF4J named graphs are referred to as contexts.

    String address = &quot;http://localhost/&quot;
    String repositoryName = &quot;myRepo&quot;
    File rdfFile = new File(&quot;some triples&quot;);

    HTTPRepository repository = new HTTPRepository(address, repositoryName);
    try (RepositoryConnection connection = repository.getConnection()) {
        connection.begin();
        connection.add(rdfFile, RDFFormat.TURTLE, &quot;http://MyGraph,com&quot;); 
        connection.commit();
    } catch (RepositoryException re){
        re.printStackTrace();
    }

To use RDf4J you will need to add the following dependency:

&lt;dependency&gt;
    &lt;groupId&gt;org.eclipse.rdf4j&lt;/groupId&gt;
    &lt;artifactId&gt;rdf4j-client&lt;/artifactId&gt;
    &lt;version&gt;4.2.3&lt;/version&gt;
    &lt;type&gt;pom&lt;/type&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2023年4月11日 02:12:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75979594.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定