From 83330598df9a806508b2157a41f17a3faaddcd56 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Wed, 2 Dec 2020 16:28:07 +0000 Subject: Unify upload of rules and facts to RDFox datastore This will also help if/when we are implementing transactions. --- .../scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/main/scala') diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala index f7abde3..193119f 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala @@ -5,7 +5,8 @@ import tech.oxfordsemantic.jrdfox.Prefixes import tech.oxfordsemantic.jrdfox.client.{ ConnectionFactory, ServerConnection, - DataStoreConnection + DataStoreConnection, + UpdateType } import tech.oxfordsemantic.jrdfox.formats.SPARQLParser import tech.oxfordsemantic.jrdfox.logic.datalog.{ @@ -47,9 +48,8 @@ object RDFoxUtil { * @return a tuple with the newly opened server and data store * connections. * - * @see [[uk.ac.ox.cs.rsacomb.util.RDFoxUtil.closeConnection - * RDFoxUtil.closeConnection]] for - * details on how to close an open connection. + * @see [[uk.ac.ox.cs.rsacomb.util.RDFoxUtil.closeConnection RDFoxUtil.closeConnection]] + * for details on how to close an open connection. */ def openConnection( datastore: String, @@ -66,6 +66,26 @@ object RDFoxUtil { (server, data) } + /** Adds a collection of rules to a data store. + * + * @param data datastore connection + * @param rules collection of rules to be added to the data store + */ + def addRules(data: DataStoreConnection, rules: Seq[Rule]): Unit = + data addRules rules + + /** Adds a collection of facts to a data store. + * + * @param data datastore connection + * @param facts collection of facts to be added to the data store + */ + def addFacts(data: DataStoreConnection, facts: Seq[TupleTableAtom]): Unit = + data.importData( + UpdateType.ADDITION, + RSA.Prefixes, + facts.map(_.toString(Prefixes.s_emptyPrefixes)).mkString("", ".\n", ".") + ) + /** Parse a SELECT query from a string in SPARQL format. * * @param query the string containing the SPARQL query -- cgit v1.2.3