public OWLOntologyID getOntologyId() { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); try { OWLOntology ontology = manager.loadOntologyFromOntologyDocument(IRI.create(location)); return ontology.getOntologyID(); } catch (Throwable t) { log.info("Exception caught trying to get ontology id for " + location, t); return null; } }
private static OWLAxiom getEntailment() { // Let's pick some class subsumption we want to explain OWLDataFactory factory = OWLManager.getOWLDataFactory(); OWLClass subsumee = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#LiquidFood")); OWLClass subsumer = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#Food")); return factory.getOWLSubClassOfAxiom(subsumee, subsumer); }
@Override public OWLOntologyManager getVolatileManager() { if (null == _volatileManager) _volatileManager = OWLManager.createConcurrentOWLOntologyManager(); return _volatileManager; }
/** * Creates an OWL ontology manager that is configured with standard parsers, * storeres etc. * * @return The new manager. */ public static OWLOntologyManager createOWLOntologyManager() { return createOWLOntologyManager(getOWLDataFactory()); }
public RLOntology(String directory, String ontologyName, boolean flag) { removeBottomRule = flag; manager = OWLManager.createOWLOntologyManager(); factory = manager.getOWLDataFactory(); inputOntology = manager.loadOntologyFromOntologyDocument(new File(documentIRI = directory + "/" + ontologyName)); ontologyIRI = inputOntology.getOntologyID().getOntologyIRI().toString(); manager.clearIRIMappers(); TOP = factory.getOWLClass(IRI.create(ontologyIRI + "#TOP")); outputOntology = manager.createOntology(IRI.create(rlOntologyIRI)); manager.setOntologyDocumentIRI(outputOntology, IRI.create(rlDocumentIRI)); restOntology = manager.createOntology(); } catch (OWLOntologyCreationException e) { e.printStackTrace();
/** * @param args * @throws OWLOntologyCreationException * @throws MalformedURLException */ public static void main(String[] args) throws Exception { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology ontology = manager.createOntology(IRI.create("tutorial")); OWLClass A = manager.getOWLDataFactory().getOWLClass(IRI.create("http://tutorial#A")); OWLClass B = manager.getOWLDataFactory().getOWLClass(IRI.create("http://tutorial#B")); OWLAxiom a = manager.getOWLDataFactory().getOWLSubClassOfAxiom(A, B); manager.addAxiom(ontology, manager.getOWLDataFactory().getOWLDeclarationAxiom(A)); manager.addAxiom(ontology, a); ontology = manager.loadOntologyFromOntologyDocument(new File("/home/me/work/datasets/smallis/experiment1/monarch_module_exp1.owl")); OWLlinkHTTPXMLReasonerFactory factory = new OWLlinkHTTPXMLReasonerFactory(); URL url = new URL("http://localhost:8088");//Configure the server end-point OWLlinkReasonerConfiguration config = new OWLlinkReasonerConfiguration(url); OWLlinkReasoner reasoner = factory.createReasoner(ontology, config); NodeSet<OWLClass> classes = reasoner.getSubClasses(manager.getOWLDataFactory().getOWLThing(), true); System.out.println(classes.getFlattened()); }
public static void saveAxioms(Set<OWLAxiom> axioms, String outputFile, String outFormat) throws OWLOntologyStorageException, OWLOntologyCreationException { OWLOntologyManager man = OWLManager.createOWLOntologyManager(); OWLOntology resultOntology = man.createOntology(); man.addAxioms(resultOntology, axioms); OWLDocumentFormat formatter; switch (outFormat) { case "OWLXML": formatter = new OWLXMLDocumentFormat(); break; case "OWLFUNCTIONAL": formatter = new FunctionalSyntaxDocumentFormat(); break; default: formatter = new OWLXMLDocumentFormat(); break; } resultOntology.getOWLOntologyManager().saveOntology(resultOntology, formatter, IRI.create(new File(outputFile))); }
/** * Loads the ontology into memory and initializes the OWL reasoner needed to * navigate the ontology. */ public void loadOntology() throws OntologyLoadingErrorException { this.ontManager = OWLManager.createOWLOntologyManager(); try { ontologyWithDOGONT = this.ontManager.loadOntologyFromOntologyDocument(getClass().getResourceAsStream(DOGONT_ONTOLOGY_BASE_PATH)); this.ontManager.loadOntologyFromOntologyDocument(getClass().getResourceAsStream(DOGONT_ONTOLOGY_UNIDA_SPECIFIC_PATH)); OWLOntologyMerger owlOntologyMerger = new OWLOntologyMerger(this.ontManager); this.ontology = owlOntologyMerger.createMergedOntology(this.ontManager, IRI.create(DOGONT_ONTOLOGY_BASE_URI)); IRI funcURI = IRI.create(ontologyWithDOGONT.getOntologyID().getOntologyIRI().toString() + "#Functionality"); FUNCTIONALITY = this.ontManager.getOWLDataFactory().getOWLClass(funcURI); IRI notifURI = IRI.create(ontologyWithDOGONT.getOntologyID().getOntologyIRI().toString() + "#NotificationFunctionality"); NOTIFICATION_FUNCTIONALITY = this.ontManager.getOWLDataFactory().getOWLClass(notifURI); IRI controlURI = IRI.create(ontologyWithDOGONT.getOntologyID().getOntologyIRI().toString() + "#ControlFunctionality"); CONTROL_FUNCTIONALITY = this.ontManager.getOWLDataFactory().getOWLClass(controlURI); } catch (OWLOntologyChangeException | OWLOntologyCreationException ex) { throw new OntologyLoadingErrorException(ex.getLocalizedMessage()); } }
public static void main (String[] args) throws Exception { OWLOntologyManager man = OWLManager.createOWLOntologyManager(); OWLDataFactory factory = man.getOWLDataFactory(); logger.info("Loading ontology..."); OWLOntology ontology = man.loadOntologyFromOntologyDocument(new File(dumpFilePath)); logger.info("Done"); OWLAxiomCBDGenerator cbdGenartor = new OWLAxiomCBDGenerator(ontology); cbdGenartor.setFetchCompleteRelatedTBox(true); OWLOntology cbdOnt = man.createOntology(); for (String uri : exampleUris) { logger.info("Creating cbd for " + uri + "..."); Set<OWLAxiom> cbdAxioms = cbdGenartor.getCBD(factory.getOWLNamedIndividual(IRI.create(uri)), cbdDepth); logger.info(" Done. Adding {} axioms to main CBD dataset...", cbdAxioms.size()); man.addAxioms(cbdOnt, cbdAxioms); logger.info(" Also done"); } man.saveOntology(cbdOnt, new RDFXMLDocumentFormat(), new FileOutputStream(new File(cbdFilePath))); } }
public static OWLOntology load(File... inputFiles) throws OWLOntologyCreationException { OWLOntologyManager manager= OWLManager.createOWLOntologyManager(); OWLOntology ont = manager.createOntology(); for (File f:inputFiles) { manager= OWLManager.createOWLOntologyManager(); manager.setSilentMissingImportsHandling(false); IRI documentIRI = IRI.create(f); OWLOntology ontology = manager.loadOntologyFromOntologyDocument(documentIRI); ont.getOWLOntologyManager().addAxioms(ont, ontology.getAxioms()); } return ont; }
public OWLOntology getGeneratedOntology(boolean withConfidenceAsAnnotations){ OWLOntology ontology = null; try { OWLOntologyManager man = OWLManager.createOWLOntologyManager(); OWLDataFactory factory = man.getOWLDataFactory(); OWLAnnotationProperty confAnnoProp = factory.getOWLAnnotationProperty(IRI.create(EnrichmentVocabulary.NS + "confidence")); Set<OWLAxiom> axioms = new HashSet<>(); for (EvaluatedAxiom evAx : learnedEvaluatedAxioms) { OWLAxiom ax = evAx.getAxiom(); if (withConfidenceAsAnnotations) { ax = ax.getAnnotatedAxiom(Collections.singleton(factory.getOWLAnnotation(confAnnoProp, factory.getOWLLiteral(evAx.getScore().getAccuracy())))); } axioms.add(ax); } ontology = man.createOntology(axioms); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } return ontology; }
public OntologyLoader(String ontologyName, File ontologyFile) throws OWLOntologyCreationException { this.ontologyFile = ontologyFile; this.manager = OWLManager.createOWLOntologyManager(); this.factory = manager.getOWLDataFactory(); this.ontologyName = ontologyName; this.ontology = manager.loadOntologyFromOntologyDocument(ontologyFile); this.ontologyIRI = ontology.getOntologyID().getOntologyIRI().toString(); }
if (willRedirectTotheWrongPlace(catalogManager, importedOntologyDocumentIRI, physicalLocation)) { OWLOntology activeOntology = editorKit.getModelManager().getActiveOntology(); addImportMapping(activeOntology, importedOntologyDocumentIRI, IRI.create(physicalLocation)); OWLImportsDeclaration decl = man.getOWLDataFactory().getOWLImportsDeclaration(importedOntologyDocumentIRI); if (!man.contains(importParameters.getOntologyID())) { try { OWLOntologyManager loadingManager = OWLManager.createConcurrentOWLOntologyManager(); loadingManager.getIRIMappers() .add(man.getIRIMappers()); ProgressDialogOntologyLoaderListener listener = new ProgressDialogOntologyLoaderListener(dlg, logger); loadingManager.addOntologyLoaderListener(listener); loadingManager.loadOntologyFromOntologyDocument( new IRIDocumentSource(IRI.create(physicalLocation)), new OWLOntologyLoaderConfiguration().setMissingImportHandlingStrategy(MissingImportHandlingStrategy.SILENT)); loadingManager.removeOntologyLoaderListener(listener); for(OWLOntology importedOntology : loadingManager.getOntologies()) { IRI ontologyDocumentIRI = loadingManager.getOntologyDocumentIRI(importedOntology); if (!man.contains(importedOntology.getOntologyID())) { logger.info("Copying imported ontology: {}", ontologyDocumentIRI); man.copyOntology(importedOntology, OntologyCopy.MOVE); logger.error("There was a problem loading the ontology from {}. Error: {}", importedOntologyDocumentIRI, e.getMessage(), e); JOptionPane.showMessageDialog(editorKit.getOWLWorkspace(), "An error occurred whilst the ontology at " + importedOntologyDocumentIRI + " was being loaded.", "Error loading ontology", JOptionPane.ERROR_MESSAGE);
public static String toRDFXMLSyntax(OWLAxiom axiom) { ByteArrayOutputStream out = new ByteArrayOutputStream(); String str = ""; try { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology ontology = manager.createOntology(IRI.create("http://example.com/")); manager.applyChange(new AddAxiom(ontology, axiom)); manager.saveOntology(ontology, new RDFXMLDocumentFormat(), out); str = new String(out.toByteArray(), "UTF-8"); } catch (OWLOntologyCreationException | OWLOntologyStorageException | UnsupportedEncodingException e) { e.printStackTrace(); } return str; }
public static void main(String[] args) throws Exception { String solrServerURL = "http://solr.aksw.org/en_dbpedia_resources/"; String searchField = "comment"; OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new File("src/test/resources/org/dllearner/algorithms/isle/dbpedia_3.9.owl")); SolrSyntacticIndex index = new SolrSyntacticIndex(ontology, solrServerURL, searchField); index.loadCache(new File("entity_frequencies.obj")); OWLDataFactory df = new OWLDataFactoryImpl(); long n = index.getNumberOfDocumentsFor(df.getOWLClass(IRI.create("http://dbpedia.org/ontology/Comics"))); System.out.println(n); n = index.getNumberOfDocumentsFor(df.getOWLClass(IRI.create("http://dbpedia.org/ontology/Comics")), df.getOWLObjectProperty(IRI.create("http://dbpedia.org/ontology/largestCity"))); System.out.println(n); }
public static void main(String[] args) { try { UnparsableOntologyException.setIncludeStackTraceInMessage(true); OWLOntologyManager man = OWLManager.createOWLOntologyManager(); long t0 = System.currentTimeMillis(); // OWLOntology ont = man.loadOntologyFromOntologyDocument(URI.create("file:/Users/matthewhorridge/ontologies/Thesaurus.08.02d.owl.zip")); // OWLOntology ont = man.loadOntologyFromOntologyDocument(URI.create("file:/Users/matthewhorridge/Desktop/SNOMED-20090731.owl.zip")); OWLOntology ont = man.loadOntologyFromOntologyDocument(IRI.create("http://www.loa-cnr.it/ontologies/DUL.owl")); long t1 = System.currentTimeMillis(); dumpMemStats(); System.out.println("TIME: " + (t1 - t0)); System.gc(); System.gc(); System.gc(); dumpMemStats(); // for(OWLAnnotationAssertionAxiom ax : ont.getAxioms(AxiomType.ANNOTATION_ASSERTION)) { // System.out.println(ax); // } } catch (OWLOntologyCreationException e) { e.printStackTrace(); } }
@Override public void run(Reasoner hermit,StatusOutput status,PrintWriter output,boolean ignoreOntologyPrefixes) { status.log(2,"Checking satisfiability of '"+conceptName+"'"); Prefixes prefixes=hermit.getPrefixes(); String conceptUri=prefixes.canBeExpanded(conceptName) ? prefixes.expandAbbreviatedIRI(conceptName) : conceptName; if (conceptUri.startsWith("<") && conceptUri.endsWith(">")) conceptUri=conceptUri.substring(1,conceptUri.length()-1); OWLClass owlClass=OWLManager.createOWLOntologyManager().getOWLDataFactory().getOWLClass(IRI.create(conceptUri)); if (!hermit.isDefined(owlClass)) { status.log(0,"Warning: class '"+conceptUri+"' was not declared in the ontology."); } boolean result=hermit.isSatisfiable(owlClass); output.println(conceptName+(result ? " is satisfiable." : " is not satisfiable.")); output.flush(); } }
public NormalizedRuleClausifier(Set<OWLObjectProperty> objectPropertiesOccurringInOWLAxioms,Collection<DescriptionGraph> descriptionGraphs,DataRangeConverter dataRangeConverter,Set<DLClause> dlClauses) { m_objectPropertiesOccurringInOWLAxioms=objectPropertiesOccurringInOWLAxioms; m_dataRangeConverter=dataRangeConverter; m_dlClauses=dlClauses; m_headAtoms=new ArrayList<Atom>(); m_bodyAtoms=new ArrayList<Atom>(); m_abstractVariables=new HashSet<Variable>(); OWLDataFactory factory=OWLManager.createOWLOntologyManager().getOWLDataFactory(); for (DescriptionGraph descriptionGraph : descriptionGraphs) for (int i=0;i<descriptionGraph.getNumberOfEdges();i++) m_graphObjectProperties.add(factory.getOWLObjectProperty(IRI.create(descriptionGraph.getEdge(i).getAtomicRole().getIRI()))); for (OWLObjectProperty objectProperty : m_graphObjectProperties) if (objectPropertiesOccurringInOWLAxioms.contains(objectProperty)) throw new IllegalArgumentException("Mixing graph and non-graph object properties is not supported."); } public void processRules(Collection<OWLAxioms.DisjunctiveRule> rules) {
@Override protected OWLOntology getOntologyAsOWLOntology(OWLOntologyID ontologyId, boolean merge, org.semanticweb.owlapi.model.IRI universalPrefix) { OWLOntology o = super.getOntologyAsOWLOntology(ontologyId, merge, universalPrefix); switch (getConnectivityPolicy()) { case LOOSE: break; case TIGHT: String s = getID(); s = s.substring(0, s.indexOf(SUFFIX)); // strip "custom" s += SpaceType.CORE.getIRISuffix(); // concatenate "core" org.semanticweb.owlapi.model.IRI target = org.semanticweb.owlapi.model.IRI.create(universalPrefix + s); o.getOWLOntologyManager().applyChange( new AddImport(o, OWLManager.getOWLDataFactory().getOWLImportsDeclaration(target))); break; default: break; } return o; }
public OWLXMLRenderer() { try { OWLOntology ont = OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://dl-learner.org/ontology/")); sw = new StringWriter(); OWLXMLWriter oxw = new OWLXMLWriter(sw, ont); delegate = new OWLXMLObjectRenderer(oxw); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } }