Java Code Examples for org.semanticweb.owlapi.model.OWLOntology#getIndividualsInSignature()
The following examples show how to use
org.semanticweb.owlapi.model.OWLOntology#getIndividualsInSignature() .
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: Sim2CommandRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@CLIMethod("--remove-dangling-annotations") public void removeDangningAnnotations(Opts opts) throws Exception { OWLOntology ont = g.getSourceOntology(); int n = 0; Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>(); for (OWLNamedIndividual i : ont.getIndividualsInSignature()) { for (OWLClassAssertionAxiom ca : ont.getClassAssertionAxioms(i)) { OWLClassExpression cx = ca.getClassExpression(); if (cx instanceof OWLClass) { OWLClass c = (OWLClass) cx; String label = g.getLabel(c); if (label == null) rmAxioms.add(ca); else n++; } } } LOG.info("Removing " + rmAxioms.size() + " axioms"); ont.getOWLOntologyManager().removeAxioms(ont, rmAxioms); LOG.info("Remaining: " + n + " axioms"); }
Example 2
Source File: ABoxUtils.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static void randomizeClassAssertions(OWLOntology ont, int num) { Set<OWLClassAssertionAxiom> caas = new HashSet<OWLClassAssertionAxiom>(); Set<OWLClassAssertionAxiom> caasNew = new HashSet<OWLClassAssertionAxiom>(); Set<OWLNamedIndividual> inds = ont.getIndividualsInSignature(Imports.INCLUDED); OWLNamedIndividual[] indArr = (OWLNamedIndividual[]) inds.toArray(); for (OWLNamedIndividual ind : inds) { caas.addAll( ont.getClassAssertionAxioms(ind) ); } for (OWLClassAssertionAxiom caa : caas) { OWLIndividual randomIndividual = null; caasNew.add(ont.getOWLOntologyManager().getOWLDataFactory().getOWLClassAssertionAxiom(caa.getClassExpression(), randomIndividual)); } ont.getOWLOntologyManager().removeAxioms(ont, caas); ont.getOWLOntologyManager().addAxioms(ont, caasNew); }
Example 3
Source File: OWLGraphWrapperEdges.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Find all edges of the form [i INST c] in the graph closure. * (this includes both direct assertions, plus assertions to objects * that link to c via a chain of SubClassOf assertions) * <p> * the semantics are the same as inferred ClassAssertion axioms * * @param c owlClass * @return all individuals classified here via basic graph traversal */ public Set<OWLIndividual> getInstancesFromClosure(OWLClass c) { Set<OWLIndividual> ins = new HashSet<OWLIndividual>(); for (OWLOntology o : getAllOntologies()) { // iterate through all individuals; sequential scan may be slow for // large knowledge bases for (OWLIndividual in : o.getIndividualsInSignature()) { for (OWLGraphEdge e : getEdgesBetween(in, c)) { List<OWLQuantifiedProperty> qps = e.getQuantifiedPropertyList(); // check for edges of the form < i INSTANCE_OF c > // we exclude relation chaims, e.g. <i [INSTANCE_OF PART_OF-some] c> if (qps.size() == 1 && qps.get(0).isInstanceOf()) { ins.add(in); break; } } } } return ins; }
Example 4
Source File: OCUtils.java From quetzal with Eclipse Public License 2.0 | 6 votes |
public static OWLOntology createOWLThingTypeDeclForIndividuals(OWLOntology ont) throws OWLOntologyCreationException, IOException { OWLOntology ret = ont.getOntologyID()!=null && ont.getOntologyID().getOntologyIRI()!=null? ont.getOWLOntologyManager().createOntology(ont.getOntologyID().getOntologyIRI()): ont.getOWLOntologyManager().createOntology(); OWLDataFactory fac = ret.getOWLOntologyManager().getOWLDataFactory(); OWLClass owlThing = ret.getOWLOntologyManager().getOWLDataFactory().getOWLThing(); for (OWLNamedIndividual ind: ont.getIndividualsInSignature()) { OWLNamedIndividual ni = fac.getOWLNamedIndividual(ind.getIRI()); OWLAxiom ax = fac.getOWLClassAssertionAxiom(owlThing, ni); ret.getOWLOntologyManager().addAxiom(ret, ax); } return ret; }
Example 5
Source File: SimpleABoxToGAF.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Set<GeneAnnotation> generateAssociations(OWLOntology ont) { Set<GeneAnnotation> assocs = new HashSet<GeneAnnotation>(); for (OWLNamedIndividual i : ont.getIndividualsInSignature(Imports.INCLUDED)) { assocs.addAll(generateAssociations(i, ont)); } return assocs; }
Example 6
Source File: OWLGraphWrapperEdges.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Finds all edges between an instance i and he given class c. * <p> * this includes inferred class assertions, as well as chains such as * <p> * i has_part j, j inst_of k, k part_of some c * * @param c owlClass * @return all edges in closure between an instance and owlClass */ public Set<OWLGraphEdge> getInstanceChainsFromClosure(OWLClass c) { Set<OWLGraphEdge> edges = new OWLGraphEdgeSet(); for (OWLOntology o : getAllOntologies()) { // iterate through all individuals; sequential scan may be slow for // large knowledge bases for (OWLIndividual in : o.getIndividualsInSignature()) { edges.addAll(getEdgesBetween(in, c)); } } return edges; }
Example 7
Source File: SolrCommandRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Experimental method for trying out the loading of complex_annotation doc type * * @param opts * @throws Exception */ @CLIMethod("--solr-load-complex-annotations") public void experimentalLoadComplexAnnotationSolr(Opts opts) throws Exception { // Check to see if the global url has been set. String url = sortOutSolrURL(globalSolrURL); // Only proceed if our environment was well-defined. if( legoCatalogs == null || legoFiles == null || legoCatalogs.isEmpty() || legoFiles.isEmpty() ){ LOG.warn("Lego environment not well defined--skipping."); }else{ // Ready the environment for every pass. ParserWrapper pw = new ParserWrapper(); // Add all of the catalogs. for( File legoCatalog : legoCatalogs ){ pw.addIRIMapper(new CatalogXmlIRIMapper(legoCatalog)); } OWLOntologyManager manager = pw.getManager(); OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); // Actual loading--iterate over our list and load individually. for( File legoFile : legoFiles ){ String fname = legoFile.getName(); OWLReasoner currentReasoner = null; OWLOntology ontology = null; // TODO: Temp cover for missing group labels and IDs. //String agID = legoFile.getCanonicalPath(); String agLabel = StringUtils.removeEnd(fname, ".owl"); String agID = new String(agLabel); try { ontology = pw.parseOWL(IRI.create(legoFile)); currentReasoner = reasonerFactory.createReasoner(ontology); // Some sanity checks--some of the genereated ones are problematic. boolean consistent = currentReasoner.isConsistent(); if( consistent == false ){ LOG.info("Skip since inconsistent: " + fname); continue; } Set<OWLClass> unsatisfiable = currentReasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); // TODO - make configurable to allow fail fast if (unsatisfiable.isEmpty() == false) { LOG.info("Skip since unsatisfiable: " + fname); continue; } Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature(); Set<OWLAnnotation> modelAnnotations = ontology.getAnnotations(); OWLGraphWrapper currentGraph = new OWLGraphWrapper(ontology); try { LOG.info("Trying complex annotation load of: " + fname); ComplexAnnotationSolrDocumentLoader loader = new ComplexAnnotationSolrDocumentLoader(url, currentGraph, currentReasoner, individuals, modelAnnotations, agID, agLabel, fname); loader.load(); } catch (SolrServerException e) { LOG.info("Complex annotation load of " + fname + " at " + url + " failed!"); e.printStackTrace(); System.exit(1); } } finally { // Cleanup reasoner and ontology. if (currentReasoner != null) { currentReasoner.dispose(); } if (ontology != null) { manager.removeOntology(ontology); } } } } }
Example 8
Source File: SolrCommandRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Experimental method for trying out the loading of complex_annotation doc type. * Works with --read-ca-list <file>. * * @param opts * @throws Exception */ @CLIMethod("--solr-load-complex-exp") public void loadComplexAnnotationSolr(Opts opts) throws Exception { // Check to see if the global url has been set. String url = sortOutSolrURL(globalSolrURL); // Only proceed if our environment was well-defined. if( caFiles == null || caFiles.isEmpty() ){ LOG.warn("LEGO environment not well defined--will skip loading LEGO/CA."); }else{ // NOTE: These two lines are remainders from old code, and I'm not sure of their place in this world of ours. // I wish there was an arcitecture diagram somehwere... OWLOntologyManager manager = pw.getManager(); OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); // Actual loading--iterate over our list and load individually. for( String fname : caFiles ){ OWLReasoner currentReasoner = null; OWLOntology ontology = null; // TODO: Temp cover for missing group labels and IDs. //String agID = legoFile.getCanonicalPath(); String pretmp = StringUtils.removeEnd(fname, ".owl"); String[] bits = StringUtils.split(pretmp, "/"); String agID = bits[bits.length -1]; String agLabel = new String(StringUtils.replaceOnce(agID, ":", "_")); try { ontology = pw.parseOWL(IRI.create(fname)); currentReasoner = reasonerFactory.createReasoner(ontology); // Some sanity checks--some of the genereated ones are problematic. boolean consistent = currentReasoner.isConsistent(); if( consistent == false ){ LOG.info("Skip since inconsistent: " + fname); continue; } Set<OWLClass> unsatisfiable = currentReasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); if (unsatisfiable.isEmpty() == false) { LOG.info("Skip since unsatisfiable: " + fname); continue; } Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature(); Set<OWLAnnotation> modelAnnotations = ontology.getAnnotations(); OWLGraphWrapper currentGraph = new OWLGraphWrapper(ontology); try { LOG.info("Trying complex annotation load of: " + fname); ComplexAnnotationSolrDocumentLoader loader = new ComplexAnnotationSolrDocumentLoader(url, currentGraph, currentReasoner, individuals, modelAnnotations, agID, agLabel, fname); loader.load(); } catch (SolrServerException e) { LOG.info("Complex annotation load of " + fname + " at " + url + " failed!"); e.printStackTrace(); System.exit(1); } } finally { // Cleanup reasoner and ontology. if (currentReasoner != null) { currentReasoner.dispose(); } if (ontology != null) { manager.removeOntology(ontology); } } } } }