diff options
Diffstat (limited to 'src/main/scala/rsacomb/RSA.scala')
-rw-r--r-- | src/main/scala/rsacomb/RSA.scala | 105 |
1 files changed, 71 insertions, 34 deletions
diff --git a/src/main/scala/rsacomb/RSA.scala b/src/main/scala/rsacomb/RSA.scala index b0e140b..1b2aa9c 100644 --- a/src/main/scala/rsacomb/RSA.scala +++ b/src/main/scala/rsacomb/RSA.scala | |||
@@ -1,11 +1,16 @@ | |||
1 | package rsacomb | 1 | package rsacomb.util |
2 | 2 | ||
3 | /* Java imports */ | 3 | /* Java imports */ |
4 | import java.util.Map | 4 | import java.util.Map |
5 | 5 | ||
6 | import tech.oxfordsemantic.jrdfox.formats.SPARQLParser | 6 | import tech.oxfordsemantic.jrdfox.formats.SPARQLParser |
7 | import tech.oxfordsemantic.jrdfox.Prefixes | 7 | import tech.oxfordsemantic.jrdfox.Prefixes |
8 | import tech.oxfordsemantic.jrdfox.logic.expression.{Variable, IRI} | 8 | import tech.oxfordsemantic.jrdfox.logic.datalog.{ |
9 | TupleTableAtom, | ||
10 | TupleTableName, | ||
11 | Negation | ||
12 | } | ||
13 | import tech.oxfordsemantic.jrdfox.logic.expression.{Term, Variable, IRI} | ||
9 | import org.semanticweb.owlapi.model.OWLOntology | 14 | import org.semanticweb.owlapi.model.OWLOntology |
10 | import org.semanticweb.owlapi.model.{ | 15 | import org.semanticweb.owlapi.model.{ |
11 | OWLAxiom, | 16 | OWLAxiom, |
@@ -13,51 +18,83 @@ import org.semanticweb.owlapi.model.{ | |||
13 | OWLObjectPropertyExpression | 18 | OWLObjectPropertyExpression |
14 | } | 19 | } |
15 | 20 | ||
21 | import rsacomb.suffix.RSASuffix | ||
22 | |||
16 | // Debug only | 23 | // Debug only |
17 | import scala.collection.JavaConverters._ | 24 | import scala.collection.JavaConverters._ |
18 | 25 | ||
19 | object RSA extends RSAAxiom { | 26 | object RSA { |
20 | 27 | ||
21 | val Prefixes: Prefixes = new Prefixes() | 28 | val Prefixes: Prefixes = new Prefixes() |
22 | Prefixes.declarePrefix(":", "http://example.com/rsa_example.owl#") | ||
23 | Prefixes.declarePrefix("rsa:", "http://127.0.0.1/") | 29 | Prefixes.declarePrefix("rsa:", "http://127.0.0.1/") |
24 | Prefixes.declarePrefix("rdf:", "http://www.w3.org/1999/02/22-rdf-syntax-ns#") | ||
25 | Prefixes.declarePrefix("rdfs:", "http://www.w3.org/2000/01/rdf-schema#") | ||
26 | Prefixes.declarePrefix("owl:", "http://www.w3.org/2002/07/owl#") | ||
27 | 30 | ||
28 | val EquivTo: IRI = this.rsa("EquivTo") | 31 | private def atom(name: IRI, vars: List[Term]) = |
29 | val Named: IRI = this.rsa("NAMED") | 32 | TupleTableAtom.create(TupleTableName.create(name.getIRI), vars: _*) |
33 | |||
34 | def PE(t1: Term, t2: Term) = | ||
35 | TupleTableAtom.rdf(t1, RSA("PE"), t2) | ||
36 | |||
37 | def U(t: Term) = | ||
38 | TupleTableAtom.rdf(t, IRI.RDF_TYPE, RSA("U")) | ||
39 | |||
40 | def In(t: Term)(implicit set: Term) = | ||
41 | TupleTableAtom.rdf(t, RSA("In"), set) | ||
42 | |||
43 | def notIn(t: Term)(implicit set: Term) = Negation.create(In(t)(set)) | ||
30 | 44 | ||
31 | // Counter used to implement a simple fresh variable generator | 45 | def EquivTo(t1: Term, t2: Term) = |
32 | private var counter = -1; | 46 | TupleTableAtom.rdf(t1, RSA("EquivTo"), t2) |
33 | 47 | ||
34 | def getFreshVariable(): Variable = { | 48 | def QM(implicit variables: (List[Term], List[Term])) = { |
35 | counter += 1 | 49 | val (answer, bounded) = variables |
36 | Variable.create(f"I$counter%03d") | 50 | atom(RSA("QM"), answer ::: bounded) |
37 | } | 51 | } |
38 | 52 | ||
39 | def base(name: Any): IRI = | 53 | def ID(t1: Term, t2: Term)(implicit variables: (List[Term], List[Term])) = { |
40 | IRI.create( | 54 | val (answer, bounded) = variables |
41 | Prefixes.getPrefixIRIsByPrefixName.get(":").getIRI | 55 | atom(RSA("ID"), (answer ::: bounded) :+ t1 :+ t2) |
42 | + name.toString | 56 | } |
43 | ) | ||
44 | 57 | ||
45 | def rsa(name: Any): IRI = | 58 | def Named(t: Term) = |
46 | IRI.create( | 59 | TupleTableAtom.rdf(t, IRI.RDF_TYPE, RSA("Named")) |
47 | Prefixes.getPrefixIRIsByPrefixName.get("rsa:").getIRI | 60 | |
48 | + name.toString | 61 | def Thing(t: Term) = |
49 | ) | 62 | TupleTableAtom.rdf(t, IRI.RDF_TYPE, IRI.THING) |
50 | 63 | ||
51 | def hashed( | 64 | def NI(t: Term) = |
52 | cls1: OWLClass, | 65 | TupleTableAtom.rdf(t, IRI.RDF_TYPE, RSA("NI")) |
53 | prop: OWLObjectPropertyExpression, | ||
54 | cls2: OWLClass | ||
55 | ): String = | ||
56 | (cls1, prop, cls2).hashCode.toString | ||
57 | 66 | ||
58 | def hashed(axiom: OWLAxiom): String = { | 67 | def TQ(t1: Term, t2: Term, sx: RSASuffix)(implicit |
59 | val (cls1, prop, cls2) = axiom.toTriple.get | 68 | variables: (List[Term], List[Term]) |
60 | this.hashed(cls1, prop, cls2) | 69 | ) = { |
70 | val (answer, bounded) = variables | ||
71 | atom(RSA("TQ" :: sx), (answer ::: bounded) :+ t1 :+ t2) | ||
61 | } | 72 | } |
62 | 73 | ||
63 | } // object RSA | 74 | def AQ(t1: Term, t2: Term, sx: RSASuffix)(implicit |
75 | variables: (List[Term], List[Term]) | ||
76 | ) = { | ||
77 | val (answer, bounded) = variables | ||
78 | atom(RSA("AQ" :: sx), (answer ::: bounded) :+ t1 :+ t2) | ||
79 | } | ||
80 | |||
81 | def FK(implicit variables: (List[Term], List[Term])) = { | ||
82 | val (answer, bounded) = variables | ||
83 | atom(RSA("FK"), answer ::: bounded) | ||
84 | } | ||
85 | |||
86 | def SP(implicit variables: (List[Term], List[Term])) = { | ||
87 | val (answer, bounded) = variables | ||
88 | atom(RSA("SP"), answer ::: bounded) | ||
89 | } | ||
90 | |||
91 | def Ans(implicit variables: (List[Term], List[Term])) = { | ||
92 | val (answer, _) = variables | ||
93 | atom(RSA("Ans"), answer) | ||
94 | } | ||
95 | |||
96 | def apply(name: Any): IRI = | ||
97 | IRI.create( | ||
98 | Prefixes.getPrefixIRIsByPrefixName.get("rsa:").getIRI + name.toString | ||
99 | ) | ||
100 | } | ||