Java Code Examples for org.semanticweb.owlapi.model.OWLOntology#getClassesInSignature()

The following examples show how to use org.semanticweb.owlapi.model.OWLOntology#getClassesInSignature() . 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: TableToAxiomConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void buildClassMap(OWLGraphWrapper g) {
	IRI x = Obo2OWLVocabulary.IRI_OIO_hasDbXref.getIRI();
	for (OWLOntology ont : g.getAllOntologies()) {
		for (OWLClass c : ont.getClassesInSignature()) {
			for (OWLAnnotationAssertionAxiom aa : ont.getAnnotationAssertionAxioms(c.getIRI())) {
				if (aa.getProperty().getIRI().equals(x)) {
					OWLAnnotationValue v = aa.getValue();
					if (v instanceof OWLLiteral) {
						String xid =((OWLLiteral)v).getLiteral();
						OWLClass xc = (OWLClass) g.getOWLObjectByIdentifier(xid);
						if (xc == null) {
							LOG.error("Cannot get class for: "+xid);
						}
						else {
							config.classMap.put(xc, c);
						}
						//LOG.info(c + " ===> "+xid);
					}
				}					
			}
		}
	}
}
 
Example 2
Source File: OWLGraphWrapperEdges.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void cacheReverseUnionMap() {
	synchronized (edgeCacheMutex) {
	    extraSubClassOfEdges = new HashMap<OWLObject, Set<OWLGraphEdge>>();
           if (!config.isGraphReasonedAndRelaxed) {
	        for (OWLOntology o : getAllOntologies()) {
	            for (OWLClass cls : o.getClassesInSignature()) {
	                for (OWLEquivalentClassesAxiom eca : o.getEquivalentClassesAxioms(cls)) {
	                    for (OWLClassExpression ce : eca.getClassExpressions()) {
	                        if (ce instanceof OWLObjectUnionOf) {
	                            for (OWLObject child : ((OWLObjectUnionOf)ce).getOperands()) {
	                                if (!extraSubClassOfEdges.containsKey(child)) {
	                                    extraSubClassOfEdges.put(child, new OWLGraphEdgeSet());
	                                }
	                                extraSubClassOfEdges.get(child).add(
	                                        createSubClassOfEdge(child,cls,o,eca));
	                            }
	                        }
	                    }
	                }
	            }
	        }
	    }
	}
}
 
Example 3
Source File: Mooncat.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Remove all classes *not* in subset.
 * 
 * This means:
 *   * remove all annotation assertions for that class
 *   * remove all logical axioms about that class
 *   
 *   If removeDangling is true, also remove all axioms that reference this class
 * 
 * @param subset
 * @param removeDangling
 */
public void removeSubsetComplementClasses(Set<OWLClass> subset, boolean removeDangling) {
	OWLOntology o = getOntology();
	Set<OWLClass> rmSet = o.getClassesInSignature();
	rmSet.removeAll(subset); // remove all classes not in subset
	Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>();
	LOG.info("Num of classes to be removed = "+rmSet.size());
	for (OWLClass c : rmSet) {
		rmAxioms.addAll(o.getAnnotationAssertionAxioms(c.getIRI()));
		rmAxioms.addAll(o.getAxioms(c, Imports.EXCLUDED));
	}
	graph.getManager().removeAxioms(o, rmAxioms);
	if (removeDangling) {
		removeDanglingAxioms(o);
	}
}
 
Example 4
Source File: OboOntologyReleaseRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean isBridgingOntology(OWLOntology ont) {
	for (OWLClass c : ont.getClassesInSignature(Imports.INCLUDED)) {

		if (ont.getDeclarationAxioms(c).size() > 0) {
			if (mooncat.getOntology().getDeclarationAxioms(c).size() >0) {
				// class already declared in main ontology - a 2ary ontology MUST
				// declare at least one of its own classes if it is a bone-fide non-bridging ontology
			}
			else if (mooncat.isDangling(ont, c)) {
				// a dangling class has no OWL annotations.
				// E.g. bp_xp_cl contains CL classes as dangling
			}
			else {
				logInfo(c+" has declaration axioms, is not in main, and is not dangling, therefore "+ont+" is NOT a bridging ontology");
				return false;
			}
		}
	}
	logInfo(ont+" is a bridging ontology");
	return true;
}
 
Example 5
Source File: RedundantInferences.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Remove the redundant and marked as inferred super class assertions for
 * each class in the ontology signature. Uses the reasoner to infer the
 * direct super classes.
 * 
 * @param ontology
 * @param reasoner
 * @return map of class to set of redundant axioms
 */
public static Map<OWLClass, Set<RedundantAxiom>> removeRedundantSubClassAxioms(OWLOntology ontology, OWLReasoner reasoner) {
	Iterable<OWLClass> classes = ontology.getClassesInSignature();
	Map<OWLClass, Set<RedundantAxiom>> axioms = findRedundantSubClassAxioms(classes, ontology, reasoner);
	if (!axioms.isEmpty()) {
		Set<OWLSubClassOfAxiom> allAxioms = new THashSet<OWLSubClassOfAxiom>();
		for(OWLClass cls : axioms.keySet()) {
			for(RedundantAxiom redundantAxiom : axioms.get(cls)) {
				allAxioms.add(redundantAxiom.getAxiom());
			}
		}
		OWLOntologyManager manager = ontology.getOWLOntologyManager();
		manager.removeAxioms(ontology, allAxioms);
		LOG.info("Removed "+axioms.size()+" redundant axioms.");
	}
	return axioms;
	
}
 
Example 6
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public static TaxonomyBuilder<OWLClassExpression>  buildClassHierarchy(NormalizedOWLQLTbox tbox, Collection<OWLClassExpression> additionalClassExpression) {
	OWLOntology ont = tbox.getNormalizedOntology();
	OWLDataFactory fac = ont.getOWLOntologyManager().getOWLDataFactory();
	Set<OWLClassExpression> classes;
	if (additionalClassExpression!=null) {
		classes = new HashSet<OWLClassExpression>(additionalClassExpression);
		classes.addAll(ont.getClassesInSignature());
	} else {
		classes = new HashSet<OWLClassExpression>(ont.getClassesInSignature());
	}
	SubClassComputation subcomp = new SubClassComputation(tbox);
	TaxonomyBuilder<OWLClassExpression> taxoBuilder = new TaxonomyBuilder<OWLClassExpression>(
			classes, 
			fac.getOWLThing(),
			fac.getOWLNothing(),
			subcomp);
	taxoBuilder.build();
	logger.debug("Number of direct subsumption tests performed: {}", subcomp.numOfDirectSubsumptionTests);
	long size = classes.size();
	logger.debug("Worst Case number of direct subsumption tests performed: {}^2 = {}",size, size*size);
	return taxoBuilder;
}
 
Example 7
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Reverse all {@code OWLObjectUnionOf}s, that are operands in 
 * an {@code OWLEquivalentClassesAxiom}, into individual {@code OWLSubClassOfAxiom}s, where 
 * the classes part of the {@code OWLObjectUnionOf} become subclasses, and 
 * the original first operand of the {@code OWLEquivalentClassesAxiom} superclass. 
 * <p>
 * Note that such {@code OWLEquivalentClassesAxiom}s are not removed from the ontology, 
 * only {@code OWLSubClassOfAxiom}s are added. The axioms containing 
 * {@code OWLObjectUnionOf}s will be removed by calling {@link #removeOWLObjectUnionOfs()}, 
 * in order to give a chance to {@link #convertEquivalentClassesToSuperClasses()} 
 * to do its job before.
 * 
 * @see #performDefaultModifications()
 * @see #removeOWLObjectUnionOfs()
 * @see #convertEquivalentClassesToSuperClasses()
 */
private void reverseOWLObjectUnionOfs() {
    log.info("Reversing OWLObjectUnionOfs into OWLSubClassOfAxioms");
    for (OWLOntology ont : this.getOwlGraphWrapper().getAllOntologies()) {
        for (OWLClass cls : ont.getClassesInSignature()) {
            for (OWLEquivalentClassesAxiom eca : ont.getEquivalentClassesAxioms(cls)) {
                for (OWLClassExpression ce : eca.getClassExpressions()) {
                    if (ce instanceof OWLObjectUnionOf) {
                        for (OWLObject child : ((OWLObjectUnionOf)ce).getOperands()) {
                            //we reverse only named classes
                            if (child instanceof OWLClass) {
                                this.getOwlGraphWrapper().getManager().addAxiom(ont, 
                                        ont.getOWLOntologyManager().getOWLDataFactory().
                                            getOWLSubClassOfAxiom((OWLClass) child, cls));
                            }
                        }
                    }
                }
            }
        }
    }
    this.triggerWrapperUpdate();
    log.info("OWLObjectUnionOf reversion done.");
}
 
Example 8
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Remove all relations incoming to or outgoing from obsolete classes. This is  
 * because we need to keep obsolete classes in the ontology for valuable replaced_by 
 * annotations, yet we do not want their relations to interfere with relation reduction, 
 * etc (obsolete classes should have no relations, but it often happen 
 * that they have some).
 * 
 * @see #performDefaultModifications()
 */
private void removeObsoleteClassRels() {
    log.info("Removing all relations incoming to or outgoing from obsolete classes...");
    
    for (OWLOntology ont : this.getOwlGraphWrapper().getAllOntologies()) {
        for (OWLClass cls: ont.getClassesInSignature()) {
            if (this.getOwlGraphWrapper().isObsolete(cls) || 
                    this.getOwlGraphWrapper().getIsObsolete(cls)) {
                Set<OWLGraphEdge> edges = this.getOwlGraphWrapper().getOutgoingEdges(cls);
                edges.addAll(this.getOwlGraphWrapper().getIncomingEdges(cls));
                this.removeEdges(edges);
            }
        }
    }
    
    log.info("Done removing relations of obsolete classes.");
}
 
Example 9
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Filter from the ontologies all {@code OWLClass}es 
 * present in {@code classesToKeep},  
 * and then update the {@code OWLGraphWrapper} container. 
 * 
 * @param classesToKeep 	a {@code Set} of {@code OWLClass}s 
 * 							that are classes to be kept in the ontology. 
 * @return                  A {@code Set} of {@code OWLClass}es representing the classes 
 *                          actually removed as a result. 
 */
public Set<OWLClass> filterClasses(Set<OWLClass> classesToKeep) {
	//now remove all classes not included in classesToKeep
    Set<OWLClass> classesRemoved = new HashSet<OWLClass>();
	for (OWLOntology o : this.getOwlGraphWrapper().getAllOntologies()) {
		for (OWLClass iterateClass: o.getClassesInSignature()) {
		    log.info(iterateClass);
		    //don't delete OBO alt IDs nor owl:Nothing and owl:Thing
		    if (this.getOwlGraphWrapper().isOboAltId(iterateClass) || 
		            iterateClass.isTopEntity() || iterateClass.isBottomEntity()) {
		        continue;
		    }
   if (!classesToKeep.contains(iterateClass) && 
           this.removeClass(iterateClass)) {
             classesRemoved.add(iterateClass);
   }
		}
	}
	return classesRemoved;
}
 
Example 10
Source File: OWLGsonRendererTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testGEdges() throws Exception{
	OWLGraphWrapper  wrapper = getOBO2OWLOntologyWrapper("caro.obo");
	final StringWriter stringWriter = new StringWriter();
	OWLGsonRenderer gr = new OWLGsonRenderer(new PrintWriter(stringWriter));
	OWLOntology ont = wrapper.getSourceOntology();
	for (OWLClass c : ont.getClassesInSignature()) {
		for (OWLGraphEdge e : wrapper.getOutgoingEdgesClosure(c)) {
			gr.render(e);
		}
	}
	if (RENDER_FLAG) {
		LOG.debug(stringWriter.toString());
	}
}
 
Example 11
Source File: RetrievingInstances.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
/**
 * @param args
 * @throws OWLOntologyCreationException
 */
public static void main(String[] args) throws OWLOntologyCreationException {
	OWLOntologyManager man = OWLManager.createOWLOntologyManager();

	// Load your ontology.
	OWLOntology ont = man
			.loadOntologyFromOntologyDocument(new File(args[0]));
	
	// Create an ELK reasoner.
	OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
	OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
	
	// Precompute instances for each named class in the ontology
	reasoner.precomputeInferences(InferenceType.CLASS_ASSERTIONS);

	// List representative instances for each class.
	for (OWLClass clazz : ont.getClassesInSignature()) {
		for (Node<OWLNamedIndividual> individual : reasoner.getInstances(
				clazz, true)) {
			System.out.println(clazz + "("
					+ individual.getRepresentativeElement() + ")");
		}
	}

	// Terminate the worker threads used by the reasoner.
	reasoner.dispose();
}
 
Example 12
Source File: CAROLCSTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testConvertXPs() throws Exception {
	ParserWrapper pw = new ParserWrapper();
	OWLGraphWrapper g =
		pw.parseToOWLGraph(getResourceIRIString("lcstest1.owl"));
	OWLOntology ont = g.getSourceOntology();
	OWLObject o2 = g.getOWLObject("http://example.org#o2");

	LOG.debug("getting ancestors for: "+o2);
	for (OWLGraphEdge e : g.getOutgoingEdgesClosure(o2)) {
		LOG.debug(e);
	}
	for (OWLClass c : ont.getClassesInSignature()) {
		LOG.debug("getting individuals for "+c+" "+g.getLabel(c));
		for (OWLIndividual i : g.getInstancesFromClosure(c)) {
			LOG.debug("  "+i);
		}
	}

	/*
	for (OWLClass c : ont.getClassesInSignature()) {
		System.out.println("c="+c+" "+g.getLabel(c));
		for (OWLGraphEdge e : g.getOutgoingEdgesClosure(c)) {
			System.out.println("CLOSURE: "+e);
		}
	}
	*/
	/*
	OWLObject s = g.getOWLObjectByIdentifier("CARO:0000014");
	OWLObject t = g.getOWLObjectByIdentifier("CARO:0000000");
	assertTrue(g.getEdgesBetween(s, t).size() > 0);
	*/
}
 
Example 13
Source File: SpeciesMergeUtilTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testMergeFly() throws Exception {
	ParserWrapper p = new ParserWrapper();
	OWLOntology owlOntology = p.parse(getResourceIRIString("interneuron-fly.obo"));
	Set<OWLClass> clsBefore = owlOntology.getClassesInSignature();
	OWLGraphWrapper graph = new OWLGraphWrapper(owlOntology);
	OWLReasonerFactory rf = new ElkReasonerFactory();
	OWLReasoner reasoner = rf.createReasoner(graph.getSourceOntology());
	SpeciesMergeUtil smu = new SpeciesMergeUtil(graph);

	smu.viewProperty = graph.getOWLObjectPropertyByIdentifier("BFO:0000050");
	smu.taxClass = graph.getOWLClassByIdentifier("NCBITaxon:7227");
	smu.reasoner = reasoner;
	smu.suffix = "fly";
	smu.includedProperties = Collections.singleton(smu.viewProperty);
	//smu.includedProperties = Collections.singleton(graph.getOWLObjectPropertyByIdentifier("BFO:0000051"));
	smu.merge();
	
	Set<OWLClass> clsAfter = smu.ont.getClassesInSignature();
	
	LOG.info("Before: "+clsBefore.size());
	LOG.info("After: "+clsAfter.size());
	assertEquals(100, clsBefore.size());
	assertEquals(90, clsAfter.size());
	p.saveOWL(smu.ont, new OBODocumentFormat(), "target/flyMergeOut.obo");

}
 
Example 14
Source File: OWLGraphWrapperEdgesExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
   * Get all <code>OWLClass</code>es from all ontologies, 
   * that are neither top entity (owl:thing), nor bottom entity (owl:nothing), 
   * nor deprecated ({@link OWLGraphWrapperExtended#isObsolete(OWLObject)} 
   * returns {@code false}), nor an OBO alt ID.
   * 
   * @return 	a <code>Set</code> containing all "real" <code>OWLClass</code>es 
   *          from all ontologies.
   */
  public Set<OWLClass> getAllRealOWLClasses() {
  	//maybe classes can be shared between ontologies?
  	//use a Set to check
  	Set<OWLClass> allClasses = new HashSet<OWLClass>();
  	for (OWLOntology ont : this.getAllOntologies()) {
	for (OWLClass cls: ont.getClassesInSignature()) {
	    if (this.isRealClass(cls)) {
		    allClasses.add(cls);
	    }
	}
}
  	return allClasses;
  }
 
Example 15
Source File: AssertInferredClassExpressions.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Map<OWLClass, Set<OWLObjectSomeValuesFrom>> getExpressions(OWLOntology ontology, Set<OWLObjectProperty> properties, OWLClassFilter filter) {
	final ExpressionMaterializingReasonerFactory rf = new ExpressionMaterializingReasonerFactory(new ElkReasonerFactory());
	final ExpressionMaterializingReasoner reasoner = rf.createReasoner(ontology);
	try {
		reasoner.materializeExpressions(properties);
		final Map<OWLClass, Set<OWLObjectSomeValuesFrom>> newAxioms = new HashMap<OWLClass, Set<OWLObjectSomeValuesFrom>>();
		for (OWLClass cls : ontology.getClassesInSignature()) {
			if (filter != null && filter.use(cls) == false) {
				continue;
			}
			// find existing some value froms
			Set<OWLObjectSomeValuesFrom> existingSVFs = getSuperSVFs(ontology.getSubClassAxiomsForSubClass(cls));
			// get all direct super classes
			Set<OWLClassExpression> directSuperCE = reasoner.getSuperClassExpressions(cls, true);
			// filter for SVFs
			Set<OWLObjectSomeValuesFrom> directSuperSVFs = getSVFs(directSuperCE);
			
			// missing direct SVFs, calculate using a set difference
			Set<OWLObjectSomeValuesFrom> missingSVFs = Sets.difference(directSuperSVFs, existingSVFs);
			
			// add to result set
			if (missingSVFs.isEmpty() == false) {
				missingSVFs = new HashSet<OWLObjectSomeValuesFrom>(missingSVFs);
				if (filter != null) {
					missingSVFs = filterSVFs(filter, missingSVFs);
				}
				if (missingSVFs.isEmpty() == false) {
					newAxioms.put(cls, missingSVFs);
				}
			}
		}
		return newAxioms;
	}
	finally {
		reasoner.dispose();
	}
}
 
Example 16
Source File: ABoxUtils.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void createRandomClassAssertions(OWLOntology ont, int num, int maxAssertionsPerInstance) {
	Set<OWLClassAssertionAxiom> caasNew = new HashSet<OWLClassAssertionAxiom>();
	Vector<OWLClass> clist = new Vector<OWLClass>(ont.getClassesInSignature(Imports.INCLUDED));
	for (int i=0; i<num; i++) {
		OWLNamedIndividual ind = ont.getOWLOntologyManager().getOWLDataFactory().
		getOWLNamedIndividual(IRI.create("http://x.org/"+i));
		for (int j=0; j< Math.random() * maxAssertionsPerInstance; j++) {
			OWLClass c = clist.get((int)(Math.random() * clist.size()));
			caasNew.add(ont.getOWLOntologyManager().getOWLDataFactory().
					getOWLClassAssertionAxiom(c, ind));
		}
		
	}
	ont.getOWLOntologyManager().addAxioms(ont, caasNew);
}
 
Example 17
Source File: SelfReferenceInDefinition.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Collection<CheckWarning> check(OWLGraphWrapper graph, Collection<OWLObject> allOwlObjects) {
	OWLOntology ontology = graph.getSourceOntology();
	List<CheckWarning> violations = new ArrayList<CheckWarning>();
	for(OWLClass cls : ontology.getClassesInSignature()) {
		Set<OWLEquivalentClassesAxiom> equivalentClassesAxioms = ontology.getEquivalentClassesAxioms(cls);
		if (equivalentClassesAxioms != null && !equivalentClassesAxioms.isEmpty()) {
			for (OWLEquivalentClassesAxiom owlEquivalentClassesAxiom : equivalentClassesAxioms) {
				for (OWLClassExpression ex : owlEquivalentClassesAxiom.getClassExpressions()) {
					if (ex instanceof OWLClass)
						continue;
					Set<OWLClass> classesInSignature = ex.getClassesInSignature();
					if (classesInSignature != null && classesInSignature.contains(cls)) {
						String id = graph.getIdentifier(cls);
						String message = "Class "+id+" has a self reference in its logical definition: "+owlEquivalentClassesAxiom;
						CheckWarning warning = new CheckWarning("Self_Reference_In_Definition", message , isFatal(), cls.getIRI());
						violations.add(warning);
					}
				}
			}
		}
	}
	if (!violations.isEmpty()) {
		return violations;
	}
	return null;
}
 
Example 18
Source File: DiffUtil.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static Diff getDiff(Diff diff) throws OWLOntologyCreationException {
    OWLOntology ontology1 = diff.ontology1;
    OWLOntology ontology2 = diff.ontology2;
    Set<OWLAxiom> axioms1 = ontology1.getAxioms();
    Set<OWLAxiom> axioms2 = ontology2.getAxioms();

    Set<OWLAxiom> sharedDeclarations = new HashSet<>();
    if (diff.isCompareClassesInCommon) {
        Set<OWLClass> cs1 = ontology1.getClassesInSignature();
        Set<OWLClass> cs2 = ontology2.getClassesInSignature();
        Set<OWLClass> cs = Sets.intersection(cs1, cs2);
        axioms1 = new HashSet<>();
        axioms2 = new HashSet<>();
        for (OWLClass c : cs) {
            sharedDeclarations.add(ontology1.
                    getOWLOntologyManager().
                    getOWLDataFactory().
                    getOWLDeclarationAxiom(c));
            axioms1.addAll(ontology1.getAxioms(c));
            axioms1.addAll(ontology1.getAnnotationAssertionAxioms(c.getIRI()));
            axioms2.addAll(ontology2.getAxioms(c));
            axioms2.addAll(ontology2.getAnnotationAssertionAxioms(c.getIRI()));
        }
    }
    
    axioms1 = filter(axioms1, diff);
    axioms2 = filter(axioms2, diff);

    // map from compared axiom to full axiom
    Map<OWLAxiom, Set<OWLAxiom>> umap1 = diff.umap1;
    Map<OWLAxiom, Set<OWLAxiom>> umap2 = diff.umap2;

    axioms1 = unannotateAxioms(axioms1, umap1, 
            ontology1.getOWLOntologyManager().getOWLDataFactory(),
            diff.isCompareUnannotatedForm);
    axioms2 = unannotateAxioms(axioms2, umap2, 
            ontology2.getOWLOntologyManager().getOWLDataFactory(),
            diff.isCompareUnannotatedForm);

    Set<OWLAxiom> intersectionAxioms = Sets.intersection(axioms1, axioms2);
    Set<OWLAxiom> unionAxioms = Sets.union(axioms1, axioms2);
    Set<OWLAxiom> axioms1remaining = Sets.difference(axioms1, axioms2);
    Set<OWLAxiom> axioms2remaining = Sets.difference(axioms2, axioms1);
    //System.out.println("A2R="+axioms2remaining);
    
    
    if (diff.isCompareUnannotatedForm) {
        intersectionAxioms = 
                Sets.union(
                        diff.mapAxioms1(intersectionAxioms),
                        diff.mapAxioms2(intersectionAxioms));
        axioms1remaining = diff.mapAxioms1(axioms1remaining);
        axioms2remaining = diff.mapAxioms2(axioms2remaining);
    }
    
    if (diff.isAddSharedDeclarations) {
        axioms1remaining = Sets.union(axioms1remaining, sharedDeclarations);
        axioms2remaining = Sets.union(axioms2remaining, sharedDeclarations);
    }
 
    diff.intersectionOntology = diff.ontology(intersectionAxioms);
    diff.ontology1remaining = diff.ontology(axioms1remaining);
    diff.ontology2remaining = diff.ontology(axioms2remaining);
    diff.ontologyDiff = diff.ontology(Sets.union(axioms1remaining , axioms2remaining ));

    return diff;
}
 
Example 19
Source File: AssertInferenceTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void assertAllInferences(OWLGraphWrapper graph, String idsInputFile) {
		final OWLOntology ontology = graph.getSourceOntology();
		final OWLOntologyManager manager = ontology.getOWLOntologyManager();
		final OWLDataFactory factory = manager.getOWLDataFactory();
		
		Set<String> ids = loadIdsInputFile(idsInputFile);
		
		final OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
		final OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);
		try {
			logger.info("Start check all");
			// check all classes from the main ontology
			AllInferenceReport report = new AllInferenceReport();
			Set<OWLClass> classes = ontology.getClassesInSignature(Imports.EXCLUDED);
			int count = 0;
			int total = ids != null ? ids.size() : classes.size();
			int step = 100;
			for (final OWLClass owlClass : classes) {
				if (ids != null) {
					String id = graph.getIdentifier(owlClass);
					if (ids.contains(id) == false) {
						continue;
					}
				}
				count += 1;
				// get axioms for the current class
				Set<OWLClassAxiom> axioms = ontology.getAxioms(owlClass, Imports.EXCLUDED);
				
				handleAxioms(owlClass, axioms, ontology, manager, factory, reasoner, report);
//				handleAxioms2(owlClass, axioms, ontology, manager, factory, reasoner, report);
				if (count % step == 0) {
					logger.info("Current count "+count+" of "+total);
				}
			}
			PrintWriter writer = new PrintWriter(System.out);
			report.printReport(writer);
			writer.close();
		}
		finally {
			reasoner.dispose();
		}
	}
 
Example 20
Source File: OldSimpleOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Deprecated
public void setAttributesFromOntology(OWLOntology o) {
	fixedAttributeClasses = o.getClassesInSignature();
}