diff options
| author | Federico Igne <git@federicoigne.com> | 2021-09-30 18:10:01 +0100 |
|---|---|---|
| committer | Federico Igne <git@federicoigne.com> | 2021-10-01 10:25:40 +0100 |
| commit | bc37ee9293d8a4098edce2a77db6efa3d87b6dd2 (patch) | |
| tree | cb85cc0b3b48855aca503b07f93c7b54e4b99c07 /src/main/scala/uk/ac/ox/cs/rsacomb/util | |
| parent | 1ef8a2502532dd1736c1e3d6a1ff78ed6b8b643c (diff) | |
| download | RSAComb-bc37ee9293d8a4098edce2a77db6efa3d87b6dd2.tar.gz RSAComb-bc37ee9293d8a4098edce2a77db6efa3d87b6dd2.zip | |
Make canonical model generation parametric over named graph
Diffstat (limited to 'src/main/scala/uk/ac/ox/cs/rsacomb/util')
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala | 29 | ||||
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/util/RSA.scala | 53 |
2 files changed, 54 insertions, 28 deletions
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 6f5ff31..568858c 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 | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | package uk.ac.ox.cs.rsacomb.util | 17 | package uk.ac.ox.cs.rsacomb.util |
| 18 | 18 | ||
| 19 | import java.io.{OutputStream, File, StringReader} | 19 | import java.io.{OutputStream, File, StringReader} |
| 20 | import scala.collection.JavaConverters._ | ||
| 20 | import tech.oxfordsemantic.jrdfox.Prefixes | 21 | import tech.oxfordsemantic.jrdfox.Prefixes |
| 21 | import tech.oxfordsemantic.jrdfox.client.{ | 22 | import tech.oxfordsemantic.jrdfox.client.{ |
| 22 | ComponentInfo, | 23 | ComponentInfo, |
| @@ -38,7 +39,8 @@ import tech.oxfordsemantic.jrdfox.logic.expression.{ | |||
| 38 | Literal, | 39 | Literal, |
| 39 | Resource, | 40 | Resource, |
| 40 | Variable, | 41 | Variable, |
| 41 | Term | 42 | Term, |
| 43 | IRI | ||
| 42 | } | 44 | } |
| 43 | import tech.oxfordsemantic.jrdfox.logic.sparql.statement.SelectQuery | 45 | import tech.oxfordsemantic.jrdfox.logic.sparql.statement.SelectQuery |
| 44 | import uk.ac.ox.cs.rsacomb.sparql.ConjunctiveQuery | 46 | import uk.ac.ox.cs.rsacomb.sparql.ConjunctiveQuery |
| @@ -92,6 +94,22 @@ object RDFoxUtil { | |||
| 92 | (server, data) | 94 | (server, data) |
| 93 | } | 95 | } |
| 94 | 96 | ||
| 97 | /** Get the IRI of a named graph (creating it if necessary) | ||
| 98 | * | ||
| 99 | * @param datastore name of the datastore to perform the action in. | ||
| 100 | * @param name name of the named graph. | ||
| 101 | * | ||
| 102 | * @return the full IRI for the (new) named graph. | ||
| 103 | */ | ||
| 104 | def getNamedGraph(datastore: String, name: String): IRI = { | ||
| 105 | val graph = RSA(name) | ||
| 106 | val (server, data) = openConnection(datastore) | ||
| 107 | if (!data.containsTupleTable(graph.getIRI)) | ||
| 108 | data.createTupleTable(graph.getIRI, Map("type" -> "named-graph").asJava) | ||
| 109 | RDFoxUtil.closeConnection(server, data) | ||
| 110 | return graph | ||
| 111 | } | ||
| 112 | |||
| 95 | /** Create a built-in `rdfox:SKOLEM` TupleTableAtom. */ | 113 | /** Create a built-in `rdfox:SKOLEM` TupleTableAtom. */ |
| 96 | def skolem(name: String, terms: Term*): TupleTableAtom = | 114 | def skolem(name: String, terms: Term*): TupleTableAtom = |
| 97 | TupleTableAtom.create( | 115 | TupleTableAtom.create( |
| @@ -143,14 +161,14 @@ object RDFoxUtil { | |||
| 143 | * @param facts collection of facts to be added to the data store | 161 | * @param facts collection of facts to be added to the data store |
| 144 | */ | 162 | */ |
| 145 | def addFacts( | 163 | def addFacts( |
| 146 | graph: String, | ||
| 147 | data: DataStoreConnection, | 164 | data: DataStoreConnection, |
| 165 | graph: IRI, | ||
| 148 | facts: Seq[TupleTableAtom] | 166 | facts: Seq[TupleTableAtom] |
| 149 | ): Unit = | 167 | ): Unit = |
| 150 | Logger.timed( | 168 | Logger.timed( |
| 151 | if (facts.length > 0) { | 169 | if (facts.length > 0) { |
| 152 | data.importData( | 170 | data.importData( |
| 153 | graph, | 171 | graph.getIRI, |
| 154 | UpdateType.ADDITION, | 172 | UpdateType.ADDITION, |
| 155 | RSA.Prefixes, | 173 | RSA.Prefixes, |
| 156 | facts | 174 | facts |
| @@ -165,12 +183,13 @@ object RDFoxUtil { | |||
| 165 | /** Imports a sequence of files directly into a datastore. | 183 | /** Imports a sequence of files directly into a datastore. |
| 166 | * | 184 | * |
| 167 | * @param data datastore connection. | 185 | * @param data datastore connection. |
| 186 | * @param graph named graph where the data should be uploaded | ||
| 168 | * @param files sequence of files to upload. | 187 | * @param files sequence of files to upload. |
| 169 | */ | 188 | */ |
| 170 | def addData(graph: String, data: DataStoreConnection, files: File*): Unit = | 189 | def addData(data: DataStoreConnection, graph: IRI, files: File*): Unit = |
| 171 | Logger.timed( | 190 | Logger.timed( |
| 172 | files.foreach { | 191 | files.foreach { |
| 173 | data.importData(graph, UpdateType.ADDITION, RSA.Prefixes, _) | 192 | data.importData(graph.getIRI, UpdateType.ADDITION, RSA.Prefixes, _) |
| 174 | }, | 193 | }, |
| 175 | "Loading data files", | 194 | "Loading data files", |
| 176 | Logger.DEBUG | 195 | Logger.DEBUG |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/util/RSA.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/util/RSA.scala index 8b341ba..96d3aa8 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/util/RSA.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/util/RSA.scala | |||
| @@ -42,32 +42,29 @@ import scala.collection.JavaConverters._ | |||
| 42 | 42 | ||
| 43 | object RSA { | 43 | object RSA { |
| 44 | 44 | ||
| 45 | /** Set of default prefixes to be included in all datastore operations */ | ||
| 45 | val Prefixes: Prefixes = new Prefixes() | 46 | val Prefixes: Prefixes = new Prefixes() |
| 46 | Prefixes.declarePrefix("rsa:", "http://www.cs.ox.ac.uk/isg/rsa/") | 47 | Prefixes.declarePrefix("rsacomb:", "http://www.cs.ox.ac.uk/isg/RSAComb#") |
| 48 | Prefixes.declarePrefix("rdfox:", "http://oxfordsemantic.tech/RDFox#") | ||
| 47 | Prefixes.declarePrefix("owl:", "http://www.w3.org/2002/07/owl#") | 49 | Prefixes.declarePrefix("owl:", "http://www.w3.org/2002/07/owl#") |
| 48 | 50 | ||
| 49 | val CONGRUENT = RSA("congruent") | 51 | /** Creates a `rsacomb:<name>` IRI */ |
| 50 | val NAMED = RSA("Named") | 52 | def apply(name: Any): IRI = |
| 51 | 53 | IRI.create( | |
| 52 | private def atom(name: IRI, vars: List[Term]): TupleTableAtom = | 54 | Prefixes.getPrefixIRIsByPrefixName.get("rsacomb:").getIRI + name.toString |
| 53 | TupleTableAtom.create(TupleTableName.create(name.getIRI), vars: _*) | 55 | ) |
| 54 | |||
| 55 | def E(t1: Term, t2: Term) = | ||
| 56 | TupleTableAtom.rdf(t1, RSA("E"), t2) | ||
| 57 | |||
| 58 | def PE(t1: Term, t2: Term) = | ||
| 59 | TupleTableAtom.rdf(t1, RSA("PE"), t2) | ||
| 60 | 56 | ||
| 61 | def U(t: Term) = | 57 | val NAMED = RSA("Named") |
| 62 | TupleTableAtom.rdf(t, IRI.RDF_TYPE, RSA("U")) | 58 | val CONGRUENT = RSA("congruent") |
| 59 | val IN = RSA("In") | ||
| 63 | 60 | ||
| 64 | def In(t: Term)(implicit set: Term) = | 61 | // def In(t: Term)(implicit set: Term) = |
| 65 | TupleTableAtom.rdf(t, RSA("In"), set) | 62 | // TupleTableAtom.rdf(t, RSA("In"), set) |
| 66 | 63 | ||
| 67 | def NotIn(t: Term)(implicit set: Term) = Negation.create(In(t)(set)) | 64 | // def NotIn(t: Term)(implicit set: Term) = Negation.create(In(t)(set)) |
| 68 | 65 | ||
| 69 | def Congruent(t1: Term, t2: Term) = | 66 | // def Congruent(t1: Term, t2: Term) = |
| 70 | TupleTableAtom.rdf(t1, RSA("congruent"), t2) | 67 | // TupleTableAtom.rdf(t1, RSA("congruent"), t2) |
| 71 | 68 | ||
| 72 | def QM(implicit q: ConjunctiveQuery) = | 69 | def QM(implicit q: ConjunctiveQuery) = |
| 73 | atom(RSA("QM"), q.answer ::: q.bounded) | 70 | atom(RSA("QM"), q.answer ::: q.bounded) |
| @@ -104,8 +101,18 @@ object RSA { | |||
| 104 | atom(RSA("Ans"), q.answer) | 101 | atom(RSA("Ans"), q.answer) |
| 105 | } | 102 | } |
| 106 | 103 | ||
| 107 | def apply(name: Any): IRI = | 104 | /* TODO: review after reworking the dependency graph construction */ |
| 108 | IRI.create( | 105 | |
| 109 | Prefixes.getPrefixIRIsByPrefixName.get("rsa:").getIRI + name.toString | 106 | // private def atom(name: IRI, vars: List[Term]): TupleTableAtom = |
| 110 | ) | 107 | // TupleTableAtom.create(TupleTableName.create(name.getIRI), vars: _*) |
| 108 | |||
| 109 | def E(t1: Term, t2: Term) = | ||
| 110 | TupleTableAtom.rdf(t1, RSA("E"), t2) | ||
| 111 | |||
| 112 | def PE(t1: Term, t2: Term) = | ||
| 113 | TupleTableAtom.rdf(t1, RSA("PE"), t2) | ||
| 114 | |||
| 115 | def U(t: Term) = | ||
| 116 | TupleTableAtom.rdf(t, IRI.RDF_TYPE, RSA("U")) | ||
| 117 | |||
| 111 | } | 118 | } |
