Java 类org.semanticweb.owlapi.model.OWLSubClassOfAxiom 实例源码

项目:uel    文件:UelOntology.java   
private OWLClassExpression loadPrimitiveDefinition(OWLClass cls) {
    Set<OWLClassExpression> allDefinitions = new HashSet<>();
    for (OWLOntology ontology : ontologies) {
        for (OWLSubClassOfAxiom definingAxiom : ontology.getSubClassAxiomsForSubClass(cls)) {
            OWLClassExpression superClass = definingAxiom.getSuperClass();
            if (!superClass.equals(top)) {
                // do not expand definitions beyond top
                allDefinitions.add(definingAxiom.getSuperClass());
            }
        }
    }
    if (allDefinitions.size() < 1) {
        return null;
    }
    if (allDefinitions.size() > 1) {
        return OWLManager.getOWLDataFactory().getOWLObjectIntersectionOf(allDefinitions);
    }
    return allDefinitions.iterator().next();
}
项目:uel    文件:UelController.java   
private void addNewDissubsumptions() {
    OWLOntology negOntology = view.getSelectedOntologyNeg();
    if (negOntology.equals(UelModel.EMPTY_ONTOLOGY)) {
        negOntology = model.createOntology();
        updateView();
        view.setSelectedOntologyNeg(negOntology);
    }

    Set<OWLAxiom> newAxioms = refineController.getDissubsumptions();

    for (OWLAxiom axiom : newAxioms) {
        if (!(axiom instanceof OWLSubClassOfAxiom)) {
            throw new IllegalStateException("Expected new dissubsumptions to be encoded as OWLSubClassOfAxioms.");
        }
        if (negOntology.containsAxiom(axiom)) {
            throw new IllegalStateException("The negative goal already contains the following axiom: " + axiom);
        }
        negOntology.getOWLOntologyManager().addAxiom(negOntology, axiom);
    }
    undoStack.push(newAxioms);
}
项目:minerva    文件:FindGoCodes.java   
private Set<OWLClass> getNamedDirectSuperClasses(OWLClass current, OWLOntology model) {
    final Set<OWLClass> dedup = new HashSet<OWLClass>();
    Set<OWLOntology> closure = model.getImportsClosure();
    for (OWLOntology ont : closure) {
        for(OWLSubClassOfAxiom ax : ont.getSubClassAxiomsForSubClass(current)) {
            ax.getSuperClass().accept(new OWLClassExpressionVisitorAdapter(){

                @Override
                public void visit(OWLClass cls) {
                    if (cls.isBuiltIn() == false) {
                        dedup.add(cls);
                    }
                }
            });
        }
    }
    return dedup;
}
项目:UMLS-Terminology-Server    文件:RestrictionVisitor.java   
@Override
public void visit(OWLClass desc) {
  if (!processedClasses.contains(desc)) {
    // If we are processing inherited restrictions then we
    // recursively visit named supers. Note that we need to keep
    // track of the classes that we have processed so that we don't
    // get caught out by cycles in the taxonomy
    processedClasses.add(desc);
    for (final OWLOntology ontology : ontologies) {
      for (final OWLSubClassOfAxiom ax : ontology
          .getSubClassAxiomsForSubClass(desc)) {
        ax.getSuperClass().accept(this);
      }
    }
  }
}
项目:logmap-matcher    文件:DisjointnessAxiomExtractor.java   
/**
 * A ^ B -> bottom
 * @param reasoner
 * @param ontology
 * @param cls
 * @author Shuo Zhang
 * @return
 */
public static OWLClassNodeSet getExplicitDLDisjointnessAxioms(OWLReasoner reasoner, OWLOntology ontology, OWLClass cls){

    OWLClassNodeSet nodeSet = new OWLClassNodeSet();

    OWLClassExpression subExp;
    Set<OWLClassExpression> set;
       for (OWLSubClassOfAxiom sax : ontology.getSubClassAxiomsForSuperClass(OWLManager.getOWLDataFactory().getOWLNothing())) {
        subExp = sax.getSubClass();
        if (subExp instanceof OWLObjectIntersectionOf) {
            set = subExp.asConjunctSet();
            if (set.contains(cls) && set.size() == 2) {
                for (OWLClassExpression op : set) {
                    if (!op.equals(cls) && !op.isAnonymous()) {
                        nodeSet.addNode(reasoner.getEquivalentClasses(op));
                        break;
                    }
                }
            }
        }
       } 

       return nodeSet;

}
项目:owltools    文件:AbstractSimPreProcessor.java   
public Set<OWLClass> materializeClassExpressionsReferencedBy(OWLObjectProperty p) {
    Set<OWLClassExpression> xs = new HashSet<OWLClassExpression>();
    for (OWLAxiom ax : outputOntology.getReferencingAxioms(p, Imports.INCLUDED)) {
        if (ax instanceof OWLSubClassOfAxiom) {
            xs.addAll(getClassExpressionReferencedBy(p, ((OWLSubClassOfAxiom)ax).getSuperClass()));
        }
        else if (ax instanceof OWLClassAssertionAxiom) {
            xs.addAll(getClassExpressionReferencedBy(p, ((OWLClassAssertionAxiom)ax).getClassExpression()));
        }
        else if (ax instanceof OWLEquivalentClassesAxiom) {
            for (OWLClassExpression x : ((OWLEquivalentClassesAxiom)ax).getClassExpressions()) {
                xs.addAll(getClassExpressionReferencedBy(p,x));
            }
        }
    }
    return materializeClassExpressions(xs);
}
项目:owltools    文件:ProvenanceReasonerWrapper.java   
public boolean isEdgeEntailed(OWLEdge e, OWLOntology currentOntology, OWLReasoner reasoner) {
    OWLOntologyManager m = getManager();

    Set<OWLSubClassOfAxiom> scas = currentOntology.getSubClassAxiomsForSubClass(e.c);
    Set<OWLSubClassOfAxiom> rmAxioms = new HashSet<OWLSubClassOfAxiom>();
    for (OWLSubClassOfAxiom sca : scas) {
        if (sca.getSuperClass().equals(e.p)) {
            LOG.info("REMOVING: "+sca);
            rmAxioms.add(sca);
        }
    }
    boolean isEdgeAsserted = rmAxioms.size() > 0;
    if (isEdgeAsserted) {
        m.removeAxioms(currentOntology, rmAxioms);
        reasoner.flush();
    }
    boolean isEntailed;
    isEntailed = reasoner.getSuperClasses(e.c, false).containsEntity(e.p);
    if (isEdgeAsserted) {
        m.addAxioms(currentOntology, rmAxioms);
        reasoner.flush();
    }

    return isEntailed;
}
项目:owltools    文件:RedundantInferences.java   
/**
 * Remove the redundant and marked as inferred super class assertions for
 * each class in the ontology signature. Uses the reasoner to infer the
 * direct super classes.
 * 
 * @param ontology
 * @param reasoner
 * @return map of class to set of redundant axioms
 */
public static Map<OWLClass, Set<RedundantAxiom>> removeRedundantSubClassAxioms(OWLOntology ontology, OWLReasoner reasoner) {
    Iterable<OWLClass> classes = ontology.getClassesInSignature();
    Map<OWLClass, Set<RedundantAxiom>> axioms = findRedundantSubClassAxioms(classes, ontology, reasoner);
    if (!axioms.isEmpty()) {
        Set<OWLSubClassOfAxiom> allAxioms = new THashSet<OWLSubClassOfAxiom>();
        for(OWLClass cls : axioms.keySet()) {
            for(RedundantAxiom redundantAxiom : axioms.get(cls)) {
                allAxioms.add(redundantAxiom.getAxiom());
            }
        }
        OWLOntologyManager manager = ontology.getOWLOntologyManager();
        manager.removeAxioms(ontology, allAxioms);
        LOG.info("Removed "+axioms.size()+" redundant axioms.");
    }
    return axioms;

}
项目:owltools    文件:LinkMaker.java   
/**
 * Check that the given subClass does not already has a matching subClass axiom.
 * 
 * @param subCls
 * @param p
 * @param superCls
 * @return existing axiom or null
 */
private OWLAxiom hasLinks(OWLClass subCls, OWLObjectProperty p, OWLClass superCls) {
    for(OWLOntology o : allOntologies) {
        Set<OWLSubClassOfAxiom> subClsAxioms = o.getSubClassAxiomsForSubClass(subCls);
        for (OWLSubClassOfAxiom subClsAxiom : subClsAxioms) {
            OWLClassExpression ce = subClsAxiom.getSuperClass();
            if (ce instanceof OWLObjectSomeValuesFrom) {
                OWLObjectSomeValuesFrom someValuesFrom = (OWLObjectSomeValuesFrom) ce;
                OWLObjectPropertyExpression property = someValuesFrom.getProperty();
                if (p.equals(property)) {
                    OWLClassExpression filler = someValuesFrom.getFiller();
                    if (superCls.equals(filler)) {
                        return subClsAxiom;
                    }
                }
            }
        }
    }
    return null;
}
项目:owltools    文件:TemplatedTransformer.java   
public Set<Mapping> getMappings() {
    Set<Mapping> ms = new HashSet<Mapping>();
    OWLAnnotationProperty vap = getVariableAnnotationProperty();
    for (OWLSubClassOfAxiom sca : ontology.getAxioms(AxiomType.SUBCLASS_OF, Imports.INCLUDED)) {
        Mapping m = new Mapping();
        Set<OWLAnnotation> anns = sca.getAnnotations(vap);
        for (OWLAnnotation ann : anns) {
            IRI v = (IRI) ann.getValue();
            m.vars.add(v);
        }
        if (m.vars.size() > 0) {
            m.src = sca.getSubClass();
            m.tgt = sca.getSuperClass();
            ms.add(m);
            LOG.info("MAPPING: "+m);
        }
    }
    return ms;

}
项目:owltools    文件:OWLGraphWrapperEdgesAdvanced.java   
Set<OWLClass> getSvfClasses(OWLClass c, OWLObjectProperty p) {
    Set<OWLSubClassOfAxiom> axioms = new HashSet<OWLSubClassOfAxiom>();
    for(OWLOntology ont : getAllOntologies()) {
        axioms.addAll(ont.getSubClassAxiomsForSubClass(c));
    }
    Set<OWLClass> superClasses = new HashSet<OWLClass>();
    for (OWLSubClassOfAxiom axiom : axioms) {
        OWLClassExpression expr = axiom.getSuperClass();
        if (expr instanceof OWLObjectSomeValuesFrom) {
            OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) expr;
            if (p.equals(svf.getProperty())) {
                OWLClassExpression filler = svf.getFiller();
                if (filler instanceof OWLClass) {
                    superClasses.add((OWLClass) filler);
                }
            }
        }
    }
    return superClasses;
}
项目:owltools    文件:OWLGraphWrapperEdgesAdvanced.java   
private Map<OWLClass, Set<OWLSubClassOfAxiom>> initNeighborAxioms() {
    Map<OWLClass, Set<OWLSubClassOfAxiom>> result = new HashMap<OWLClass, Set<OWLSubClassOfAxiom>>();
    for(OWLOntology ont : getAllOntologies()) {
        for(OWLSubClassOfAxiom ax : ont.getAxioms(AxiomType.SUBCLASS_OF)) {
            Set<OWLClass> inSignature = ax.getClassesInSignature();
            for (OWLClass cls : inSignature) {
                Set<OWLSubClassOfAxiom> neighbors = result.get(cls);
                if (neighbors == null) {
                    neighbors = new HashSet<OWLSubClassOfAxiom>();
                    result.put(cls, neighbors);
                }
                neighbors.add(ax);
            }
        }
    }

    return result;
}
项目:owltools    文件:CardinalityContraintsTools.java   
@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);
    }
}
项目:owltools    文件:RedundantInferencesTest.java   
@Test
    public void test() throws Exception {
        Map<OWLClass, Set<RedundantAxiom>> redundantAxiomMap = RedundantInferences.removeRedundantSubClassAxioms(graph.getSourceOntology(), reasoner);
        assertNotNull(redundantAxiomMap);
        assertEquals(1, redundantAxiomMap.size());

        OWLClass test1Sub = graph.getOWLClassByIdentifier("FOO:0004");
        OWLClass test1Super = graph.getOWLClassByIdentifier("FOO:0002");
        Set<RedundantAxiom> redundantAxioms = redundantAxiomMap.get(test1Sub);
        assertEquals(1, redundantAxioms.size());
        RedundantAxiom redundantAxiom = redundantAxioms.iterator().next();
        OWLSubClassOfAxiom owlAxiom = redundantAxiom.getAxiom();
        assertTrue(AxiomAnnotationTools.isMarkedAsInferredAxiom(owlAxiom));
        assertEquals(test1Super, owlAxiom.getSuperClass());
        Set<OWLClass> moreSpecific = redundantAxiom.getMoreSpecific();
        assertEquals(1, moreSpecific.size());
        OWLClass moreSpecificClass = moreSpecific.iterator().next();
        assertEquals(graph.getOWLClassByIdentifier("FOO:0003"), moreSpecificClass);


//      graph.getManager().saveOntology(graph.getSourceOntology(), System.err);
    }
项目:owltools    文件:CycleCheck.java   
@Override
public List<OWLClass> getAdjacent(OWLClass cls) {
    Set<OWLClass> results = new HashSet<OWLClass>();
    Set<OWLOntology> allOntologies = graph.getAllOntologies();
    for (OWLOntology owlOntology : allOntologies) {
        Set<OWLSubClassOfAxiom> axioms = owlOntology.getSubClassAxiomsForSubClass(cls);
        if (axioms != null && !axioms.isEmpty()) {
            for (OWLSubClassOfAxiom axiom : axioms) {
                OWLClassExpression expression = axiom.getSuperClass();
                if (!expression.isAnonymous()) {
                    results.add(expression.asOWLClass());
                }
            }
        }
    }
    if (results.isEmpty()) {
        return Collections.emptyList();
    }
    return new ArrayList<OWLClass>(results);
}
项目:owltools    文件:NCBIConverter.java   
/**
 * Check to make sure that this taxon has the required properties.
 *
 * <ul>
 * <li>label exists</li>
 * <li>exactly one superClass</li>
 * </ul>
 *
 * @param ontology the current ontology
 * @param taxon the subject
 * @return true if the check succeeds, otherwise false.
 */
public static Boolean checkTaxon(OWLOntology ontology, 
        OWLClass taxon) {
    String id = getTaxonID(taxon);

    String label = getFirstLiteral(ontology, taxon,
        "rdfs:label");
    if (label == null || label.trim().length() == 0) {
        logger.error("No SCIENTIFIC NAME provided for " + id);
        return false;
    }
    Set<OWLSubClassOfAxiom> axioms = ontology.getSubClassAxiomsForSubClass(taxon);
    Set<OWLClassExpression> superClasses = new HashSet<>();
    for(OWLSubClassOfAxiom ax : axioms) {
        superClasses.add(ax.getSuperClass());
    }
    if (superClasses.size() < 1 && !id.equals("1")) {
        logger.error("No PARENT ID for " + id);
        return false;
    } else if (superClasses.size() > 1) {
        logger.error("Multiple PARENT IDs for " + id);
        return false;
    }

    return true;
}
项目:SciGraph    文件:ReasonerUtil.java   
void removeRedundantAxioms() {
  final List<RemoveAxiom> changes = new ArrayList<RemoveAxiom>();
  Set<OWLClass> allClasses = ont.getClassesInSignature(true);
  logger.info("Check classes for redundant super class axioms, all OWL classes count: " + allClasses.size());
  for (OWLClass cls: allClasses) {
    final Set<OWLClass> directSuperClasses = reasoner.getSuperClasses(cls, true).getFlattened();
    for (final OWLOntology importedOntology: ont.getImportsClosure()) {
      Set<OWLSubClassOfAxiom> subClassAxioms = importedOntology.getSubClassAxiomsForSubClass(cls);
      for (final OWLSubClassOfAxiom subClassAxiom : subClassAxioms) {
        subClassAxiom.getSuperClass().accept(new OWLClassExpressionVisitorAdapter(){
          @Override
          public void visit(OWLClass desc) {
            if (directSuperClasses.contains(desc) == false) {
              changes.add(new RemoveAxiom(importedOntology, subClassAxiom));
            }
          }
        });
      }
    }
  }
  logger.info("Found redundant axioms: " + changes.size());
  List<OWLOntologyChange> result = manager.applyChanges(changes);
  logger.info("Removed axioms: " + result.size());
}
项目:SciGraph    文件:GraphOwlVisitor.java   
@Override
public Void visit(OWLSubClassOfAxiom axiom) {
  long subclass = getOrCreateNode(getIri(axiom.getSubClass()));
  long superclass = getOrCreateNode(getIri(axiom.getSuperClass()));
  long relationship =
      getOrCreateRelationship(subclass, superclass, OwlRelationships.RDFS_SUBCLASS_OF);
  for (OWLAnnotation annotation : axiom.getAnnotations()) {
    // TODO: Is there a more elegant way to process these annotations?
    String property = annotation.getProperty().getIRI().toString();
    if (annotation.getValue() instanceof OWLLiteral) {
      Optional<Object> value =
          OwlApiUtils.getTypedLiteralValue((OWLLiteral) annotation.getValue());
      if (value.isPresent()) {
        graph.addRelationshipProperty(relationship, property, value.get());
      }
    }
  }
  return null;
}
项目:semantika    文件:OwlClassStructureHandler.java   
private void addSubClassAxiom(OWLSubClassOfAxiom axiom)
{
   OWLClassExpression subClass = axiom.getSubClass();
   OWLClassExpression superClass = axiom.getSuperClass();

   OwlNode<OWLClassExpression> subClassNode = createNode(subClass);
   OwlNode<OWLClassExpression> superClassNode = createNode(superClass);

   if (mClassCache.contains(subClass)) {
      subClassNode = findNode(subClass);
      superClassNode.setParent(subClassNode.getParent());
      subClassNode.setParent(superClassNode);
   }
   else if (mClassCache.contains(superClass)) {
      superClassNode = findNode(superClass);
      subClassNode.setParent(superClassNode);
   }
   else {
      superClassNode.setParent(mRoot);
      subClassNode.setParent(superClassNode);
   }
   mClassCache.add(subClass);
   mClassCache.add(superClass);
}
项目:semantika    文件:AbstractOwlOntology.java   
/**
 * Gets the set of subclass axioms that build the hierarchy structure from specified class
 * expression down to its all descendants.
 * 
 * @param entity
 *           The class expression whose subclasses are to be traced.
 * @param includeSelf
 *           Specifies if the given class expression is included in the returned set.
 * @return Returns a set of subclass axioms.
 */
public Set<OWLSubClassOfAxiom> traceDescendants(OWLClassExpression entity, boolean includeSelf)
{
   Set<OWLSubClassOfAxiom> toReturn = new LinkedHashSet<OWLSubClassOfAxiom>();

   OwlNodeSet<OWLClassExpression> descendants = new OwlNodeSet<OWLClassExpression>();
   if (includeSelf) {
      descendants.addNode(mClassStructureHandler.findNode(entity));
   }
   descendants.addNodeSet(mClassStructureHandler.getDescendants(entity, false));
   for (OwlNode<OWLClassExpression> node : descendants.getNodes()) {
      if (!node.getParent().isRoot()) {
         OWLClassExpression subClass = node.getEntity();
         OWLClassExpression superClass = node.getParent().getEntity();
         OWLSubClassOfAxiom ax = mOwlDataFactory.getOWLSubClassOfAxiom(subClass, superClass);
         toReturn.add(ax);
      }
   }
   return toReturn;
}
项目:semantika    文件:AbstractOwlOntology.java   
/**
 * Gets the set of subclass axioms that build the hierarchy structure from specified class
 * expression up to its all ancestors.
 * 
 * @param entity
 *           The class expression whose super classes are to be traced.
 * @param includeSelf
 *           Specifies if the given class expression is included in the returned set.
 * @return Returns a set of subclass axioms.
 */
public Set<OWLSubClassOfAxiom> traceAncestors(OWLClassExpression entity, boolean includeSelf)
{
   Set<OWLSubClassOfAxiom> toReturn = new LinkedHashSet<OWLSubClassOfAxiom>();

   OwlNodeSet<OWLClassExpression> ancestors = new OwlNodeSet<OWLClassExpression>();
   if (includeSelf) {
      ancestors.addNode(mClassStructureHandler.findNode(entity));
   }
   ancestors.addNodeSet(mClassStructureHandler.getAncestors(entity, false));
   for (OwlNode<OWLClassExpression> node : ancestors.getNodes()) {
      if (!node.getParent().isRoot()) {
         OWLClassExpression subClass = node.getEntity();
         OWLClassExpression superClass = node.getParent().getEntity();
         OWLSubClassOfAxiom ax = mOwlDataFactory.getOWLSubClassOfAxiom(subClass, superClass);
         toReturn.add(ax);
      }
   }
   return toReturn;
}
项目:OWL2SPARQL    文件:OWLAxiomToSPARQLConverter.java   
@Override
public void visit(OWLSubClassOfAxiom axiom) {
    // process subclass
    OWLClassExpression subClass = axiom.getSubClass();
    if(!subClass.isOWLThing()){// we do not need to convert owl:Thing
        String subClassPattern = expressionConverter.asGroupGraphPattern(subClass, subjectVar);
        sparql += subClassPattern;
    }

    // process superclass
    OWLClassExpression superClass = axiom.getSuperClass();
    boolean needsOuterTriplePattern = subClass.isOWLThing() &&
            (superClass.getClassExpressionType() == ClassExpressionType.OBJECT_COMPLEMENT_OF ||
            superClass.getClassExpressionType() == ClassExpressionType.DATA_ALL_VALUES_FROM ||
            superClass.getClassExpressionType() == ClassExpressionType.OBJECT_ALL_VALUES_FROM);
    String superClassPattern = expressionConverter.asGroupGraphPattern(superClass, subjectVar,
                                                                       needsOuterTriplePattern);
    sparql += superClassPattern;
}
项目:gate-semano    文件:OntologyParser.java   
/**
     * @param subaxiom
     * @param subCls
     */
    private void registerSubsumption(OWLSubClassOfAxiom subaxiom,
                                     OWLClassExpression subCls) {
        ONodeID superNode = registerNode((OWLClass) subaxiom.getSuperClass());
        if (isNumericID(superNode.getResourceName())) {
//      System.out.println("node "+superNode.getResourceName()+" has no label!");
        }
        ONodeID subNode = registerNode((OWLClass) subCls);
        if (isNumericID(subNode.getResourceName())) {
//      System.out.println("node "+subNode.getResourceName()+" has no label!");
        }
        // if the opposite is not yet included
        if (!subsumptions.containsKey(subNode)
                || !subsumptions.get(subNode).contains(superNode)) {
            Set<ONodeID> subs = getStoredSubConcepts(superNode);
            subs.add(subNode);
            subsumptions.put(superNode, subs);
//      logger.debug("added subclass axiom");

        }
    }
项目:gate-semano    文件:OntologyParser.java   
public void addClass(String classURI, String superClassURI) {
    OWLClass superClass = this.getOWLClass(superClassURI);
    OWLOntology o = entities2Ontologies.get(superClass);
    if (o != null) {
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        OWLDataFactory factory = manager.getOWLDataFactory();
        OWLClass subClass = factory.getOWLClass(IRI.create(classURI));
        OWLAxiom a = factory.getOWLDeclarationAxiom(subClass);
        OntologyUtil.addAxiom(o, a, manager);
        OWLSubClassOfAxiom subaxiom = factory.getOWLSubClassOfAxiom(subClass, superClass);
        OntologyUtil.addAxiom(o, subaxiom, manager);
        //update structures
        registerSubsumption(subaxiom, subClass);
        modifiedOntologies.add(o);
        this.entities2Ontologies.put(subClass, o);
    } else {
        System.err.println("ontology was null");
    }
}
项目:owlapi-gwt    文件:OWLSubClassOfAxiomImpl.java   
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!super.equals(obj)) {
        return false;
    }
    // superclass is responsible for null, identity, owlaxiom type and
    // annotations
    if (!(obj instanceof OWLSubClassOfAxiom)) {
        return false;
    }
    OWLSubClassOfAxiom other = (OWLSubClassOfAxiom) obj;
    return other.getSubClass().equals(subClass)
            && other.getSuperClass().equals(superClass);
}
项目:owlapi-gwt    文件:OWLSameIndividualAxiomImpl.java   
@Override
public Set<OWLSubClassOfAxiom> asOWLSubClassOfAxioms() {
    List<OWLClassExpression> nominalsList = new ArrayList<>();
    for (OWLIndividual individual : getIndividuals()) {
        assert individual != null;
        nominalsList.add(new OWLObjectOneOfImpl(CollectionFactory
                .createSet(individual)));
    }
    Set<OWLSubClassOfAxiom> result = new HashSet<>();
    for (int i = 0; i < nominalsList.size() - 1; i++) {
        OWLClassExpression ceI = nominalsList.get(i);
        OWLClassExpression ceJ = nominalsList.get(i + 1);
        assert ceI != null;
        assert ceJ != null;
        result.add(new OWLSubClassOfAxiomImpl(ceI, ceJ, NO_ANNOTATIONS));
        result.add(new OWLSubClassOfAxiomImpl(ceJ, ceI, NO_ANNOTATIONS));
    }
    return result;
}
项目:owlapi-gwt    文件:OWLDifferentIndividualsAxiomImpl.java   
@Override
public Set<OWLSubClassOfAxiom> asOWLSubClassOfAxioms() {
    List<OWLClassExpression> nominalsList = new ArrayList<>();
    for (OWLIndividual individual : getIndividuals()) {
        assert individual != null;
        nominalsList.add(new OWLObjectOneOfImpl(CollectionFactory
                .createSet(individual)));
    }
    Set<OWLSubClassOfAxiom> result = new HashSet<>();
    for (int i = 0; i < nominalsList.size() - 1; i++) {
        for (int j = i + 1; j < nominalsList.size(); j++) {
            OWLClassExpression ceI = nominalsList.get(i);
            OWLClassExpression ceJ = nominalsList.get(j)
                    .getObjectComplementOf();
            assert ceI != null;
            assert ceJ != null;
            result.add(new OWLSubClassOfAxiomImpl(ceI, ceJ, NO_ANNOTATIONS));
        }
    }
    return result;
}
项目:ecco    文件:CategoricalDiff.java   
/**
 * Check whether a given change is a new or retired description
 * @param effAdds   true if checking additions, false if checking removals
 * @param man   OWL ontology manager
 * @param ax    OWL axiom to be checked
 * @param newTerms  Set of new terms used in this axiom
 * @param eval  Syntactic locality evaluator
 * @return New or Retired Description-type change, or null if not one
 * @throws OWLOntologyCreationException Ontology creation exception
 */
private CategorisedChange checkNewOrRetiredDescription(boolean effAdds, OWLOntologyManager man, OWLAxiom ax, 
        Set<OWLEntity> newTerms, SyntacticLocalityEvaluator eval) throws OWLOntologyCreationException {
    CategorisedChange change = null;
    if(!newTerms.isEmpty()) {
        boolean atomicLhs = true;
        if(ax instanceof OWLSubClassOfAxiom) {
            OWLClassExpression c = ((OWLSubClassOfAxiom)ax).getSubClass();
            if(c.isAnonymous() || !newTerms.contains(c))
                atomicLhs = false;
        }
        else if(ax instanceof OWLEquivalentClassesAxiom)
            atomicLhs = false;

        if(atomicLhs && !(eval.isLocal(ax, newTerms))) {
            if(effAdds) 
                change = new CategorisedEffectualAddition(ax, EffectualAdditionCategory.NEWDESCRIPTION, new HashSet<OWLAxiom>(), newTerms);
            else 
                change = new CategorisedEffectualRemoval(ax, EffectualRemovalCategory.RETIREDDESCRIPTION, new HashSet<OWLAxiom>(), newTerms);
        }
    }
    return change;
}
项目:owlexplanation    文件:LaconicExplanationGeneratorBasedOnIncrementalOPlusWithDeltaPlusFiltering.java   
private OWLSubClassOfAxiom createSubClassAxiom(OWLDataFactory dataFactory, Set<OWLClassExpression> subClassDisjuncts, Set<OWLClassExpression> superClassConjuncts) {
    OWLClassExpression mergedSubClass;
    if (subClassDisjuncts.size() == 1) {
        mergedSubClass = subClassDisjuncts.iterator().next();
    }
    else {
        mergedSubClass = dataFactory.getOWLObjectUnionOf(subClassDisjuncts);
    }
    OWLClassExpression mergedSuperClass;
    if (superClassConjuncts.size() == 1) {
        mergedSuperClass = superClassConjuncts.iterator().next();
    }
    else {
        mergedSuperClass = dataFactory.getOWLObjectIntersectionOf(superClassConjuncts);
    }
    return dataFactory.getOWLSubClassOfAxiom(mergedSubClass, mergedSuperClass);
}
项目:neo4j-sparql-extension-yars    文件:SubClassOfExtractor.java   
private void addAxiom(List<Rule> list, OWLSubClassOfAxiom a) {
    if (!(a.getSubClass().isAnonymous() ||
          a.getSuperClass().isAnonymous())) {
        String ce1 = getString(a.getSubClass());
        String ce2 = getString(a.getSuperClass());
        list.add(new SubClassOf(ce1, ce2));
    }
}
项目:ontocomplib    文件:IndividualContext.java   
/**
 * Checks whether a class expression is a subclass of another class expression.
 * @param subClassExpr class expression on the left-hand side 
 * @param superClassExpr class expression on the right-hand side
 * @return <code>true</code> if the class expression on the left-hand side is a subclass of the class expression
 * on the right-hand side, <code>false</code> otherwise
 */
protected boolean isSubClassOf(OWLClassExpression subClassExpr, OWLClassExpression superClassExpr) {
    boolean ret = subClassExpr.isOWLNothing() || superClassExpr.isOWLThing() || subClassExpr.equals(superClassExpr);
    if (!ret) {
        OWLSubClassOfAxiom axiom = getReasoner().getRootOntology().
            getOWLOntologyManager().getOWLDataFactory().getOWLSubClassOfAxiom(subClassExpr, superClassExpr);
        if (!getReasoner().isEntailmentCheckingSupported(axiom.getAxiomType())){
            throw new RuntimeException("ERROR : Entailment not supported by reasoner '" + getReasoner().getReasonerName() + "'.");
        }
        ret = getReasoner().isEntailed(axiom);
    }
    return ret;
}
项目:ontocomplib    文件:QuestionConfirmedAction.java   
/**
 * Adds the confirmed question to the set of implications of the context, adds the corresponing
 * axiom to the ontology, pushes the change to the history stack and continues exploration with 
 * the next premise computed by using the new set of implications.
 */
@Override
public void actionPerformed(ActionEvent e) {
    logger.info("Expert accepted implication: " + getQuestion());
    // first create the GCI
    OWLSubClassOfAxiom axiom = getContext().getFactory().getOWLSubClassOfAxiom(
            getContext().toOWLDescription(getQuestion().getPremise()),
            getContext().toOWLDescription(getQuestion().getConclusion()));
    // create a new AddAxiom object
    AddAxiom addAxiom = new AddAxiom(getContext().getOntology(),axiom);
    // apply the change
    try {
        // add the new implication to the base
        getContext().getImplications().add(getQuestion());
        // also to the KB as a GCI
        getContext().getManager().applyChange(addAxiom);
        getContext().getHistory().push(new NewSubClassAxiomChange(getContext(),getQuestion(),addAxiom));
        getContext().reClassifyOntology();
        // update objects, update object descriptions
        getContext().updateObjects(Constants.AFTER_MODIFICATION);
        getContext().updateObjectDescriptions(Constants.AFTER_MODIFICATION);
        getContext().continueExploration(getContext().getNextPremise(getQuestion().getPremise()));
    }
    catch (OWLOntologyChangeException x) {
        x.printStackTrace();
        System.exit(-1);
    }

}
项目:uel    文件:AlternativeUelStarter.java   
public Iterator<Set<OWLEquivalentClassesAxiom>> modifyOntologyAndSolve(Set<OWLSubClassOfAxiom> subsumptions,
        Set<OWLEquivalentClassesAxiom> equations, Set<OWLSubClassOfAxiom> dissubsumptions,
        Set<OWLEquivalentClassesAxiom> disequations, Set<OWLClass> variables, String algorithmName) {

    UelModel uelModel = new UelModel(new BasicOntologyProvider(ontologyManager));
    uelModel.setupGoal(ontologies, subsumptions, equations, dissubsumptions, disequations, owlThingAlias, true);

    return modifyOntologyAndSolve(uelModel, variables, algorithmName);
}
项目:uel    文件:UelOntologyGoal.java   
public void addPositiveAxioms(Set<? extends OWLAxiom> axioms) {
    for (OWLAxiom axiom : axioms) {
        if (axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)) {
            addEquation((OWLEquivalentClassesAxiom) axiom);
        } else if (axiom.isOfType(AxiomType.SUBCLASS_OF)) {
            addSubsumption((OWLSubClassOfAxiom) axiom);
        } else {
            throw new RuntimeException("Unsupported axiom type: " + axiom);
        }
    }
}
项目:uel    文件:UelOntologyGoal.java   
public void addNegativeAxioms(Set<? extends OWLAxiom> axioms) {
    for (OWLAxiom axiom : axioms) {
        if (axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)) {
            addDisequation((OWLEquivalentClassesAxiom) axiom);
        } else if (axiom.isOfType(AxiomType.SUBCLASS_OF)) {
            addDissubsumption((OWLSubClassOfAxiom) axiom);
        } else {
            throw new RuntimeException("Unsupported axiom type: " + axiom);
        }
    }
}
项目:uel    文件:UelModel.java   
/**
 * Initializes the unification goal with the given ontologies and axioms.
 * 
 * @param bgOntologies
 *            a set of background ontologies with definitions
 * @param subsumptions
 *            the goal subsumptions, as OWLSubClassOfAxioms
 * @param equations
 *            the goal equations, as binary OWLEquivalentClassesAxioms
 * @param dissubsumptions
 *            the goal dissubsumptions, as OWLSubClassOfAxioms
 * @param disequations
 *            the goal disequations, as binary OWLEquivalentClassesAxioms
 * @param owlThingAlias
 *            (optional) an alias for owl:Thing, e.g., 'SNOMED CT Concept'
 * @param resetShortFormCache
 *            reset short form cache
 */
public void setupGoal(Set<OWLOntology> bgOntologies, Set<OWLSubClassOfAxiom> subsumptions,
        Set<OWLEquivalentClassesAxiom> equations, Set<OWLSubClassOfAxiom> dissubsumptions,
        Set<OWLEquivalentClassesAxiom> disequations, OWLClass owlThingAlias, boolean resetShortFormCache) {

    algorithm = null;
    unifierList = new ArrayList<>();
    currentUnifierIndex = -1;
    allUnifiersFound = false;
    atomManager = new AtomManagerImpl();

    if (resetShortFormCache) {
        resetShortFormCache();
    }

    OWLClass top = (owlThingAlias != null) ? owlThingAlias : OWLManager.getOWLDataFactory().getOWLThing();
    goal = new UelOntologyGoal(atomManager, new UelOntology(atomManager, bgOntologies, top));

    goal.addPositiveAxioms(subsumptions);
    goal.addPositiveAxioms(equations);
    goal.addNegativeAxioms(dissubsumptions);
    goal.addNegativeAxioms(disequations);

    // define top as the empty conjunction
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    goal.addEquation(factory.getOWLEquivalentClassesAxiom(top, factory.getOWLObjectIntersectionOf()));
    Integer topId = atomManager.createConceptName(top.toStringID());
    atomManager.makeDefinitionVariable(topId);

    goal.disposeOntology();
    if (resetShortFormCache) {
        cacheShortForms();
    }
}
项目:pronto    文件:ProntoLoaderUtils.java   
/**
 * Loads conditional constraints from an ontology with annotated axioms
 * 
 * @param ontology
 * @param signature 
 * @param declAxioms Used to return declaration axioms for auto-generated class names
 * @param iriPrefix IRI prefix for auto-generated class names
 * @param raxList
 * @return
 */
public static Set<ConditionalConstraint> loadDefaultConstraintsFromOWL(
        OWLOntology ontology,
        Map<String, OWLClassExpression> nameMap,
        Set<OWLEntity> signature,
        List<RemoveAxiom> raxList, String iriPrefix,
        OWLOntologyManager manager) {

    Set<ConditionalConstraint> ccSet = new HashSet<ConditionalConstraint>();
    //Begin with generic (default) subclass-of axioms
    for( OWLAxiom axiom : ontology.getAxioms( AxiomType.SUBCLASS_OF ) ) {
        for( OWLAnnotation annotation : axiom.getAnnotations() ) {

            if( Constants.CERTAINTY_ANNOTATION_URI.equals(annotation.getProperty().getIRI().toURI() ) ) {

                OWLSubClassOfAxiom sbAxiom = (OWLSubClassOfAxiom) axiom;
                String subClassIRI = generateClassName(sbAxiom.getSubClass(), nameMap, iriPrefix);
                String superClassIRI = generateClassName(sbAxiom.getSuperClass(), nameMap, iriPrefix);
                ConditionalConstraint cc = newConstraint(subClassIRI, superClassIRI, annotation.getValue().toString());

                signature.addAll( sbAxiom.getSubClass().getClassesInSignature() );
                signature.addAll( sbAxiom.getSuperClass().getClassesInSignature() );

                if( null != cc ) {

                    ccSet.add( cc );

                    if( null != raxList ) {
                        raxList.add( new RemoveAxiom( ontology, axiom ) );
                    }
                }
            }
        }
    }

    return ccSet;
}
项目:logmap-matcher    文件:StructuralReasoner2.java   
public Collection<OWLClass> getChildren(OWLClass parent) {
    Collection<OWLClass> result = new HashSet<OWLClass>();
    for (OWLOntology ont : getRootOntology().getImportsClosure()) {
        for (OWLAxiom ax : ont.getReferencingAxioms(parent)) {
            if (ax instanceof OWLSubClassOfAxiom) {
                OWLSubClassOfAxiom sca = (OWLSubClassOfAxiom) ax;
                if (!sca.getSubClass().isAnonymous()) {
                    Set<OWLClassExpression> conjuncts = sca.getSuperClass().asConjunctSet();
                    if (conjuncts.contains(parent)) {
                        result.add(sca.getSubClass().asOWLClass());
                    }
                }
            }
            else if (ax instanceof OWLEquivalentClassesAxiom) {
                OWLEquivalentClassesAxiom eca = (OWLEquivalentClassesAxiom) ax;
                for (OWLClassExpression ce : eca.getClassExpressions()) {
                    if (ce.containsConjunct(parent)) {
                        for (OWLClassExpression sub : eca.getClassExpressions()) {
                            if (!sub.isAnonymous() && !sub.equals(ce)) {
                                result.add(sub.asOWLClass());
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}
项目:jopa    文件:IntegrityConstraintParser.java   
public void visit(OWLSubClassOfAxiom axiom) {
    try {
        if (!axiom.getSubClass().isAnonymous()) {
            processSubClassConstraintCandidate(axiom.getSubClass().asOWLClass(),
                axiom.getSuperClass());
        } else {
            notSupported(axiom);
        }
    } catch (UnsupportedICException e) {
        notSupported(axiom);
    }
}
项目:elk-reasoner    文件:AbstractOwlAxiomConverterVisitor.java   
@Override
public T visit(OWLSubClassOfAxiom axiom) {
    throw new IllegalArgumentException(
            OWLSubClassOfAxiom.class.getSimpleName()
                    + " cannot be converted to "
                    + getTargetClass().getSimpleName());
}