英文:
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工作台进行导入时,它允许你指定一个命名图,如下所示。
在编程方面,你可以使用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.
Programmatically you can do it as follows using RDF4J. Note that in RDF4J named graphs are referred to as contexts.
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();
}
To use RDf4J you will need to add the following dependency:
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-client</artifactId>
<version>4.2.3</version>
<type>pom</type>
</dependency>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论