diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-08-06 12:04:38 +0100 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-08-06 12:04:38 +0100 |
commit | 3408515a868ca65ab907e21160f75c858ead8d46 (patch) | |
tree | 8dcc1e2ec9a43aeb68dca6a9246415ec6569fa3e /src/main/scala/rsacomb/RSAComb.scala | |
parent | a9e44e1b67d373faa05dd957c124eae343ff0cfa (diff) | |
download | RSAComb-3408515a868ca65ab907e21160f75c858ead8d46.tar.gz RSAComb-3408515a868ca65ab907e21160f75c858ead8d46.zip |
Refactor code into different files
This has been done to better accommodate the code to detect all unsafe
roles in an ontology.
Diffstat (limited to 'src/main/scala/rsacomb/RSAComb.scala')
-rw-r--r-- | src/main/scala/rsacomb/RSAComb.scala | 167 |
1 files changed, 0 insertions, 167 deletions
diff --git a/src/main/scala/rsacomb/RSAComb.scala b/src/main/scala/rsacomb/RSAComb.scala deleted file mode 100644 index 62414e9..0000000 --- a/src/main/scala/rsacomb/RSAComb.scala +++ /dev/null | |||
@@ -1,167 +0,0 @@ | |||
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.IRI | ||
14 | import org.semanticweb.owlapi.model.parameters.Imports | ||
15 | import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl | ||
16 | |||
17 | import tech.oxfordsemantic.jrdfox.Prefixes | ||
18 | import tech.oxfordsemantic.jrdfox.client.{ConnectionFactory, ServerConnection, DataStoreConnection} | ||
19 | import tech.oxfordsemantic.jrdfox.client.UpdateType | ||
20 | import tech.oxfordsemantic.jrdfox.logic.{Rule, Atom, Literal, Term, Variable} | ||
21 | import tech.oxfordsemantic.jrdfox.logic.{BuiltinFunctionCall, TupleTableName} | ||
22 | import tech.oxfordsemantic.jrdfox.logic.{LogicFormat} | ||
23 | |||
24 | import scala.collection.JavaConverters._ | ||
25 | |||
26 | import rsacomb.SkolemStrategy | ||
27 | import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer | ||
28 | |||
29 | class RSA(ontology : OWLOntology) { | ||
30 | |||
31 | /* Alternative constructor(s) */ | ||
32 | def this(file : File) = this(RSA.loadOntology(file)) | ||
33 | |||
34 | def getOntology : OWLOntology = ontology | ||
35 | |||
36 | } // class RSA | ||
37 | |||
38 | object RSA { | ||
39 | |||
40 | def loadOntology( onto : File ) : OWLOntology = { | ||
41 | /* Retrieve ontology manager */ | ||
42 | val manager : OWLOntologyManager = OWLManager.createOWLOntologyManager() | ||
43 | /* Retrieve ontology */ | ||
44 | manager.loadOntologyFromOntologyDocument(onto) | ||
45 | } | ||
46 | |||
47 | def isRSA( onto : OWLOntology ) : Boolean = { | ||
48 | /* TODO: Steps for RSA check | ||
49 | * 1) convert ontology axioms into LP rules | ||
50 | * 2) call RDFox on the onto and compute materialization | ||
51 | * 3) build graph from E(x,y) facts | ||
52 | * 4) check if the graph is tree-like | ||
53 | * ideally this annotates the graph with info about the reasons | ||
54 | * why the ontology might not be RSA. This could help a second | ||
55 | * step of approximation of an Horn-ALCHOIQ to RSA | ||
56 | */ | ||
57 | |||
58 | val renderer = new DLSyntaxObjectRenderer() | ||
59 | |||
60 | // Here we need to compute the unsafe roles. This is hardcoded for now. | ||
61 | val unsafe = List( | ||
62 | new OWLObjectPropertyImpl(IRI.create("http://example.com/rsa_example.owl#S")).getInverseProperty() | ||
63 | ) | ||
64 | |||
65 | /* Print TBox axioms */ | ||
66 | println("TBox/RBox:") | ||
67 | for { | ||
68 | axiom <- onto.tboxAxioms(Imports.EXCLUDED).collect(Collectors.toList()).asScala | ||
69 | } yield println(renderer.render(axiom)) | ||
70 | for { | ||
71 | axiom <- onto.rboxAxioms(Imports.EXCLUDED).collect(Collectors.toList()).asScala | ||
72 | } yield println(renderer.render(axiom)) | ||
73 | |||
74 | /* Ontology axiom convertion into LP rules */ | ||
75 | println("Logic rules:") | ||
76 | for { | ||
77 | axiom <- onto.tboxAxioms(Imports.EXCLUDED).collect(Collectors.toList()).asScala | ||
78 | visitor = new RDFoxAxiomConverter(Variable.create("x"), SkolemStrategy.ConstantRSA(axiom.toString), unsafe) | ||
79 | rule <- axiom.accept(visitor) | ||
80 | } yield println(rule) | ||
81 | for { | ||
82 | axiom <- onto.rboxAxioms(Imports.EXCLUDED).collect(Collectors.toList()).asScala | ||
83 | visitor = new RDFoxAxiomConverter(Variable.create("x"), SkolemStrategy.ConstantRSA(axiom.toString), unsafe) | ||
84 | rule <- axiom.accept(visitor) | ||
85 | } yield println(rule) | ||
86 | |||
87 | /* Return true for now... */ | ||
88 | true | ||
89 | } | ||
90 | |||
91 | } // object RSA | ||
92 | |||
93 | object RSAComb { | ||
94 | |||
95 | val help : String = """ | ||
96 | rsacomb - combined approach for CQ answering for RSA ontologies. | ||
97 | |||
98 | USAGE | ||
99 | rsacomb <path/to/ontology.owl> <path/to/query.sparql> | ||
100 | |||
101 | where | ||
102 | the ontology is expected to be an OWL file and the (single) | ||
103 | query a SPARQL query file. | ||
104 | """ | ||
105 | |||
106 | def main( args : Array[String] ) : Unit = { | ||
107 | |||
108 | /* Simple arguments handling | ||
109 | * | ||
110 | * TODO: use something better later on | ||
111 | */ | ||
112 | |||
113 | if (args.length < 2) { | ||
114 | println(help) | ||
115 | return () | ||
116 | } | ||
117 | |||
118 | val ontologyPath = new File(args(0)) | ||
119 | val queryPath = new File(args(1)) | ||
120 | |||
121 | if (!ontologyPath.isFile || !queryPath.isFile) { | ||
122 | println("The provided arguments are not regular files.\n\n") | ||
123 | println(help) | ||
124 | return () | ||
125 | } | ||
126 | |||
127 | /* Create RSA object from generic OWLOntology | ||
128 | * | ||
129 | * TODO: It might be required to check if the ontology in input is | ||
130 | * Horn-ALCHOIQ. At the moment we are assuming this is always the | ||
131 | * case. | ||
132 | */ | ||
133 | val rsa = new RSA(ontologyPath) | ||
134 | RSA.isRSA(rsa.getOntology) | ||
135 | |||
136 | /* Build canonical model */ | ||
137 | //val tboxCanon = rsa.canonicalModel() | ||
138 | |||
139 | /* Load query */ | ||
140 | //val query = ... | ||
141 | |||
142 | /* Compute the filtering program from the given query */ | ||
143 | //val tboxFilter = rsa.filteringProgram(query) | ||
144 | |||
145 | /* ... */ | ||
146 | |||
147 | /* DEBUG ONLY */ | ||
148 | println("Ok!") | ||
149 | } | ||
150 | } | ||
151 | |||
152 | /* Notes: | ||
153 | * | ||
154 | * To establish a connection with a local RDFox instance, do the | ||
155 | * following: | ||
156 | * | ||
157 | * ``` | ||
158 | * val serverConnection : ServerConnection = ConnectionFactory.newServerConnection("rdfox:local", "", "") | ||
159 | * serverConnection.createDataStore("test","seq",new HashMap()) | ||
160 | * val dataStoreConnection : DataStoreConnection = serverConnection.newDataStoreConnection("test") | ||
161 | * dataStoreConnection.importData( | ||
162 | * UpdateType.ADDITION, | ||
163 | * Prefixes.s_emptyPrefixes, | ||
164 | * new File("./path/to/file") | ||
165 | * ) | ||
166 | * ``` | ||
167 | */ | ||