From 17bd9beaf7f358a44e5bf36a5855fe6727d506dc Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Tue, 10 May 2022 18:17:06 +0100 Subject: [pagoda] Move project to Scala This commit includes a few changes: - The repository still uses Maven to manage dependency but it is now a Scala project. - The code has been ported from OWLAPI 3.4.10 to 5.1.20 - A proof of concept program using both RSAComb and PAGOdA has been added. --- .../pagoda/rules/approximators/Approximator.java | 42 ---- .../LimitedSkolemisationApproximator.java | 146 -------------- .../pagoda/rules/approximators/OverApproxBoth.java | 24 --- .../pagoda/rules/approximators/OverApproxDisj.java | 100 --------- .../rules/approximators/OverApproxExist.java | 224 --------------------- .../rules/approximators/SkolemTermsManager.java | 139 ------------- .../approximators/TupleDependentApproximator.java | 19 -- 7 files changed, 694 deletions(-) delete mode 100644 src/uk/ac/ox/cs/pagoda/rules/approximators/Approximator.java delete mode 100644 src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java delete mode 100644 src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxBoth.java delete mode 100644 src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxDisj.java delete mode 100644 src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxExist.java delete mode 100644 src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java delete mode 100644 src/uk/ac/ox/cs/pagoda/rules/approximators/TupleDependentApproximator.java (limited to 'src/uk/ac/ox/cs/pagoda/rules/approximators') diff --git a/src/uk/ac/ox/cs/pagoda/rules/approximators/Approximator.java b/src/uk/ac/ox/cs/pagoda/rules/approximators/Approximator.java deleted file mode 100644 index f910c64..0000000 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/Approximator.java +++ /dev/null @@ -1,42 +0,0 @@ -package uk.ac.ox.cs.pagoda.rules.approximators; - -import org.semanticweb.HermiT.model.DLClause; - -import java.util.Collection; - -public interface Approximator { - - Collection convert(DLClause clause, DLClause originalClause); - -} - -// TODO remove -//class IgnoreExist implements Approximator { -// -// @Override -// public Collection convert(DLClause clause, DLClause originalClause) { -// Collection ret = new LinkedList(); -// DLPredicate p; -// for (Atom headAtom: clause.getHeadAtoms()) { -// p = headAtom.getDLPredicate(); -// if (p instanceof AtLeast) return ret; -// } -// -// ret.add(clause); -// return ret; -// } -// -//} -// -// -// -//class IgnoreDisj implements Approximator { -// -// @Override -// public Collection convert(DLClause clause, DLClause originalClause) { -// Collection ret = new LinkedList(); -// if (clause.getHeadLength() > 1) return ret; -// ret.add(clause); -// return ret; -// } -//} diff --git a/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java b/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java deleted file mode 100644 index a140225..0000000 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java +++ /dev/null @@ -1,146 +0,0 @@ -package uk.ac.ox.cs.pagoda.rules.approximators; - -import org.semanticweb.HermiT.model.*; -import uk.ac.ox.cs.pagoda.multistage.MultiStageUpperProgram; -import uk.ac.ox.cs.pagoda.util.tuples.Tuple; -import uk.ac.ox.cs.pagoda.util.tuples.TupleBuilder; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - -/*** - * Approximates existential rules through a limited form of Skolemisation. - *

- * Given a rule and a ground substitution, - * it Skolemises the rule - * if all the terms in the substitution have depth less than a given depth, - * otherwise it approximates using an alternative TupleDependentApproximator. - */ -public class LimitedSkolemisationApproximator implements TupleDependentApproximator { - - private static final Atom[] EMPTY_BODY = new Atom[0]; - private static final Variable X = Variable.create("X"); - private final int maxTermDepth; - private final SkolemTermsManager skolemTermsManager; - - public LimitedSkolemisationApproximator(int maxTermDepth) { - this.maxTermDepth = maxTermDepth; - this.skolemTermsManager = SkolemTermsManager.getInstance(); - } - - @Override - public Collection convert(DLClause clause, - DLClause originalClause, - Collection> violationTuples) { - switch(clause.getHeadLength()) { - case 1: - return overApprox(clause, originalClause, violationTuples); - case 0: - return Collections.singletonList(clause); - default: - throw new IllegalArgumentException( - "Expected clause with head length < 1, but it is " + clause.getHeadLength()); - } - - - } - - public int getMaxDepth(Tuple violationTuple) { - int maxDepth = 0; - for(Individual individual : violationTuple) - maxDepth = Integer.max(maxDepth, skolemTermsManager.getDepthOf(individual)); - - return maxDepth; - } - - private Collection overApprox(DLClause clause, DLClause originalClause, Collection> violationTuples) { - ArrayList result = new ArrayList<>(); - for(Tuple violationTuple : violationTuples) { - result.addAll(getGroundSkolemisation(clause, - originalClause, violationTuple, getMaxDepth(violationTuple) >= maxTermDepth)); - } - - return result; - } - - private Collection getGroundSkolemisation(DLClause clause, - DLClause originalClause, - Tuple violationTuple, - boolean useClauseUniqueIndividual) { - - String[] commonVars = MultiStageUpperProgram.getCommonVars(clause); - - // TODO check: strong assumption, the first tuples are the common ones - TupleBuilder commonIndividualsBuilder = new TupleBuilder<>(); - for(int i = 0; i < commonVars.length; i++) - commonIndividualsBuilder.append(violationTuple.get(i)); - Tuple commonIndividuals = commonIndividualsBuilder.build(); - - Atom headAtom = clause.getHeadAtom(0); - -// Atom[] bodyAtoms = clause.getBodyAtoms(); - int offset = OverApproxExist.indexOfExistential(headAtom, originalClause); - - // BEGIN: copy and paste - ArrayList ret = new ArrayList<>(); - DLPredicate predicate = headAtom.getDLPredicate(); - if(predicate instanceof AtLeastConcept) { - AtLeastConcept atLeastConcept = (AtLeastConcept) predicate; - LiteralConcept concept = atLeastConcept.getToConcept(); - Role role = atLeastConcept.getOnRole(); - AtomicConcept atomicConcept; - - if(concept instanceof AtomicNegationConcept) { - Atom atom1 = - Atom.create(atomicConcept = ((AtomicNegationConcept) concept).getNegatedAtomicConcept(), X); - Atom atom2 = Atom.create(atomicConcept = OverApproxExist.getNegationConcept(atomicConcept), X); - ret.add(DLClause.create(new Atom[0], new Atom[]{atom1, atom2})); - } - else { - atomicConcept = (AtomicConcept) concept; - if(atomicConcept.equals(AtomicConcept.THING)) - atomicConcept = null; - } - - int card = atLeastConcept.getNumber(); - Individual[] individuals = new Individual[card]; - SkolemTermsManager termsManager = SkolemTermsManager.getInstance(); - for(int i = 0; i < card; ++i) - if(useClauseUniqueIndividual) - individuals[i] = termsManager.getFreshIndividual(originalClause, - offset + i, - maxTermDepth + 1); - else - individuals[i] = termsManager.getFreshIndividual(originalClause, - offset + i, - commonIndividuals); - - for(int i = 0; i < card; ++i) { - if(atomicConcept != null) - ret.add(DLClause.create(new Atom[]{Atom.create(atomicConcept, individuals[i])}, EMPTY_BODY)); - - Atom atom = role instanceof AtomicRole ? - Atom.create((AtomicRole) role, commonIndividuals.get(0), individuals[i]) : - Atom.create(((InverseRole) role).getInverseOf(), individuals[i], commonIndividuals.get(0)); - - ret.add(DLClause.create(new Atom[]{atom}, EMPTY_BODY)); - } - - for(int i = 0; i < card; ++i) - for(int j = i + 1; j < card; ++j) - // TODO to be checked ... different as - ret.add(DLClause.create(new Atom[]{Atom.create(Inequality.INSTANCE, individuals[i], individuals[j])}, EMPTY_BODY)); - - } - else if(predicate instanceof AtLeastDataRange) { - // TODO to be implemented ... - } - else - ret.add(DLClause.create(new Atom[]{headAtom}, EMPTY_BODY)); - - return ret; - - // END: copy and paste - } -} diff --git a/src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxBoth.java b/src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxBoth.java deleted file mode 100644 index ae2a2cf..0000000 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxBoth.java +++ /dev/null @@ -1,24 +0,0 @@ -package uk.ac.ox.cs.pagoda.rules.approximators; - -import org.semanticweb.HermiT.model.AtLeastDataRange; -import org.semanticweb.HermiT.model.DLClause; - -import java.util.Collection; -import java.util.LinkedList; - -public class OverApproxBoth implements Approximator { - - Approximator approxDist = new OverApproxDisj(), approxExist = new OverApproxExist(); - - @Override - public Collection convert(DLClause clause, DLClause originalClause) { - Collection ret = new LinkedList(); - for (DLClause tClause: approxDist.convert(clause, originalClause)) { - if (tClause.getHeadLength() > 0 && tClause.getHeadAtom(0).getDLPredicate() instanceof AtLeastDataRange) - continue; - ret.addAll(approxExist.convert(tClause, originalClause)); - } - return ret; - } - -} diff --git a/src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxDisj.java b/src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxDisj.java deleted file mode 100644 index 05d9442..0000000 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxDisj.java +++ /dev/null @@ -1,100 +0,0 @@ -package uk.ac.ox.cs.pagoda.rules.approximators; - -import org.semanticweb.HermiT.model.*; -import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; - -import java.util.*; - -public class OverApproxDisj implements Approximator { - - /** - * Splits a disjunctive rule into a bunch of rules. - *

- * It returns a collection containing a rule for each atom in the head of the input rule. - * Each rule has the same body of the input rule, - * and the relative head atom as head. - * */ - @Override - public Collection convert(DLClause clause, DLClause originalClause) { - LinkedList distincts = new LinkedList(); - Atom[] headAtoms = clause.getHeadAtoms(), bodyAtoms = clause.getBodyAtoms(); - LinkedList newClauses = new LinkedList(); - DLClause newClause; - if (headAtoms.length > 1) { - for (Atom headAtom: headAtoms) { - newClause = DLClause.create(new Atom[] {headAtom}, bodyAtoms); - newClauses.add(newClause); -// distincts.add(newClause); - } - - for (DLClause cls: newClauses) { - newClause = DLClauseHelper.simplified(cls); - if (!isSubsumedBy(newClause, distincts)) - distincts.add(newClause); - } - } - else distincts.add(clause); - - return distincts; - } - - public static boolean isSubsumedBy(DLClause newClause, Collection distinctClauses) { - Map unifier; - Set bodyAtoms = new HashSet(); - for (DLClause clause: distinctClauses) { - if (newClause.getHeadLength() > 0 && clause.getHeadLength() > 0 && - (unifier = isSubsumedBy(newClause.getHeadAtom(0), clause.getHeadAtom(0))) == null) - continue; - else - unifier = new HashMap(); - - for (Atom atom: clause.getBodyAtoms()) - bodyAtoms.add(rename(atom, unifier)); - unifier.clear(); - - for (Atom atom: newClause.getBodyAtoms()) - if (!bodyAtoms.contains(atom)) - continue; - - return true; - } - - return false; - } - - public static Map isSubsumedBy(Atom atom1, Atom atom2) { - DLPredicate predicate = atom1.getDLPredicate(); - if (!predicate.equals(atom2.getDLPredicate())) - return null; - - Map unifier = new HashMap(); - Term term1, term2; - for (int index = 0; index < predicate.getArity(); ++index) { - term1 = rename(atom1.getArgument(index), unifier); - term2 = rename(atom2.getArgument(index), unifier); - - if (term1.equals(term2)); - else if (term1 instanceof Variable) - unifier.put((Variable) term1, term2); - else - return null; - } - return unifier; - } - - public static Atom rename(Atom atom, Map unifier) { - Term[] arguments = new Term[atom.getArity()]; - for (int i = 0; i < atom.getArity(); ++i) - arguments[i] = rename(atom.getArgument(i), unifier); - return Atom.create(atom.getDLPredicate(), arguments); - } - - public static Term rename(Term argument, Map unifier) { - Term newArg; - while ((newArg = unifier.get(argument)) != null) - return newArg; - return argument; - } - - -} diff --git a/src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxExist.java b/src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxExist.java deleted file mode 100644 index 028568c..0000000 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxExist.java +++ /dev/null @@ -1,224 +0,0 @@ -package uk.ac.ox.cs.pagoda.rules.approximators; - -import org.semanticweb.HermiT.model.*; -import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; - -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; - -public class OverApproxExist implements Approximator { - - public static final String negativeSuffix = "_neg"; - private static final Variable X = Variable.create("X"); - - static int indexOfExistential(Atom headAtom, DLClause originalClause) { - if (!(headAtom.getDLPredicate() instanceof AtLeast)) return -1; - AtLeastConcept alc = (AtLeastConcept) headAtom.getDLPredicate(); - if (alc.getToConcept() instanceof AtomicConcept) { - AtomicConcept ac = (AtomicConcept) alc.getToConcept(); - if (ac.getIRI().endsWith(negativeSuffix)) { - alc = AtLeastConcept.create(alc.getNumber(), alc.getOnRole(), AtomicNegationConcept.create(getNegationConcept(ac))); - headAtom = Atom.create(alc, headAtom.getArgument(0)); - } - } - - int index = 0; - for (Atom atom: originalClause.getHeadAtoms()) { - if (atom.equals(headAtom)) - return index; - if (atom.getDLPredicate() instanceof AtLeast) - index += ((AtLeast) atom.getDLPredicate()).getNumber(); - } - return -1; - } - - public static AtomicConcept getNegationConcept(DLPredicate p) { - if (p.equals(AtomicConcept.THING)) return AtomicConcept.NOTHING; - if (p.equals(AtomicConcept.NOTHING)) return AtomicConcept.THING; - - if (p instanceof AtomicConcept) { - String iri = ((AtomicConcept) p).getIRI(); - if (iri.endsWith(negativeSuffix)) - iri = iri.substring(0, iri.length() - 4); - else - iri += negativeSuffix; - - return AtomicConcept.create(iri); - } - if (p instanceof AtLeastConcept) { - // FIXME !!! here - return null; - } - return null; - } - - @Override - public Collection convert(DLClause clause, DLClause originalClause) { - Collection ret; - switch (clause.getHeadLength()) { - case 1: - return overApprox(clause.getHeadAtom(0), clause.getBodyAtoms(), originalClause); - case 0: - ret = new LinkedList(); - ret.add(clause); - return ret; - default: - ret = new LinkedList(); - for (Iterator iter = new DisjunctiveHeads(clause, originalClause); iter.hasNext(); ) - ret.add(iter.next()); - return ret; - } - } - - public Collection overApprox(Atom headAtom, Atom[] bodyAtoms, DLClause originalClause) { - return overApprox(headAtom, bodyAtoms, originalClause, indexOfExistential(headAtom, originalClause)); - } - - public Collection overApprox(Atom headAtom, Atom[] bodyAtoms, DLClause originalClause, int offset) { - Collection ret = new LinkedList(); - DLPredicate predicate = headAtom.getDLPredicate(); - if (predicate instanceof AtLeastConcept) { - AtLeastConcept atLeastConcept = (AtLeastConcept) predicate; - LiteralConcept concept = atLeastConcept.getToConcept(); - Role role = atLeastConcept.getOnRole(); - AtomicConcept atomicConcept = null; - - if (concept instanceof AtomicNegationConcept) { - // TODO CHECK: is this already in MultiStageUpperProgram? - Atom atom1 = Atom.create(atomicConcept = ((AtomicNegationConcept) concept).getNegatedAtomicConcept(), X); - Atom atom2 = Atom.create(atomicConcept = getNegationConcept(atomicConcept), X); - ret.add(DLClause.create(new Atom[0], new Atom[] {atom1, atom2})); - } - else { - atomicConcept = (AtomicConcept) concept; - if (atomicConcept.equals(AtomicConcept.THING)) - atomicConcept = null; - } - - int card = atLeastConcept.getNumber(); - Individual[] individuals = new Individual[card]; - SkolemTermsManager termsManager = SkolemTermsManager.getInstance(); - for (int i = 0; i < card; ++i) individuals[i] = termsManager.getFreshIndividual(originalClause, offset + i); - - for (int i = 0; i < card; ++i) { - if (atomicConcept != null) - ret.add(DLClause.create(new Atom[] {Atom.create(atomicConcept, individuals[i])}, bodyAtoms)); - - Atom atom = role instanceof AtomicRole ? - Atom.create((AtomicRole) role, X, individuals[i]) : - Atom.create(((InverseRole) role).getInverseOf(), individuals[i], X); - - ret.add(DLClause.create(new Atom[] {atom}, bodyAtoms)); - } - - for (int i = 0; i < card; ++i) - for (int j = i + 1; j < card; ++j) - // TODO to be checked ... different as - ret.add(DLClause.create(new Atom[] {Atom.create(Inequality.INSTANCE, individuals[i], individuals[j])}, bodyAtoms)); - //DLClauseHelper.contructor_differentAs(individuals[i], individuals[j])); - - } - else if (predicate instanceof AtLeastDataRange) { - // TODO to be implemented ... - } - else - ret.add(DLClause.create(new Atom[] {headAtom}, bodyAtoms)); - - return ret; - } - - class DisjunctiveHeads implements Iterator { - - Atom[] bodyAtoms; - Atom[][] disjunctHeadAtoms; - int[] pointer; - int length, l; - LinkedList auxiliaryClauses = new LinkedList(); - - public DisjunctiveHeads(DLClause clause, DLClause originalClause) { - length = clause.getHeadLength(); - - bodyAtoms = clause.getBodyAtoms(); - disjunctHeadAtoms = new Atom[length][]; - pointer = new int[length]; - if (length > 0) l = length - 1; - else length = 0; - - int index = 0, offset = 0; - Collection datalogRules; - DLClause newClause; - for (Atom headAtom: clause.getHeadAtoms()) { - pointer[index] = 0; - - datalogRules = overApprox(headAtom, bodyAtoms, originalClause, offset); - - if (datalogRules.isEmpty()) { - l = -1; - auxiliaryClauses.clear(); - return ; - } - - for (Iterator iter = datalogRules.iterator(); iter.hasNext(); ) { - newClause = iter.next(); - if (!DLClauseHelper.hasSubsetBodyAtoms(newClause, clause)) { - auxiliaryClauses.add(newClause); - iter.remove(); - } - } - - disjunctHeadAtoms[index] = new Atom[datalogRules.size()]; - - int j = 0; - for (DLClause disjunct: datalogRules) { - disjunctHeadAtoms[index][j++] = disjunct.getHeadAtom(0); - } - - ++index; - if (headAtom.getDLPredicate() instanceof AtLeast) - offset += ((AtLeast) headAtom.getDLPredicate()).getNumber(); - - } - - } - - @Override - public boolean hasNext() { - return l != -1 || !auxiliaryClauses.isEmpty(); - } - - @Override - public DLClause next() { - if (l == -1) - return auxiliaryClauses.removeFirst(); - - if (length > 0) { - Atom[] headAtoms = new Atom[length]; - for (int i = 0; i < length; ++i) - headAtoms[i] = disjunctHeadAtoms[i][pointer[i]]; - - ++pointer[l]; - while (l >= 0 && pointer[l] >= disjunctHeadAtoms[l].length) { - pointer[l] = 0; - --l; - if (l >= 0) - ++pointer[l]; - } - - if (l >= 0) l = length - 1; - - return DLClauseHelper.simplified(DLClause.create(headAtoms, bodyAtoms)); -// return DLClause.create(headAtoms, bodyAtoms); - } - else { - --l; - return DLClauseHelper.simplified(DLClause.create(new Atom[0], bodyAtoms)); -// return DLClause.create(new Atom[0], bodyAtoms); - } - } - - @Override - public void remove() { } - - } -} diff --git a/src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java b/src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java deleted file mode 100644 index ed93d0e..0000000 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java +++ /dev/null @@ -1,139 +0,0 @@ -package uk.ac.ox.cs.pagoda.rules.approximators; - -import org.semanticweb.HermiT.model.*; -import uk.ac.ox.cs.pagoda.util.Namespace; -import uk.ac.ox.cs.pagoda.util.tuples.Tuple; - -import java.util.HashMap; -import java.util.Map; - -/** - * If you need a Skolem term (i.e. fresh individual), ask this class. - */ -public class SkolemTermsManager { - - public static final String SKOLEMISED_INDIVIDUAL_PREFIX = Namespace.PAGODA_ANONY + "individual"; - public static final String RULE_UNIQUE_SKOLEMISED_INDIVIDUAL_PREFIX = SKOLEMISED_INDIVIDUAL_PREFIX + "_unique"; - - private static SkolemTermsManager skolemTermsManager; - - private int termsCounter = 0; - private Map clauseToId_map = new HashMap<>(); - private Map individualToDepth_map = new HashMap<>(); - private int dependenciesCounter = 0; - - private Map, Integer> dependencyToId_map = new HashMap<>(); - - private SkolemTermsManager() { - } - - public static int indexOfSkolemisedIndividual(Atom atom) { - Term t; - for(int index = 0; index < atom.getArity(); ++index) { - t = atom.getArgument(index); - if(t instanceof Individual && ((Individual) t).getIRI().contains(SKOLEMISED_INDIVIDUAL_PREFIX)) - return index; - } - return -1; - } - - /** - * Returns the existing unique SkolemTermsManager or a new one. - *

- * Indeed the SkolemTermsManager is a singleton. - */ - public static SkolemTermsManager getInstance() { - if(skolemTermsManager == null) skolemTermsManager = new SkolemTermsManager(); - return skolemTermsManager; - } - - /** - * Get a fresh Individual, unique for the clause, the offset and the dependency. - */ - public Individual getFreshIndividual(DLClause originalClause, int offset, Tuple dependency) { - String termId = Integer.toString(mapClauseToId(originalClause) + offset) - + "_" + mapDependencyToId(dependency); - Individual newIndividual = Individual.create(SKOLEMISED_INDIVIDUAL_PREFIX + termId); - - if(!individualToDepth_map.containsKey(newIndividual)) { - int depth = 0; - for (Individual individual : dependency) - depth = Integer.max(depth, getDepthOf(individual)); - individualToDepth_map.put(newIndividual, depth + 1); - } - - return newIndividual; - } - - /*** - * Create a term of a given depth, unique for the clause and the depth. - * - * @param originalClause - * @param offset - * @param depth - * @return - */ - public Individual getFreshIndividual(DLClause originalClause, int offset, int depth) { - String termId = Integer.toString(mapClauseToId(originalClause) + offset) + "_depth_" + depth; - Individual newIndividual = Individual.create(RULE_UNIQUE_SKOLEMISED_INDIVIDUAL_PREFIX + termId); - - individualToDepth_map.putIfAbsent(newIndividual, depth); - - return newIndividual; - } - - /** - * Get a fresh Individual, unique for the clause and the offset. - */ - public Individual getFreshIndividual(DLClause originalClause, int offset) { - String termId = Integer.toString(mapClauseToId(originalClause) + offset); - return Individual.create(SKOLEMISED_INDIVIDUAL_PREFIX + termId); - } - - /** - * Get the depth of a term. - *

- * The term must have been generated by this manager. - */ - public int getDepthOf(Individual individual) { - if(individualToDepth_map.containsKey(individual)) return individualToDepth_map.get(individual); - else return 0; - } - - /** - * Get the number of individuals generated by this manager. - */ - public int getSkolemIndividualsCount() { - return individualToDepth_map.keySet().size(); - } - - /** - * Just for reading the clause id from LimitedSkolemisationApproximator. - */ - int getClauseId(DLClause clause) { - return clauseToId_map.get(clause); - } - - private int mapClauseToId(DLClause clause) { - if(!clauseToId_map.containsKey(clause)) { - clauseToId_map.put(clause, termsCounter); - termsCounter += noOfExistential(clause); - } - return clauseToId_map.get(clause); - } - - private int mapDependencyToId(Tuple dependency) { - if(!dependencyToId_map.containsKey(dependency)) - dependencyToId_map.put(dependency, dependenciesCounter++); - return dependencyToId_map.get(dependency); - } - - private int noOfExistential(DLClause originalClause) { - int no = 0; - for(Atom atom : originalClause.getHeadAtoms()) - if(atom.getDLPredicate() instanceof AtLeast) - no += ((AtLeast) atom.getDLPredicate()).getNumber(); - return no; - } - -} diff --git a/src/uk/ac/ox/cs/pagoda/rules/approximators/TupleDependentApproximator.java b/src/uk/ac/ox/cs/pagoda/rules/approximators/TupleDependentApproximator.java deleted file mode 100644 index c99a1ad..0000000 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/TupleDependentApproximator.java +++ /dev/null @@ -1,19 +0,0 @@ -package uk.ac.ox.cs.pagoda.rules.approximators; - -import org.semanticweb.HermiT.model.DLClause; -import org.semanticweb.HermiT.model.Individual; -import uk.ac.ox.cs.pagoda.util.tuples.Tuple; - -import java.util.Collection; - -/** - * It can approximate clauses according to a collection of tuples of individuals. - *

- * In particular it can be used to approximate rules given some body instantiations. - */ -public interface TupleDependentApproximator { - - Collection convert(DLClause clause, - DLClause originalClause, - Collection> individualsTuples); -} -- cgit v1.2.3