public void processAxioms(Collection<? extends OWLAxiom> axioms) { AxiomVisitor axiomVisitor=new AxiomVisitor(); for (OWLAxiom axiom : axioms) axiom.accept(axiomVisitor); // now all axioms are in NNF and converted into disjunctions wherever possible // exact cardinalities are rewritten into at least and at most cardinalities etc // Rules with multiple head atoms are rewritten into several rules (Lloyd-Topor transformation) // normalize rules, this might add new concept and data range inclusions // in case a rule atom uses a complex concept or data range // we keep this inclusions separate because they are only applied to named individuals RuleNormalizer ruleNormalizer=new RuleNormalizer(m_axioms.m_rules,axiomVisitor.m_classExpressionInclusionsAsDisjunctions,axiomVisitor.m_dataRangeInclusionsAsDisjunctions); for (SWRLRule rule : axiomVisitor.m_rules) ruleNormalizer.visit(rule); // in normalization, we now simplify the disjuncts where possible (eliminate // unnecessary conjuncts/disjuncts) and introduce fresh atomic concepts for complex // concepts m_axioms.m_conceptInclusions contains the normalized axioms after the normalization normalizeInclusions(axiomVisitor.m_classExpressionInclusionsAsDisjunctions,axiomVisitor.m_dataRangeInclusionsAsDisjunctions); }
public void processAxioms(Collection<? extends OWLAxiom> axioms) { AxiomVisitor axiomVisitor=new AxiomVisitor(); for (OWLAxiom axiom : axioms) { axiom = preprocessAssertion(axiom); axiom.accept(axiomVisitor); } // now all axioms are in NNF and converted into disjunctions wherever possible // exact cardinalities are rewritten into at least and at most cardinalities etc // Rules with multiple head atoms are rewritten into several rules (Lloyd-Topor transformation) // normalize rules, this might add new concept and data range inclusions // in case a rule atom uses a complex concept or data range // we keep this inclusions separate because they are only applied to named individuals RuleNormalizer ruleNormalizer=new RuleNormalizer(m_axioms.m_rules,axiomVisitor.m_classExpressionInclusionsAsDisjunctions,axiomVisitor.m_dataRangeInclusionsAsDisjunctions); for (SWRLRule rule : axiomVisitor.m_rules) ruleNormalizer.visit(rule); // in normalization, we now simplify the disjuncts where possible (eliminate // unnecessary conjuncts/disjuncts) and introduce fresh atomic concepts for complex // concepts m_axioms.m_conceptInclusions contains the normalized axioms after the normalization normalizeInclusions(axiomVisitor.m_classExpressionInclusionsAsDisjunctions,axiomVisitor.m_dataRangeInclusionsAsDisjunctions); }
protected static boolean isUnsupportedExtensionAxiom(OWLAxiom axiom) { return axiom instanceof OWLSubObjectPropertyOfAxiom || axiom instanceof OWLTransitiveObjectPropertyAxiom || axiom instanceof OWLSubPropertyChainOfAxiom || axiom instanceof OWLFunctionalObjectPropertyAxiom || axiom instanceof OWLInverseFunctionalObjectPropertyAxiom || axiom instanceof SWRLRule; }
@Override public SWRLRule getAxiomWithoutAnnotations() { if (!isAnnotated()) { return this; } return new SWRLRuleImpl(getBody(), getHead(), NO_ANNOTATIONS); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (!(obj instanceof SWRLRule)) { return false; } SWRLRule other = (SWRLRule) obj; return other.getBody().equals(body) && other.getHead().equals(head); }
@Override protected int compareObjectOfSameType(OWLObject object) { SWRLRule other = (SWRLRule) object; int diff = compareSets(getBody(), other.getBody()); if (diff == 0) { diff = compareSets(getHead(), other.getHead()); } return diff; }
public void visit(SWRLRule axiom) { notSupported(axiom); }
public AxiomVisitor() { m_classExpressionInclusionsAsDisjunctions=new ArrayList<OWLClassExpression[]>(); m_dataRangeInclusionsAsDisjunctions=new ArrayList<OWLDataRange[]>(); m_rules=new HashSet<SWRLRule>(); m_alreadyExists=new boolean[1]; }
public void visit(SWRLRule rule) { }
public void visit(SWRLRule rule) { // Process head one-by-one and thus break up the conjunction in the head. for (SWRLAtom headAtom : rule.getHead()) { m_individualsToVariables.clear(); m_bodyAtoms.clear(); m_headAtoms.clear(); m_variableRepresentative.clear(); m_normalizedBodyAtoms.clear(); m_normalizedHeadAtoms.clear(); m_bodyDataRangeVariables.clear(); m_headDataRangeVariables.clear(); // Initialize body with all atoms, and initialize head with just the atom we are processing. m_bodyAtoms.addAll(rule.getBody()); m_headAtoms.add(headAtom); // First process sameIndividual in the body to set up variable normalizations. for (SWRLAtom atom : rule.getBody()) { if (atom instanceof SWRLSameIndividualAtom) { m_bodyAtoms.remove(atom); SWRLSameIndividualAtom sameIndividualAtom=(SWRLSameIndividualAtom)atom; SWRLVariable variable1=getVariableFor(sameIndividualAtom.getFirstArgument()); SWRLIArgument argument2=sameIndividualAtom.getSecondArgument(); if (argument2 instanceof SWRLVariable) m_variableRepresentative.put((SWRLVariable)argument2,variable1); else { OWLIndividual individual=((SWRLIndividualArgument)argument2).getIndividual(); if (individual.isAnonymous()) throw new IllegalArgumentException("Internal error: Rules with anonymous individuals are not supported. "); m_individualsToVariables.put(individual.asOWLNamedIndividual(),variable1); m_bodyAtoms.add(m_factory.getSWRLClassAtom(m_factory.getOWLObjectOneOf(individual),variable1)); } } } // Now process head atoms; this might increase the number of body atoms. m_isPositive=true; while (!m_headAtoms.isEmpty()) m_headAtoms.remove(0).accept(this); // Now process body atoms. m_isPositive=false; while (!m_bodyAtoms.isEmpty()) m_bodyAtoms.remove(0).accept(this); // Do some checking and return the rule. if (!m_bodyDataRangeVariables.containsAll(m_headDataRangeVariables)) throw new IllegalArgumentException("A SWRL rule contains data range variables in the head, but not in the body, and this is not supported."); m_rules.add(new OWLAxioms.DisjunctiveRule(m_normalizedBodyAtoms.toArray(new SWRLAtom[m_normalizedBodyAtoms.size()]),m_normalizedHeadAtoms.toArray(new SWRLAtom[m_normalizedHeadAtoms.size()]))); } }
public Atom visit(SWRLRule rule) { throw new IllegalStateException("Internal error: this part of the code is unused."); }
public Boolean visit(SWRLRule rule) { throw new UnsupportedOperationException(); }
@Override public T visit(SWRLRule rule) { throw new IllegalArgumentException(SWRLRule.class.getSimpleName() + " cannot be converted to " + getTargetClass().getSimpleName()); }
@SuppressWarnings("static-method") public ElkSWRLRule convert(SWRLRule rule) { return new ElkSWRLRuleWrap<SWRLRule>(rule); }
@Override public ElkAxiom visit(SWRLRule rule) { return CONVERTER.convert(rule); }
@Override public void visit(SWRLRule rule) { defaultVisit(rule); }
@Override public OWLAxiom visit(SWRLRule rule) { return factory.getSWRLRule(rule.getBody(), rule.getHead(), annotations); }
@Override public void visit(SWRLRule rule) { }
@Override public Boolean visit(SWRLRule axiom) { return true; }
@Override public Boolean visit(SWRLRule axiom) { return false; }
@Override public Boolean visit(SWRLRule rule) { Objects.requireNonNull(rule); return add(this.df.getSWRLRule(rule.getBody(), rule.getHead(), reg(rule.getAnnotations()))); }
@Override public Boolean visit(SWRLRule rule) { Objects.requireNonNull(rule); return add(this.df.getSWRLRule(rule.getBody(), rule.getHead(), empty())); }
@Override public Set<ComplexIntegerAxiom> visit(SWRLRule axiom) { Objects.requireNonNull(axiom); throw TranslationException.newUnsupportedAxiomException(axiom); }
@Override public void visit(SWRLRule axiom) { ignoreOwlAxiom("SWRLRule", axiom); }
@Override public void visit(SWRLRule rule) { LOGGER.warn("Ignoring axiom {} . Reason: SWRL rules not supported.", rule); }
@Override public O visit(SWRLRule rule) { return doDefault(rule); }
@Override public void visit(SWRLRule rule) { type = AXIOM_TYPE_INDEX_BASE + rule.getAxiomType().getIndex(); }
@Override public OWLAxiom visit(SWRLRule rule) { return rule; }