/** * @param signature the signature to use * @param moduletype module type * @param useSemantics true if semantic locality should be used * @return a set of axioms that corresponds to the atom with the id INDEX */ public Collection<AxiomWrapper> getModule(Stream<OWLEntity> signature, boolean useSemantics, ModuleType moduletype) { // init signature Signature sig = new Signature(signature); sig.setLocality(false); modularizer.extract(axioms, sig, moduletype); return modularizer.getModule(); } }
/** * @param axioms axioms * @param c locality checker * @return new modularizer */ public static Modularizer buildModulariser(List<AxiomWrapper> axioms, LocalityChecker c) { Modularizer m = new Modularizer(c); m.preprocessOntology(axioms); return m; }
/** * add an axiom to a module * * @param axiom axiom */ private void addAxiomToModule(AxiomWrapper axiom) { axiom.setInModule(true); module.add(axiom); // update the signature addAxiomSig(axiom); }
/** * @param ax axiom add an axiom if it is non-local (or if noCheck is true) * @param noCheck true if locality check is not to be performed */ private void addNonLocal(AxiomWrapper ax, boolean noCheck) { if (noCheck || isNonLocal(ax)) { addAxiomToModule(ax); } }
/** * remove tautologies (axioms that are always local) from the ontology * temporarily */ private void removeTautologies() { // we might use it for another decomposition tautologies.clear(); for (AxiomWrapper p : axioms) { if (p.isUsed()) { // check whether an axiom is local wrt its own signature modularizer.extract(p, new Signature(p.getAxiom().signature()), type); if (modularizer.isTautology(p.getAxiom(), type)) { tautologies.add(p); p.setUsed(false); } } } }
/** * @param signature the signature to use * @param moduletype the module type * @return a set of axioms that corresponds to the atom with the id INDEX */ public Set<OWLAxiom> getNonLocal(Stream<OWLEntity> signature, ModuleType moduletype) { // init signature Signature sig = new Signature(signature); sig.setLocality(false); // do check modularizer.getLocalityChecker().setSignatureValue(sig); Set<OWLAxiom> result = new HashSet<>(); for (AxiomWrapper p : axioms) { if (!modularizer.getLocalityChecker().local(p.getAxiom())) { result.add(p.getAxiom()); } } return result; }
/** * build a module traversing axioms by a signature */ private void extractModuleQueue() { // init queue with a sig workQueue.addAll(sig.getSignature()); // add all the axioms that are non-local wrt given value of a // top-locality addNonLocal(sigIndex.getNonLocal(sig.topCLocal()), true); // main cycle while (!workQueue.isEmpty()) { // for all the axioms that contains entity in their signature Collection<AxiomWrapper> axioms = sigIndex.getAxioms(workQueue.poll()); addNonLocal(axioms, false); } }
/** * build signature for ENTITY and all dependent entities from toProcess; * look for modules in Module; * * @param entity * entity * @param module * Module * @param toProcess * toProcess */ @PortedFrom(file = "Incremental.cpp", name = "buildSignature") public void buildSignature(OWLEntity entity, Collection<AxiomWrapper> module, Set<OWLEntity> toProcess) { toProcess.remove(entity); setupSig(entity); Collection<AxiomWrapper> newModule = getModExtractor(false, null).getModularizer().getModule(); if (module.size() == newModule.size()) { return; } // smaller module: recurse Signature modSig = getModExtractor(false, null).getModularizer().getSignature(); modSig.getSignature().stream().filter(toProcess::contains).forEach(p -> buildSignature(p, newModule, toProcess)); }
/** * @param axiom axiom * @param signature signature * @param type type */ public void extract(AxiomWrapper axiom, Signature signature, ModuleType type) { this.extract(Collections.singletonList(axiom), signature, type); } }
/** * extract module wrt presence of a sig index * * @param list axioms */ private void extractModule(Collection<AxiomWrapper> list) { module.clear(); // clear the module flag in the input list.forEach(p -> p.setInModule(false)); list.stream().filter(AxiomWrapper::isUsed).forEach(p -> p.setInSearchSpace(true)); extractModuleQueue(); list.forEach(p -> p.setInSearchSpace(false)); }
/** * extract module wrt SIGNATURE and TYPE from the set of axioms * * @param axioms axiom * @param signature signature * @param type type */ public void extract(List<AxiomWrapper> axioms, Signature signature, ModuleType type) { boolean topLocality = type == ModuleType.TOP; sig = new Signature(signature.getSignature().stream()); checker.setSignatureValue(sig); sig.setLocality(topLocality); extractModule(axioms); if (type != ModuleType.STAR) { return; } // here there is a star: do the cycle until stabilization int size; do { size = module.size(); List<AxiomWrapper> oldModule = new ArrayList<>(module); topLocality = !topLocality; sig = new Signature(signature.getSignature().stream()); checker.setSignatureValue(sig); sig.setLocality(topLocality); extractModule(oldModule); } while (size != module.size()); }
/** * @param ax axiom add an axiom if it is non-local (or if noCheck is true) * @param noCheck true if locality check is not to be performed */ private void addNonLocal(AxiomWrapper ax, boolean noCheck) { if (noCheck || isNonLocal(ax)) { addAxiomToModule(ax); } }
/** * remove tautologies (axioms that are always local) from the ontology * temporarily */ private void removeTautologies() { // we might use it for another decomposition tautologies.clear(); for (AxiomWrapper p : axioms) { if (p.isUsed()) { // check whether an axiom is local wrt its own signature modularizer.extract(p, new Signature(p.getAxiom().signature()), type); if (modularizer.isTautology(p.getAxiom(), type)) { tautologies.add(p); p.setUsed(false); } } } }
/** * @param signature the signature to use * @param moduletype the module type * @return a set of axioms that corresponds to the atom with the id INDEX */ public Set<OWLAxiom> getNonLocal(Stream<OWLEntity> signature, ModuleType moduletype) { // init signature Signature sig = new Signature(signature); sig.setLocality(false); // do check modularizer.getLocalityChecker().setSignatureValue(sig); Set<OWLAxiom> result = new HashSet<>(); for (AxiomWrapper p : axioms) { if (!modularizer.getLocalityChecker().local(p.getAxiom())) { result.add(p.getAxiom()); } } return result; }
/** * build a module traversing axioms by a signature */ private void extractModuleQueue() { // init queue with a sig workQueue.addAll(sig.getSignature()); // add all the axioms that are non-local wrt given value of a // top-locality addNonLocal(sigIndex.getNonLocal(sig.topCLocal()), true); // main cycle while (!workQueue.isEmpty()) { // for all the axioms that contains entity in their signature Collection<AxiomWrapper> axioms = sigIndex.getAxioms(workQueue.poll()); addNonLocal(axioms, false); } }
/** * @param axiom axiom * @param signature signature * @param type type */ public void extract(AxiomWrapper axiom, Signature signature, ModuleType type) { this.extract(Collections.singletonList(axiom), signature, type); } }
/** * extract module wrt presence of a sig index * * @param list axioms */ private void extractModule(Collection<AxiomWrapper> list) { module.clear(); // clear the module flag in the input list.forEach(p -> p.setInModule(false)); list.stream().filter(AxiomWrapper::isUsed).forEach(p -> p.setInSearchSpace(true)); extractModuleQueue(); list.forEach(p -> p.setInSearchSpace(false)); }
/** * extract module wrt SIGNATURE and TYPE from the set of axioms * * @param axioms axiom * @param signature signature * @param type type */ public void extract(List<AxiomWrapper> axioms, Signature signature, ModuleType type) { boolean topLocality = type == ModuleType.TOP; sig = new Signature(signature.getSignature().stream()); checker.setSignatureValue(sig); sig.setLocality(topLocality); extractModule(axioms); if (type != ModuleType.STAR) { return; } // here there is a star: do the cycle until stabilization int size; do { size = module.size(); List<AxiomWrapper> oldModule = new ArrayList<>(module); topLocality = !topLocality; sig = new Signature(signature.getSignature().stream()); checker.setSignatureValue(sig); sig.setLocality(topLocality); extractModule(oldModule); } while (size != module.size()); }
/** * @param signature the signature to use * @param moduletype module type * @param useSemantics true if semantic locality should be used * @return a set of axioms that corresponds to the atom with the id INDEX */ public Collection<AxiomWrapper> getModule(Stream<OWLEntity> signature, boolean useSemantics, ModuleType moduletype) { // init signature Signature sig = new Signature(signature); sig.setLocality(false); modularizer.extract(axioms, sig, moduletype); return modularizer.getModule(); } }
/** * @param ax axiom add an axiom if it is non-local (or if noCheck is true) * @param noCheck true if locality check is not to be performed */ private void addNonLocal(AxiomWrapper ax, boolean noCheck) { if (noCheck || isNonLocal(ax)) { addAxiomToModule(ax); } }