diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-09-23 19:59:06 +0200 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-09-23 19:59:06 +0200 |
commit | 099cad0129edb9822cc6ccb044b2109834715bb9 (patch) | |
tree | 66a8b2fb048467e6c65ecb2f43531f4051a6dcd3 /src/main/scala | |
parent | 5e1a39b0a4863268764de949d0f25d87fec00cce (diff) | |
download | RSAComb-099cad0129edb9822cc6ccb044b2109834715bb9.tar.gz RSAComb-099cad0129edb9822cc6ccb044b2109834715bb9.zip |
Add method to parse a string into a Query
This is using `SPARQLParser`, an undocumented class provided by JRDFox
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/rsacomb/Main.scala | 4 | ||||
-rw-r--r-- | src/main/scala/rsacomb/RDFoxUtil.scala | 13 | ||||
-rw-r--r-- | src/main/scala/rsacomb/RSA.scala | 13 |
3 files changed, 16 insertions, 14 deletions
diff --git a/src/main/scala/rsacomb/Main.scala b/src/main/scala/rsacomb/Main.scala index 35c682e..c6bd6a1 100644 --- a/src/main/scala/rsacomb/Main.scala +++ b/src/main/scala/rsacomb/Main.scala | |||
@@ -53,7 +53,9 @@ object RSAComb extends App { | |||
53 | //val tboxCanon = rsa.canonicalModel() | 53 | //val tboxCanon = rsa.canonicalModel() |
54 | 54 | ||
55 | /* Load query */ | 55 | /* Load query */ |
56 | val query = RSA.test_query | 56 | val query = RDFoxUtil.parseQuery( |
57 | "SELECT ?X WHERE {?X ?Y ?Z}" | ||
58 | ) | ||
57 | 59 | ||
58 | /* Compute the filtering program from the given query */ | 60 | /* Compute the filtering program from the given query */ |
59 | val filter = ontology.filteringProgram(query) | 61 | val filter = ontology.filteringProgram(query) |
diff --git a/src/main/scala/rsacomb/RDFoxUtil.scala b/src/main/scala/rsacomb/RDFoxUtil.scala index d5a4dbb..b523d4e 100644 --- a/src/main/scala/rsacomb/RDFoxUtil.scala +++ b/src/main/scala/rsacomb/RDFoxUtil.scala | |||
@@ -2,13 +2,16 @@ package rsacomb | |||
2 | 2 | ||
3 | /* Java imports */ | 3 | /* Java imports */ |
4 | import java.util.HashMap | 4 | import java.util.HashMap |
5 | import java.io.ByteArrayInputStream | ||
5 | import tech.oxfordsemantic.jrdfox.Prefixes | 6 | import tech.oxfordsemantic.jrdfox.Prefixes |
6 | import tech.oxfordsemantic.jrdfox.logic.IRI | 7 | import tech.oxfordsemantic.jrdfox.logic.{IRI, Query} |
7 | import tech.oxfordsemantic.jrdfox.client.{ | 8 | import tech.oxfordsemantic.jrdfox.client.{ |
8 | ConnectionFactory, | 9 | ConnectionFactory, |
9 | ServerConnection, | 10 | ServerConnection, |
10 | DataStoreConnection | 11 | DataStoreConnection |
11 | } | 12 | } |
13 | import tech.oxfordsemantic.jrdfox.formats.SPARQLParser | ||
14 | |||
12 | object RDFoxUtil { | 15 | object RDFoxUtil { |
13 | 16 | ||
14 | implicit def owlapi2rdfox(iri: org.semanticweb.owlapi.model.IRI): IRI = { | 17 | implicit def owlapi2rdfox(iri: org.semanticweb.owlapi.model.IRI): IRI = { |
@@ -41,6 +44,14 @@ object RDFoxUtil { | |||
41 | (server, data) | 44 | (server, data) |
42 | } | 45 | } |
43 | 46 | ||
47 | def parseQuery(query: String): Query = { | ||
48 | val parser = new SPARQLParser( | ||
49 | RSA.Prefixes, | ||
50 | new ByteArrayInputStream(query.getBytes()) | ||
51 | ) | ||
52 | parser.parseSingleQuery() | ||
53 | } | ||
54 | |||
44 | def submitQuery( | 55 | def submitQuery( |
45 | data: DataStoreConnection, | 56 | data: DataStoreConnection, |
46 | prefixes: Prefixes, | 57 | prefixes: Prefixes, |
diff --git a/src/main/scala/rsacomb/RSA.scala b/src/main/scala/rsacomb/RSA.scala index 9125f9f..edabc6a 100644 --- a/src/main/scala/rsacomb/RSA.scala +++ b/src/main/scala/rsacomb/RSA.scala | |||
@@ -4,6 +4,7 @@ package rsacomb | |||
4 | import java.io.File | 4 | import java.io.File |
5 | import java.util.Map | 5 | import java.util.Map |
6 | 6 | ||
7 | import tech.oxfordsemantic.jrdfox.formats.SPARQLParser | ||
7 | import tech.oxfordsemantic.jrdfox.Prefixes | 8 | import tech.oxfordsemantic.jrdfox.Prefixes |
8 | import tech.oxfordsemantic.jrdfox.logic.IRI | 9 | import tech.oxfordsemantic.jrdfox.logic.IRI |
9 | import org.semanticweb.owlapi.apibinding.OWLManager | 10 | import org.semanticweb.owlapi.apibinding.OWLManager |
@@ -38,18 +39,6 @@ object RSA extends RSAOntology { | |||
38 | Variable.create(f"I$counter%03d") | 39 | Variable.create(f"I$counter%03d") |
39 | } | 40 | } |
40 | 41 | ||
41 | val varX = Variable.create("X") | ||
42 | val varY = Variable.create("Y") | ||
43 | val varZ = Variable.create("Z") | ||
44 | val testAnswerVars = List[Variable](varX, varY, varZ).asJava; | ||
45 | val testFormula: Formula = | ||
46 | Conjunction.create( | ||
47 | Atom.rdf(varX, IRI.TOP_OBJECT_PROPERTY, varY), | ||
48 | Atom.rdf(varY, IRI.TOP_OBJECT_PROPERTY, varZ) | ||
49 | ) | ||
50 | val test_query = | ||
51 | Query.create(QueryType.SELECT, false, testAnswerVars, testFormula) | ||
52 | |||
53 | def internal(name: Any): IRI = | 42 | def internal(name: Any): IRI = |
54 | IRI.create( | 43 | IRI.create( |
55 | Prefixes.getPrefixIRIsByPrefixName.get("internal:").getIRI | 44 | Prefixes.getPrefixIRIsByPrefixName.get("internal:").getIRI |