public void setOntology(OWLOntology ont) { this.ont = ont; List<Object> data = new ArrayList<>(); data.add(directImportsHeader); // @@TODO ordering for (OWLImportsDeclaration decl : ont.getImportsDeclarations()) { data.add(new OntologyImportItem(ont, decl, editorKit)); } data.add(indirectImportsHeader); // @@TODO ordering try { for (OWLOntology ontRef : editorKit.getOWLModelManager().getOWLOntologyManager().getImportsClosure(ont)) { if (!ontRef.equals(ont)) { for (OWLImportsDeclaration dec : ontRef.getImportsDeclarations()) { if (!data.contains(dec)) { data.add(new OntologyImportItem(ontRef, dec, editorKit)); } } } } } catch (UnknownOWLOntologyException e) { throw new OWLRuntimeException(e); } setListData(data.toArray()); }
public Map<String, OWLIndividual> returnSitesInOntology() { // map that contains the correspondance between the names of the sites // and their OWLIndividual representations. Map<String, OWLIndividual> returnMap = new HashMap<>(); List<OWLIndividual> returnList = new ArrayList<>(); OWLAnnotationProperty hasNameAnnotationProperty = OWLFactory.getOWLAnnotationProperty(":individualName", topIxPrefixManager); OWLClassExpression tempSiteClassExpression = OWLFactory.getOWLClass(":Site", topIxPrefixManager); for (OWLClassAssertionAxiom tempClassAssAx : topIxOnt.getClassAssertionAxioms(tempSiteClassExpression)) { returnList.add(tempClassAssAx.getIndividual()); Set<OWLAnnotationAssertionAxiom> tempSiteAnnotationsSet = topIxOnt.getAnnotationAssertionAxioms( tempClassAssAx.getIndividual().asOWLNamedIndividual().getIRI()); for (OWLAnnotationAssertionAxiom tempAnnotationAssertionAxiom : tempSiteAnnotationsSet) { if (tempAnnotationAssertionAxiom.getProperty().equals(hasNameAnnotationProperty)) { String tempString = tempAnnotationAssertionAxiom.getValue().toString(); logger.info(tempString); tempString = tempString.substring(tempString.indexOf('"') + 1, tempString.indexOf('^') - 1); logger.info(tempString); logger.info(tempClassAssAx.getIndividual().toString()); returnMap.put(tempString, tempClassAssAx.getIndividual()); } } } return returnMap; }
public void retrieveRoomsMap() { // this method retrieves the rooms to be insserted in the two rooms lists. // it deposits the retrieved data in a map where the key is the room name (String) and the value // is the corresponding entity IRI. // the above data structure will be used in passing the entity IRIs in the jess working memory // when constructing the facts // when the respective room name (String) is selected in the rooms list combo box. for (OWLSubClassOfAxiom scoAx : topIxOnt.getSubClassAxiomsForSuperClass( OWLFactory.getOWLClass( IRI.create( "http://www.semanticweb.org/ontologies/ptyxiaki_v0.6/2011/5/Ontology1308067064597.owl#Room")))) { String tmpS = scoAx.getSubClass().toString(); Set<OWLAnnotationAssertionAxiom> tmpAnnSet = topIxOnt.getAnnotationAssertionAxioms( IRI.create(tmpS.substring(tmpS.indexOf('<') + 1, tmpS.indexOf('>')))); for (OWLAnnotationAssertionAxiom aaAx : tmpAnnSet) { if (aaAx.getProperty() .toString() .equals( "<http://www.semanticweb.org/ontologies/ptyxiaki_v0.6/2011/5/Ontology1308067064597.owl#classID>")) { roomToIRI.put( aaAx.getValue().toString().substring(1, aaAx.getValue().toString().indexOf('^') - 1), tmpS.substring(tmpS.indexOf('<') + 1, tmpS.indexOf('>'))); } } } }
private OWLOntology findOntology(List<OWLOntology> loadedOntologies, IRI documentIRI) { for (OWLOntology o : loadedOntologies) { if (documentIRI.equals(o.getOntologyID().getOntologyIRI())) { return o; } } return null; }
public OWLOntology loadOWLOntology( OWLOntologyDocumentSource documentSource, final OWLOntologyCreationHandler mediator) throws OWLOntologyCreationException { // Attempt to parse the ontology by looping through the parsers. If the // ontology is parsed successfully then we break out and return the ontology. // I think that this is more reliable than selecting a parser based on a file extension // for example (perhaps the parser list could be ordered based on most likely parser, which // could be determined by file extension). Map<OWLParser, OWLParserException> exceptions = new LinkedHashMap<OWLParser, OWLParserException>(); // Call the super method to create the ontology - this is needed, because // we throw an exception if someone tries to create an ontology directly OWLOntology existingOntology = null; IRI iri = documentSource.getDocumentIRI(); if (getOWLOntologyManager().contains(iri)) { existingOntology = getOWLOntologyManager().getOntology(iri); } OWLOntologyID ontologyID = new OWLOntologyID(); OWLOntology ont = super.createOWLOntology(ontologyID, documentSource.getDocumentIRI(), mediator); // Now parse the input into the empty ontology that we created for (final OWLParser parser : getParsers()) { try { if (existingOntology == null && !ont.isEmpty()) { // Junk from a previous parse. We should clear the ont getOWLOntologyManager().removeOntology(ont); ont = super.createOWLOntology(ontologyID, documentSource.getDocumentIRI(), mediator); } OWLOntologyFormat format = parser.parse(documentSource, ont); mediator.setOntologyFormat(ont, format); return ont; } catch (IOException e) { // No hope of any parsers working? // First clean up getOWLOntologyManager().removeOntology(ont); throw new OWLOntologyCreationIOException(e); } catch (UnloadableImportException e) { // First clean up getOWLOntologyManager().removeOntology(ont); throw e; } catch (OWLParserException e) { // Record this attempts and continue trying to parse. exceptions.put(parser, e); } catch (RuntimeException e) { // Clean up and rethrow getOWLOntologyManager().removeOntology(ont); throw e; } } if (existingOntology == null) { getOWLOntologyManager().removeOntology(ont); } // We haven't found a parser that could parse the ontology properly. Throw an // exception whose message contains the stack traces from all of the parsers // that we have tried. throw new UnparsableOntologyException(documentSource.getDocumentIRI(), exceptions); }
private void runWithSeparateFiles() { if (owlFile == null) { throw new NullPointerException("You have to specify an ontology file!"); } OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology ontology = null; OBDADataFactory obdaDataFactory = OBDADataFactoryImpl.getInstance(); try { ontology = manager.loadOntologyFromOntologyDocument((new File(owlFile))); if (disableReasoning) { /* * when reasoning is disabled, we extract only the declaration assertions for the vocabulary */ ontology = extractDeclarations(manager, ontology); } Collection<Predicate> predicates = new ArrayList<>(); for (OWLClass owlClass : ontology.getClassesInSignature()) { Predicate predicate = obdaDataFactory.getClassPredicate(owlClass.getIRI().toString()); predicates.add(predicate); } for (OWLDataProperty owlDataProperty : ontology.getDataPropertiesInSignature()) { Predicate predicate = obdaDataFactory.getDataPropertyPredicate(owlDataProperty.getIRI().toString()); predicates.add(predicate); } for (OWLObjectProperty owlObjectProperty : ontology.getObjectPropertiesInSignature()) { Predicate predicate = obdaDataFactory.getObjectPropertyPredicate(owlObjectProperty.getIRI().toString()); predicates.add(predicate); } OBDAModel obdaModel = loadMappingFile(mappingFile); Ontology inputOntology = OWLAPI3TranslatorUtility.translate(ontology); obdaModel.declareAll(inputOntology.getVocabulary()); int numPredicates = predicates.size(); int i = 1; for (Predicate predicate : predicates) { System.err.println(String.format("Materializing %s (%d/%d)", predicate, i, numPredicates)); serializePredicate(ontology, inputOntology, obdaModel, predicate, outputFile, format); i++; } } catch (OWLOntologyCreationException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
public void visit(OWLOntology ontology) { checkOccurrence(ontology.getAnnotations()); for (AxiomType<?> t : AxiomType.AXIOM_TYPES) { for (OWLAxiom ax : ontology.getAxioms(t)) { checkOccurrence(ax.getAnnotations()); ax.accept(this); } } singleAppearance.clear(); }
public void retrieveSubObjectPropertyAxioms() { // this method is to perform a dual operation; it shall retrieve all the declarative object // properties categories' annotations, // thus filling the objPropCategories Set, while parallelly will, for each category entry // retrieve the object properties themselves // and adding their entries in the objPropEntries Set. Set<OWLSubObjectPropertyOfAxiom> tmpSet; OWLObjectPropertyExpression tempDeclarativePropertyClass = OWLFactory.getOWLObjectProperty(":DeclarativeProperty", topIxPrefixManager); tmpSet = topIxOnt.getObjectSubPropertyAxiomsForSuperProperty( tempDeclarativePropertyClass); // OWLFactory.getOWLObjectProperty(IRI.create("http://www.semanticweb.org/ontologies/ptyxiaki_v0.6/2011/5/Ontology1308067064597.owl#DeclarativeProperty"))); Set<OWLSubObjectPropertyOfAxiom> tmpSet2; Set<OWLAnnotationAssertionAxiom> tmpAnnSet1; Set<OWLAnnotationAssertionAxiom> tmpAnnSet2; // to become class variables. for (OWLSubObjectPropertyOfAxiom sopAx : tmpSet) { String tmpS = sopAx.getSubProperty().toString(); // categories... tmpAnnSet1 = topIxOnt.getAnnotationAssertionAxioms( IRI.create( tmpS.substring( 1, tmpS.indexOf('>')))); // this set only contains one annotation per entry for (OWLAnnotationAssertionAxiom aaAx : tmpAnnSet1) { String currentObjPropCatName = aaAx.getValue().toString().substring(1, aaAx.getValue().toString().indexOf('^') - 1); tmpSet2 = topIxOnt.getObjectSubPropertyAxiomsForSuperProperty( OWLFactory.getOWLObjectProperty(IRI.create(tmpS.substring(1, tmpS.length() - 1)))); for (OWLSubObjectPropertyOfAxiom sopAx2 : tmpSet2) { String tmpS2 = sopAx2.getSubProperty().toString(); tmpAnnSet2 = topIxOnt.getAnnotationAssertionAxioms( IRI.create(tmpS2.substring(1, tmpS2.length() - 1))); for (OWLAnnotationAssertionAxiom aaAx2 : tmpAnnSet2) { String currentObjPropEntryName = aaAx2 .getValue() .toString() .substring(1, aaAx2.getValue().toString().indexOf('^') - 1); propEntryNameToPropCatName.put(currentObjPropEntryName, currentObjPropCatName); propEntryNametoPropEntryIRI.put( currentObjPropEntryName, tmpS2.substring(1, tmpS2.length() - 1)); } } } } }
public OWLProfileReport checkOntology(OWLOntology ontology) { this.ont = ontology; OWL2DLProfile profile = new OWL2DLProfile(); OWLProfileReport report = profile.checkOntology(ontology); Set<OWLProfileViolation> violations = new HashSet<OWLProfileViolation>(); violations.addAll(report.getViolations()); OWLOntologyWalker ontologyWalker = new OWLOntologyWalker(ontology.getImportsClosure()); OWL2ELProfileObjectVisitor visitor = new OWL2ELProfileObjectVisitor(ontologyWalker, ontology.getOWLOntologyManager()); ontologyWalker.walkStructure(visitor); violations.addAll(visitor.getProfileViolations()); return new OWLProfileReport(this, violations); }
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; }
private void handleNotesOntologyChanged(List<OWLOntologyChange> changes) { try { OWLOntologyManager notesOntologyManager = notesOntology.getOWLOntologyManager(); if (notesOntologyManager.getOntologyFormat(notesOntology) instanceof BinaryOWLOntologyDocumentFormat) { OWLAPIProjectDocumentStore documentStore = OWLAPIProjectDocumentStore.getProjectDocumentStore(project.getProjectId()); List<OWLOntologyChangeData> infoList = new ArrayList<OWLOntologyChangeData>(); for (OWLOntologyChange change : changes) { OWLOntologyChangeRecord rec = change.getChangeRecord(); OWLOntologyChangeData info = rec.getData(); infoList.add(info); } BinaryOWLOntologyDocumentSerializer serializer = new BinaryOWLOntologyDocumentSerializer(); serializer.appendOntologyChanges( notesOntologyDocument, new OntologyChangeDataList(infoList, System.currentTimeMillis())); } else { // Swap it over notesOntologyManager.saveOntology(notesOntology, new BinaryOWLOntologyDocumentFormat()); } } catch (OWLOntologyStorageException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Serializes a batch of triples corresponding to a predicate into one file. Upper bound: * TRIPLE_LIMIT_PER_FILE. */ private static int serializeTripleBatch( OWLOntology ontology, QuestOWLIndividualAxiomIterator iterator, String filePrefix, String predicateName, int fileCount, String format) throws Exception { String fileName = filePrefix + fileCount + ".owl"; OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); // Main buffer OWLOntology aBox = manager.createOntology(IRI.create(predicateName)); // Add the signatures for (OWLDeclarationAxiom axiom : ontology.getAxioms(AxiomType.DECLARATION)) { manager.addAxiom(aBox, axiom); } int tripleCount = 0; while (iterator.hasNext() && (tripleCount < TRIPLE_LIMIT_PER_FILE)) { manager.addAxiom(aBox, iterator.next()); tripleCount++; } // BufferedOutputStream output = new BufferedOutputStream(new // FileOutputStream(outputPath.toFile())); // BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output, "UTF-8")); BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); manager.saveOntology(aBox, getOntologyFormat(format), new WriterDocumentTarget(writer)); return tripleCount; }
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); }
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; }
/** * Uses some heuristics to determine if the specified ontology and its imports closure is an OBO * ontology. * * @param ontology The ontology to check * @return <code>true</code> if the ontology is an OBO ontology (or could be an OBO ontology) * otherwise false. */ public boolean isOBOOntology(OWLOntology ontology) { if (isOBOFormat(ontology)) { return true; } for (AxiomType<?> axiomType : AxiomType.AXIOM_TYPES) { for (OWLAxiom ax : ontology.getAxioms(axiomType, true)) { if (!isOBOAxiom(ax)) { return false; } } } for (OWLAnnotationProperty property : ontology.getAnnotationPropertiesInSignature()) { if (isOBOEntity(property)) { return true; } } return false; }
@Test public void shouldHandleNullManager_For_GetBottomClassNode() { try { when(ontology.getOWLOntologyManager()).thenReturn(null); reasoner.getBottomClassNode(); } catch (NullPointerException e) { fail("NullPointerException"); } }
/** * Refills the section with rows. This method will be called by the system and should be directly * called. */ protected void refill(OWLOntology ontology) { added.clear(); for (OWLEquivalentObjectPropertiesAxiom ax : ontology.getEquivalentObjectPropertiesAxioms(getRootObject())) { addRow( new OWLEquivalentObjectPropertiesAxiomFrameSectionRow( getOWLEditorKit(), this, ontology, getRootObject(), ax)); added.add(ax); } }
public void actionPerformed(ActionEvent actionEvent) { List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(); int axiomsRemoved = 0; int axiomsAdded = 0; int numberOfDisjoints = 0; for (OWLOntology ont : getOWLModelManager().getActiveOntologies()) { // act on each ontology in turn CliqueFinder<OWLClassExpression> merger = new CliqueFinder<OWLClassExpression>(); Set<OWLDisjointClassesAxiom> oldAxioms = ont.getAxioms(AxiomType.DISJOINT_CLASSES); numberOfDisjoints += oldAxioms.size(); for (OWLDisjointClassesAxiom ax : oldAxioms) { merger.add(ax.getClassExpressions()); } for (Set<OWLClassExpression> newAxioms : merger.getResults()) { OWLDisjointClassesAxiom newAxiom = getOWLModelManager().getOWLDataFactory().getOWLDisjointClassesAxiom(newAxioms); if (oldAxioms.contains(newAxiom)) { oldAxioms.remove(newAxiom); } else { changes.add(new AddAxiom(ont, newAxiom)); axiomsAdded++; } } for (OWLDisjointClassesAxiom oldAxiom : oldAxioms) { changes.add(new RemoveAxiom(ont, oldAxiom)); axiomsRemoved++; } } getOWLModelManager().applyChanges(changes); logger.info( axiomsRemoved + " (of " + numberOfDisjoints + " total) disjoint class axioms replaced with " + axiomsAdded); }
/** * Gets OWL class by given name * * @param className * @return * @throws OWLReasonerException */ public OWLClass getNamedClass(String className) { if (classnameCache == null) { classnameCache = new HashMap<String, URI>(); for (OWLOntology ont : reasoner.getLoadedOntologies()) { for (OWLClass cls : ont.getReferencedClasses()) { classnameCache.put(cls.toString(), cls.getURI()); } } } OWLClass namedCls = null; URI uri = classnameCache.get(className); if (uri != null) { namedCls = manager.getOWLDataFactory().getOWLClass(uri); } else { System.err.println("Cannot find class: " + className + " in loaded ontologies"); } return namedCls; }
/** * Gets the property by given name, e.g. has_topping * * @param propName * @return */ public OWLObjectProperty getNamedObjectProperty(String propName) { if (objPropNameCache == null) { objPropNameCache = new HashMap<String, URI>(); for (OWLOntology ont : reasoner.getLoadedOntologies()) { for (OWLObjectProperty prop : ont.getReferencedObjectProperties()) { objPropNameCache.put(prop.toString(), prop.getURI()); } } } // search the HashMap OWLObjectProperty namedProp = null; URI uri = objPropNameCache.get(propName); if (uri != null) { namedProp = manager.getOWLDataFactory().getOWLObjectProperty(uri); } else { System.err.println("Cannot find object property: " + propName + " in loaded ontologies"); } return namedProp; }
@Before public void setUp() { when(ontology.getOWLOntologyManager()).thenReturn(manager); when(manager.getOWLDataFactory()).thenReturn(dataFactory); when(dataFactory.getOWLThing()).thenReturn(owlThing); when(dataFactory.getOWLNothing()).thenReturn(owlNothing); when(dataFactory.getOWLTopObjectProperty()).thenReturn(owlTopObjectProperty); when(dataFactory.getOWLBottomObjectProperty()).thenReturn(owlBottomObjectProperty); when(dataFactory.getOWLTopDataProperty()).thenReturn(owlTopDataProperty); when(dataFactory.getOWLBottomDataProperty()).thenReturn(owlBottomDataProperty); reasoner = new NoOpReasoner(ontology, dataFactory); }
// 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 Object visit(OWLSubPropertyChainOfAxiom axiom) { Set<OWLObjectPropertyRangeAxiom> rangeAxioms = getCurrentOntology().getAxioms(AxiomType.OBJECT_PROPERTY_RANGE, true); if (rangeAxioms.isEmpty()) { return false; } // Do we have a range restriction imposed on our super property? for (OWLObjectPropertyRangeAxiom rngAx : rangeAxioms) { if (getPropertyManager().isSubPropertyOf(axiom.getSuperProperty(), rngAx.getProperty())) { // Imposed range restriction! OWLClassExpression imposedRange = rngAx.getRange(); // There must be an axiom that imposes a range on the last prop in the chain List<OWLObjectPropertyExpression> chain = axiom.getPropertyChain(); if (!chain.isEmpty()) { OWLObjectPropertyExpression lastProperty = chain.get(chain.size() - 1); boolean rngPresent = false; for (OWLOntology ont : getCurrentOntology().getImportsClosure()) { for (OWLObjectPropertyRangeAxiom lastPropRngAx : ont.getObjectPropertyRangeAxioms(lastProperty)) { if (lastPropRngAx.getRange().equals(imposedRange)) { // We're o.k. rngPresent = true; break; } } } if (!rngPresent) { profileViolations.add( new LastPropertyInChainNotInImposedRange(getCurrentOntology(), axiom, rngAx)); } } } } return null; }
private void importFile( InputStream in, IRI documentIRI, File inDir, Authorizations authorizations) throws Exception { byte[] inFileData = IOUtils.toByteArray(in); Reader inFileReader = new InputStreamReader(new ByteArrayInputStream(inFileData)); OWLOntologyLoaderConfiguration config = new OWLOntologyLoaderConfiguration(); OWLOntologyManager m = createOwlOntologyManager(config, documentIRI); OWLOntologyDocumentSource documentSource = new ReaderDocumentSource(inFileReader, documentIRI); OWLOntology o = m.loadOntologyFromOntologyDocument(documentSource, config); storeOntologyFile(new ByteArrayInputStream(inFileData), documentIRI); for (OWLClass ontologyClass : o.getClassesInSignature()) { if (!o.isDeclared(ontologyClass, false)) { continue; } importOntologyClass(o, ontologyClass, inDir, authorizations); } for (OWLDataProperty dataTypeProperty : o.getDataPropertiesInSignature()) { if (!o.isDeclared(dataTypeProperty, false)) { continue; } importDataProperty(o, dataTypeProperty); } for (OWLObjectProperty objectProperty : o.getObjectPropertiesInSignature()) { if (!o.isDeclared(objectProperty, false)) { continue; } importObjectProperty(o, objectProperty); } for (OWLObjectProperty objectProperty : o.getObjectPropertiesInSignature()) { if (!o.isDeclared(objectProperty, false)) { continue; } importInverseOf(o, objectProperty); } }
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); } }
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 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 void actionPerformed(ActionEvent e) { OWLClass selClass = getOWLWorkspace().getOWLSelectionModel().getLastSelectedClass(); List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(); Set<OWLClassExpression> operands = new HashSet<OWLClassExpression>(); for (OWLOntology ont : getOWLModelManager().getActiveOntologies()) { for (OWLSubClassOfAxiom ax : ont.getSubClassAxiomsForSubClass(selClass)) { changes.add(new RemoveAxiom(ont, ax)); operands.add(ax.getSuperClass()); } } if (operands.isEmpty()) { return; } OWLDataFactory df = getOWLModelManager().getOWLDataFactory(); OWLClassExpression equCls; if (operands.size() == 1) { equCls = operands.iterator().next(); } else { equCls = df.getOWLObjectIntersectionOf(operands); } OWLAxiom ax = df.getOWLEquivalentClassesAxiom(CollectionFactory.createSet(selClass, equCls)); changes.add(new AddAxiom(getOWLModelManager().getActiveOntology(), ax)); getOWLModelManager().applyChanges(changes); }
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()); } }