0

I'm able to add custom rules to a named graph in Stardog with the following CLI command:

stardog data add db_name -g "http://graph_name"/path/to/rules/test.ttl

Is there a possibility to do this via the Java API, for instance with the AdminConnection class?

tstorms
  • 4,941
  • 1
  • 25
  • 47

1 Answers1

2

Adding data to the database would be done using the Connection class. You can specify a named graph for the file you are adding as follows:

conn.begin();
conn.add().io().context(graphURI).file(new File("/path/to/rules/test.ttl"));
conn.commit();

See the connection and adder classes for more details.

Evren Sirin
  • 356
  • 1
  • 2
  • 1
    Additionally, in Stardog 3, `ExpressionFactory#rule` can be used to create an `Expression` from a Stardog Rule (as a string). An `Expression` can be turned into a graph via the `graph` method, we can then be passed to `Adder` to insert it into the database. – Michael Mar 18 '15 at 02:44
  • Thanks for both suggestions! I will try the second solution as well when Stardog 3 is released – tstorms Mar 19 '15 at 08:55