@Override public KuabaRepository load(String url) throws RepositoryLoadException { IRI iri; File f = new File(url); if (!url.contains(":/")) { iri = IRI.create(f); } else iri = IRI.create(url); try { OWLOntology inst = manager.loadOntologyFromOntologyDocument(iri); if (inst == null) throw new RepositoryLoadException(url, "Invalid Location."); if (inst.getOntologyID().getOntologyIRI() == null) { // An anonymous Ontology was loaded, and they are not supported by the Kuaba Subsystem manager.removeOntology(inst); throw new RepositoryLoadException(url, "It is probably an incompatible or malformed file."); } KuabaRepository repo = new OwlApiKuabaRepository(inst, manager.getOWLDataFactory()); repoMap.put(inst.getOntologyID().getOntologyIRI(), repo); fileMap.put(repo, f); return repo; } catch (OWLOntologyAlreadyExistsException ex) { OWLOntologyID id = ex.getOntologyID(); // System.err.println("Ontologia "+id.getOntologyIRI().toString()+" já está // carregada, esta será retornada."); return repoMap.get(id.getOntologyIRI()); } catch (OWLOntologyCreationException ex) { throw new RepositoryLoadException(url, "Invalid Location."); // Logger.getLogger(OwlApiFileGateway.class.getName()).log(Level.SEVERE, null, ex); } }
public DLOntology_withMaps preprocessAndClausify(OWLOntology rootOntology) { OWLDataFactory factory = rootOntology.getOWLOntologyManager().getOWLDataFactory(); String ontologyIRI = rootOntology.getOntologyID().getDefaultDocumentIRI() == null ? "urn:hermit:kb" : rootOntology.getOntologyID().getDefaultDocumentIRI().toString(); Collection<OWLOntology> importClosure = rootOntology.getImportsClosure(); OWLAxioms_withMaps axioms = new OWLAxioms_withMaps(); OWLNormalization_withMaps normalization = new OWLNormalization_withMaps(factory, axioms, 0, m_datatypeManager); for (OWLOntology ontology : importClosure) normalization.processOntology(ontology); BuiltInPropertyManager_withMaps builtInPropertyManager = new BuiltInPropertyManager_withMaps(factory); builtInPropertyManager.axiomatizeBuiltInPropertiesAsNeeded(axioms); ObjectPropertyInclusionManager_withMaps objectPropertyInclusionManager = new ObjectPropertyInclusionManager_withMaps(axioms); // now object property inclusion manager added all non-simple properties to // axioms.m_complexObjectPropertyExpressions // now that we know which roles are non-simple, we can decide which negative object property // assertions have to be // expressed as concept assertions so that transitivity rewriting applies properly. objectPropertyInclusionManager.rewriteNegativeObjectPropertyAssertions( factory, axioms, normalization.getDefinitions().size()); objectPropertyInclusionManager.rewriteAxioms(factory, axioms, 0); OWLAxiomsExpressivity_withMaps axiomsExpressivity = new OWLAxiomsExpressivity_withMaps(axioms); DLOntology_withMaps dlOntology = clausify_withMaps(factory, ontologyIRI, axioms, axiomsExpressivity); return dlOntology; }
public OWLOntology getMergedOntology() { final IRI mergedOntologyIRI = IRI.create(queryOntology.getOntologyID().getDefaultDocumentIRI() + "-merged"); final OWLOntologyManager mm = controller.getOWLOntologyManager(); if (mm.contains(mergedOntologyIRI)) { return mm.getOntology(mergedOntologyIRI); } else { try { final OWLOntology mergedOntology = mm.createOntology(mergedOntologyIRI); mm.setOntologyFormat(mergedOntology, new RDFXMLOntologyFormat()); final String mergedOntologyFileName = mergedOntologyIRI .toURI() .toString() .substring(mergedOntologyIRI.toURI().toString().lastIndexOf("/") + 1) + ".owl"; mm.setOntologyDocumentIRI( mergedOntology, IRI.create( controller.getRuleSpec().getOutputDir().toURI() + "/" + mergedOntologyFileName)); mm.applyChange( new AddImport( mergedOntology, mm.getOWLDataFactory() .getOWLImportsDeclaration( queryOntology.getOntologyID().getDefaultDocumentIRI()))); return mergedOntology; } catch (OWLOntologyCreationException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } } }
public void writeOntologyHeader(OWLOntology ontology) { event = new RendererEvent(this, ontology); fireFrameRenderingPrepared(ONTOLOGY.toString()); write(ONTOLOGY.toString()); write(":"); writeSpace(); if (!ontology.isAnonymous()) { int indent = getIndent(); writeFullURI(ontology.getOntologyID().getOntologyIRI().toString()); writeNewLine(); pushTab(indent); if (ontology.getOntologyID().getVersionIRI() != null) { writeFullURI(ontology.getOntologyID().getVersionIRI().toString()); } popTab(); } fireFrameRenderingStarted(ONTOLOGY.toString()); writeNewLine(); for (OWLImportsDeclaration decl : ontology.getImportsDeclarations()) { fireSectionItemPrepared(IMPORT.toString()); write(IMPORT.toString()); write(":"); writeSpace(); fireSectionRenderingStarted(IMPORT.toString()); writeFullURI(decl.getURI().toString()); writeNewLine(); fireSectionRenderingFinished(IMPORT.toString()); } writeNewLine(); writeSection(ANNOTATIONS, ontology.getAnnotations(), ",", true); fireFrameRenderingFinished(ONTOLOGY.toString()); }
@Test public void testCreateAnonymousOntology() throws Exception { OWLOntologyManager manager = Factory.getManager(); OWLOntology ontology = manager.createOntology(); assertNotNull("ontology should not be null", ontology); assertNotNull("ontology id should not be null", ontology.getOntologyID()); assertNull(ontology.getOntologyID().getDefaultDocumentIRI()); assertNull(ontology.getOntologyID().getOntologyIRI()); assertNull(ontology.getOntologyID().getVersionIRI()); assertNotNull("iri should not be null", manager.getOntologyDocumentIRI(ontology)); }
@Test public void testCreateOntologyWithIRI() throws Exception { OWLOntologyManager manager = Factory.getManager(); IRI ontologyIRI = IRI("http://www.semanticweb.org/ontologies/ontology"); OWLOntology ontology = manager.createOntology(ontologyIRI); assertNotNull("ontology should not be null", ontology); assertNotNull("ontology id should not be null", ontology.getOntologyID()); assertEquals(ontologyIRI, ontology.getOntologyID().getDefaultDocumentIRI()); assertEquals(ontologyIRI, ontology.getOntologyID().getOntologyIRI()); assertNull(ontology.getOntologyID().getVersionIRI()); assertEquals(ontologyIRI, manager.getOntologyDocumentIRI(ontology)); }
/** * This method makes sure is used to setup a new/fresh OBDA model. This is done by replacing the * instance this.obdacontroller (the OBDA model) with a new object. On creation listeners for the * datasources, mappings and queries are setup so that changes in these trigger and ontology * change. * * <p>Additionally, this method configures all available OBDAOWLReasonerFacotry objects to have a * reference to the newly created OBDA model and to the global preference object. This is * necessary so that the factories are able to pass the OBDA model to the reasoner instances when * they are created. */ private void setupNewOBDAModel() { OBDAModel activeOBDAModel = getActiveOBDAModel(); if (activeOBDAModel != null) { return; } activeOBDAModel = dfac.getOBDAModel(); activeOBDAModel.addSourcesListener(dlistener); activeOBDAModel.addMappingsListener(mlistener); queryController.addListener(qlistener); OWLModelManager mmgr = owlEditorKit.getOWLWorkspace().getOWLModelManager(); Set<OWLOntology> ontologies = mmgr.getOntologies(); for (OWLOntology ontology : ontologies) { // Setup the entity declarations for (OWLClass c : ontology.getClassesInSignature()) { OClass pred = ofac.createClass(c.getIRI().toString()); activeOBDAModel.declareClass(pred); } for (OWLObjectProperty r : ontology.getObjectPropertiesInSignature()) { ObjectPropertyExpression pred = ofac.createObjectProperty(r.getIRI().toString()); activeOBDAModel.declareObjectProperty(pred); } for (OWLDataProperty p : ontology.getDataPropertiesInSignature()) { DataPropertyExpression pred = ofac.createDataProperty(p.getIRI().toString()); activeOBDAModel.declareDataProperty(pred); } } // Setup the prefixes PrefixOWLOntologyFormat prefixManager = PrefixUtilities.getPrefixOWLOntologyFormat(mmgr.getActiveOntology()); // addOBDACommonPrefixes(prefixManager); PrefixManagerWrapper prefixwrapper = new PrefixManagerWrapper(prefixManager); activeOBDAModel.setPrefixManager(prefixwrapper); OWLOntology activeOntology = mmgr.getActiveOntology(); String defaultPrefix = prefixManager.getDefaultPrefix(); if (defaultPrefix == null) { OWLOntologyID ontologyID = activeOntology.getOntologyID(); defaultPrefix = ontologyID.getOntologyIRI().toURI().toString(); } activeOBDAModel.getPrefixManager().addPrefix(PrefixManager.DEFAULT_PREFIX, defaultPrefix); // Add the model URI modelUri = activeOntology.getOntologyID().getOntologyIRI().toURI(); obdamodels.put(modelUri, activeOBDAModel); }
public boolean assertDataPropertyInstance(String ind, String prop, int value) { OWLDataProperty dataProp = OWLFactory.getOWLDataProperty( IRI.create(topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + prop)); OWLDataPropertyAssertionAxiom tmpAx = OWLFactory.getOWLDataPropertyAssertionAxiom( dataProp, OWLFactory.getOWLNamedIndividual( IRI.create(topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + ind)), OWLFactory.getOWLLiteral(value)); manager.addAxiom(topIxOnt, tmpAx); return true; }
//////////////////////////////// // INDIVIDUAL ASSERTION METHODS// //////////////////////////////// public boolean assertSiteIndividual(String siteNameHash, String siteNameAnnotation) { OWLClassExpression tmpCE = OWLFactory.getOWLClass(":Site", topIxPrefixManager); OWLIndividual tmpInd = OWLFactory.getOWLNamedIndividual(':' + siteNameHash, topIxPrefixManager); manager.addAxiom(topIxOnt, OWLFactory.getOWLClassAssertionAxiom(tmpCE, tmpInd)); manager.addAxiom( topIxOnt, OWLFactory.getOWLAnnotationAssertionAxiom( OWLFactory.getOWLAnnotationProperty( IRI.create( topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + "individualName")), IRI.create(topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + siteNameHash), OWLFactory.getOWLLiteral(siteNameAnnotation))); return true; }
public KuabaRepository createNewRepository(String url, File destination) { IRI iri; if (url == null) iri = IRI.generateDocumentIRI(); else iri = IRI.create(url); try { OWLOntology inst = manager.createOntology(iri); OWLImportsDeclaration imp = manager.getOWLDataFactory().getOWLImportsDeclaration(IRI.create(ONTOLOGY_URL)); AddImport addi = new AddImport(inst, imp); manager.applyChange(addi); KuabaRepository repo = new OwlApiKuabaRepository(inst, manager.getOWLDataFactory()); repoMap.put(inst.getOntologyID().getOntologyIRI(), repo); fileMap.put(repo, destination); TemplateGenerator.generateRootQuestion(repo); if (destination != null) this.save(repo); return repo; } catch (OWLOntologyCreationException ex) { Logger.getLogger(OwlApiFileGateway.class.getName()).log(Level.SEVERE, null, ex); } return null; }
@Test public void testCreateOntologyWithIRIAndVersionIRIWithMapper() throws Exception { OWLOntologyManager manager = Factory.getManager(); IRI ontologyIRI = IRI("http://www.semanticweb.org/ontologies/ontology"); IRI versionIRI = IRI("http://www.semanticweb.org/ontologies/ontology/version"); IRI documentIRI = IRI("file:documentIRI"); SimpleIRIMapper mapper = new SimpleIRIMapper(versionIRI, documentIRI); manager.addIRIMapper(mapper); OWLOntology ontology = manager.createOntology(new OWLOntologyID(ontologyIRI, versionIRI)); assertNotNull("ontology should not be null", ontology); assertNotNull("ontology id should not be null", ontology.getOntologyID()); assertEquals(versionIRI, ontology.getOntologyID().getDefaultDocumentIRI()); assertEquals(ontologyIRI, ontology.getOntologyID().getOntologyIRI()); assertEquals(versionIRI, ontology.getOntologyID().getVersionIRI()); assertEquals(documentIRI, manager.getOntologyDocumentIRI(ontology)); }
OntologyDataProperty( OWLOntologyManager manager, OWLOntology localContext, OntologyChangeManager changeManager) { this.manager = manager; this.localContext = localContext; this.changeManager = changeManager; prefix = localContext.getOntologyID().getOntologyIRI() + "#"; }
public void classifyOntology(OWLOntology ontology, OWLReasonerFactory factory) { ToStringRenderer.getInstance().setRenderer(new ManchesterOWLSyntaxOWLObjectRendererImpl()); OWLReasoner reasoner = factory.createNonBufferingReasoner(ontology); // reasoner.precomputeInferences(InferenceType.values()); long time = System.currentTimeMillis(); boolean isConsistent = reasoner.isConsistent(); int numOfUnsatClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size(); time = System.currentTimeMillis() - time; DLExpressivityChecker checker = new DLExpressivityChecker(Collections.singleton(ontology)); String e = checker.getDescriptionLogicName(); String name = ontology.getOntologyID().getOntologyIRI().getFragment(); logger.info( "ontology: " + name + ", reasoner: " + factory.getReasonerName() + ", expressivity: " + e + ", consistent: " + isConsistent + ", unsat classes: " + numOfUnsatClasses + ", time: " + time); }
@Deprecated protected boolean isInternal(OWLEntity ent) { return ent.getIRI() .toURI() .getPath() .equals(_ontology.getOntologyID().getOntologyIRI().get().toURI().getPath()); }
public static Map<EdamUri, Concept> load(String edamPath) throws OWLOntologyCreationException { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File(edamPath)); String prefix = ontology.getOntologyID().getOntologyIRI().get().toString(); return ontology .classesInSignature() .filter(c -> EdamUri.isEdamUri(c.getIRI().toString(), prefix)) .collect( Collectors.toMap( c -> new EdamUri(c.getIRI().toString(), prefix), c -> { Concept concept = new Concept(); EntitySearcher.getAnnotations(c, ontology) .forEachOrdered( a -> { if (a.getProperty().isLabel()) concept.setLabel(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty().isDeprecated()) concept.setObsolete(true); else if (a.getProperty() .toStringID() .equals( "http://www.geneontology.org/formats/oboInOwl#hasExactSynonym") && a.getValue().asLiteral().isPresent()) concept.addExactSynonym(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty() .toStringID() .equals( "http://www.geneontology.org/formats/oboInOwl#hasNarrowSynonym") && a.getValue().asLiteral().isPresent()) concept.addNarrowSynonym(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty() .toStringID() .equals( "http://www.geneontology.org/formats/oboInOwl#hasBroadSynonym") && a.getValue().asLiteral().isPresent()) concept.addBroadSynonym(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty() .toStringID() .equals( "http://www.geneontology.org/formats/oboInOwl#hasDefinition") && a.getValue().asLiteral().isPresent()) concept.setDefinition(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty().isComment() && a.getValue().asLiteral().isPresent()) concept.setComment(a.getValue().asLiteral().get().getLiteral()); }); if (concept.getLabel().isEmpty()) throw new IllegalStateException( String.format("Label of concept %s is empty", c.getIRI())); return concept; }, (u, v) -> { throw new IllegalStateException(String.format("Duplicate key %s", u)); }, LinkedHashMap::new)); }
private OWLOntology findOntology(List<OWLOntology> loadedOntologies, IRI documentIRI) { for (OWLOntology o : loadedOntologies) { if (documentIRI.equals(o.getOntologyID().getOntologyIRI())) { return o; } } return null; }
public boolean assertHouseIndividual(String houseEntryHash, String houseEntryAnnotation) { OWLClassExpression tempClassExpression = OWLFactory.getOWLClass(":House", topIxPrefixManager); OWLIndividual tempIndividual = OWLFactory.getOWLNamedIndividual(':' + houseEntryHash, topIxPrefixManager); manager.addAxiom( topIxOnt, OWLFactory.getOWLClassAssertionAxiom(tempClassExpression, tempIndividual)); manager.addAxiom( topIxOnt, OWLFactory.getOWLAnnotationAssertionAxiom( OWLFactory.getOWLAnnotationProperty( IRI.create( topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + "individualName")), IRI.create(topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + houseEntryHash), OWLFactory.getOWLLiteral(houseEntryAnnotation))); return true; }
/** * Initialization consists of: * * <ul> * <li>Setting aboxOntology, if not set - defaults to a new ontology using tbox.IRI as base. * Adds import to tbox. * <li>Setting queryOntology, if not set. Adds abox imports queryOntology declaration * </ul> * * @throws OWLOntologyCreationException */ private void init() throws OWLOntologyCreationException { // reasoner -> query -> abox -> tbox if (aboxOntology == null) { LOG.debug("Creating abox ontology. mgr = " + getOWLOntologyManager()); IRI ontologyIRI = IRI.create(tboxOntology.getOntologyID().getOntologyIRI() + "__abox"); aboxOntology = getOWLOntologyManager().getOntology(ontologyIRI); if (aboxOntology != null) { LOG.warn("Clearing existing abox ontology"); getOWLOntologyManager().removeOntology(aboxOntology); } aboxOntology = getOWLOntologyManager().createOntology(ontologyIRI); AddImport ai = new AddImport( aboxOntology, getOWLDataFactory() .getOWLImportsDeclaration(tboxOntology.getOntologyID().getOntologyIRI())); getOWLOntologyManager().applyChange(ai); } // add listener to abox to set modified flag OWLOntologyChangeBroadcastStrategy strategy = new SpecificOntologyChangeBroadcastStrategy(aboxOntology); OWLOntologyChangeListener listener = new OWLOntologyChangeListener() { @Override public void ontologiesChanged(List<? extends OWLOntologyChange> changes) throws OWLException { for (OWLOntologyChange owlOntologyChange : changes) { if (aboxOntology.equals(owlOntologyChange.getOntology())) { setAboxModified(true); } } } }; aboxOntology.getOWLOntologyManager().addOntologyChangeListener(listener, strategy); if (queryOntology == null) { // Imports: {q imports a, a imports t} LOG.debug("Creating query ontology"); IRI ontologyIRI = IRI.create(tboxOntology.getOntologyID().getOntologyIRI() + "__query"); queryOntology = getOWLOntologyManager().getOntology(ontologyIRI); if (queryOntology == null) { queryOntology = getOWLOntologyManager().createOntology(ontologyIRI); } AddImport ai = new AddImport( queryOntology, getOWLDataFactory() .getOWLImportsDeclaration(aboxOntology.getOntologyID().getOntologyIRI())); getOWLOntologyManager().applyChange(ai); } if (LOG.isDebugEnabled()) { LOG.debug(modelId + " manager(T) = " + tboxOntology.getOWLOntologyManager()); LOG.debug(modelId + " manager(A) = " + aboxOntology.getOWLOntologyManager()); LOG.debug(modelId + " manager(Q) = " + queryOntology.getOWLOntologyManager()); LOG.debug(modelId + " id(T) = " + tboxOntology.getOntologyID().getOntologyIRI()); LOG.debug(modelId + " id(A) = " + aboxOntology.getOntologyID().getOntologyIRI()); LOG.debug(modelId + " id(Q) = " + queryOntology.getOntologyID().getOntologyIRI()); } }
@Override protected Set<? extends OWLAxiom> createAxioms() { OWLOntology ont = getOWLOntology("Ont"); OWLClass cls = getFactory().getOWLClass(IRI.create(ont.getOntologyID().getOntologyIRI() + "/Office")); Set<OWLAxiom> axs = new HashSet<OWLAxiom>(); axs.add(getFactory().getOWLDeclarationAxiom(cls)); return axs; }
public void mergeOntologies() { List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(); for (OWLOntology ont : ontologies) { if (!ont.equals(targetOntology)) { // move the axioms for (OWLAxiom ax : ont.getAxioms()) { changes.add(new AddAxiom(targetOntology, ax)); } // move ontology annotations for (OWLAnnotation annot : ont.getAnnotations()) { changes.add(new AddOntologyAnnotation(targetOntology, annot)); } if (!targetOntology.getOntologyID().isAnonymous()) { // move ontology imports for (OWLImportsDeclaration decl : ont.getImportsDeclarations()) { if (ontologies.contains(ont.getOWLOntologyManager().getImportedOntology(decl))) { continue; } Optional<IRI> defaultDocumentIRI = targetOntology.getOntologyID().getDefaultDocumentIRI(); if (defaultDocumentIRI.isPresent() && !decl.getIRI().equals(defaultDocumentIRI.get())) { changes.add(new AddImport(targetOntology, decl)); } else { logger.warn( "Merge: ignoring import declaration for ontology " + targetOntology.getOntologyID() + " (would result in target ontology importing itself)."); } } } } } try { owlOntologyManager.applyChanges(changes); } catch (OWLOntologyChangeException e) { ErrorLogPanel.showErrorDialog(e); } }
// asserts a hasHouse property instance between a house and its corresponding // site public boolean assertHasHousePropertyInstance(String houseEntryHash, String siteNameHash) { OWLObjectProperty objProp = OWLFactory.getOWLObjectProperty( IRI.create(topIxOnt.getOntologyID().getOntologyIRI() + "#hasHouse")); OWLIndividual houseIndividual = OWLFactory.getOWLNamedIndividual(':' + houseEntryHash, topIxPrefixManager); OWLIndividual siteIndividual = OWLFactory.getOWLNamedIndividual(':' + siteNameHash, topIxPrefixManager); manager.addAxiom( topIxOnt, OWLFactory.getOWLObjectPropertyAssertionAxiom(objProp, siteIndividual, houseIndividual)); return true; }
public KuabaRepository copy(KuabaRepository kr, String url, File destination) { IRI iri; if (url == null) iri = IRI.generateDocumentIRI(); else iri = IRI.create(url); try { OWLOntology model = (OWLOntology) kr.getModel(); OWLOntology inst = manager.createOntology(iri); OntologyMigrator migrator = new OntologyMigrator(manager, model, inst); migrator.performMigration(); EntityFindAndReplaceURIRenamer renamer = new EntityFindAndReplaceURIRenamer( manager, inst.getSignature(false), Collections.singleton(inst), model.getOntologyID().getOntologyIRI().toString(), iri.toString()); if (renamer.hasErrors()) System.err.println("ERRO durante a cópia - rename"); manager.applyChanges(renamer.getChanges()); KuabaRepository repo = new OwlApiKuabaRepository(inst, manager.getOWLDataFactory()); repoMap.put(inst.getOntologyID().getOntologyIRI(), repo); fileMap.put(repo, destination); return repo; } catch (OWLOntologyCreationException ex) { System.err.println("ERRO em copy"); Logger.getLogger(OwlApiFileGateway.class.getName()).log(Level.SEVERE, null, ex); } return null; }
public void executeRuleSpec(final RuleSpec r) { this.controller.clearResults(); IRI id = queryOntology.getOntologyID().getDefaultDocumentIRI(); int i = 0; for (final Rule rule : r.getRuleList()) { if (rule.isActive()) { if (rule.getException() != null) { log.info("The query " + rule.getName() + " is not valid, execution cancelled."); controller.setStatus(rule.getException().getMessage()); return; } id = executeRule(rule, id); } } }
public boolean assertHasRoomPropertyInstance( String houseIndividualHash, String roomIndividualHash) { OWLObjectProperty tempOWLbjectProperty = OWLFactory.getOWLObjectProperty( IRI.create(topIxOnt.getOntologyID().getOntologyIRI() + "#hasRoom")); OWLIndividual houseIndividual = OWLFactory.getOWLNamedIndividual(':' + houseIndividualHash, topIxPrefixManager); OWLIndividual roomIndividual = OWLFactory.getOWLNamedIndividual(':' + roomIndividualHash, topIxPrefixManager); manager.addAxiom( topIxOnt, OWLFactory.getOWLObjectPropertyAssertionAxiom( tempOWLbjectProperty, houseIndividual, roomIndividual)); return true; }
public boolean assertRoomIndividual( String roomName, String roomIndividualHash, String roomIndividualAnnotation) { OWLClassExpression tempClassExpression = OWLFactory.getOWLClass( IRI.create( roomToIRI.get( roomName))); // retrieves the Room Class IRI fron the roomToIRI map, using // roomID as a key. OWLIndividual tempIndividual = OWLFactory.getOWLNamedIndividual(':' + roomIndividualHash, topIxPrefixManager); manager.addAxiom( topIxOnt, OWLFactory.getOWLClassAssertionAxiom(tempClassExpression, tempIndividual)); manager.addAxiom( topIxOnt, OWLFactory.getOWLAnnotationAssertionAxiom( OWLFactory.getOWLAnnotationProperty( IRI.create( topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + "individualName")), IRI.create( topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + roomIndividualHash), OWLFactory.getOWLLiteral(String.format(roomIndividualAnnotation)))); return true; }
public OBDAModel getActiveOBDAModel() { OWLOntology ontology = owlEditorKit.getOWLModelManager().getActiveOntology(); if (ontology != null) { OWLOntologyID ontologyID = ontology.getOntologyID(); IRI ontologyIRI = ontologyID.getOntologyIRI(); URI uri = null; if (ontologyIRI != null) { uri = ontologyIRI.toURI(); } else { uri = URI.create(ontologyID.toString()); } return obdamodels.get(uri); } return null; }
@Test public void testNamedOntologyToString() throws Exception { OWLOntologyManager man = Factory.getManager(); IRI ontIRI = IRI("http://owlapi.sourceforge.net/ont"); OWLOntology ont = man.createOntology(ontIRI); String s = ont.toString(); String expected = "Ontology(" + ont.getOntologyID().toString() + ") [Axioms: " + ont.getAxiomCount() + " Logical Axioms: " + ont.getLogicalAxiomCount() + "]"; assertEquals(expected, s); }
public TurtleRenderer( OWLOntology ontology, OWLOntologyManager manager, Writer writer, OWLOntologyFormat format) { super(ontology, manager, format); this.writer = new PrintWriter(writer); pending = new HashSet<RDFResourceNode>(); pm = new DefaultPrefixManager(); if (!ontology.isAnonymous()) { pm.setDefaultPrefix(ontology.getOntologyID().getOntologyIRI() + "#"); } if (format instanceof PrefixOWLOntologyFormat) { PrefixOWLOntologyFormat prefixFormat = (PrefixOWLOntologyFormat) format; for (String prefixName : prefixFormat.getPrefixNames()) { pm.setPrefix(prefixName, prefixFormat.getPrefix(prefixName)); } } base = ""; }
public HGDBOntology createOntologyInDatabase(IRI ontologyIRI) throws OWLOntologyCreationException { try { HGDBOntologyFormat format = new HGDBOntologyFormat(); IRI hgdbDocumentIRI = HGDBOntologyFormat.convertToHGDBDocumentIRI(ontologyIRI); OWLOntology o = super.createOntology(ontologyIRI); setOntologyFormat(o, format); setOntologyDocumentIRI(o, hgdbDocumentIRI); saveOntology(o, format, hgdbDocumentIRI); HGDBOntology result = ontologyRepository.getOntologyByDocumentIRI(hgdbDocumentIRI); result.setOWLOntologyManager(this); this.ontologiesByID.put(o.getOntologyID(), result); return result; } catch (Exception ex) { throw new RuntimeException(ex); } }
public void loadOntology() { try { /* * --apaitoymena vimata gia th dhmioyrgia mapped ontologias: * 1.dhmioyrgoyme ena toBeMappedIRI me skopo toy thn antistoixish me * to local File. 2.dhmioyrgoyme ena File me th dieythynsh ths * ontologias sto topiko apothikeytiko meso. 3.dhmioyrgoyme enan * SimpleIRIMapper kai ton prosthetoyme mesw toy manager. o * SimpleIRIMapper syndeei to toBeMappedIRI poy dwsame arxika, me * thn fysikh topothesia ths ontologias sto topiko apothikeytiko * meso. 4.dhmioyrgoyme ena ontologyIRI me akrivws thn idia arxiki * timh me to toBeMappedIRI to opoio tha einai to IRI ths ontologias * mas 5.dhmioyrgoyme thn ontologia mas xrhsimopoiwntas to * manager.loadOntology(ontologyIRI); */ String sep = File.separator; manager = OWLManager.createOWLOntologyManager(); toBeMappedIRI = IRI.create( "http://www.semanticweb.org/ontologies/ptyxiaki_v0.6/2011/5/Ontology1308067064597.owl"); // ontFile = new File("../src/ontologyresources/ptyxiaki_v0.8.owl"); ontFile = new File("src/ontologyresources/ptyxiaki_v0.8.owl"); // in case of alternative location on load time when the application is jar'ed! if (!ontFile.canRead()) { ontFile = new File("ontologyresources/ptyxiaki_v0.8.owl"); } manager.addIRIMapper(new SimpleIRIMapper(toBeMappedIRI, IRI.create(ontFile))); ontologyIRI = IRI.create( "http://www.semanticweb.org/ontologies/ptyxiaki_v0.6/2011/5/Ontology1308067064597.owl"); topIxOnt = manager.loadOntology(ontologyIRI); OWLFactory = manager.getOWLDataFactory(); topIxFormat = manager.getOntologyFormat(topIxOnt); topIxPrefixManager = new DefaultPrefixManager(topIxOnt.getOntologyID().getOntologyIRI().toString() + '#'); System.out.println("loaded ontology: " + this.topIxOnt); System.out.println("from: " + this.manager.getOntologyDocumentIRI(this.topIxOnt)); } catch (OWLException oex) { logger.info(oex.getMessage()); } }