From afe0128a89a1d92fac8056bc356ba1dea8122925 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Thu, 5 Nov 2020 20:33:13 +0000 Subject: Update tests to RDFox v4.0 --- src/main/scala/rsacomb/FilteringProgram.scala | 45 ++- src/main/scala/rsacomb/Main.scala | 3 +- src/test/scala/rsacomb/CanonicalModelSpec.scala | 3 +- src/test/scala/rsacomb/FilteringProgramSpecs.scala | 447 ++++++++++----------- src/test/scala/rsacomb/OWLAxiomSpec.scala | 58 +-- src/test/scala/rsacomb/OWLClassSpec.scala | 63 +-- 6 files changed, 313 insertions(+), 306 deletions(-) (limited to 'src') diff --git a/src/main/scala/rsacomb/FilteringProgram.scala b/src/main/scala/rsacomb/FilteringProgram.scala index dc5e95e..b0d4aab 100644 --- a/src/main/scala/rsacomb/FilteringProgram.scala +++ b/src/main/scala/rsacomb/FilteringProgram.scala @@ -32,8 +32,29 @@ class FilteringProgram(query: SelectQuery, constants: List[Term]) /* Makes mplicit conversion OWLAPI IRI <-> RDFox IRI available */ import RDFoxUtil._ - val answer: List[Term] = query.getSelection.asScala.map(_.getVariable).toList - val bounded: List[Term] = this.getBoundedVariables + lazy val variables = { + query.getQueryBody.getWherePattern match { + case b: ConjunctionPattern => { + b.getConjuncts.asScala.toSet.flatMap { conj: QueryPattern => + conj match { + case c: TriplePattern => + Set(c.getSubject, c.getPredicate, c.getObject) + .filter(_.isInstanceOf[Variable]) + case _ => Set() + } + } + } + case _ => Set() + } + }.toList + + val answer: List[Term] = + if (query.getAllPossibleVariables) { + variables + } else { + query.getSelection.asScala.map(_.getVariable).toList + } + val bounded: List[Term] = this.variables.filterNot(answer.contains(_)) val facts: List[TupleTableAtom] = constants.map(named) val rules: List[Rule] = this.generateFilteringProgram().map(reifyRule) @@ -45,26 +66,6 @@ class FilteringProgram(query: SelectQuery, constants: List[Term]) RSA.internal("NAMED") ) - private def getBoundedVariables: List[Term] = { - def extract(body: GroupGraphPattern): Set[Term] = { - body match { - case b: ConjunctionPattern => { - b.getConjuncts.asScala.toSet.flatMap { conj: QueryPattern => - conj match { - case c: TriplePattern => - Set(c.getSubject, c.getPredicate, c.getObject).filter( - _.isInstanceOf[Variable] - ) - case _ => Set() - } - } - } - case _ => Set() - } - } - extract(query.getQueryBody.getWherePattern).toList - } - /* NOTE: we are restricting to queries that contain conjunctions of * atoms for the time being. This might need to be reviewed in the * future. diff --git a/src/main/scala/rsacomb/Main.scala b/src/main/scala/rsacomb/Main.scala index 5d92061..830f1e0 100644 --- a/src/main/scala/rsacomb/Main.scala +++ b/src/main/scala/rsacomb/Main.scala @@ -62,8 +62,7 @@ object RSAComb extends App { "SELECT ?X WHERE {?X ?Y ?Z}" ) - /* Compute the filtering program from the given query */ - val filter = ontology.filteringProgram(query) + val filter = query map { q => ontology.filteringProgram(q) } /* ... */ } diff --git a/src/test/scala/rsacomb/CanonicalModelSpec.scala b/src/test/scala/rsacomb/CanonicalModelSpec.scala index e8db89d..88a0d29 100644 --- a/src/test/scala/rsacomb/CanonicalModelSpec.scala +++ b/src/test/scala/rsacomb/CanonicalModelSpec.scala @@ -9,7 +9,8 @@ import org.semanticweb.owlapi.model._ import uk.ac.manchester.cs.owl.owlapi._ import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer -import tech.oxfordsemantic.jrdfox.logic.{Rule, Variable} +import tech.oxfordsemantic.jrdfox.logic.datalog.Rule +import tech.oxfordsemantic.jrdfox.logic.expression.Variable import scala.collection.JavaConverters._ diff --git a/src/test/scala/rsacomb/FilteringProgramSpecs.scala b/src/test/scala/rsacomb/FilteringProgramSpecs.scala index 2dcf682..26b0857 100644 --- a/src/test/scala/rsacomb/FilteringProgramSpecs.scala +++ b/src/test/scala/rsacomb/FilteringProgramSpecs.scala @@ -7,15 +7,14 @@ import org.scalatest.Inspectors import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers -import tech.oxfordsemantic.jrdfox.logic.{Variable, Atom, IRI} -import tech.oxfordsemantic.jrdfox.logic.{Query, QueryType} -import tech.oxfordsemantic.jrdfox.logic.LogicFormat +import tech.oxfordsemantic.jrdfox.logic.datalog.TupleTableAtom +import tech.oxfordsemantic.jrdfox.logic.expression.{Variable, IRI} +import tech.oxfordsemantic.jrdfox.logic.sparql.statement.{Query, SelectQuery} import tech.oxfordsemantic.jrdfox.Prefixes import scala.collection.JavaConverters._ import rsacomb.RDFoxUtil._ -import tech.oxfordsemantic.jrdfox.logic.Conjunction object FilteringProgramSpec { @@ -34,254 +33,254 @@ object FilteringProgramSpec { // QUERY 0 - // val query0 = parseQuery(""" - // SELECT ?subj - // WHERE { - // ?subj ?pred ?obj - // } - // """, prefixes) - - val query0 = Query.create( - QueryType.SELECT, - false, - List(v("subj")).asJava, - Atom.rdf(v("subj"), v("pred"), v("obj")) - ) + val query0 = parseQuery(""" + SELECT ?subj + WHERE { + ?subj ?pred ?obj + } + """, prefixes).get + + // val query0 = Query.create( + // QueryType.SELECT, + // false, + // List(v("subj")).asJava, + // Atom.rdf(v("subj"), v("pred"), v("obj")) + // ) // QUERY 1 - // val query1 = parseQuery(""" - // SELECT * - // WHERE { - // ?w a :Wellbore - // } - // """, prefixes) - - val query1 = Query.create( - QueryType.SELECT, - false, - List(v("w")).asJava, - Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")) - ) + val query1 = parseQuery(""" + SELECT * + WHERE { + ?w a :Wellbore + } + """, prefixes).get + + // val query1 = Query.create( + // QueryType.SELECT, + // false, + // List(v("w")).asJava, + // Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")) + // ) // QUERY 2 - // val query2 = parseQuery( - // """ - // SELECT * - // WHERE { - // ?w a :Wellbore ; - // :wellboreDocument ?doc . - // ?doc :hasURL ?document_hyperlink - // } - // """, - // prefixes + val query2 = parseQuery( + """ + SELECT * + WHERE { + ?w a :Wellbore ; + :wellboreDocument ?doc . + ?doc :hasURL ?document_hyperlink + } + """, + prefixes + ).get + + // val query2 = Query.create( + // QueryType.SELECT, + // false, + // List(v("w"), v("doc"), v("document_hyperlink")).asJava, + // Conjunction.create( + // Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), + // Atom.rdf(v("w"), c("wellboreDocument"), v("doc")), + // Atom.rdf(v("doc"), c("hasURL"), v("document_hyperlink")) + // ) // ) - val query2 = Query.create( - QueryType.SELECT, - false, - List(v("w"), v("doc"), v("document_hyperlink")).asJava, - Conjunction.create( - Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), - Atom.rdf(v("w"), c("wellboreDocument"), v("doc")), - Atom.rdf(v("doc"), c("hasURL"), v("document_hyperlink")) - ) - ) - // QUERY 3 - // val query3 = parseQuery( - // """ - // SELECT ?wellbore ?formation_pressure - // WHERE { - // ?w a :Wellbore ; - // :name ?wellbore ; - // :hasFormationPressure ?fp . - // ?fp :valueInStandardUnit ?formation_pressure - // } - // """, - // prefixes + val query3 = parseQuery( + """ + SELECT ?wellbore ?formation_pressure + WHERE { + ?w a :Wellbore ; + :name ?wellbore ; + :hasFormationPressure ?fp . + ?fp :valueInStandardUnit ?formation_pressure + } + """, + prefixes + ).get + + // val query3 = Query.create( + // QueryType.SELECT, + // false, + // List(v("wellbore"), v("formation_pressure")).asJava, + // Conjunction.create( + // Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), + // Atom.rdf(v("w"), c("name"), v("wellbore")), + // Atom.rdf(v("w"), c("hasFormationPressure"), v("fp")), + // Atom.rdf(v("fp"), c("valueInStandardUnit"), v("formation_pressure")) + // ) // ) - val query3 = Query.create( - QueryType.SELECT, - false, - List(v("wellbore"), v("formation_pressure")).asJava, - Conjunction.create( - Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), - Atom.rdf(v("w"), c("name"), v("wellbore")), - Atom.rdf(v("w"), c("hasFormationPressure"), v("fp")), - Atom.rdf(v("fp"), c("valueInStandardUnit"), v("formation_pressure")) - ) - ) - // QUERY 4 - // val query4 = parseQuery( - // """ - // SELECT * - // WHERE { - // ?w a :Wellbore ; - // :hasGeochemicalMeasurement ?measurement . - // ?measurement :cgType ?cgtype ; - // :peakName ?peakType ; - // :peakHeight ?peak_height ; - // :peakAmount ?peak_amount - // } - // """, - // prefixes + val query4 = parseQuery( + """ + SELECT * + WHERE { + ?w a :Wellbore ; + :hasGeochemicalMeasurement ?measurement . + ?measurement :cgType ?cgtype ; + :peakName ?peakType ; + :peakHeight ?peak_height ; + :peakAmount ?peak_amount + } + """, + prefixes + ).get + + // val query4 = Query.create( + // QueryType.SELECT, + // false, + // List( + // v("w"), + // v("measurement"), + // v("cgtype"), + // v("peakType"), + // v("peak_height"), + // v("peak_amount") + // ).asJava, + // Conjunction.create( + // Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), + // Atom.rdf(v("w"), c("hasGeochemicalMeasurement"), v("measurement")), + // Atom.rdf(v("measurement"), c("cgType"), v("cgtype")), + // Atom.rdf(v("measurement"), c("peakName"), v("peakType")), + // Atom.rdf(v("measurement"), c("peakHeight"), v("peak_height")), + // Atom.rdf(v("measurement"), c("peakAmount"), v("peak_amount")) + // ) // ) - val query4 = Query.create( - QueryType.SELECT, - false, - List( - v("w"), - v("measurement"), - v("cgtype"), - v("peakType"), - v("peak_height"), - v("peak_amount") - ).asJava, - Conjunction.create( - Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), - Atom.rdf(v("w"), c("hasGeochemicalMeasurement"), v("measurement")), - Atom.rdf(v("measurement"), c("cgType"), v("cgtype")), - Atom.rdf(v("measurement"), c("peakName"), v("peakType")), - Atom.rdf(v("measurement"), c("peakHeight"), v("peak_height")), - Atom.rdf(v("measurement"), c("peakAmount"), v("peak_amount")) - ) - ) - // QUERY 5 - // val query5 = parseQuery( - // """ - // SELECT ?wellbore ?unit_name ?discovery - // WHERE { - // ?w a :Wellbore ; - // :name ?wellbore ; - // :hasWellboreInterval ?c_int ; - // :hasWellboreInterval ?f_int . - // ?c_int :hasUnit ?c_unit . - // ?c_unit :name ?unit_name . - // ?f_int a :FluidZone ; - // :name ?discovery ; - // :overlapsWellboreInterval ?c_int - // } - // """, - // prefixes + val query5 = parseQuery( + """ + SELECT ?wellbore ?unit_name ?discovery + WHERE { + ?w a :Wellbore ; + :name ?wellbore ; + :hasWellboreInterval ?c_int ; + :hasWellboreInterval ?f_int . + ?c_int :hasUnit ?c_unit . + ?c_unit :name ?unit_name . + ?f_int a :FluidZone ; + :name ?discovery ; + :overlapsWellboreInterval ?c_int + } + """, + prefixes + ).get + + // val query5 = Query.create( + // QueryType.SELECT, + // false, + // List(v("wellbore"), v("unit_name"), v("discovery")).asJava, + // Conjunction.create( + // Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), + // Atom.rdf(v("w"), c("name"), v("wellbore")), + // Atom.rdf(v("w"), c("hasWellboreInterval"), v("c_int")), + // Atom.rdf(v("w"), c("hasWellboreInterval"), v("f_int")), + // Atom.rdf(v("c_int"), c("hasUnit"), v("c_unit")), + // Atom.rdf(v("c_unit"), c("name"), v("unit_name")), + // Atom.rdf(v("f_int"), IRI.RDF_TYPE, c("FluidZone")), + // Atom.rdf(v("f_int"), c("name"), v("discovery")), + // Atom.rdf(v("f_int"), c("overlapsWellboreInterval"), v("c_int")) + // ) // ) - val query5 = Query.create( - QueryType.SELECT, - false, - List(v("wellbore"), v("unit_name"), v("discovery")).asJava, - Conjunction.create( - Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), - Atom.rdf(v("w"), c("name"), v("wellbore")), - Atom.rdf(v("w"), c("hasWellboreInterval"), v("c_int")), - Atom.rdf(v("w"), c("hasWellboreInterval"), v("f_int")), - Atom.rdf(v("c_int"), c("hasUnit"), v("c_unit")), - Atom.rdf(v("c_unit"), c("name"), v("unit_name")), - Atom.rdf(v("f_int"), IRI.RDF_TYPE, c("FluidZone")), - Atom.rdf(v("f_int"), c("name"), v("discovery")), - Atom.rdf(v("f_int"), c("overlapsWellboreInterval"), v("c_int")) - ) - ) - // QUERY 6 - // val query6 = parseQuery( - // """ - // SELECT DISTINCT ?wellbore ?content - // WHERE { - // ?w a :Wellbore ; - // :name ?wellbore ; - // :hasWellboreInterval ?int . - // ?int a :FluidZone ; - // :fluidZoneContent ?content - // } - // """, - // prefixes + val query6 = parseQuery( + """ + SELECT DISTINCT ?wellbore ?content + WHERE { + ?w a :Wellbore ; + :name ?wellbore ; + :hasWellboreInterval ?int . + ?int a :FluidZone ; + :fluidZoneContent ?content + } + """, + prefixes + ).get + + // val query6 = Query.create( + // QueryType.SELECT, + // true, + // List(v("wellbore"), v("content")).asJava, + // Conjunction.create( + // Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), + // Atom.rdf(v("w"), c("name"), v("wellbore")), + // Atom.rdf(v("w"), c("hasWellboreInterval"), v("int")), + // Atom.rdf(v("int"), IRI.RDF_TYPE, c("FluidZone")), + // Atom.rdf(v("int"), c("fluidZoneContent"), v("content")) + // ) // ) - val query6 = Query.create( - QueryType.SELECT, - true, - List(v("wellbore"), v("content")).asJava, - Conjunction.create( - Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), - Atom.rdf(v("w"), c("name"), v("wellbore")), - Atom.rdf(v("w"), c("hasWellboreInterval"), v("int")), - Atom.rdf(v("int"), IRI.RDF_TYPE, c("FluidZone")), - Atom.rdf(v("int"), c("fluidZoneContent"), v("content")) - ) - ) - // QUERY 7 - // val query7 = parseQuery( - // """ - // SELECT ?wName ?sample ?porosity ?top_depth_md ?bot_depth_md - // WHERE { - // ?w a :Wellbore ; - // :name ?wName ; - // :hasWellboreInterval ?z . - // ?z :hasUnit ?u . - // ?u :name ?strat_unit_name . - // ?wellbore :hasWellboreInterval ?cored_int . - // ?c :extractedFrom ?cored_int ; - // :hasCoreSample ?sample . - // ?sample :hasDepth ?sample_depth . - // ?sample_depth - // :inWellboreInterval ?z . - // ?sample :hasPorosity ?p . - // ?p :valueInStandardUnit ?porosity . - // ?z :hasTopDepth ?top . - // ?top a :MeasuredDepth ; - // :valueInStandardUnit ?top_depth_md . - // ?z :hasBottomDepth ?bot . - // ?bot a :MeasuredDepth ; - // :valueInStandardUnit ?bot_depth_md - // } - // """, - // prefixes + val query7 = parseQuery( + """ + SELECT ?wName ?sample ?porosity ?top_depth_md ?bot_depth_md + WHERE { + ?w a :Wellbore ; + :name ?wName ; + :hasWellboreInterval ?z . + ?z :hasUnit ?u . + ?u :name ?strat_unit_name . + ?wellbore :hasWellboreInterval ?cored_int . + ?c :extractedFrom ?cored_int ; + :hasCoreSample ?sample . + ?sample :hasDepth ?sample_depth . + ?sample_depth + :inWellboreInterval ?z . + ?sample :hasPorosity ?p . + ?p :valueInStandardUnit ?porosity . + ?z :hasTopDepth ?top . + ?top a :MeasuredDepth ; + :valueInStandardUnit ?top_depth_md . + ?z :hasBottomDepth ?bot . + ?bot a :MeasuredDepth ; + :valueInStandardUnit ?bot_depth_md + } + """, + prefixes + ).get + + // val query7 = Query.create( + // QueryType.SELECT, + // false, + // List( + // v("wName"), + // v("sample"), + // v("porosity"), + // v("top_depth_md"), + // v("bot_depth_md") + // ).asJava, + // Conjunction.create( + // Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), + // Atom.rdf(v("w"), c("name"), v("wName")), + // Atom.rdf(v("w"), c("hasWellboreInterval"), v("z")), + // Atom.rdf(v("z"), c("hasUnit"), v("u")), + // Atom.rdf(v("u"), c("name"), v("strat_unit_name")), + // Atom.rdf(v("wellbore"), c("hasWellboreInterval"), v("cored_int")), + // Atom.rdf(v("c"), c("extractedFrom"), v("cored_int")), + // Atom.rdf(v("c"), c("hasCoreSample"), v("sample")), + // Atom.rdf(v("sample"), c("hasDepth"), v("sample_depth")), + // Atom.rdf(v("sample_depth"), c("inWellboreInterval"), v("z")), + // Atom.rdf(v("sample"), c("hasPorosity"), v("p")), + // Atom.rdf(v("p"), c("valueInStandardUnit"), v("porosity")), + // Atom.rdf(v("z"), c("hasTopDepth"), v("top")), + // Atom.rdf(v("top"), IRI.RDF_TYPE, c("MeasuredDepth")), + // Atom.rdf(v("top"), c("valueInStandardUnit"), v("top_depth_md")), + // Atom.rdf(v("z"), c("hasBottomDepth"), v("bot")), + // Atom.rdf(v("bot"), IRI.RDF_TYPE, c("MeasuredDepth")), + // Atom.rdf(v("bot"), c("valueInStandardUnit"), v("bot_depth_md")) + // ) // ) - val query7 = Query.create( - QueryType.SELECT, - false, - List( - v("wName"), - v("sample"), - v("porosity"), - v("top_depth_md"), - v("bot_depth_md") - ).asJava, - Conjunction.create( - Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), - Atom.rdf(v("w"), c("name"), v("wName")), - Atom.rdf(v("w"), c("hasWellboreInterval"), v("z")), - Atom.rdf(v("z"), c("hasUnit"), v("u")), - Atom.rdf(v("u"), c("name"), v("strat_unit_name")), - Atom.rdf(v("wellbore"), c("hasWellboreInterval"), v("cored_int")), - Atom.rdf(v("c"), c("extractedFrom"), v("cored_int")), - Atom.rdf(v("c"), c("hasCoreSample"), v("sample")), - Atom.rdf(v("sample"), c("hasDepth"), v("sample_depth")), - Atom.rdf(v("sample_depth"), c("inWellboreInterval"), v("z")), - Atom.rdf(v("sample"), c("hasPorosity"), v("p")), - Atom.rdf(v("p"), c("valueInStandardUnit"), v("porosity")), - Atom.rdf(v("z"), c("hasTopDepth"), v("top")), - Atom.rdf(v("top"), IRI.RDF_TYPE, c("MeasuredDepth")), - Atom.rdf(v("top"), c("valueInStandardUnit"), v("top_depth_md")), - Atom.rdf(v("z"), c("hasBottomDepth"), v("bot")), - Atom.rdf(v("bot"), IRI.RDF_TYPE, c("MeasuredDepth")), - Atom.rdf(v("bot"), c("valueInStandardUnit"), v("bot_depth_md")) - ) - ) - val queries = List(query0, query1, query2, query3, query4, query5, query6, query7) diff --git a/src/test/scala/rsacomb/OWLAxiomSpec.scala b/src/test/scala/rsacomb/OWLAxiomSpec.scala index c685987..75803d8 100644 --- a/src/test/scala/rsacomb/OWLAxiomSpec.scala +++ b/src/test/scala/rsacomb/OWLAxiomSpec.scala @@ -19,18 +19,22 @@ import uk.ac.manchester.cs.owl.owlapi.{ import uk.ac.manchester.cs.owl.owlapi.{OWLObjectPropertyImpl} import org.semanticweb.owlapi.model.{OWLAxiom} -import tech.oxfordsemantic.jrdfox.logic.{Rule, BindAtom, BuiltinFunctionCall} -import tech.oxfordsemantic.jrdfox.logic.{ - Atom, - TupleTableName, +import tech.oxfordsemantic.jrdfox.logic.Datatype +import tech.oxfordsemantic.jrdfox.logic.datalog.{ + Rule, + BindAtom, + TupleTableAtom, + TupleTableName +} +import tech.oxfordsemantic.jrdfox.logic.expression.{ + FunctionCall, Term, Variable, - Literal, - Datatype + Literal } import org.semanticweb.owlapi.model.{IRI => OWLIRI} -import tech.oxfordsemantic.jrdfox.logic.{IRI => RDFIRI} +import tech.oxfordsemantic.jrdfox.logic.expression.{IRI => RDFIRI} object OWLAxiomSpec { @@ -188,15 +192,15 @@ class OWLAxiomSpec extends AnyFlatSpec with Matchers with LoneElement { it should "contain a conjuction of atoms (Student[?x],Worker[?x]) in the body of the rule" in { val result = convertAxiom(axiom_OWLSubClassOf1, term_x) val body = List( - Atom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student), - Atom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Worker) + TupleTableAtom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student), + TupleTableAtom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Worker) ) result.loneElement.getBody should contain theSameElementsAs body } it should "contain a single atom (PartTimeStudent[?x]) in the head of the rule" in { val result = convertAxiom(axiom_OWLSubClassOf1, term_x) - val head = Atom.rdf(term_x, RDFIRI.RDF_TYPE, iri_PartTimeStudent) + val head = TupleTableAtom.rdf(term_x, RDFIRI.RDF_TYPE, iri_PartTimeStudent) result.loneElement.getHead.loneElement should be(head) } @@ -212,7 +216,7 @@ class OWLAxiomSpec extends AnyFlatSpec with Matchers with LoneElement { val skolem = SkolemStrategy.Constant(axiom_OWLSubClassOf2.toString) val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) val body = - Atom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student.getIRIString) + TupleTableAtom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student.getIRIString) result.loneElement.getBody.loneElement should equal(body) } @@ -221,8 +225,8 @@ class OWLAxiomSpec extends AnyFlatSpec with Matchers with LoneElement { // val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) // val term_c = RSA.internal(skolem.const.getIRI) // val head = List( - // Atom.rdf(term_x, iri_hasSupervisor, term_c), - // Atom.rdf(term_c, RDFIRI.RDF_TYPE, iri_Professor) + // TupleTableAtom.rdf(term_x, iri_hasSupervisor, term_c), + // TupleTableAtom.rdf(term_c, RDFIRI.RDF_TYPE, iri_Professor) // ) // result.loneElement.getHead should contain theSameElementsAs (head) // } @@ -239,7 +243,7 @@ class OWLAxiomSpec extends AnyFlatSpec with Matchers with LoneElement { val skolem = SkolemStrategy.Standard(axiom_OWLSubClassOf2.toString) val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) val body = - Atom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student) + TupleTableAtom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student) result.loneElement.getBody should contain(body) } @@ -255,8 +259,8 @@ class OWLAxiomSpec extends AnyFlatSpec with Matchers with LoneElement { // val skolem = SkolemStrategy.Standard(axiom_OWLSubClassOf2.toString) // val result = convertAxiom(axiom_OWLSubClassOf2, term_x, skolem) // val head = List( - // Atom.rdf(term_x, iri_hasSupervisor, term_y), - // Atom.rdf(term_y, RDFIRI.RDF_TYPE, iri_Professor) + // TupleTableAtom.rdf(term_x, iri_hasSupervisor, term_y), + // TupleTableAtom.rdf(term_y, RDFIRI.RDF_TYPE, iri_Professor) // ) // result.loneElement.getHead should contain theSameElementsAs head // } @@ -270,8 +274,8 @@ class OWLAxiomSpec extends AnyFlatSpec with Matchers with LoneElement { // it should "contain a conjunction of atoms (hasSupervisor[?x,?y],Professor[?y]) in the body of the rule" in { // val result = convertAxiom(axiom_OWLSubClassOf3, term_x) // val body = List( - // Atom.rdf(term_x, iri_hasSupervisor, term_y), - // Atom.rdf(term_y, RDFIRI.RDF_TYPE, iri_Professor) + // TupleTableAtom.rdf(term_x, iri_hasSupervisor, term_y), + // TupleTableAtom.rdf(term_y, RDFIRI.RDF_TYPE, iri_Professor) // ) // result.loneElement.getBody should contain theSameElementsAs body // } @@ -279,7 +283,7 @@ class OWLAxiomSpec extends AnyFlatSpec with Matchers with LoneElement { it should "contain a single atom (Student[?x]) in the head of the rule" in { val result = convertAxiom(axiom_OWLSubClassOf3, term_x) val head = - Atom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student) + TupleTableAtom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student) result.loneElement.getHead.loneElement should be(head) } @@ -292,13 +296,13 @@ class OWLAxiomSpec extends AnyFlatSpec with Matchers with LoneElement { it should "contain a single atoms (Student[?x]) in the body of the rule" in { val result = convertAxiom(axiom_OWLSubClassOf4, term_x) val body = - Atom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student) + TupleTableAtom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student) result.loneElement.getBody.loneElement should be(body) } it should "contain a single atom (sameAs[?x,alice])) in the head of the rule" in { val result = convertAxiom(axiom_OWLSubClassOf4, term_x) - val head = Atom.rdf(term_x, RDFIRI.SAME_AS, term_alice) + val head = TupleTableAtom.rdf(term_x, RDFIRI.SAME_AS, term_alice) result.loneElement.getHead.loneElement should be(head) } @@ -311,18 +315,18 @@ class OWLAxiomSpec extends AnyFlatSpec with Matchers with LoneElement { // it should "contain a conjunction of atoms (...) in the body of the rule" in { // val result = convertAxiom(axiom_OWLSubClassOf5, term_x) // val body = List( - // Atom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student), - // Atom.rdf(term_x, iri_hasSupervisor, term_y), - // Atom.rdf(term_y, RDFIRI.RDF_TYPE, iri_Professor), - // Atom.rdf(term_x, iri_hasSupervisor, term_z), - // Atom.rdf(term_z, RDFIRI.RDF_TYPE, iri_Professor) + // TupleTableAtom.rdf(term_x, RDFIRI.RDF_TYPE, iri_Student), + // TupleTableAtom.rdf(term_x, iri_hasSupervisor, term_y), + // TupleTableAtom.rdf(term_y, RDFIRI.RDF_TYPE, iri_Professor), + // TupleTableAtom.rdf(term_x, iri_hasSupervisor, term_z), + // TupleTableAtom.rdf(term_z, RDFIRI.RDF_TYPE, iri_Professor) // ) // result.loneElement.getBody should contain theSameElementsAs body // } // it should "contain a single atom (sameAs[?x,?z])) in the head of the rule" in { // val result = convertAxiom(axiom_OWLSubClassOf5, term_x) - // val head = Atom.rdf(term_y, RDFIRI.SAME_AS, term_z) + // val head = TupleTableAtom.rdf(term_y, RDFIRI.SAME_AS, term_z) // result.loneElement.getHead.loneElement should be(head) // } diff --git a/src/test/scala/rsacomb/OWLClassSpec.scala b/src/test/scala/rsacomb/OWLClassSpec.scala index ed91ba7..a8ac14e 100644 --- a/src/test/scala/rsacomb/OWLClassSpec.scala +++ b/src/test/scala/rsacomb/OWLClassSpec.scala @@ -18,16 +18,19 @@ import uk.ac.manchester.cs.owl.owlapi.{ } import uk.ac.manchester.cs.owl.owlapi.{OWLObjectPropertyImpl} import org.semanticweb.owlapi.model.IRI -import tech.oxfordsemantic.jrdfox.logic.{IRI => RDFIRI} +import tech.oxfordsemantic.jrdfox.logic.expression.{IRI => RDFIRI} -import tech.oxfordsemantic.jrdfox.logic.{BindAtom, BuiltinFunctionCall} -import tech.oxfordsemantic.jrdfox.logic.{ - Atom, +import tech.oxfordsemantic.jrdfox.logic.Datatype +import tech.oxfordsemantic.jrdfox.logic.datalog.{ + TupleTableAtom, TupleTableName, + BindAtom +} +import tech.oxfordsemantic.jrdfox.logic.expression.{ + FunctionCall, Term, Variable, - Literal, - Datatype + Literal } import rsacomb.RDFoxRuleShards @@ -116,10 +119,10 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { result shouldBe a[RDFoxRuleShards] } - it should "have a single Atom in its result list" in { + it should "have a single TupleTableAtom in its result list" in { val visitor = RDFoxClassExprConverter(term_x) val result = class_OWLClass.accept(visitor) - result.res.loneElement shouldBe an[Atom] + result.res.loneElement shouldBe an[TupleTableAtom] } it should "have an empty extension list" in { @@ -156,10 +159,10 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { result shouldBe a[RDFoxRuleShards] } - // it should "be converted into a single Atom" in { + // it should "be converted into a single TupleTableAtom" in { // val visitor = RDFoxClassExprConverter(term_x) // val result = class_OWLObjectOneOf.accept(visitor) - // result.res.loneElement should (be (a [Atom]) and have ('tupleTableName (pred_sameAs))) + // result.res.loneElement should (be (a [TupleTableAtom]) and have ('tupleTableName (pred_sameAs))) // } it should "have an empty extension list" in { @@ -176,12 +179,12 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { result shouldBe a[RDFoxRuleShards] } - it should "have two Atoms in its result list" in { + it should "have two TupleTableAtoms in its result list" in { val visitor = RDFoxClassExprConverter(term_x) val result = class_OWLObjectSomeValuesFrom.accept(visitor) - exactly(2, result.res) should (be(an[Atom]) and have( - 'numberOfArguments (3) - )) + exactly(2, result.res) should (be(an[TupleTableAtom]) + //and have('numberOfArguments (3)) + ) } it should "have an empty extension list" in { @@ -198,13 +201,13 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { result shouldBe a[RDFoxRuleShards] } - it should "have exactly two Atoms in its result list" in { + it should "have exactly two TupleTableAtoms in its result list" in { val skolem = SkolemStrategy.Standard(class_OWLObjectSomeValuesFrom.toString) val visitor = RDFoxClassExprConverter(term_x, List(), skolem) val result = class_OWLObjectSomeValuesFrom.accept(visitor) - exactly(2, result.res) should (be(an[Atom]) and have( - 'numberOfArguments (3) - )) + exactly(2, result.res) should (be(an[TupleTableAtom]) + //and have('numberOfArguments (3)) + ) } it should "should have a single SKOLEM call in the extension list" in { @@ -212,8 +215,8 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { val visitor = RDFoxClassExprConverter(term_x, List(), skolem) val result = class_OWLObjectSomeValuesFrom.accept(visitor) result.ext.loneElement shouldBe a[BindAtom] - val builtin = result.ext.head.asInstanceOf[BindAtom].getBuiltinExpression - builtin should (be(a[BuiltinFunctionCall]) and have( + val builtin = result.ext.head.asInstanceOf[BindAtom].getExpression + builtin should (be(a[FunctionCall]) and have( 'functionName ("SKOLEM") )) } @@ -226,13 +229,13 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { result shouldBe a[RDFoxRuleShards] } - it should "have exactly two Atoms in its result list" in { + it should "have exactly two TupleTableAtoms in its result list" in { val skolem = SkolemStrategy.Constant(class_OWLObjectSomeValuesFrom.toString) val visitor = RDFoxClassExprConverter(term_x, List(), skolem) val result = class_OWLObjectSomeValuesFrom.accept(visitor) - exactly(2, result.res) should (be(an[Atom]) and have( - 'numberOfArguments (3) - )) + exactly(2, result.res) should (be(an[TupleTableAtom]) + //and have('numberOfArguments (3)) + ) } it should "have an empty extension list" in { @@ -250,20 +253,20 @@ class OWLClassSpec extends AnyFlatSpec with Matchers with LoneElement { result shouldBe a[RDFoxRuleShards] } - // it should "have a single Atom in the result list" in { + // it should "have a single TupleTableAtom in the result list" in { // val visitor = RDFoxClassExprConverter(term_x) // val result = class_OWLObjectMaxCardinality.accept(visitor) - // result.res.loneElement should (be(an[Atom]) and have( + // result.res.loneElement should (be(an[TupleTableAtom]) and have( // 'tupleTableName (pred_sameAs) // )) // } - it should "have 4 Atoms in its extension list" in { + it should "have 4 TupleTableAtoms in its extension list" in { val visitor = RDFoxClassExprConverter(term_x) val result = class_OWLObjectMaxCardinality.accept(visitor) - exactly(4, result.ext) should (be(an[Atom]) and have( - 'numberOfArguments (3) - )) + exactly(4, result.ext) should (be(an[TupleTableAtom]) + //and have('numberOfArguments (3)) + ) } } // class OWLClassSpec -- cgit v1.2.3