0

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 Answers1

1

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

Specifying a named graph

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>
Henriette Harmse
  • 4,167
  • 1
  • 13
  • 22