org.semanticweb.owlapi.model.AxiomType Java Examples

The following examples show how to use org.semanticweb.owlapi.model.AxiomType. 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: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Find all corresponding {@link OWLObject}s with an OBO-style alternate identifier.
 * <p>
 * WARNING: This methods scans all object annotations in all ontologies. 
 * This is an expensive method.
 * 
 * @return map of altId to OWLObject (never null)
 */
public Map<String, OWLObject> getAllOWLObjectsByAltId() {
	final Map<String, OWLObject> results = new HashMap<String, OWLObject>();
	final OWLAnnotationProperty altIdProperty = getAnnotationProperty(OboFormatTag.TAG_ALT_ID.getTag());
	if (altIdProperty == null) {
		return Collections.emptyMap();
	}
	for (OWLOntology o : getAllOntologies()) {
		Set<OWLAnnotationAssertionAxiom> aas = o.getAxioms(AxiomType.ANNOTATION_ASSERTION);
		for (OWLAnnotationAssertionAxiom aa : aas) {
			OWLAnnotationValue v = aa.getValue();
			OWLAnnotationProperty property = aa.getProperty();
			if (altIdProperty.equals(property) && v instanceof OWLLiteral) {
				String altId = ((OWLLiteral)v).getLiteral();
				OWLAnnotationSubject subject = aa.getSubject();
				if (subject instanceof IRI) {
					OWLObject obj = getOWLObject((IRI) subject);
					if (obj != null) {
						results.put(altId, obj);
					}
				}
			}
		}
	}
	return results;
}
 
Example #2
Source File: AutomaticSimPreProcessorTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testAutoSimOnGO() throws Exception, MathException {

	ParserWrapper pw = new ParserWrapper();
	sourceOntol = pw.parseOBO(getResourceIRIString("go-subset-t1.obo"));
	g = new OWLGraphWrapper(sourceOntol);
	IRI vpIRI = g.getOWLObjectPropertyByIdentifier("GOTESTREL:0000001").getIRI();
	TableToAxiomConverter ttac = new TableToAxiomConverter(g);
	ttac.config.axiomType = AxiomType.CLASS_ASSERTION;
	ttac.config.property = vpIRI;
	ttac.config.isSwitchSubjectObject = true;
	ttac.parse("src/test/resources/simplegaf-t1.txt");

	OWLPrettyPrinter pp = new OWLPrettyPrinter(g);
	
	AutomaticSimPreProcessor pproc = new AutomaticSimPreProcessor();
	try {
		pproc.setInputOntology(sourceOntol);
		pproc.setOutputOntology(sourceOntol);
		pproc.preprocess();
	} finally {
		pproc.dispose();
	}

}
 
Example #3
Source File: PhenoSimHQEPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void makeHasPhenotypeInstancesDirect() {
	// x Type has_phenotype some C ==> x Type C
	LOG.info("x Type has_phenotype some C ==> x Type C");
	OWLObjectProperty hasPhenotype = getOWLObjectPropertyViaOBOSuffix(HAS_PHENOTYPE);
	Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>();
	Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>();
	for (OWLClassAssertionAxiom caa : outputOntology.getAxioms(AxiomType.CLASS_ASSERTION)) {
		OWLClassExpression ex = caa.getClassExpression();
		OWLIndividual i = caa.getIndividual();
		if (ex instanceof OWLObjectSomeValuesFrom) {
			OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom)ex;
			if (svf.getProperty().equals(hasPhenotype)) {
				rmAxioms.add(caa);
				newAxioms.add(getOWLDataFactory().getOWLClassAssertionAxiom(svf.getFiller(), i));
			}

		}
	}
	LOG.info("making instances direct: +"+newAxioms.size()+ " -"+rmAxioms.size());
	addAxiomsToOutput(newAxioms, false);
	removeAxiomsFromOutput(rmAxioms, false);
}
 
Example #4
Source File: PropertyViewOntologyBuilder.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Set<List<OWLObjectPropertyExpression>> getPropertyChains(OWLObjectProperty p) {
	LOG.info("Getting chains for: "+p);
	Set<List<OWLObjectPropertyExpression>> chains = new HashSet<List<OWLObjectPropertyExpression>>();
	for (OWLSubPropertyChainOfAxiom spca : sourceOntology.getAxioms(AxiomType.SUB_PROPERTY_CHAIN_OF)) {
		if (spca.getSuperProperty().equals(p)) {
			List<OWLObjectPropertyExpression> chain = spca.getPropertyChain();
			chains.add(chain);

			// note: limited form of cycle checking
			if (!chain.contains(p)) {
				chains.addAll(expandPropertyChain(chain));
			}
		}
	}
	LOG.info(p+" ==> "+chains);
	return chains;
}
 
Example #5
Source File: Mooncat.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void addSubAnnotationProperties(Set<OWLAxiom> axioms) {
	// add ALL subannotprop axioms
	// - this is quite geared towards obo ontologies, where
	//   we want to preserve obo headers.
	// TODO: make this configurable
	LOG.info("adding SubAnnotationProperties");
	Set<OWLAxiom> sapAxioms = new HashSet<OWLAxiom>();
	for (OWLOntology refOnt : this.getReferencedOntologies()) {
		for (OWLSubAnnotationPropertyOfAxiom a : refOnt.getAxioms(AxiomType.SUB_ANNOTATION_PROPERTY_OF)) {
			sapAxioms.add(a);
			Set<OWLAnnotationAssertionAxiom> s = refOnt.getAnnotationAssertionAxioms(a.getSubProperty().getIRI());
			if (s != null && !s.isEmpty()) {
				for (OWLAnnotationAssertionAxiom owlAnnotationAssertionAxiom : s) {
					sapAxioms.add(owlAnnotationAssertionAxiom);
				}
			}
		}
	}
	axioms.addAll(sapAxioms);
}
 
Example #6
Source File: OWLHandler.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Deprecated
public void deleteFactCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException {
	if (isHelp()) {
		info("generates ClassAssertion");
		return;
	}
	OWLOntology ont = resolveOntology(Param.ontology);
	OWLIndividual i = resolveIndividual(Param.individualId);
	OWLIndividual j = resolveIndividual(Param.fillerId);
	OWLObjectProperty p = resolveObjectProperty(Param.propertyId);
	for (OWLObjectPropertyAssertionAxiom ax : ont.getAxioms(AxiomType.OBJECT_PROPERTY_ASSERTION)) {
		if (ax.getSubject().equals(i)) {
			if (p == null || ax.getProperty().equals(p)) {
				if (j == null || ax.getObject().equals(j)) {
					removeAxiom(ont, graph.getDataFactory().getOWLObjectPropertyAssertionAxiom(p, i, j));
				}
			}
		}
	}
	String jsonStr = "";
	response.getWriter().write(jsonStr);
}
 
Example #7
Source File: SubClassComputation.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public SubClassComputation(NormalizedOWLQLTbox tbox) {
	super();
	numOfDirectSubsumptionTests =0;
	this.tbox = tbox;
	sub2ToldSubsumers = new HashMap<OWLClassExpression, Set<OWLClassExpression>>();
	Set<OWLSubClassOfAxiom> axioms = tbox.getNormalizedOntology().getAxioms(AxiomType.SUBCLASS_OF);
	int maxToldSubsumers =0;
	if (axioms!=null) {
		for (OWLSubClassOfAxiom ax: axioms) {
			OWLClassExpression sub = ax.getSubClass();
			OWLClassExpression sup = ax.getSuperClass();
			//if (!sub.isAnonymous()) 
			{
				Set<OWLClassExpression> s = sub2ToldSubsumers.get(sub);
				if (s == null) {
					s = new HashSet<OWLClassExpression>();
					sub2ToldSubsumers.put(sub, s);
				}
				s.add(sup);
				maxToldSubsumers = Math.max(s.size(), maxToldSubsumers);
			}
		}
	}
	logger.debug("Max told subsumers: {}", maxToldSubsumers);
	
}
 
Example #8
Source File: TemplatedTransformer.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
	
}
 
Example #9
Source File: OWLGraphWrapperEdgesAdvanced.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
}
 
Example #10
Source File: OWLGraphWrapperEdges.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Map<OWLObjectProperty,Set<List<OWLObjectProperty>>> getPropertyChainMap() {
	if (pcMap == null) {
		pcMap = new HashMap<OWLObjectProperty,Set<List<OWLObjectProperty>>>();
		for (OWLSubPropertyChainOfAxiom a : sourceOntology.getAxioms(AxiomType.SUB_PROPERTY_CHAIN_OF)) {
			//LOG.info("CHAIN:"+a+" // "+a.getPropertyChain().size());
			if (a.getPropertyChain().size() == 2) {
				OWLObjectPropertyExpression p1 = a.getPropertyChain().get(0);
				OWLObjectPropertyExpression p2 = a.getPropertyChain().get(1);
				//LOG.info("  xxCHAIN:"+p1+" o "+p2);
				if (p1 instanceof OWLObjectProperty && p2 instanceof OWLObjectProperty) {
					List<OWLObjectProperty> list = new Vector<OWLObjectProperty>();
					list.add((OWLObjectProperty) p2);
					list.add((OWLObjectProperty) a.getSuperProperty());
					if (!pcMap.containsKey(p1)) 
						pcMap.put((OWLObjectProperty) p1, new HashSet<List<OWLObjectProperty>>());
					pcMap.get((OWLObjectProperty) p1).add(list);
					//LOG.info("  xxxCHAIN:"+p1+" ... "+list);
				}
			}
			else {
				// TODO
			}
		}
	}
	return pcMap;
}
 
Example #11
Source File: OwlHelper.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Set<OWLAnnotationProperty> getSubProperties(OWLAnnotationProperty superProp, Set<OWLOntology> ontologies) {
	Set<OWLAnnotationProperty> result = new HashSet<OWLAnnotationProperty>();
	for (OWLOntology ont : ontologies) {
		for (OWLSubAnnotationPropertyOfAxiom ax : ont.getAxioms(AxiomType.SUB_ANNOTATION_PROPERTY_OF)) {
			if (ax.getSuperProperty().equals(superProp)) {
				result.add(ax.getSubProperty());
			}
		}
	}
	return result;
}
 
Example #12
Source File: SimpleOntology.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
private Stream<IRI> getSubClassesFor(OWLClass owlClass, boolean direct) {
    if (direct) {
        return owlOntology.axioms(AxiomType.SUBCLASS_OF, Imports.INCLUDED)
                .filter(axiom -> axiom.getSuperClass().equals(owlClass))
                .map(OWLSubClassOfAxiom::getSubClass)
                .filter(subclass -> !subclass.isBottomEntity() && subclass.isOWLClass()
                            && !subclass.asOWLClass().getIRI().equals(owlClass.getIRI()))
                .map(subclass -> SimpleOntologyValues.mobiIRI(subclass.asOWLClass().getIRI()));
    } else {
        return owlReasoner.getSubClasses(owlClass, false).entities()
                .filter(subclass -> !subclass.isBottomEntity() && !subclass.getIRI().equals(owlClass.getIRI()))
                .map(subclass -> SimpleOntologyValues.mobiIRI(subclass.getIRI()));
    }
}
 
Example #13
Source File: Mooncat.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * For every pair X DisjointWith Y, generate an axiom
 * A and Y = Nothing
 * 
 * (may become deprecated after Elk supports disjoints)
 * 
 * @param ont
 * @param manager
 * @param dataFactory
 */
public static void translateDisjointsToEquivalents(OWLOntology ont, OWLOntologyManager manager, OWLDataFactory dataFactory) {
	for (OWLDisjointClassesAxiom dca : ont.getAxioms(AxiomType.DISJOINT_CLASSES, Imports.INCLUDED)) {
		for (OWLClassExpression ce1 : dca.getClassExpressions()) {
			for (OWLClassExpression ce2 : dca.getClassExpressions()) {
				if (ce1.compareTo(ce2) <= 0)
					continue;
				OWLEquivalentClassesAxiom eca = dataFactory.getOWLEquivalentClassesAxiom(dataFactory.getOWLNothing(),
						dataFactory.getOWLObjectIntersectionOf(ce1, ce2));
				manager.addAxiom(ont, eca);
				// TODO - remove if requested
			}
		}
	}
}
 
Example #14
Source File: Mooncat.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Set<OWLObject> findTaggedEntities(OWLAnnotationProperty p, Set<OWLAnnotationValue> values, final OWLGraphWrapper graph) {
	if (p == null || values == null || values.isEmpty()) {
		return Collections.emptySet();
	}
	final Set<OWLObject> entities = new HashSet<OWLObject>();
	Set<OWLOntology> allOntologies = graph.getAllOntologies();
	for (OWLOntology ontology : allOntologies) {
		Set<OWLAnnotationAssertionAxiom> axioms = ontology.getAxioms(AxiomType.ANNOTATION_ASSERTION);
		for (OWLAnnotationAssertionAxiom axiom : axioms) {
			if (p.equals(axiom.getProperty()) && values.contains(axiom.getValue())) {
				axiom.getSubject().accept(new OWLAnnotationSubjectVisitor(){

					@Override
					public void visit(IRI iri) {
						OWLObject owlObject = graph.getOWLObject(iri);
						if (owlObject != null) {
							entities.add(owlObject);
						}
					}

					@Override
					public void visit(OWLAnonymousIndividual individual) {
						// do nothing
					}
				});
			}
		}
	}
	return entities;
}
 
Example #15
Source File: OwlHelper.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Set<OWLAnnotationProperty> getSuperProperties(OWLAnnotationProperty subProp, Set<OWLOntology> ontologies) {
	Set<OWLAnnotationProperty> result = new HashSet<OWLAnnotationProperty>();
	for (OWLOntology ont : ontologies) {
		for (OWLSubAnnotationPropertyOfAxiom ax : ont.getAxioms(AxiomType.SUB_ANNOTATION_PROPERTY_OF)) {
			if (ax.getSubProperty().equals(subProp)) {
				result.add(ax.getSuperProperty());
			}
		}
	}
	return result;
}
 
Example #16
Source File: RedundantAxiomTagger.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void tagRedundantAxioms(OWLReasoner reasoner) {
    OWLOntology ont = reasoner.getRootOntology();
    OWLOntologyManager mgr = ont.getOWLOntologyManager();
    OWLDataFactory df = mgr.getOWLDataFactory();
    OWLAnnotationProperty anProp = df.getOWLAnnotationProperty(IRI.create("http://www.geneontology.org/formats/oboInOwl#source"));
    for (OWLSubClassOfAxiom ax : ont.getAxioms(AxiomType.SUBCLASS_OF)) {
        if (!ax.getSuperClass().isAnonymous()) {
            OWLClass supc = (OWLClass) ax.getSuperClass();
            
            mgr.removeAxiom(ont, ax);
            reasoner.flush();
            NodeSet<OWLClass> ancs = reasoner.getSuperClasses(ax.getSubClass(), false);
            //LOG.info(ax + " ANCS="+ancs);
            if (ancs.containsEntity( supc)) {
                String direct = "indirect";
                if (reasoner.getSuperClasses(ax.getSubClass(), true).containsEntity( supc)) {
                    direct = "direct";
                }
                LOG.info("SCA = "+ax+" D="+direct);
                OWLAnnotation ann = df.getOWLAnnotation(anProp, df.getOWLLiteral(direct));
                OWLAxiom newAxiom = changeAxiomAnnotations(ax, Collections.singleton(ann), df);
                mgr.addAxiom(ont, newAxiom);
            }
            else {
                // put it back
                mgr.addAxiom(ont, ax);
            }
        }
    }
   
}
 
Example #17
Source File: LegoTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Set<OWLObjectPropertyAssertionAxiom> getAllPropertyAssertionAxioms(Set<OWLOntology> ontologies) {
	Set<OWLObjectPropertyAssertionAxiom> axioms = new HashSet<OWLObjectPropertyAssertionAxiom>();
	for(OWLOntology o : ontologies) {
		axioms.addAll(o.getAxioms(AxiomType.OBJECT_PROPERTY_ASSERTION));
	}
	return axioms;
}
 
Example #18
Source File: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Find the corresponding {@link OWLObject}s for a given set of OBO-style alternate identifiers.
 * <p>
 * WARNING: This methods scans all object annotations in all ontologies. 
 * This is an expensive method.
 * <p>
 * Consider loading all altId-mappings using {@link #getAllOWLObjectsByAltId()}.
 * 
 * @param altIds
 * @return map of altId to OWLObject (never null)
 * @see #getAllOWLObjectsByAltId()
 */
public Map<String, OWLObject> getOWLObjectsByAltId(Set<String> altIds) {
	final Map<String, OWLObject> results = new HashMap<String, OWLObject>();
	final OWLAnnotationProperty altIdProperty = getAnnotationProperty(OboFormatTag.TAG_ALT_ID.getTag());
	if (altIdProperty == null) {
		return Collections.emptyMap();
	}
	for (OWLOntology o : getAllOntologies()) {
		Set<OWLAnnotationAssertionAxiom> aas = o.getAxioms(AxiomType.ANNOTATION_ASSERTION);
		for (OWLAnnotationAssertionAxiom aa : aas) {
			OWLAnnotationValue v = aa.getValue();
			OWLAnnotationProperty property = aa.getProperty();
			if (altIdProperty.equals(property) && v instanceof OWLLiteral) {
				String altId = ((OWLLiteral)v).getLiteral();
				if (altIds.contains(altId)) {
					OWLAnnotationSubject subject = aa.getSubject();
					if (subject instanceof IRI) {
						OWLObject obj = getOWLObject((IRI) subject);
						if (obj != null) {
							results.put(altId, obj);
						}
					}
				}
			}
		}
	}
	return results;
}
 
Example #19
Source File: PhenoSimHQEPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void expandInheresInPartOf() {
	LOG.info("Expanding IPO; axioms before="+outputOntology.getAxiomCount());
	IRI ipoIRI = getIRIViaOBOSuffix(INHERES_IN_PART_OF);

	OWLAnnotationProperty eap = getOWLDataFactory().getOWLAnnotationProperty(IRI.create("http://purl.obolibrary.org/obo/IAO_0000424"));
	OWLAnnotationProperty aap = getOWLDataFactory().getOWLAnnotationProperty(IRI.create("http://purl.obolibrary.org/obo/IAO_0000425"));

	Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>();
	for (OWLAnnotationAssertionAxiom ax : outputOntology.getAxioms(AxiomType.ANNOTATION_ASSERTION)) {
		if (ax.getProperty().equals(eap) || ax.getProperty().equals(aap)) {
			rmAxioms.add(ax);
		}
	}
	LOG.info("Clearing old expansions: "+rmAxioms.size());
	getOWLOntologyManager().removeAxioms(outputOntology, rmAxioms);

	OWLAnnotationAssertionAxiom aaa = getOWLDataFactory().getOWLAnnotationAssertionAxiom(eap, ipoIRI, 
			getOWLDataFactory().getOWLLiteral("BFO_0000052 some (BFO_0000050 some ?Y)"));
	addAxiomToOutput(aaa, false);

	MacroExpansionVisitor mev;
	mev = new MacroExpansionVisitor(outputOntology);
	mev.expandAll();
	flush();



	//mev.expandAll();
	LOG.info("Expanded IPO; axioms after="+outputOntology.getAxiomCount());
}
 
Example #20
Source File: SimpleOntology.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
private Stream<IRI> getSubObjectPropertiesFor(OWLObjectProperty property, boolean direct) {
    if (direct) {
        return owlOntology.axioms(AxiomType.SUB_OBJECT_PROPERTY, Imports.INCLUDED)
                .filter(axiom -> axiom.getSuperProperty().equals(property))
                .map(OWLSubPropertyAxiom::getSubProperty)
                .filter(subproperty -> !subproperty.isBottomEntity() && subproperty.isOWLObjectProperty()
                        && !subproperty.getNamedProperty().getIRI().equals(property.getIRI()))
                .map(subproperty -> SimpleOntologyValues.mobiIRI(subproperty.getNamedProperty().getIRI()));
    } else {
        return owlReasoner.getSubObjectProperties(property, false).entities()
                .filter(subproperty -> !subproperty.isBottomEntity()
                        && !subproperty.getNamedProperty().getIRI().equals(property.getIRI()))
                .map(subproperty -> SimpleOntologyValues.mobiIRI(subproperty.getNamedProperty().getIRI()));
    }
}
 
Example #21
Source File: OCUtils.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean isAboxAxiom(OWLAxiom ax) {
	return ax.getAxiomType().equals(AxiomType.DATA_PROPERTY_ASSERTION)
	|| ax.getAxiomType().equals(AxiomType.OBJECT_PROPERTY_ASSERTION)
	|| ax.getAxiomType().equals(AxiomType.CLASS_ASSERTION)
	|| ax.getAxiomType().equals(AxiomType.SAME_INDIVIDUAL)
	|| ax.getAxiomType().equals(AxiomType.DIFFERENT_INDIVIDUALS);
}
 
Example #22
Source File: SimpleOntology.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
private Stream<IRI> getSubDatatypePropertiesFor(OWLDataProperty property, boolean direct) {
    if (direct) {
        return owlOntology.axioms(AxiomType.SUB_DATA_PROPERTY, Imports.INCLUDED)
                .filter(axiom -> axiom.getSuperProperty().equals(property))
                .map(OWLSubPropertyAxiom::getSubProperty)
                .filter(subproperty -> !subproperty.isBottomEntity() && subproperty.isOWLDataProperty()
                        && !subproperty.asOWLDataProperty().getIRI().equals(property.getIRI()))
                .map(subproperty -> SimpleOntologyValues.mobiIRI(subproperty.asOWLDataProperty().getIRI()));
    } else {
        return owlReasoner.getSubDataProperties(property, false).entities()
                .filter(subproperty -> !subproperty.isBottomEntity()
                        && !subproperty.getIRI().equals(property.getIRI()))
                .map(subproperty -> SimpleOntologyValues.mobiIRI(subproperty.getIRI()));
    }
}
 
Example #23
Source File: NormalizedOWLQLTbox.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public Set<OWLObjectProperty> getIrreflexiveProperties() {
	if (irreflexiveProps == null) {
		irreflexiveProps = new HashSet<OWLObjectProperty>();
		for (OWLIrreflexiveObjectPropertyAxiom ax: normalizedOntology.getAxioms(AxiomType.IRREFLEXIVE_OBJECT_PROPERTY)) {
			irreflexiveProps.add(ax.getProperty().getNamedProperty());
		}
	}
	return irreflexiveProps;
}
 
Example #24
Source File: NormalizedOWLQLTbox.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public Set<OWLObjectProperty> getReflexiveProperties() {
	if (reflexiveProps == null) {
		reflexiveProps = new HashSet<OWLObjectProperty>();
		for (OWLReflexiveObjectPropertyAxiom ax: normalizedOntology.getAxioms(AxiomType.REFLEXIVE_OBJECT_PROPERTY)) {
			reflexiveProps.add(ax.getProperty().getNamedProperty());
		}
	}
	return reflexiveProps;
}
 
Example #25
Source File: SimpleOntology.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
private Stream<IRI> getSubAnnotationPropertiesFor(OWLAnnotationProperty property, boolean direct) {
    Set<OWLAnnotationProperty> directProps = owlOntology.axioms(AxiomType.SUB_ANNOTATION_PROPERTY_OF,
            Imports.INCLUDED)
            .filter(axiom -> axiom.getSuperProperty().equals(property))
            .map(OWLSubAnnotationPropertyOfAxiom::getSubProperty)
            .filter(subproperty -> !subproperty.isBottomEntity() && subproperty.isOWLAnnotationProperty()
                    && !subproperty.getIRI().equals(property.getIRI()))
            .collect(Collectors.toSet());
    if (direct) {
        return directProps.stream()
                .map(subproperty -> SimpleOntologyValues.mobiIRI(subproperty.getIRI()));
    } else {
        Set<IRI> rtn = directProps.stream()
                .map(subproperty -> SimpleOntologyValues.mobiIRI(subproperty.getIRI()))
                .collect(Collectors.toSet());
        while (directProps.size() > 0) {
            OWLAnnotationProperty nextProp = directProps.iterator().next();
            directProps.remove(nextProp);
            owlOntology.axioms(AxiomType.SUB_ANNOTATION_PROPERTY_OF, Imports.INCLUDED)
                    .filter(axiom -> axiom.getSuperProperty().equals(nextProp))
                    .map(OWLSubAnnotationPropertyOfAxiom::getSubProperty)
                    .filter(subproperty -> !subproperty.isBottomEntity() && subproperty.isOWLAnnotationProperty()
                            && !subproperty.getIRI().equals(nextProp.getIRI()))
                    .forEach(subproperty -> {
                        rtn.add(SimpleOntologyValues.mobiIRI(subproperty.getIRI()));
                        directProps.add(subproperty);
                    });
        }
        return rtn.stream();
    }
}
 
Example #26
Source File: OWLQLNormalizer.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean isAboxAxiom(OWLAxiom ax) {
	return ax.getAxiomType().equals(AxiomType.DATA_PROPERTY_ASSERTION)
	|| ax.getAxiomType().equals(AxiomType.OBJECT_PROPERTY_ASSERTION)
	|| ax.getAxiomType().equals(AxiomType.CLASS_ASSERTION)
	|| ax.getAxiomType().equals(AxiomType.SAME_INDIVIDUAL)
	|| ax.getAxiomType().equals(AxiomType.DIFFERENT_INDIVIDUALS);
}
 
Example #27
Source File: ElkReasoner.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isEntailmentCheckingSupported(final AxiomType<?> axiomType) {
	Class<? extends ElkObject> elkAxiomClass = OwlConverter
			.convertType(axiomType.getActualClass());
	if (elkAxiomClass == null
			|| !ElkAxiom.class.isAssignableFrom(elkAxiomClass)) {
		// not supported
		return false;
	}
	// else
	return EntailmentQueryConverter.isEntailmentCheckingSupported(
			elkAxiomClass.asSubclass(ElkAxiom.class));
}
 
Example #28
Source File: ReasonerUtil.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
/***
 * Remove all axioms that would generate extra unsatisfiable classes for the reasoner
 */
Collection<OWLOntologyChange> removeUnsatisfiableClasses() {
  Collection<OWLOntologyChange> removals = new HashSet<>();
  removals.addAll(removeAxioms(AxiomType.DISJOINT_CLASSES));
  removals.addAll(removeAxioms(AxiomType.DATA_PROPERTY_DOMAIN));
  removals.addAll(removeAxioms(AxiomType.DATA_PROPERTY_RANGE));
  if (removals.size() > 0) {
    reasoner.flush();
  }
  logger.info("Removed " + removals.size() + " axioms to prevent unsatisfiable classes");
  return removals;
}
 
Example #29
Source File: ReasonerUtil.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
Collection<OWLOntologyChange> removeAxioms(AxiomType<?> type) {
  Collection<OWLOntologyChange> removals = new HashSet<>();
  for (OWLOntology importedOnt: ont.getImportsClosure()) {
    Set<? extends OWLAxiom> axioms = importedOnt.getAxioms(type);
    removals.addAll(manager.removeAxioms(importedOnt, axioms));
  }
  return removals;
}
 
Example #30
Source File: PredicateVariableExtractor.java    From neo4j-sparql-extension with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extracts {@link PredicateVariableExtractor} rules.
 * 
 * @param ot ontology
 * @return extracted rules
 */
@Override
public List<Rule> extract(OWLOntology ot) {
	List<Rule> list = new ArrayList<>();
	// list of predicates in ontology
	List<String> ps = new ArrayList<>();
	ps.add(TOPOBJ);
	ps.add(TOPDATA);
	OWLEntity e;
	String op;
	// check all declarations
	for (OWLDeclarationAxiom a : ot.getAxioms(AxiomType.DECLARATION)) {
		e = a.getEntity();
		if (e.isOWLObjectProperty()) {
			// if it is a object property declaration, add it to the list
			// and also add it as subproperty of owl:topObjectProperty
			op = getString(e.asOWLObjectProperty());
			ps.add(op);
			list.add(new SubPropertyOf(op, TOPOBJ));
		} else if (e.isOWLDataProperty()) {
			// if it is a data property declaration, add it to the list
			// and also add it as subproperty of owl:topDataProperty
			op = getString(e.asOWLDataProperty());
			ps.add(op);
			list.add(new SubPropertyOf(op, TOPDATA));
		}
	}
	list.add(new PredicateVariable(ps));
	return list;
}