Java Code Examples for org.semanticweb.owlapi.model.OWLClassExpression#accept()
The following examples show how to use
org.semanticweb.owlapi.model.OWLClassExpression#accept() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TBoxUnFoldingTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
OWLEquivalentClassesAxiom unfoldAxiom(OWLEquivalentClassesAxiom ax, OWLClass owlClass) { Set<OWLClassExpression> existing = ax.getClassExpressionsMinus(owlClass); OWLClassExpression ce; if (existing == null || existing.isEmpty()) { return null; } else if (existing.size() == 1) { ce = existing.iterator().next(); } else { ce = factory.getOWLObjectIntersectionOf(existing); } if(LOG.isDebugEnabled()) { LOG.debug("Unfolding axiom: "+ax); } OWLClassExpression unfolded = ce.accept(this); if (unfolded != null) { return factory.getOWLEquivalentClassesAxiom(owlClass, unfolded); } return null; }
Example 2
Source File: TBoxUnFoldingTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
Set<OWLClassExpression> unfoldExpressions(Collection<OWLClassExpression> expressions) { Set<OWLClassExpression> unfolded = new HashSet<OWLClassExpression>(); boolean changed = false; for (OWLClassExpression expression : expressions) { OWLClassExpression unfoldedExpression = expression.accept(this); if (unfoldedExpression != null) { changed = true; unfolded.add(unfoldedExpression); } else { unfolded.add(expression); } } if (changed) { return unfolded; } return null; }
Example 3
Source File: TBoxUnFoldingTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public OWLClassExpression visit(OWLClass owlClass) { OWLClassExpression ce = unfoldClasses.get(owlClass); if (ce != null) { if (LOG.isDebugEnabled()) { LOG.debug("Unfolding class: "+owlClass.getIRI()); } // recursive unfold OWLClassExpression unfold = ce.accept(this); if (unfold != null) { return unfold; } } return ce; }
Example 4
Source File: AssertInferredClassExpressions.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static Set<OWLObjectSomeValuesFrom> filterSVFs(final OWLClassFilter clsFilter, Set<OWLObjectSomeValuesFrom> svfs) { Predicate<OWLObjectSomeValuesFrom> predicate = new Predicate<OWLObjectSomeValuesFrom>() { @Override public boolean apply(OWLObjectSomeValuesFrom input) { OWLClassExpression filler = input.getFiller(); Boolean result = filler.accept(new OWLClassExpressionVisitorExAdapter<Boolean>(Boolean.FALSE){ @Override public Boolean visit(OWLClass cls) { return clsFilter.use(cls); } }); if (result != null) { return result.booleanValue(); } return false; } }; svfs = Sets.filter(svfs, predicate); return svfs; }
Example 5
Source File: CardinalityContraintsTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public HandlerResult visit(OWLObjectExactCardinality ce) { if (ce.getCardinality() == 0) { // remove the ce if the max cardinality is zero return HandlerResult.remove(); } final OWLClassExpression filler = ce.getFiller(); final HandlerResult recursive = filler.accept(this); OWLObjectSomeValuesFrom newCE; if (recursive == null) { newCE = factory.getOWLObjectSomeValuesFrom(ce.getProperty(), filler); } else if (recursive.remove) { return HandlerResult.remove(); } else { newCE = factory.getOWLObjectSomeValuesFrom(ce.getProperty(), recursive.modified); } return HandlerResult.modified(newCE); }
Example 6
Source File: CardinalityContraintsTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public HandlerResult visit(OWLObjectMinCardinality ce) { final OWLClassExpression filler = ce.getFiller(); final HandlerResult recursive = filler.accept(this); OWLObjectSomeValuesFrom newCE; if (recursive == null) { newCE = factory.getOWLObjectSomeValuesFrom(ce.getProperty(), filler); } else if (recursive.remove) { return HandlerResult.remove(); } else { newCE = factory.getOWLObjectSomeValuesFrom(ce.getProperty(), recursive.modified); } return HandlerResult.modified(newCE); }
Example 7
Source File: CardinalityContraintsTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public HandlerResult visit(OWLObjectUnionOf unionOf) { Set<OWLClassExpression> newOperands = new HashSet<OWLClassExpression>(); boolean changed = false; for (OWLClassExpression ce : unionOf.getOperands()) { HandlerResult handlerResult = ce.accept(this); if (handlerResult != null) { if (handlerResult.remove) { return HandlerResult.remove(); } changed = true; newOperands.add(handlerResult.modified); } else { newOperands.add(ce); } } if (changed) { if (newOperands.size() == 1) { return HandlerResult.modified(newOperands.iterator().next()); } return HandlerResult.modified(factory.getOWLObjectUnionOf(newOperands)); } return null; }
Example 8
Source File: CardinalityContraintsTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public HandlerResult visit(OWLObjectIntersectionOf intersectionOf) { Set<OWLClassExpression> newOperands = new HashSet<OWLClassExpression>(); boolean changed = false; for (OWLClassExpression ce : intersectionOf.getOperands()) { HandlerResult handlerResult = ce.accept(this); if (handlerResult != null) { if (handlerResult.remove) { return HandlerResult.remove(); } changed = true; newOperands.add(handlerResult.modified); } else { newOperands.add(ce); } } if (changed) { if (newOperands.size() == 1) { return HandlerResult.modified(newOperands.iterator().next()); } return HandlerResult.modified(factory.getOWLObjectIntersectionOf(newOperands)); } return null; }
Example 9
Source File: CardinalityContraintsTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void visit(OWLSubClassOfAxiom axiom) { OWLClassExpression subClass = axiom.getSubClass(); OWLClassExpression superClass = axiom.getSuperClass(); HandlerResult modifiedSubClass = subClass.accept(handler); HandlerResult modifiedSuperClass = superClass.accept(handler); if (modifiedSubClass != null || modifiedSuperClass != null) { if (modifiedSubClass != null) { if (modifiedSubClass.remove) { remove(ontology, axiom); return; } subClass = modifiedSubClass.modified; } if (modifiedSuperClass != null) { if (modifiedSuperClass.remove) { remove(ontology, axiom); return; } superClass = modifiedSuperClass.modified; } remove(ontology, axiom); OWLSubClassOfAxiom newAxiom = factory.getOWLSubClassOfAxiom(subClass, superClass, axiom.getAnnotations()); add(ontology, newAxiom); } }
Example 10
Source File: CardinalityContraintsTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void visit(OWLEquivalentClassesAxiom axiom) { Set<OWLClassExpression> newExpressions = new HashSet<OWLClassExpression>(); boolean changed = false; for (OWLClassExpression ce : axiom.getClassExpressions()) { HandlerResult result = ce.accept(handler); if (result != null) { if (result.remove) { // skip handling and immediately remove and return remove(ontology, axiom); return; } changed = true; newExpressions.add(result.modified); } else { newExpressions.add(ce); } } if (changed) { remove(ontology, axiom); OWLEquivalentClassesAxiom newAxiom = factory.getOWLEquivalentClassesAxiom(newExpressions, axiom.getAnnotations()); add(ontology, newAxiom); } }
Example 11
Source File: TBoxUnFoldingTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public OWLObjectMaxCardinality visit(OWLObjectMaxCardinality ce) { if (LOG.isDebugEnabled()) { LOG.debug("Unfolding max_cardinality: "+ce); } OWLClassExpression filler = ce.getFiller(); if (filler != null) { OWLClassExpression unfold = filler.accept(this); if (unfold != null) { return factory.getOWLObjectMaxCardinality(ce.getCardinality(), ce.getProperty(), unfold); } } return null; }
Example 12
Source File: AssertInferredClassExpressions.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static Set<OWLObjectSomeValuesFrom> getSuperSVFs(Set<OWLSubClassOfAxiom> axioms) { final Set<OWLObjectSomeValuesFrom> svfs = new HashSet<OWLObjectSomeValuesFrom>(); for (OWLSubClassOfAxiom existing : axioms) { OWLClassExpression superCE = existing.getSuperClass(); superCE.accept(new OWLClassExpressionVisitorAdapter() { @Override public void visit(OWLObjectSomeValuesFrom svf) { svfs.add(svf); } }); } return svfs; }
Example 13
Source File: AssertInferredClassExpressions.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static Set<OWLObjectSomeValuesFrom> getSVFs(Set<OWLClassExpression> expressions) { final Set<OWLObjectSomeValuesFrom> svfs = new HashSet<OWLObjectSomeValuesFrom>(); for(OWLClassExpression ce : expressions) { ce.accept(new OWLClassExpressionVisitorAdapter(){ @Override public void visit(OWLObjectSomeValuesFrom svf) { svfs.add(svf); } }); } return svfs; }
Example 14
Source File: TBoxUnFoldingTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public OWLObjectExactCardinality visit(OWLObjectExactCardinality ce) { if (LOG.isDebugEnabled()) { LOG.debug("Unfolding exact_cardinality: "+ce); } OWLClassExpression filler = ce.getFiller(); if (filler != null) { OWLClassExpression unfold = filler.accept(this); if (unfold != null) { return factory.getOWLObjectExactCardinality(ce.getCardinality(), ce.getProperty(), unfold); } } return null; }
Example 15
Source File: TBoxUnFoldingTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public OWLObjectMinCardinality visit(OWLObjectMinCardinality ce) { if (LOG.isDebugEnabled()) { LOG.debug("Unfolding min_cardinality: "+ce); } OWLClassExpression filler = ce.getFiller(); if (filler != null) { OWLClassExpression unfold = filler.accept(this); if (unfold != null) { return factory.getOWLObjectMinCardinality(ce.getCardinality(), ce.getProperty(), unfold); } } return null; }
Example 16
Source File: TBoxUnFoldingTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public OWLObjectAllValuesFrom visit(OWLObjectAllValuesFrom ce) { if (LOG.isDebugEnabled()) { LOG.debug("Unfolding all_values_from: "+ce); } OWLClassExpression filler = ce.getFiller(); if (filler != null) { OWLClassExpression unfold = filler.accept(this); if (unfold != null) { return factory.getOWLObjectAllValuesFrom(ce.getProperty(), unfold); } } return null; }
Example 17
Source File: TBoxUnFoldingTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public OWLObjectSomeValuesFrom visit(OWLObjectSomeValuesFrom ce) { if (LOG.isDebugEnabled()) { LOG.debug("Unfolding some_values_from: "+ce); } OWLClassExpression filler = ce.getFiller(); if (filler != null) { OWLClassExpression unfold = filler.accept(this); if (unfold != null) { return factory.getOWLObjectSomeValuesFrom(ce.getProperty(), unfold); } } return null; }
Example 18
Source File: TBoxUnFoldingTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public OWLObjectComplementOf visit(OWLObjectComplementOf ce) { if (LOG.isDebugEnabled()) { LOG.debug("Unfolding complement_of: "+ce); } OWLClassExpression operand = ce.getOperand(); if (operand != null) { OWLClassExpression unfold = operand.accept(this); if (unfold != null) { return factory.getOWLObjectComplementOf(unfold); } } return null; }
Example 19
Source File: OwlConverter.java From elk-reasoner with Apache License 2.0 | 4 votes |
@SuppressWarnings("static-method") public ElkClassExpression convert(OWLClassExpression owlClassExpression) { return owlClassExpression.accept(OWL_CLASS_EXPRESSION_CONVERTER); }
Example 20
Source File: TransitivityGraphTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Use the {@link ExpressionMaterializingReasoner} to also infer * 'REL some value from TARGET' unnamed super classes. * * @throws Exception */ @Test public void testExpectedRelations() throws Exception { final OWLClass in = graph.getOWLClassByIdentifier("GO:0030414"); // GO:0030414 ! peptidase inhibitor activity final OWLClass ac = graph.getOWLClassByIdentifier("GO:0008233"); // GO:0008233 ! peptidase activity List<String> propIds = Arrays.asList("BFO:0000050", "BFO:0000066", "RO:0002211", "RO:0002212", "RO:0002213", "RO:0002215", "RO:0002216"); Set<OWLObjectProperty> props = graph.relationshipIDsToPropertySet(propIds); ExpressionMaterializingReasoner r = new ExpressionMaterializingReasoner(graph.getSourceOntology(), new ElkReasonerFactory()); Logger.getLogger(ExpressionMaterializingReasoner.class).setLevel(Level.ERROR); Logger.getLogger("org.semanticweb.elk").setLevel(Level.ERROR); r.materializeExpressions(props); Set<OWLClassExpression> superClassExpressions = r.getSuperClassExpressions(in, false); final Set<String> foundProperties = new HashSet<String>(); for (OWLClassExpression ce : superClassExpressions) { ce.accept(new OWLClassExpressionVisitorAdapter(){ @Override public void visit(OWLClass cls) { if (cls.isBuiltIn() == false && ac.equals(cls)) { foundProperties.add("is_a"); } } @Override public void visit(OWLObjectSomeValuesFrom svf) { if (ac.equals(svf.getFiller())) { foundProperties.add(graph.getIdentifier(svf.getProperty())); } } }); } assertEquals(2, foundProperties.size()); assertTrue(foundProperties.contains("RO:0002211")); assertTrue(foundProperties.contains("RO:0002212")); }