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

项目:owltools    文件:OWLGraphWrapperEdges.java   
protected void filterEdges(Set<OWLGraphEdge> edges, Set<? extends OWLPropertyExpression> overProperties) {
    Set<OWLGraphEdge> rmEdges = new OWLGraphEdgeSet();
    for (OWLGraphEdge e : edges) {
        if (overProperties != null) {
            if (e.getQuantifiedPropertyList().size() > 1) {
                // if a filter set is provided, do not yield any chains
                rmEdges.add(e);
                continue;                   
            }
            OWLQuantifiedProperty qp = e.getSingleQuantifiedProperty();
            if (qp.isSomeValuesFrom() && !overProperties.contains(qp.getProperty())) {
                rmEdges.add(e);
                continue;
            }
        }
        if (isExcludeEdge(e)) {
            rmEdges.add(e);
        }
    }

    edges.removeAll(rmEdges);
}
项目:owltools    文件:ShuntGraphUtilsNRTest.java   
@Test
public void testSagaComplex() throws Exception {
    OWLObject focusObject = g.getOWLClassByIdentifier("GO:0000124"); // SAGA complex
    Set<OWLPropertyExpression> props = new HashSet<OWLPropertyExpression>();
    props.add(g.getOWLObjectProperty(OBOUpperVocabulary.BFO_part_of.getIRI()));

    ShuntGraphPair pair = ShuntGraphUtils.createShuntGraphPair(g, focusObject, props, true);

    OWLShuntGraph topology = pair.getTopologyGraph();

    checkNodesSagaComplex(g, topology);
    checkTopologyRelationsSagaComplex(g, topology);

    OWLShuntGraph inferred = pair.getInferredGraph();

    checkNodesSagaComplex(g, inferred);
    checkInferredRelationsSagaComplex(g, inferred);
}
项目:owltools    文件:ShuntGraphUtilsNRTest.java   
@Test
public void testSagaTypeComplexWithChildren() throws Exception {
    OWLObject focusObject = g.getOWLClassByIdentifier("GO:0070461"); // SAGA-type complex
    Set<OWLPropertyExpression> props = new HashSet<OWLPropertyExpression>();
    props.add(g.getOWLObjectProperty(OBOUpperVocabulary.BFO_part_of.getIRI()));

    ShuntGraphPair pair = ShuntGraphUtils.createShuntGraphPair(g, focusObject, props, true);

    OWLShuntGraph topology = pair.getTopologyGraph();

    checkNodesSagaTypeComplexWithChildren(g, topology);
    checkTopologyRelationsSagaTypeComplexWithChildren(g, topology);

    OWLShuntGraph inferred = pair.getInferredGraph();

    checkNodesSagaTypeComplexWithChildren(g, inferred);
    checkInferredRelationsSagaTypeComplexWithChildren(g, inferred);
}
项目:owltools    文件:ShuntGraphUtilsNRTest.java   
@Test
public void testSagaTypeComplexWithoutChildren() throws Exception {
    OWLObject focusObject = g.getOWLClassByIdentifier("GO:0070461"); // SAGA-type complex
    Set<OWLPropertyExpression> props = new HashSet<OWLPropertyExpression>();
    props.add(g.getOWLObjectProperty(OBOUpperVocabulary.BFO_part_of.getIRI()));

    ShuntGraphPair pair = ShuntGraphUtils.createShuntGraphPair(g, focusObject, props, false);

    OWLShuntGraph topology = pair.getTopologyGraph();

    checkNodesSagaTypeComplexWithoutChildren(g, topology);
    checkTopologyRelationsSagaTypeComplexWithoutChildren(g, topology);

    OWLShuntGraph inferred = pair.getInferredGraph();

    checkNodesSagaTypeComplexWithoutChildren(g, inferred);
    checkInferredRelationsSagaTypeComplexWithoutChildren(g, inferred);
}
项目:owltools    文件:ShuntGraphUtilsTest.java   
@Test
public void testSagaComplex() throws Exception {
    OWLObject focusObject = g.getOWLClassByIdentifier("GO:0000124"); // SAGA complex
    Set<OWLPropertyExpression> props = new HashSet<OWLPropertyExpression>();
    props.add(g.getOWLObjectProperty(OBOUpperVocabulary.BFO_part_of.getIRI()));

    ShuntGraphPair pair = ShuntGraphUtils.createShuntGraphPair(g, focusObject, props, true);

    OWLShuntGraph topology = pair.getTopologyGraph();

    checkNodesSagaComplex(g, topology);
    checkTopologyRelationsSagaComplex(g, topology);

    OWLShuntGraph inferred = pair.getInferredGraph();

    checkNodesSagaComplex(g, inferred);
    checkInferredRelationsSagaComplex(g, inferred);
}
项目:owltools    文件:ShuntGraphUtilsTest.java   
@Test
public void testSagaTypeComplexWithChildren() throws Exception {
    OWLObject focusObject = g.getOWLClassByIdentifier("GO:0070461"); // SAGA-type complex
    Set<OWLPropertyExpression> props = new HashSet<OWLPropertyExpression>();
    props.add(g.getOWLObjectProperty(OBOUpperVocabulary.BFO_part_of.getIRI()));

    ShuntGraphPair pair = ShuntGraphUtils.createShuntGraphPair(g, focusObject, props, true);

    OWLShuntGraph topology = pair.getTopologyGraph();

    checkNodesSagaTypeComplexWithChildren(g, topology);
    checkTopologyRelationsSagaTypeComplexWithChildren(g, topology);

    OWLShuntGraph inferred = pair.getInferredGraph();

    checkNodesSagaTypeComplexWithChildren(g, inferred);
    checkInferredRelationsSagaTypeComplexWithChildren(g, inferred);
}
项目:owltools    文件:ShuntGraphUtilsTest.java   
@Test
public void testSagaTypeComplexWithoutChildren() throws Exception {
    OWLObject focusObject = g.getOWLClassByIdentifier("GO:0070461"); // SAGA-type complex
    Set<OWLPropertyExpression> props = new HashSet<OWLPropertyExpression>();
    props.add(g.getOWLObjectProperty(OBOUpperVocabulary.BFO_part_of.getIRI()));

    ShuntGraphPair pair = ShuntGraphUtils.createShuntGraphPair(g, focusObject, props, false);

    OWLShuntGraph topology = pair.getTopologyGraph();

    checkNodesSagaTypeComplexWithoutChildren(g, topology);
    checkTopologyRelationsSagaTypeComplexWithoutChildren(g, topology);

    OWLShuntGraph inferred = pair.getInferredGraph();

    checkNodesSagaTypeComplexWithoutChildren(g, inferred);
    checkInferredRelationsSagaTypeComplexWithoutChildren(g, inferred);
}
项目:owltools    文件:OWLGraphWrapperEdgesExtendedTest.java   
/**
 * Test {@link OWLGraphWrapperEdgesExtended#getOntologyRoots(Set)} and 
 * {@link OWLGraphWrapperEdgesExtended#getOntologyRoots()}.
 */
@Test
public void shouldGetOntologyRoots() {
    //the ontology has 2 roots, FOO:0001 and FOO:0100
    //NCBITaxon are due to GCI relations
    Set<OWLClass> expectedRoots = new HashSet<OWLClass>(Arrays.asList(
            wrapper.getOWLClassByIdentifier("FOO:0001"), 
            wrapper.getOWLClassByIdentifier("FOO:0100"), 
            wrapper.getOWLClassByIdentifier("NCBITaxon:1"))); 
    assertEquals("Incorrect roots returned", expectedRoots, wrapper.getOntologyRoots());

    expectedRoots = new HashSet<OWLClass>(Arrays.asList(
               wrapper.getOWLClassByIdentifier("FOO:0001"), 
               wrapper.getOWLClassByIdentifier("FOO:0100"), 
               wrapper.getOWLClassByIdentifier("NCBITaxon:1"), 
               wrapper.getOWLClassByIdentifier("FOO:0012"), 
               wrapper.getOWLClassByIdentifier("FOO:0007"), 
               wrapper.getOWLClassByIdentifier("FOO:0008"), 
               wrapper.getOWLClassByIdentifier("FOO:0009")));
       assertEquals("Incorrect roots returned", expectedRoots, 
               wrapper.getOntologyRoots(new HashSet<OWLPropertyExpression>(
                   Arrays.asList(wrapper.getOWLObjectPropertyByIdentifier("BFO:0000050")))));
}
项目:semantika    文件:OwlPropertyStructureHandler.java   
private void addSubPropertyAxiom(OWLSubPropertyAxiom<?> axiom)
{
   OWLPropertyExpression<?,?> subProperty = axiom.getSubProperty();
   OWLPropertyExpression<?,?> superProperty = axiom.getSuperProperty();

   OwlNode<OWLPropertyExpression<?,?>> subClassNode = createNode(subProperty);
   OwlNode<OWLPropertyExpression<?,?>> superClassNode = createNode(superProperty);

   if (mPropertyCache.contains(subProperty)) {
      subClassNode = findNode(subProperty);
      superClassNode.setParent(subClassNode.getParent());
      subClassNode.setParent(superClassNode);
   }
   else if (mPropertyCache.contains(superProperty)) {
      superClassNode = findNode(superProperty);
      subClassNode.setParent(superClassNode);
   }
   else {
      superClassNode.setParent(mRoot);
      subClassNode.setParent(superClassNode);
   }
   mPropertyCache.add(subProperty);
   mPropertyCache.add(superProperty);
}
项目:semantika    文件:OwlPropertyStructureHandler.java   
@Override
public OwlNodeSet<OWLPropertyExpression<?, ?>> getAncestors(OWLPropertyExpression<?, ?> entity, boolean direct)
{
   OwlNodeSet<OWLPropertyExpression<?, ?>> ancestors = new OwlNodeSet<OWLPropertyExpression<?, ?>>();
   OwlNode<OWLPropertyExpression<?, ?>> node = mRoot.findNode(entity);
   if (node != null) {
      OwlNode<OWLPropertyExpression<?, ?>> parent = node.getParent();
      while (!parent.isRoot()) {
         ancestors.addNode(parent);
         if (direct) {
            break;
         }
         parent = parent.getParent();
      }
   }
   return ancestors;
}
项目:semantika    文件:OwlPropertyStructureHandler.java   
@Override
public OwlNodeSet<OWLPropertyExpression<?,?>> getDescendants(OWLPropertyExpression<?,?> entity, boolean direct)
{
   OwlNodeSet<OWLPropertyExpression<?,?>> descendants = new OwlNodeSet<OWLPropertyExpression<?,?>>();
   OwlNode<OWLPropertyExpression<?,?>> node = mRoot.findNode(entity);
   if (node != null) {
      OwlNodeSet<OWLPropertyExpression<?,?>> children = node.getChildren();
      if (direct) {
         descendants.addNodeSet(children);
      }
      else {
         collectChildren(children, descendants);
      }
   }
   return descendants;
}
项目:owltools    文件:AbstractAnnotationPredictor.java   
/**
 * side-effects: removes redundant predictions over a set of relationships.
 * If overProps set is empty, only the subClassOf hierarchy is used, if it's
 * null all relationships are used.
 * 
 * @param predictions
 * @param aClasses
 * @param overProps
 */
protected void setAndFilterRedundantPredictions(Set<Prediction> predictions, Set<OWLClass> aClasses, Set<OWLPropertyExpression> overProps) {
    Set<Prediction> newPredictions = new HashSet<Prediction>();

    for (Prediction p : predictions) {
        boolean isRedundant = false;
        GeneAnnotation a = p.getGeneAnnotation();
        OWLClass cls = (OWLClass) graph.getOWLObjectByIdentifier(a.getCls());
        for (OWLClass aClass : aClasses) {
            if (graph.getAncestorsReflexive(aClass, overProps).contains(cls)) {
                isRedundant = true;
                break;
            }
        }
        if (isRedundant && this.removeAllRedundant) {
            continue;
        }
        p.setRedundantWithExistingAnnotations(isRedundant);

        isRedundant = false;
        for (Prediction p2 : predictions) {
            GeneAnnotation a2 = p2.getGeneAnnotation();
            OWLClass cls2 = (OWLClass) graph.getOWLObjectByIdentifier(a2.getCls());
            if (graph.getAncestors(cls2).contains(cls)) {
                isRedundant = true;
                break;
            }
        }
        if (isRedundant && this.removeAllRedundant) {
            continue;
        }
        p.setRedundantWithOtherPredictions(isRedundant);
        newPredictions.add(p);
    }
    predictions.clear();
    predictions.addAll(newPredictions);

}
项目:owltools    文件:OWLGraphWrapperEdgesAdvanced.java   
/**
 * Classify the an edge and target as a human readable string for further processing.
 * 
 * @param owlGraphEdge edge under consideration
 * @param edgeDirector 
 * @param props properties set
 * @return null, "simplesubclass", "typesubclass", or "identity".
 * @see #addDirectDescendentsToShuntGraph
 * @see #addStepwiseAncestorsToShuntGraph
 */
public String classifyRelationship(OWLGraphEdge owlGraphEdge, OWLObject edgeDirector, Set<? extends OWLPropertyExpression> props){      
    String retval = null;

    OWLQuantifiedProperty qp = owlGraphEdge.getSingleQuantifiedProperty();
    if( qp.isSubClassOf() || props.contains(qp.getProperty()) ){
        //OWLObject target = owlGraphEdge.getTarget();
        if( edgeDirector instanceof OWLClass ){
            retval = "simplesubclass";
        }else if( edgeDirector instanceof OWLObjectSomeValuesFrom ){
            OWLObjectSomeValuesFrom some = (OWLObjectSomeValuesFrom)edgeDirector;
            if( props.contains(some.getProperty()) ){
                OWLClassExpression clsexp = some.getFiller();
                if( ! clsexp.isAnonymous()){
                    retval = "typesubclass";
                }
            }
        }
    }else if( qp.isIdentity() ){
        retval = "identity";
    }else{
        if (LOG.isDebugEnabled()) {
            LOG.debug("Skipping complex edge: "+owlGraphEdge);
        }
    }

    return retval;
}
项目:owltools    文件:OWLGraphUtil.java   
/**
 * Find lest common ancestors to {@code x} and {@code y} that can be reached 
 * over the specified set of relations. 
 * @param g
 * @param x
 * @param y
 * @param overProps
 * @return
 */
public static Set<OWLObject> findLeastCommonAncestors(OWLGraphWrapper g,
        OWLObject x, OWLObject y, Set<OWLPropertyExpression> overProps) {
    Set<OWLObject> cas = findCommonAncestors(g,x,y, overProps);
    Set<OWLObject> lcas = new HashSet<OWLObject>();
    lcas.addAll(cas);
    for (OWLObject z : cas) {
        lcas.removeAll(g.getAncestors(z, overProps));
    }
    return lcas;
}
项目:owltools    文件:OWLGraphWrapperEdges.java   
/**
 * retrieves direct edges from a source
 * to the direct **named** target for a given set of properties
 * <ul>
 * <li>e.g. if (A SubClassOf B) then outgoing(A) = { &lt;A,sub,B&gt;}</li>
 * <li>e.g. if (A SubClassOf R some B) then outgoing(A) = { &lt;A, R-some, B&gt; }</li>
 * <li>e.g. if (A SubClassOf R some (R2 some B)) then outgoing(A) = { &lt;A, [R-some,R2-same], B&gt; }</li>
 * </ul>
 * @param cls source
 * @param props
 * @return all edges that originate from source to nearest named object target
 */
public Set<OWLGraphEdge> getOutgoingEdges(OWLObject cls, Set<? extends OWLPropertyExpression> props) {
    Set<OWLGraphEdge> pEdges = getPrimitiveOutgoingEdges(cls);
    LOG.debug("primitive edges:"+cls+" --> "+pEdges);

    Set<OWLGraphEdge> edges = new OWLGraphEdgeSet();
    for (OWLGraphEdge e : pEdges) {
        edges.addAll(primitiveEdgeToFullEdges(e));
    }
       if (props != null) {
           filterEdges(edges, props);
       }
    LOG.debug("  all:"+cls+" --> "+edges);
    return edges;
}
项目:owltools    文件:OWLGraphWrapperEdges.java   
/**
 * As {@link getAncestors(OWLObject s, Set<OWLProperty) overProps}, 
 * but if isStrict is true, then only consider paths that include at least one edge
 * with a property in the specified set. i.e. exclude subclass-only paths. 
 * 
 * @param s
 * @param overProperties
 * @return
 */

public Set<OWLObject> getAncestors(OWLObject x, Set<OWLPropertyExpression> overProps, boolean isStrict) {
    Set<OWLObject> ancs = new HashSet<OWLObject>();
    for (OWLGraphEdge e : getOutgoingEdgesClosure(x, overProps)) {
        boolean isAddMe = false;
        if (overProps != null) {
            List<OWLQuantifiedProperty> qps = e.getQuantifiedPropertyList();
            if (qps.size() == 0) {
                // identity
                if (!isStrict)
                    isAddMe = true;
            }
            else if (qps.size() == 1) {
                OWLQuantifiedProperty qp = qps.get(0);
                if (qp.isIdentity()) {
                    if (!isStrict)
                        isAddMe = true;
                }
                else if (qp.isSubClassOf()) {
                    if (!isStrict)
                        isAddMe = true;
                }
                else if (qp.isSomeValuesFrom() && overProps.contains(qp.getProperty())) {
                    isAddMe = true;
                }
            }
            else if (!isStrict) {
                isAddMe = true;
            }
        }
        else {
            isAddMe = true;
        }
        if (isAddMe)
            ancs.add(e.getTarget());
    }
    return ancs;
}
项目:owltools    文件:OWLGraphWrapperEdgesExtendedTest.java   
/**
 * Test {@link OWLGraphWrapperEdgesExtended#getNamedAncestorsWithGCI(OWLClass, Set)}.
 */
@SuppressWarnings("rawtypes")
@Test
public void shouldGetGCIAncestorsOverProps() throws OWLOntologyCreationException, 
OBOFormatParserException, IOException {
    ParserWrapper parserWrapper = new ParserWrapper();
    OWLOntology ont = parserWrapper.parse(this.getClass().getResource(
            "/graph/gciRelRetrieval.obo").getFile());
    OWLGraphWrapper wrapper = new OWLGraphWrapper(ont);

    OWLClass cls8 = wrapper.getOWLClassByIdentifier("ID:8");
    OWLClass cls6 = wrapper.getOWLClassByIdentifier("ID:6");
    OWLClass cls4 = wrapper.getOWLClassByIdentifier("ID:4");
    OWLClass cls5 = wrapper.getOWLClassByIdentifier("ID:5");
    OWLClass cls9 = wrapper.getOWLClassByIdentifier("ID:9");
    OWLClass cls10 = wrapper.getOWLClassByIdentifier("ID:10");

    Set<OWLClass> expectedAncestors = new HashSet<OWLClass>();
    Set<OWLPropertyExpression> overProps = new HashSet<OWLPropertyExpression>();
    overProps.add(wrapper.getOWLObjectPropertyByIdentifier("BFO:0000050"));
    //no ancestors through GCI
    expectedAncestors.add(cls4);
    expectedAncestors.add(cls6);
    assertEquals("Incorrect ancestors with GCI over props", expectedAncestors, 
            wrapper.getNamedAncestorsWithGCI(cls8, overProps));
    //ancestors with GCI
    expectedAncestors = new HashSet<OWLClass>();
    overProps = new HashSet<OWLPropertyExpression>();
    overProps.add(wrapper.getOWLObjectPropertyByIdentifier("RO:0002202"));
    expectedAncestors.add(cls10);
    expectedAncestors.add(cls6);
    expectedAncestors.add(cls5);
    assertEquals("Incorrect ancestors through GCI and classical relations", 
            expectedAncestors, wrapper.getNamedAncestorsWithGCI(cls9, overProps));
}
项目:semantika    文件:OwlPropertyStructureHandler.java   
private static void collectChildren(OwlNodeSet<OWLPropertyExpression<?,?>> children, OwlNodeSet<OWLPropertyExpression<?,?>> descendants)
{
   if (children.isEmpty()) {
      return;
   }
   descendants.addNodeSet(children);
   OwlNodeSet<OWLPropertyExpression<?,?>> newChildren = new OwlNodeSet<OWLPropertyExpression<?,?>>();
   for (OwlNode<OWLPropertyExpression<?,?>> node : children.getNodes()) {
      newChildren.addNodeSet(node.getChildren());
   }
   collectChildren(newChildren, descendants);
}
项目:semantika    文件:OwlClassStructureHandler.java   
@Override
public void visit(OWLObjectPropertyDomainAxiom axiom)
{
   addSubClassAxiom(axiom.asOWLSubClassOfAxiom());

   OWLObjectPropertyExpression op = axiom.getProperty();
   OwlNodeSet<OWLPropertyExpression<?,?>> descendants = mPropertyStructureHandler.getDescendants(op, false);
   for (OwlNode<OWLPropertyExpression<?,?>> node : descendants.getNodes()) {
      op = (OWLObjectPropertyExpression) node.getEntity();
      axiom = mOwlDataFactory.getOWLObjectPropertyDomainAxiom(op, axiom.getDomain());
      addSubClassAxiom(axiom.asOWLSubClassOfAxiom());
   }
}
项目:semantika    文件:OwlClassStructureHandler.java   
@Override
public void visit(OWLObjectPropertyRangeAxiom axiom)
{
   addSubClassAxiom(asSubClassOfAxiom(axiom));

   OWLObjectPropertyExpression op = axiom.getProperty();
   OwlNodeSet<OWLPropertyExpression<?,?>> descendants = mPropertyStructureHandler.getDescendants(op, false);
   for (OwlNode<OWLPropertyExpression<?,?>> node : descendants.getNodes()) {
      op = (OWLObjectPropertyExpression) node.getEntity();
      axiom = mOwlDataFactory.getOWLObjectPropertyRangeAxiom(op, axiom.getRange());
      addSubClassAxiom(asSubClassOfAxiom(axiom));
   }
}
项目:owlapi-gwt    文件:OWLPropertyExpressionImpl.java   
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    return obj instanceof OWLPropertyExpression;
}
项目:owlapi-gwt    文件:AbstractEntityRegistrationManager.java   
@Override
public void visit(@Nonnull OWLHasKeyAxiom axiom) {
    axiom.getClassExpression().accept(this);
    for (OWLPropertyExpression prop : axiom.getPropertyExpressions()) {
        prop.accept(this);
    }
    processAxiomAnnotations(axiom);
}
项目:owltools    文件:OWLGraphWrapperEdges.java   
public Set<OWLObject> getAncestorsReflexive(OWLObject x, Set<OWLPropertyExpression> overProps) {
    Set<OWLObject> ancs = new HashSet<OWLObject>(getAncestors(x, overProps));
    ancs.add(x);
    return ancs;
}
项目:owltools    文件:OWLGraphWrapperEdgesExtended.java   
/**
 * Retrieve OBO GCI relations for {@code obj} as a {@code Set} of {@code OWLGraphEdge}s.
 * See {@link #getGCIOutgoingEdges(OWLObject)} for details about OBO GCI relations, 
 * and about retrieving the associated "gci_filler" and "gci_relation".
 * <p>
 * If {@code bySource} is {@code true}, edges outgoing from {@code obj} are retrieved, 
 * otherwise, edges incoming to {@code obj} are retrieved. If {@code overProperties} 
 * is not {@code null}, only the specified set of properties will be considered. Note 
 * that this does not filter for the "gci_relation" (as returned by 
 * {@link OWLGraphEdge#getGCIRelation()}), but for the actual property 
 * of the {@code OWLGraphEdge}s (as returned by 
 * {@link OWLGraphEdge#getQuantifiedPropertyList()}). 
 * <p>
 * Advanced usage notice: note that if the desired set of properties is {P},
 * and there exists a property chain Q o R --> P, then be sure to include Q and R in
 * the specified set.
 * 
 * @param obj               The {@code OWLObject} for which we want to retrieve 
 *                          OBO GCI relations
 * @param bySource          A {@code boolean} defining whether outgoing edges 
 *                          (when {@code true}) or incoming edges (when {@code false}) 
 *                          should be retrieved.
 * @param overProperties    A {@code Set} of {@code OWLPropertyExpression} allowing 
 *                          to filter the {@code OWLGraphEdge}s returned.
 * @return                  A {@code Set} of {@code OWLGraphEdge}s corresponding to 
 *                          GCI relations for {@code obj}.
 */
private Set<OWLGraphEdge> getGCIEdges(OWLClass obj, boolean bySource, 
        Set<OWLPropertyExpression> overProperties) {
    lazyLoadGCIRelCache();

    Set<OWLGraphEdge> cachedEdges = null;
    if (bySource) {
        cachedEdges = this.gciRelationBySource.get(obj);
    } else {
        cachedEdges = this.gciRelationByTarget.get(obj);
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("GCI edges retrieved for " + obj + ": " + cachedEdges);
    }
    if (cachedEdges != null) {
        //defensive copying
        Set<OWLGraphEdge> edges = new OWLGraphEdgeSet(cachedEdges);
        filterEdges(edges, overProperties);
        return edges;
    } 

    return new OWLGraphEdgeSet();
}
项目:owltools    文件:OWLGraphWrapperEdgesExtended.java   
/**
 * Returns either the ancestors or the descendants of an {@code OWLObject} 
 * through both classical relations an OBO GCI relations. Ancestors will be returned 
 * if {@code ancestors} is {@code true}, otherwise, descendants will be returned. 
 * Only {@code OWLNamedObject} ancestors or descendants are returned.
 * 
 * @param x         An {@code OWLObject} for which we want to retrieve either the ancestors, 
 *                  or the descendants.
 * @param ancestors A {@code boolean} defining whether ancestors should be retrieved 
 *                  (if {@code true}), or descendants (if {@code false}).
 * @param overProps A {@code Set} of {@code OWLPropertyExpression} allowing to filter 
 *                  the relations considered to retrieve ancestors.
 * @return  A {@code Set} of {@code OWLNamedObject}es that are either the named ancestors 
 *          (if {@code ancestors} is {@code true}) or the named descendants 
 *          (if {@code ancestors} is {@code false}) of {@code x} through 
 *          both classical and OBO GCI relations.
 */
private Set<OWLNamedObject> getNamedGCIRelatives(OWLObject x, boolean ancestors, 
        @SuppressWarnings("rawtypes") Set<OWLPropertyExpression> overProps) {
    Set<OWLNamedObject> relatives = new HashSet<OWLNamedObject>();
    Deque<OWLObject> walkRelatives = new ArrayDeque<OWLObject>();
    //seed the Deque with the starting OWLClass
    walkRelatives.addFirst(x);
    OWLObject iteratedRelative;
    while ((iteratedRelative = walkRelatives.pollFirst()) != null) {
        Set<OWLGraphEdge> edges = null;
        if (ancestors) {
            edges = this.getOutgoingEdgesWithGCI(iteratedRelative);
        } else {
            edges = this.getIncomingEdgesWithGCI(iteratedRelative);
        }
        filterEdges(edges, overProps);
        for (OWLGraphEdge edge: edges) {
            OWLObject relative = null;
            if (ancestors) {
                relative = edge.getTarget();
            } else {
                relative = edge.getSource();
            }
            //protect against cycles
            if (relatives.contains(relative)) {
                continue;
            }
            //not interested in OBO alt IDs
            if (relative instanceof OWLClass && this.isOboAltId((OWLClass) relative)) {
                continue;
            }
            //we only want OWLNamedObjects and non OBO alt IDs
            if (relative instanceof OWLNamedObject) {
                relatives.add((OWLNamedObject) relative);
            }
            walkRelatives.addLast(relative);
        }
    }

    return relatives;
}
项目:owltools    文件:OWLGraphWrapperEdgesExtendedTest.java   
/**
 * Test {@link OWLGraphWrapperEdgesExtended#getGCIOutgoingEdges(OWLObject)},  
 * {@link OWLGraphWrapperEdgesExtended#getGCIOutgoingEdges(OWLObject, Set)} and 
 * {@link OWLGraphWrapperEdgesExtended#getGCIIncomingEdges(OWLObject)}
 * @throws OWLOntologyCreationException
 * @throws OBOFormatParserException
 * @throws IOException
 */
@Test
public void shouldGetGCIEdges() throws OWLOntologyCreationException, 
    OBOFormatParserException, IOException {
    ParserWrapper parserWrapper = new ParserWrapper();
       OWLOntology ont = parserWrapper.parse(this.getClass().getResource(
               "/graph/gciRelRetrieval.obo").getFile());
       OWLGraphWrapper wrapper = new OWLGraphWrapper(ont);

       OWLObjectProperty partOf = wrapper.getOWLObjectPropertyByIdentifier("BFO:0000050");
       OWLObjectProperty developsFrom = wrapper.getOWLObjectPropertyByIdentifier("RO:0002202");
       OWLClass cls1 = wrapper.getOWLClassByIdentifier("ID:1");
       OWLClass cls2 = wrapper.getOWLClassByIdentifier("ID:2");
       OWLClass taxon1 = wrapper.getOWLClassByIdentifier("NCBITaxon:9606");
       OWLClass taxon2 = wrapper.getOWLClassByIdentifier("NCBITaxon:10090");

       Set<OWLGraphEdge> expectedEdges = new HashSet<OWLGraphEdge>();
       expectedEdges.add(new OWLGraphEdge(cls2, cls1, partOf, Quantifier.SOME, 
               ont, null, taxon1, partOf));
       expectedEdges.add(new OWLGraphEdge(cls2, cls1, developsFrom, Quantifier.SOME, 
               ont, null, taxon2, partOf));
       assertEquals("Incorrect gci_relations retrieved", expectedEdges, 
               wrapper.getGCIOutgoingEdges(cls2));
       assertEquals("Incorrect gci_relations retrieved", expectedEdges, 
               wrapper.getGCIIncomingEdges(cls1));

       expectedEdges = new HashSet<OWLGraphEdge>();
       expectedEdges.add(new OWLGraphEdge(cls2, cls1, developsFrom, Quantifier.SOME, 
               ont, null, taxon2, partOf));
       assertEquals("Incorrect gci_relations retrieved", expectedEdges, 
               wrapper.getGCIOutgoingEdges(cls2, 
                       new HashSet<OWLPropertyExpression>(Arrays.asList(developsFrom))));

       //check empty GCIs
       expectedEdges = new HashSet<OWLGraphEdge>();
       assertEquals("Incorrect gci_relations retrieved", expectedEdges, 
               wrapper.getGCIOutgoingEdges(wrapper.getOWLClassByIdentifier("ID:3")));
       assertEquals("Incorrect gci_relations retrieved", expectedEdges, 
               wrapper.getGCIIncomingEdges(wrapper.getOWLClassByIdentifier("ID:3")));

       //check that usual getOutgoingEdges is not affected
       expectedEdges = new HashSet<OWLGraphEdge>();
       expectedEdges.add(new OWLGraphEdge(cls2, cls1, ont));
       assertEquals("Incorrect non-gci_relations retrieved", expectedEdges, 
               wrapper.getOutgoingEdges(cls2));
       assertEquals("Incorrect non-gci_relations retrieved", expectedEdges, 
               wrapper.getIncomingEdges(cls1));
}
项目:owltools    文件:OWLGraphWrapperEdgesExtendedTest.java   
/**
 * Test {@link OWLGraphWrapperEdgesExtended#getOutgoingEdgesWithGCI(OWLObject, Set)} 
 * and {@link OWLGraphWrapperEdgesExtended#getOutgoingEdgesWithGCI(OWLObject)}
 */
@Test
public void shouldGetOutgoingEdgesWithGCI() throws OWLOntologyCreationException, 
OBOFormatParserException, IOException {
    ParserWrapper parserWrapper = new ParserWrapper();
       OWLOntology ont = parserWrapper.parse(this.getClass().getResource(
               "/graph/gciRelRetrieval.obo").getFile());
       OWLGraphWrapper wrapper = new OWLGraphWrapper(ont);

       OWLObjectProperty partOf = wrapper.getOWLObjectPropertyByIdentifier("BFO:0000050");
       OWLObjectProperty developsFrom = wrapper.getOWLObjectPropertyByIdentifier("RO:0002202");
       OWLClass cls6 = wrapper.getOWLClassByIdentifier("ID:6");
       OWLClass cls7 = wrapper.getOWLClassByIdentifier("ID:7");
       OWLClass cls8 = wrapper.getOWLClassByIdentifier("ID:8");
       OWLClass cls9 = wrapper.getOWLClassByIdentifier("ID:9");
       OWLClass cls10 = wrapper.getOWLClassByIdentifier("ID:10");
       OWLClass taxon1 = wrapper.getOWLClassByIdentifier("NCBITaxon:9606");

       Set<OWLGraphEdge> expectedEdges = new HashSet<OWLGraphEdge>();
       //class with no GCI relations
       expectedEdges.add(new OWLGraphEdge(cls8, cls6, partOf, Quantifier.SOME, 
               ont, null));
       expectedEdges.add(new OWLGraphEdge(cls8, cls7, developsFrom, Quantifier.SOME, 
               ont, null));
       assertEquals("Incorrect outgoing edges with GCI retrieved", expectedEdges, 
               wrapper.getOutgoingEdgesWithGCI(cls8));
       expectedEdges = new HashSet<OWLGraphEdge>();
       //class with no GCI relations with filtering of properties
       expectedEdges.add(new OWLGraphEdge(cls8, cls6, partOf, Quantifier.SOME, 
               ont, null));
       assertEquals("Incorrect outgoing edges with GCI retrieved", expectedEdges, 
               wrapper.getOutgoingEdgesWithGCI(cls8, 
                       new HashSet<OWLPropertyExpression>(Arrays.asList(partOf))));

       //class with both a classical relation and a GCI relation
       expectedEdges = new HashSet<OWLGraphEdge>();
       expectedEdges.add(new OWLGraphEdge(cls9, cls7, partOf, Quantifier.SOME, 
               ont, null));
       expectedEdges.add(new OWLGraphEdge(cls9, cls10, developsFrom, Quantifier.SOME, 
               ont, null, taxon1, partOf));
       assertEquals("Incorrect outgoing edges with GCI retrieved", expectedEdges, 
               wrapper.getOutgoingEdgesWithGCI(cls9));

       //class with both a classical relation and a GCI relation, with filtering of properties
       expectedEdges = new HashSet<OWLGraphEdge>();
       expectedEdges.add(new OWLGraphEdge(cls9, cls10, developsFrom, Quantifier.SOME, 
               ont, null, taxon1, partOf));
       assertEquals("Incorrect outgoing edges with GCI retrieved", expectedEdges, 
               wrapper.getOutgoingEdgesWithGCI(cls9, 
                       new HashSet<OWLPropertyExpression>(Arrays.asList(developsFrom))));
       expectedEdges = new HashSet<OWLGraphEdge>();
       expectedEdges.add(new OWLGraphEdge(cls9, cls7, partOf, Quantifier.SOME, 
               ont, null));
       assertEquals("Incorrect outgoing edges with GCI retrieved", expectedEdges, 
               wrapper.getOutgoingEdgesWithGCI(cls9, 
                       new HashSet<OWLPropertyExpression>(Arrays.asList(partOf))));
}
项目:semantika    文件:OwlPropertyStructureHandler.java   
@Override
public OwlNode<OWLPropertyExpression<?,?>> findNode(OWLPropertyExpression<?,?> entity)
{
   return mRoot.findNode(entity);
}
项目:semantika    文件:OwlPropertyStructureHandler.java   
private static OwlNode<OWLPropertyExpression<?,?>> createNode(OWLPropertyExpression<?,?> entity)
{
   return new OwlNode<OWLPropertyExpression<?,?>>(entity);
}
项目:owlapi-gwt    文件:OWLHasKeyAxiomImpl_CustomFieldSerializer.java   
public static OWLHasKeyAxiomImpl instantiate(SerializationStreamReader streamReader) throws SerializationException {
    Set<OWLAnnotation> annotations = CustomFieldSerializerUtil.deserializeAnnotations(streamReader);
    OWLClass cls = (OWLClass) streamReader.readObject();
    Set<OWLPropertyExpression> properties = CustomFieldSerializerUtil.deserializeSet(streamReader);
    return new OWLHasKeyAxiomImpl(cls, properties, annotations);
}
项目:Widoco    文件:OntologyDifferencesRenderer.java   
private static String axiomSetToHTML(Set<Object> set, boolean isAddition, Properties lang){
    String v = "";
    String message;
    if(isAddition){
        message=lang.getProperty(Constants.LANG_ADDED)+": ";
    }else{
        message=lang.getProperty(Constants.LANG_DELETED)+": ";
    }
    for(Object f:set){
        try{
            v+="<li>";
            if(f instanceof OWLSubClassOfAxiom){
                v+=message+lang.getProperty(Constants.LANG_SUBCLASS_OF) +" "+ ((OWLSubClassOfAxiom)f).getSuperClass().asOWLClass().getIRI();
            }else if(f instanceof OWLSubPropertyAxiom){
                OWLPropertyExpression prop = ((OWLSubPropertyAxiom)f).getSuperProperty();
                if(prop instanceof OWLObjectPropertyImpl){
                    v+=message+lang.getProperty(Constants.LANG_SUBPROP_OF) +" "+ ((OWLObjectPropertyImpl)prop).getIRI();
                }else if(prop instanceof OWLDataPropertyImpl){
                    v+=message+lang.getProperty(Constants.LANG_SUBPROP_OF) +" "+ ((OWLDataPropertyImpl)prop).getIRI();
                }
            }else if(f instanceof OWLObjectPropertyDomainAxiom){
                v+=message+Constants.LANG_DOMAIN+" "+expressionToHTML(((OWLObjectPropertyDomainAxiom)f).getDomain(), lang);
            }else if(f instanceof OWLDataPropertyDomainAxiom){
                v+=message+lang.getProperty(Constants.LANG_DOMAIN)+" "+expressionToHTML(((OWLDataPropertyDomainAxiom)f).getDomain(), lang);
            }else if(f instanceof OWLObjectPropertyRangeAxiom){
                v+=message+lang.getProperty(Constants.LANG_RANGE)+" "+expressionToHTML(((OWLObjectPropertyRangeAxiom)f).getRange(), lang);
            }else if(f instanceof OWLDataPropertyRangeAxiom){
                v+=message+lang.getProperty(Constants.LANG_RANGE)+" "+((OWLDataPropertyRangeAxiom)f).getRange().asOWLDatatype().getIRI();
            }else if(f instanceof OWLAnnotationAssertionAxiom){
                v+= message+((OWLAnnotationAssertionAxiom)f).getProperty().toString() +" "+ ((OWLAnnotationAssertionAxiom)f).getValue().toString();
            }else{
                //other less typical axioms
                v+=message+((OWLAxiom)f).getAxiomType().getName()+" "+f.toString().replace("<", "&lt;").replace(">", "&gt;");
            }
            /**
             * To add if we want to refine
             * OWLDisjointClassesAxiom, OWLDisjointDataPropertiesAxiom, OWLDisjointObjectPropertiesAxiom,
             * OWLEquivalentClassesAxiom, OWLEquivalentDataPropertiesAxiom, OWLEquivalentObjectPropertiesAxiom, 
             * OWLFunctionalDataPropertyAxiom, OWLFunctionalObjectPropertyAxiom,
             */
            v+="</li>\n";
        }catch (Exception e){
            System.out.println("Error while transforming "+f.toString() +" "+e.getMessage());
        }

    }

    return v;
}
项目:owltools    文件:OWLGraphUtil.java   
/**
* Find common ancestors to {@code x} and {@code y} that can be reached 
* over the specified set of relations. 
* 
* @param g  
* @param x            
* @param y
* @param overProps
* @return
*/
  public static Set<OWLObject> findCommonAncestors(OWLGraphWrapper g,
              OWLObject x, OWLObject y, Set<OWLPropertyExpression> overProps) {
      Set<OWLObject> xs = g.getAncestors(x, overProps);
      Set<OWLObject> ys = g.getAncestors(y, overProps);
      xs.retainAll(ys);
      return xs;
  }
项目:owltools    文件:OWLGraphWrapperEdgesExtended.java   
/**
 * Similar to {@link OWLGraphWrapperEdges#getOutgoingEdges(OWLObject, Set)}, but the returned 
 * {@code Set} also includes OBO GCI outgoing edges (see 
 * {@link #getGCIOutgoingEdges(OWLClass)}).
 * 
 * @param s             An {@code OWLObject} for which we want to retrieve outgoing edges, 
 *                      including OBO GCI relations.
 * @param overProps     A {@code Set} of {@code OWLPropertyExpression} allowing 
 *                      to filter the {@code OWLGraphEdge}s returned.
 * @return      A {@code Set} of {@code OWLGraphEdge}s outgoing from {@code s}, 
 *              including OBO GCI relations.
 * @see #getGCIOutgoingEdges(OWLClass)
 */
public Set<OWLGraphEdge> getOutgoingEdgesWithGCI(OWLObject s, 
        Set<OWLPropertyExpression> overProperties) {
    Set<OWLGraphEdge> edges = super.getOutgoingEdges(s, overProperties);
    if (s instanceof OWLClass) {
        edges.addAll(getGCIOutgoingEdges((OWLClass) s, overProperties));
    }
    return edges;
}
项目:owltools    文件:OWLGraphWrapperEdgesExtended.java   
/**
 * Similar to {@link #getOWLClassDescendantsWithGCI(OWLObject)} but allowing to filter 
 * the relations considered. 
 * @param parentClass   An {@code OWLClass} for which we want to retrieve descendants 
 *                      through classical relations and through OBO GCI relations.
 * @param overProps     A {@code Set} of {@code OWLPropertyExpression} allowing to filter 
 *                      the relations considered to retrieve descendants.
 * @return  A {@code Set} of {@code OWLClass}s that are descendants of {@code parentClass} 
 *          through classical relations and through OBO GCI relations, 
 *          filtered using {@code overProps}.
 */
public Set<OWLClass> getOWLClassDescendantsWithGCI(OWLClass parentClass, 
        @SuppressWarnings("rawtypes") Set<OWLPropertyExpression> overProps) {
    Set<OWLClass> descendants = new HashSet<OWLClass>();
    for (OWLNamedObject desc: this.getNamedGCIRelatives(parentClass, false, overProps)) {
        if (desc instanceof OWLClass) {
            descendants.add((OWLClass) desc);
        }
    }
    return descendants;
}
项目:semantika    文件:AbstractOwlOntology.java   
/**
 * Gets the set of properties that are the strict (potentially direct) sub properties of the
 * specified property expression.
 * 
 * @param entity
 *           The property expression whose strict (direct) sub properties are to be retrieved.
 * @param direct
 *           Specifies if the direct sub properties should be retrieved (<code>true</code>) or if
 *           the all sub properties (descendant) should be retrieved (<code>false</code>).
 * @return Returns a set of sub properties, or an empty set if the input entity doesn't exist.
 */
public Set<OWLPropertyExpression<?,?>> getSubProperties(OWLPropertyExpression<?,?> entity, boolean direct)
{
   Set<OWLPropertyExpression<?,?>> toReturn = new LinkedHashSet<OWLPropertyExpression<?,?>>();
   OwlNodeSet<OWLPropertyExpression<?,?>> descendants = mPropertyStructureHandler.getDescendants(entity, direct);
   for (OwlNode<OWLPropertyExpression<?,?>> node : descendants.getNodes()) {
      toReturn.add(node.getEntity());
   }
   return toReturn;
}
项目:semantika    文件:AbstractOwlOntology.java   
/**
 * Gets the set of properties that are the strict (potentially direct) super properties of the
 * specified property expression.
 * 
 * @param entity
 *           The property expression whose strict (direct) super properties are to be retrieved.
 * @param direct
 *           Specifies if the direct super properties should be retrieved (<code>true</code>) or
 *           if the all super properties (ancestors) should be retrieved (<code>false</code>).
 * @return Returns a set of super properties, or an empty set if the input entity doesn't exist.
 */
public Set<OWLPropertyExpression<?,?>> getSuperProperties(OWLPropertyExpression<?,?> entity, boolean direct)
{
   Set<OWLPropertyExpression<?,?>> toReturn = new LinkedHashSet<OWLPropertyExpression<?,?>>();
   OwlNodeSet<OWLPropertyExpression<?,?>> ancestors = mPropertyStructureHandler.getAncestors(entity, direct);
   for (OwlNode<OWLPropertyExpression<?,?>> node : ancestors.getNodes()) {
      toReturn.add(node.getEntity());
   }
   return toReturn;
}
项目:owltools    文件:OWLGraphWrapperEdges.java   
/**
 * as {@link #getOutgoingEdgesClosure(OWLObject, Set)}, but also include an identify edge
 * @param s
 * @param props
 * @return
 */
public Set<OWLGraphEdge> getOutgoingEdgesClosureReflexive(OWLObject s, Set<? extends OWLPropertyExpression> props) {
    Set<OWLGraphEdge> edges = getOutgoingEdgesClosure(s, props);
    edges.add(new OWLGraphEdge(s,s,null,Quantifier.IDENTITY,getSourceOntology()));
    return edges;
}
项目:owltools    文件:OWLGraphWrapperEdges.java   
/**
 * returns all ancestors that can be reached over subclass or
 * the specified set of relations
 * 
 * @param x the sourceObject
 * @param overProps
 * @return set of ancestors
 */
public Set<OWLObject> getAncestors(OWLObject x, Set<OWLPropertyExpression> overProps) {
    return getAncestors(x, overProps, false);
}
项目:owltools    文件:OWLGraphWrapperEdgesExtended.java   
/**
 * Same as {@link #getGCIOutgoingEdges(OWLClass)}, but with a {@code Set} of 
 * {@code OWLPropertyExpression} allowing to filter the relations retrieved.
 * @param s             See {@link #getGCIOutgoingEdges(OWLClass)}.
 * @param overProps     A {@code Set} of {@code OWLPropertyExpression} allowing 
 *                      to filter the {@code OWLGraphEdge}s returned.
 * @return              See {@link #getGCIOutgoingEdges(OWLClass)}.
 * @see #getGCIOutgoingEdges(OWLClass)
 */
public Set<OWLGraphEdge> getGCIOutgoingEdges(OWLClass s, 
        Set<OWLPropertyExpression> overProps) {
    return this.getGCIEdges(s, true, overProps);
}
项目:owltools    文件:OWLGraphWrapperEdgesExtended.java   
/**
 * Similar to {@link #getNamedAncestorsWithGCI(OWLObject, Set)} but allowing to filter 
 * the relations considered. 
 * @param sourceObject  An {@code OWLObject} for which we want to retrieve ancestors 
 *                      through classical relations and through OBO GCI relations.
 * @param overProps     A {@code Set} of {@code OWLPropertyExpression} allowing to filter 
 *                      the relations considered to retrieve ancestors.
 * @return  A {@code Set} of {@code OWLObject}s that are ancestors of 
 *          {@code sourceObject} through classical relations and through OBO GCI relations, 
 *          filtered using {@code overProps}.
 * @see #getNamedAncestorsWithGCI(OWLObject)
 * @see #getOWLClassAncestorsWithGCI(OWLObject)
 */
public Set<OWLNamedObject> getNamedAncestorsWithGCI(OWLObject sourceObject, 
        @SuppressWarnings("rawtypes") Set<OWLPropertyExpression> overProps) {
    return this.getNamedGCIRelatives(sourceObject, true, overProps);
}