本文整理汇总了Java中org.semanticweb.owlapi.model.SWRLRule.getBody方法的典型用法代码示例。如果您正苦于以下问题:Java SWRLRule.getBody方法的具体用法?Java SWRLRule.getBody怎么用?Java SWRLRule.getBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.semanticweb.owlapi.model.SWRLRule
的用法示例。
在下文中一共展示了SWRLRule.getBody方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.semanticweb.owlapi.model.SWRLRule; //导入方法依赖的package包/类
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()])));
}
}