diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-07-15 17:48:11 +0100 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-07-15 17:48:11 +0100 |
commit | 0ccecbe8718c90201700897ee33e9082b7bfce50 (patch) | |
tree | 04a696141e8a6f5dd5e1e6c681b32dd03995cd41 /src/main/scala/rsacomb/RSAComb.scala | |
parent | 58b8d3c11a9deebb40e21c70d0b085d01cada745 (diff) | |
download | RSAComb-0ccecbe8718c90201700897ee33e9082b7bfce50.tar.gz RSAComb-0ccecbe8718c90201700897ee33e9082b7bfce50.zip |
Rename source code directory structure
Diffstat (limited to 'src/main/scala/rsacomb/RSAComb.scala')
-rw-r--r-- | src/main/scala/rsacomb/RSAComb.scala | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/src/main/scala/rsacomb/RSAComb.scala b/src/main/scala/rsacomb/RSAComb.scala new file mode 100644 index 0000000..bc94a8d --- /dev/null +++ b/src/main/scala/rsacomb/RSAComb.scala | |||
@@ -0,0 +1,138 @@ | |||
1 | package rsacomb | ||
2 | |||
3 | import java.io.File | ||
4 | import java.util.HashMap | ||
5 | import java.util.stream.{Stream,Collectors} | ||
6 | |||
7 | import org.semanticweb.owlapi.apibinding.OWLManager | ||
8 | import org.semanticweb.owlapi.model.{AxiomType, ClassExpressionType, OWLObjectSomeValuesFrom} | ||
9 | import org.semanticweb.owlapi.model.{OWLAxiom, OWLSubClassOfAxiom, OWLEquivalentClassesAxiom} | ||
10 | import org.semanticweb.owlapi.model.OWLClassExpression | ||
11 | import org.semanticweb.owlapi.model.OWLOntology | ||
12 | import org.semanticweb.owlapi.model.OWLOntologyManager | ||
13 | import org.semanticweb.owlapi.model.parameters.Imports | ||
14 | |||
15 | import tech.oxfordsemantic.jrdfox.Prefixes | ||
16 | import tech.oxfordsemantic.jrdfox.client.{ConnectionFactory, ServerConnection, DataStoreConnection} | ||
17 | import tech.oxfordsemantic.jrdfox.client.UpdateType | ||
18 | import tech.oxfordsemantic.jrdfox.logic.{Rule, Atom, Literal, Predicate, Term, Variable} | ||
19 | import tech.oxfordsemantic.jrdfox.logic.{Bind, BuiltinFunctionCall} | ||
20 | |||
21 | import scala.collection.JavaConverters._ | ||
22 | |||
23 | import rsacomb.SkolemStrategy | ||
24 | |||
25 | class RSA(ontology : OWLOntology) { | ||
26 | |||
27 | /* Alternative constructor(s) */ | ||
28 | def this(file : File) = this(RSA.loadOntology(file)) | ||
29 | |||
30 | def getOntology : OWLOntology = ontology | ||
31 | |||
32 | } // class RSA | ||
33 | |||
34 | object RSA { | ||
35 | |||
36 | def loadOntology( onto : File ) : OWLOntology = { | ||
37 | /* Retrieve ontology manager */ | ||
38 | val manager : OWLOntologyManager = OWLManager.createOWLOntologyManager() | ||
39 | /* Retrieve ontology */ | ||
40 | manager.loadOntologyFromOntologyDocument(onto) | ||
41 | } | ||
42 | |||
43 | def isRSA( onto : OWLOntology ) : Boolean = { | ||
44 | /* TODO: Steps for RSA check | ||
45 | * 1) convert ontology axioms into LP rules | ||
46 | * 2) call RDFox on the onto and compute materialization | ||
47 | * 3) build graph from E(x,y) facts | ||
48 | * 4) check if the graph is tree-like | ||
49 | */ | ||
50 | |||
51 | /* Ontology axiom convertion into LP rules */ | ||
52 | for { | ||
53 | axiom <- onto.tboxAxioms(Imports.EXCLUDED).collect(Collectors.toList()).asScala | ||
54 | visitor = new RDFoxAxiomConverter(Variable.create("x"), SkolemStrategy.Constant(axiom.toString)) | ||
55 | rule <- axiom.accept(visitor) | ||
56 | } yield println(rule) | ||
57 | |||
58 | /* Return true for now... */ | ||
59 | true | ||
60 | } | ||
61 | |||
62 | } // object RSA | ||
63 | |||
64 | object RSAComb { | ||
65 | |||
66 | val help : String = """ | ||
67 | rsacomb - combined approach for CQ answering for RSA ontologies. | ||
68 | |||
69 | USAGE | ||
70 | rsacomb <path/to/ontology.owl> <path/to/query.sparql> | ||
71 | |||
72 | where | ||
73 | the ontology is expected to be an OWL file and the (single) | ||
74 | query a SPARQL query file. | ||
75 | """ | ||
76 | |||
77 | def main( args : Array[String] ) : Unit = { | ||
78 | |||
79 | /* Simple arguments handling | ||
80 | * | ||
81 | * TODO: use something better later on | ||
82 | */ | ||
83 | |||
84 | if (args.length < 2) { | ||
85 | println(help) | ||
86 | return () | ||
87 | } | ||
88 | |||
89 | val ontologyPath = new File(args(0)) | ||
90 | val queryPath = new File(args(1)) | ||
91 | |||
92 | if (!ontologyPath.isFile || !queryPath.isFile) { | ||
93 | println("The provided arguments are not regular files.\n\n") | ||
94 | println(help) | ||
95 | return () | ||
96 | } | ||
97 | |||
98 | /* Create RSA object from generic OWLOntology | ||
99 | * | ||
100 | * TODO: It might be required to check if the ontology in input is | ||
101 | * Horn-ALCHOIQ. At the moment we are assuming this is always the | ||
102 | * case. | ||
103 | */ | ||
104 | val rsa = new RSA(ontologyPath) | ||
105 | RSA.isRSA(rsa.getOntology) | ||
106 | |||
107 | /* Build canonical model */ | ||
108 | //val tboxCanon = rsa.canonicalModel() | ||
109 | |||
110 | /* Load query */ | ||
111 | //val query = ... | ||
112 | |||
113 | /* Compute the filtering program from the given query */ | ||
114 | //val tboxFilter = rsa.filteringProgram(query) | ||
115 | |||
116 | /* ... */ | ||
117 | |||
118 | /* DEBUG ONLY */ | ||
119 | println("Ok!") | ||
120 | } | ||
121 | } | ||
122 | |||
123 | /* Notes: | ||
124 | * | ||
125 | * To establish a connection with a local RDFox instance, do the | ||
126 | * following: | ||
127 | * | ||
128 | * ``` | ||
129 | * val serverConnection : ServerConnection = ConnectionFactory.newServerConnection("rdfox:local", "", "") | ||
130 | * serverConnection.createDataStore("test","seq",new HashMap()) | ||
131 | * val dataStoreConnection : DataStoreConnection = serverConnection.newDataStoreConnection("test") | ||
132 | * dataStoreConnection.importData( | ||
133 | * UpdateType.ADDITION, | ||
134 | * Prefixes.s_emptyPrefixes, | ||
135 | * new File("./path/to/file") | ||
136 | * ) | ||
137 | * ``` | ||
138 | */ | ||