org.semanticweb.owlapi.model.OWLPropertyExpression Java Examples

The following examples show how to use org.semanticweb.owlapi.model.OWLPropertyExpression. 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: ShuntGraphUtilsTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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);
}
 
Example #2
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public static  TaxonomyBuilder<OWLPropertyExpression> buildObjectPropertyHierarchy(NormalizedOWLQLTbox tbox, Collection<? extends OWLPropertyExpression> additionalPropertyExpressions) {
	OWLOntology ont = tbox.getNormalizedOntology();
	OWLDataFactory fac = ont.getOWLOntologyManager().getOWLDataFactory();
	Set< OWLPropertyExpression> props;
	if (additionalPropertyExpressions!=null) {
		props = new HashSet<OWLPropertyExpression>(additionalPropertyExpressions);
		props.addAll(ont.getObjectPropertiesInSignature());
	} else {
		props = new HashSet<OWLPropertyExpression>( ont.getObjectPropertiesInSignature());
	}
	SubPropertyComputation subcomp = new SubPropertyComputation(tbox);
	TaxonomyBuilder<OWLPropertyExpression> taxoBuilder = new TaxonomyBuilder<OWLPropertyExpression>(
			props, 
			fac.getOWLTopObjectProperty(),
			fac.getOWLBottomObjectProperty(),
			subcomp);
	taxoBuilder.build();
	logger.debug("Number of direct subsumption tests performed: {}", subcomp.numOfDirectSubsumptionTests);
	long size = props.size(); 
	logger.debug("Worst Case number of direct subsumption tests performed: {}^2 = {}",size, size*size);
	return taxoBuilder;
}
 
Example #3
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public static  TaxonomyBuilder<OWLPropertyExpression> buildDataPropertyHierarchy(NormalizedOWLQLTbox tbox, Collection<? extends OWLPropertyExpression> additionalPropertyExpressions) {
	OWLOntology ont = tbox.getNormalizedOntology();
	OWLDataFactory fac = ont.getOWLOntologyManager().getOWLDataFactory();
	Set< OWLPropertyExpression> props;
	if (additionalPropertyExpressions!=null) {
		props = new HashSet<OWLPropertyExpression>(additionalPropertyExpressions);
		props.addAll(ont.getDataPropertiesInSignature());
	} else {
		props = new HashSet<OWLPropertyExpression>( ont.getDataPropertiesInSignature());
	}
	SubPropertyComputation subcomp = new SubPropertyComputation(tbox);
	TaxonomyBuilder<OWLPropertyExpression> taxoBuilder = new TaxonomyBuilder<OWLPropertyExpression>(
			props, 
			fac.getOWLTopDataProperty(),
			fac.getOWLBottomDataProperty(),
			subcomp);
	taxoBuilder.build();
	logger.debug("Number of direct subsumption tests performed: {}", subcomp.numOfDirectSubsumptionTests);
	long size = props.size(); 
	logger.debug("Worst Case number of direct subsumption tests performed: {}^2 = {}",size, size*size);
	return taxoBuilder;
}
 
Example #4
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void build() {
	//build taxonomies
	logger.debug("building data property taxonomy ...");
	dataPropTaxo = buildDataPropertyHierarchy(tbox, additionalDataPropertyExpressions);
	logger.debug("building object property taxonomy ...");
	objPropTaxo = buildObjectPropertyHierarchy(tbox, additionalObjectPropertyExpressions);
	
	logger.debug("building class taxonomy ...");
	classTaxo = buildClassHierarchy(tbox, additionalClassExpressions);
	
	logger.debug("All taxonomies built!");
	//
	Graph<TaxonomyBuilder<OWLPropertyExpression>.TaxoNode> lattice = objPropTaxo.getLattice();
	logger.debug("{}", lattice);
	
}
 
Example #5
Source File: OWLGraphWrapperEdges.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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);
}
 
Example #6
Source File: NormalizedOWLQLTbox.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * returns a query triple corresponding to a property expression
 * 	<ul>
 * 	<li> R  --> x R y </li>
 *  <li> inv(R) --> y R x </li>
 * </ul>
 * 
 */
protected static Triple toTriple(OWLPropertyExpression pe, Node x, Node y, NewVariableGenerator varGen) {
	pe = getSimplified(pe);
	if (!pe.isAnonymous()) {
		OWLProperty p = (OWLProperty) pe;
		 return new Triple(
					x,
					NodeFactory.createURI(p.getIRI().toString()),
					y); 
	} else {
		assert pe instanceof OWLObjectInverseOf: pe;
		OWLObjectInverseOf inv = (OWLObjectInverseOf) pe;
		OWLObjectProperty p = (OWLObjectProperty) inv.getInverse();
		 return new Triple(
					y,
					NodeFactory.createURI(p.getIRI().toString()),
					x); 
	}
}
 
Example #7
Source File: ShuntGraphUtilsTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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);
}
 
Example #8
Source File: ShuntGraphUtilsTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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);
}
 
Example #9
Source File: SubPropertyComputation.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Set<OWLPropertyExpression> getToldSubsumers(
		OWLPropertyExpression sub) {
	if (!sub.isAnonymous()) {
		Set<OWLPropertyExpression> ret = new HashSet<OWLPropertyExpression>();
		Set<? extends OWLSubPropertyAxiom> axioms;// = new HashSet<? extends OWLSubPropertyAxiom>();
		if (sub.isObjectPropertyExpression()) {
			axioms = tbox.getNormalizedOntology().getObjectSubPropertyAxiomsForSubProperty(
					(OWLObjectPropertyExpression) sub);
		} else if (!sub.isAnonymous()) {
			axioms = tbox.getNormalizedOntology().getDataSubPropertyAxiomsForSubProperty(
					((OWLDataPropertyExpression) sub).asOWLDataProperty());
		} else {
			axioms = Collections.EMPTY_SET;
		}
		if (axioms!=null) {
			for (OWLSubPropertyAxiom ax: axioms) {
				assert ax.getSubProperty().equals(sub) : ax+"\n"+sub;
				ret.add(ax.getSuperProperty());
			}
		}
		return ret;
	}
	return Collections.EMPTY_SET;
}
 
Example #10
Source File: OWLGraphWrapperEdgesExtendedTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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")))));
}
 
Example #11
Source File: ShuntGraphUtilsNRTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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);
}
 
Example #12
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public Set<OWLPropertyExpression> getUnsatisfiablePropertyExpressions() {
	Set<OWLPropertyExpression> ret = new HashSet<OWLPropertyExpression>();
	ret.addAll(dataPropTaxo.getBottomNode().getEquivalentElements());
	ret.remove(dataPropTaxo.getBottom());
	/*for (OWLPropertyExpression c : objPropTaxo.getBottomNode().getEquivalentElements()) {
		if (!c.isAnonymous()) {
			ret.add(c); 
		} else {
			//OWLObjectProperty op =  ((OWLObjectPropertyExpression) c).getNamedProperty();//fac.getOWLObjectProperty(IRI.create(ATermUtils.makeInv(c).getAFun().getName()));
			//if (oprops.contains(op)) 
			{
				ret.add(c);
			} 
			//else {
				// do nothing: inverse of a create role R, where R is defined as equivalent to the inverse of an existing role
			//}
		}
	}*/
	ret.addAll(objPropTaxo.getBottomNode().getEquivalentElements());
	ret.remove(objPropTaxo.getBottom());
	ret.remove(fac.getOWLObjectInverseOf((OWLObjectPropertyExpression) objPropTaxo.getBottom()).getSimplified());
	return ret;
}
 
Example #13
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public Set<OWLPropertyExpression> getAllSubproperties(
		OWLPropertyExpression roleSup) {
	Set<OWLPropertyExpression> subs = new HashSet<OWLPropertyExpression>();
	for (OWLPropertyExpression sub : 
			roleSup.isDataPropertyExpression()? dataPropTaxo.getSubsumeesOrSelf(roleSup)
			: objPropTaxo.getSubsumeesOrSelf(roleSup)) {
		if (!sub.isAnonymous()) {
			subs.add(sub); 
		} else {
			//OWLObjectProperty op = ((OWLObjectPropertyExpression) c).getNamedProperty(); //fac.getOWLObjectProperty(IRI.create(sub.getInverse().getName().getAFun().getName()));
			//if (oprops.contains(op))
			{
				subs.add(sub);
			} 
			//else {
				// do nothing: inverse of a create role R, where R is defined as equivalent to the inverse of an existing role
			//}
		}
	}
	subs.remove(dataPropTaxo.getBottom());
	subs.remove(objPropTaxo.getBottom());
	subs.remove(fac.getOWLObjectInverseOf((OWLObjectPropertyExpression) objPropTaxo.getBottom()).getSimplified());

	return subs;
}
 
Example #14
Source File: ShuntGraphUtilsNRTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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);
}
 
Example #15
Source File: ShuntGraphUtilsNRTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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);
}
 
Example #16
Source File: OWLGraphWrapperEdgesExtendedTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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));
}
 
Example #17
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public Set<OWLClassExpression> getMostGeneralSubsumees(
		Set<OWLClassExpression> classes,
		Set<OWLPropertyExpression> properties) {
	 Set<OWLClassExpression> existentialRestCandidates = getCommunSubsumees(classes, true);
	 Set<OWLPropertyExpression> roleCandidates = new HashSet<OWLPropertyExpression>();
	 Boolean isDataRole = null;
	 for (OWLClassExpression sub: existentialRestCandidates) {
		 assert sub.getClassExpressionType().equals(ClassExpressionType.DATA_SOME_VALUES_FROM)
		 || sub.getClassExpressionType().equals(ClassExpressionType.OBJECT_SOME_VALUES_FROM): sub;
		 OWLQuantifiedRestriction qSub = (OWLQuantifiedRestriction) sub;
		 OWLPropertyExpression subRole =  qSub.getProperty();
		 assert subRole!=null : "Unkown role : "+ qSub; 
		 roleCandidates.add(subRole);
		 isDataRole = subRole.isDataPropertyExpression();
	 }
	 if (roleCandidates.isEmpty()) {
		 return Collections.EMPTY_SET;
	 }
	 roleCandidates.retainAll(getCommunSubproperty(properties));
	 if (roleCandidates.isEmpty()) {
		 return Collections.EMPTY_SET;
	 }
	
	 // check maximality wrt inverse
	 Set<OWLClassExpression> ret = getMaximum(roleCandidates);
	 //
	return ret;
	

}
 
Example #18
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public boolean isSubProperty(OWLPropertyExpression normalizedSub,
		OWLPropertyExpression normalizedSup) {
	if (normalizedSub.isObjectPropertyExpression() ^ normalizedSup.isDataPropertyExpression()) {
		return false;
	}
	if (normalizedSub.isObjectPropertyExpression()) {
		return objPropTaxo.isSubsumedBy(normalizedSub, normalizedSup);
	} else {
		return dataPropTaxo.isSubsumedBy(normalizedSub, normalizedSup);
	}
}
 
Example #19
Source File: DeleteRuleWithUnsatifiableAtoms.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public String getName(OWLPropertyExpression propexp) {
	String name;
	if (!propexp.isAnonymous()) {
		if (propexp.isDataPropertyExpression()) {
			name = ((OWLDataPropertyExpression) propexp).asOWLDataProperty().getIRI().toString();
		} else {
			name = ((OWLObjectPropertyExpression) propexp).asOWLObjectProperty().getIRI().toString();
		}
	} else {
		assert propexp.isObjectPropertyExpression();
		name = ((OWLObjectPropertyExpression) propexp).getNamedProperty().getIRI().toString();
	}
	return name;
}
 
Example #20
Source File: DeleteRuleWithConceptOrPropertyNotInAbox.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public String getName(OWLPropertyExpression propexp) {
	String name;
	if (!propexp.isAnonymous()) {
		if (propexp.isDataPropertyExpression()) {
			name = ((OWLDataPropertyExpression) propexp).asOWLDataProperty().getIRI().toString();
		} else {
			name = ((OWLObjectPropertyExpression) propexp).asOWLObjectProperty().getIRI().toString();
		}
	} else {
		assert propexp.isObjectPropertyExpression();
		name = ((OWLObjectPropertyExpression) propexp).getNamedProperty().getIRI().toString();
	}
	return name;
}
 
Example #21
Source File: DeleteRuleWithConceptOrPropertyNotInAbox.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public OWLProperty getNamedProperty(OWLPropertyExpression propexp) {
	OWLProperty ret;
	if (!propexp.isAnonymous()) {
		if (propexp.isDataPropertyExpression()) {
			ret = ((OWLDataPropertyExpression) propexp).asOWLDataProperty();;
		} else {
			ret = ((OWLObjectPropertyExpression) propexp).asOWLObjectProperty();
		}
	} else {
		assert propexp.isObjectPropertyExpression();
		ret = ((OWLObjectPropertyExpression) propexp).getNamedProperty();
	}
	return ret;
}
 
Example #22
Source File: TaxonomyWildcardHelper.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * returns a map associating a number of wildcards processed (>= minimalNumberOfConceptWildcardsToReport) to the most general subsumees for the corresponding number of wildcards.
 * In other words, for k>= minimalNumberOfConceptWildcardsToReport),  map.get(k) =  getMostGeneralSubsumees(classes, properties, 0,0,k) . 
 * NOTE: for k>= minimalNumberOfConceptWildcardsToReport, map.get(k) may be null if getMostGeneralSubsumees(classes, properties, 0,0,k).isEmpty().
 * @param classes
 * @param properties
 * @param conceptWildcardsToProcess
 * @param minimalNumberOfConceptWildcardsToReport
 * @return
 */
public Map<Integer, Set<OWLClassExpression>> computeMostGeneralSubsumees(
		Set<OWLClassExpression> classes,
		Set<OWLPropertyExpression> properties,
		int conceptWildcardsToProcess, 
		int minimalNumberOfConceptWildcardsToReport) {
	if (minimalNumberOfConceptWildcardsToReport> conceptWildcardsToProcess) {
		throw new IllegalArgumentException("minimalNumberOfConceptWildcardsToReport must be less than or equals to conceptWildcardsToProcess");
	}
	Map<Integer, Set<OWLClassExpression>> ret = new HashMap<Integer, Set<OWLClassExpression>>();
	computeMostGeneralSubsumees(classes, properties, conceptWildcardsToProcess, minimalNumberOfConceptWildcardsToReport, 
			ret, 0);
	return ret;
}
 
Example #23
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
protected Set<OWLPropertyExpression> getCommunSubproperty(Set<OWLPropertyExpression> props) {
	Set<OWLPropertyExpression> communSubsumees = null;
	
	for (OWLPropertyExpression propRole: props) {
		Set<OWLPropertyExpression> subs = new HashSet<OWLPropertyExpression>
				(propRole.isDataPropertyExpression()? dataPropTaxo.getSubsumeesOrSelf(propRole)
				: objPropTaxo.getSubsumeesOrSelf(propRole));
		if (propRole.isDataPropertyExpression()) {
			subs.removeAll(dataPropTaxo.getBottomNode().getEquivalentElements());
		} else {
			assert propRole.isObjectPropertyExpression() : propRole;
			subs.removeAll(objPropTaxo.getBottomNode().getEquivalentElements());
		}
		
		if (communSubsumees == null) {
			communSubsumees = new HashSet<OWLPropertyExpression>();
			communSubsumees.addAll(subs);
		} else {
			communSubsumees.retainAll(subs);
		}
		
		if (communSubsumees.isEmpty()) {
			return Collections.EMPTY_SET;
		}
	}
	return communSubsumees == null? new HashSet<OWLPropertyExpression>(): communSubsumees;
}
 
Example #24
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * returns a map associating a number of wildcards processed (>= minimalNumberOfConceptWildcardsToReport) to the most general subsumees for the corresponding number of wildcards.
 * In other words, for k>= minimalNumberOfConceptWildcardsToReport),  map.get(k) =  getMostGeneralSubsumees(classes, properties, 0,0,k) . 
 * NOTE: for k>= minimalNumberOfConceptWildcardsToReport, map.get(k) may be null if getMostGeneralSubsumees(classes, properties, 0,0,k).isEmpty().
 * @param classes
 * @param properties
 * @param conceptWildcardsToProcess
 * @param minimalNumberOfConceptWildcardsToReport
 * @return
 */
public Map<Integer, Set<OWLClassExpression>> computeMostGeneralSubsumees(
		Set<OWLClassExpression> classes,
		Set<OWLPropertyExpression> properties,
		int conceptWildcardsToProcess, 
		int minimalNumberOfConceptWildcardsToReport) {
	if (minimalNumberOfConceptWildcardsToReport> conceptWildcardsToProcess) {
		throw new IllegalArgumentException("minimalNumberOfConceptWildcardsToReport must be less than or equals to conceptWildcardsToProcess");
	}
	Map<Integer, Set<OWLClassExpression>> ret = new HashMap<Integer, Set<OWLClassExpression>>();
	computeMostGeneralSubsumees(classes, properties, conceptWildcardsToProcess, minimalNumberOfConceptWildcardsToReport, 
			ret, 0);
	return ret;
}
 
Example #25
Source File: OWLGraphWrapperEdges.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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;
}
 
Example #26
Source File: NormalizedOWLQLTbox.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * returns the key associated with a property expression
 * @param pe
 * @return
 */
public static String getKey(OWLPropertyExpression pe) {
	if (pe.isObjectPropertyExpression()) {
		pe = ((OWLObjectPropertyExpression) pe).getSimplified();
	}
	if (!pe.isAnonymous()) {
		return ((OWLNamedObject) pe).getIRI().toString();
	} else {
		OWLObjectInverseOf ope = (OWLObjectInverseOf) pe;
		OWLObjectProperty op = (OWLObjectProperty) ope.getInverse();
		return op.getIRI().toString();
		
	}
}
 
Example #27
Source File: OWLGraphWrapperEdges.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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;
}
 
Example #28
Source File: OWLGraphUtil.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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;
}
 
Example #29
Source File: AbstractAnnotationPredictor.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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);

}
 
Example #30
Source File: OWLGraphWrapperEdgesAdvanced.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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;
}