protected void importDataProperty(OWLOntology o, OWLDataProperty dataTypeProperty) { String propertyIRI = dataTypeProperty.getIRI().toString(); String propertyDisplayName = getLabel(o, dataTypeProperty); PropertyType propertyType = getPropertyType(o, dataTypeProperty); boolean userVisible = getUserVisible(o, dataTypeProperty); boolean searchable = getSearchable(o, dataTypeProperty); Boolean displayTime = getDisplayTime(o, dataTypeProperty); Double boost = getBoost(o, dataTypeProperty); if (propertyType == null) { throw new LumifyException("Could not get property type on data property " + propertyIRI); } for (OWLClassExpression domainClassExpr : dataTypeProperty.getDomains(o)) { OWLClass domainClass = domainClassExpr.asOWLClass(); String domainClassUri = domainClass.getIRI().toString(); Concept domainConcept = getConceptByIRI(domainClassUri); checkNotNull(domainConcept, "Could not find class with uri: " + domainClassUri); LOGGER.info("Adding data property " + propertyIRI + " to class " + domainConcept.getTitle()); ArrayList<PossibleValueType> possibleValues = getPossibleValues(o, dataTypeProperty); Collection<TextIndexHint> textIndexHints = getTextIndexHints(o, dataTypeProperty); addPropertyTo( domainConcept, propertyIRI, propertyDisplayName, propertyType, possibleValues, textIndexHints, userVisible, searchable, displayTime, boost); } }
@Test public void testBadDataproperty() throws Exception { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology ontology = manager.createOntology(IRI.create(NS)); OWLClassExpression restriction = factory.getOWLDataSomeValuesFrom( P, factory.getOWLDatatype(XSDVocabulary.DURATION.getIRI())); OWLAxiom axiom = factory.getOWLSubClassOfAxiom(A, restriction); manager.addAxiom(ontology, axiom); assertTrue(ontology.containsDataPropertyInSignature(P.getIRI())); StringDocumentTarget t = new StringDocumentTarget(); manager.saveOntology(ontology, new RDFXMLOntologyFormat(), t); manager.removeOntology(ontology); ontology = manager.loadOntologyFromOntologyDocument(new StringDocumentSource(t.toString())); assertTrue(ontology.containsDataPropertyInSignature(P.getIRI())); }
/** * Возвращает IRI типа данных, которое связано с этим свойством. Т.е. само ограничение * игнорируется. * * @param prpExp ограничение на свойство, которое определяет неименованный класс * @return * @deprecated */ public OWLDatatype getDataPrpopertyRestrictionRANGE(OWLClassExpression prpExp) { OWLDataProperty prp = (OWLDataProperty) ((OWLRestriction) prpExp).getProperty(); // для каждого свойства находим его RANGE - берем оттуда типы OWLDatatype datatype = OWLont.getOWLont().getDatatypeFromRange(prp.getIRI().toString()); return datatype; }
// TODO necessary method?? public String getDataRetriavablePropertyFragments() { for (OWLDataProperty prop : _ontology.getDataPropertiesInSignature()) { if (isKeywordSearchable(prop)) { return prop.getIRI().getRemainder().get(); } } return null; }
protected PropertyType getPropertyType(OWLOntology o, OWLDataProperty dataTypeProperty) { Set<OWLDataRange> ranges = dataTypeProperty.getRanges(o); if (ranges.size() == 0) { return null; } if (ranges.size() > 1) { throw new LumifyException( "Unexpected number of ranges on data property " + dataTypeProperty.getIRI().toString()); } for (OWLDataRange range : ranges) { if (range instanceof OWLDatatype) { OWLDatatype datatype = (OWLDatatype) range; return getPropertyType(datatype.getIRI().toString()); } } throw new LumifyException( "Could not find range on data property " + dataTypeProperty.getIRI().toString()); }
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(); } }
/** * 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 isDomainOfDataProperty(OWLClass clase, OWLDataProperty prop) { for (OWLClass owlClass1 : _reasoner.getDataPropertyDomains(prop, false).getFlattened()) { if (owlClass1.getIRI().equals(clase.getIRI())) { Log.d( TAG, "<idDomainOfDataProperty> " + clase.getIRI().getRemainder().get() + " dominio de " + prop.getIRI().getRemainder().get() + "? SI!"); return true; } } Log.d( TAG, "<isDomainOfDataProperty> " + clase.getIRI().getRemainder().get() + " dominio de " + prop.getIRI().getRemainder().get() + "? NO"); return false; }
@Override public void visit(OWLDataProperty property) { handleObject(property); property.getIRI().accept(this); }
@Override public void ontologiesChanged(List<? extends OWLOntologyChange> changes) throws OWLException { Map<OWLEntity, OWLEntity> renamings = new HashMap<OWLEntity, OWLEntity>(); Set<OWLEntity> removals = new HashSet<OWLEntity>(); for (int idx = 0; idx < changes.size(); idx++) { OWLOntologyChange change = changes.get(idx); if (change instanceof SetOntologyID) { IRI newiri = ((SetOntologyID) change).getNewOntologyID().getOntologyIRI(); if (newiri == null) continue; IRI oldiri = ((SetOntologyID) change).getOriginalOntologyID().getOntologyIRI(); log.debug("Ontology ID changed"); log.debug("Old ID: {}", oldiri); log.debug("New ID: {}", newiri); OBDAModel model = obdamodels.get(oldiri.toURI()); if (model == null) { setupNewOBDAModel(); model = getActiveOBDAModel(); } PrefixManager prefixManager = model.getPrefixManager(); prefixManager.addPrefix(PrefixManager.DEFAULT_PREFIX, newiri.toURI().toString()); obdamodels.remove(oldiri.toURI()); obdamodels.put(newiri.toURI(), model); continue; } else if (change instanceof AddAxiom) { OWLAxiom axiom = change.getAxiom(); if (axiom instanceof OWLDeclarationAxiom) { OWLEntity entity = ((OWLDeclarationAxiom) axiom).getEntity(); OBDAModel activeOBDAModel = getActiveOBDAModel(); if (entity instanceof OWLClass) { OWLClass oc = (OWLClass) entity; OClass c = ofac.createClass(oc.getIRI().toString()); activeOBDAModel.declareClass(c); } else if (entity instanceof OWLObjectProperty) { OWLObjectProperty or = (OWLObjectProperty) entity; ObjectPropertyExpression r = ofac.createObjectProperty(or.getIRI().toString()); activeOBDAModel.declareObjectProperty(r); } else if (entity instanceof OWLDataProperty) { OWLDataProperty op = (OWLDataProperty) entity; DataPropertyExpression p = ofac.createDataProperty(op.getIRI().toString()); activeOBDAModel.declareDataProperty(p); } } } else if (change instanceof RemoveAxiom) { OWLAxiom axiom = change.getAxiom(); if (axiom instanceof OWLDeclarationAxiom) { OWLEntity entity = ((OWLDeclarationAxiom) axiom).getEntity(); OBDAModel activeOBDAModel = getActiveOBDAModel(); if (entity instanceof OWLClass) { OWLClass oc = (OWLClass) entity; OClass c = ofac.createClass(oc.getIRI().toString()); activeOBDAModel.unDeclareClass(c); } else if (entity instanceof OWLObjectProperty) { OWLObjectProperty or = (OWLObjectProperty) entity; ObjectPropertyExpression r = ofac.createObjectProperty(or.getIRI().toString()); activeOBDAModel.unDeclareObjectProperty(r); } else if (entity instanceof OWLDataProperty) { OWLDataProperty op = (OWLDataProperty) entity; DataPropertyExpression p = ofac.createDataProperty(op.getIRI().toString()); activeOBDAModel.unDeclareDataProperty(p); } } } if (idx + 1 >= changes.size()) { continue; } if (change instanceof RemoveAxiom && changes.get(idx + 1) instanceof AddAxiom) { // Found the pattern of a renaming refactoring RemoveAxiom remove = (RemoveAxiom) change; AddAxiom add = (AddAxiom) changes.get(idx + 1); if (!(remove.getAxiom() instanceof OWLDeclarationAxiom && add.getAxiom() instanceof OWLDeclarationAxiom)) { continue; } // Found the patter we are looking for, a remove and add of // declaration axioms OWLEntity olde = ((OWLDeclarationAxiom) remove.getAxiom()).getEntity(); OWLEntity newe = ((OWLDeclarationAxiom) add.getAxiom()).getEntity(); renamings.put(olde, newe); } else if (change instanceof RemoveAxiom && ((RemoveAxiom) change).getAxiom() instanceof OWLDeclarationAxiom) { // Found the pattern of a deletion OWLDeclarationAxiom declaration = (OWLDeclarationAxiom) ((RemoveAxiom) change).getAxiom(); OWLEntity removedEntity = declaration.getEntity(); removals.add(removedEntity); } } // Applying the renaming to the OBDA model OBDAModel obdamodel = getActiveOBDAModel(); for (OWLEntity olde : renamings.keySet()) { OWLEntity removedEntity = olde; OWLEntity newEntity = renamings.get(removedEntity); // This set of changes appears to be a "renaming" operation, // hence we will modify the OBDA model accordingly Predicate removedPredicate = getPredicate(removedEntity); Predicate newPredicate = getPredicate(newEntity); obdamodel.renamePredicate(removedPredicate, newPredicate); } // Applying the deletions to the obda model for (OWLEntity removede : removals) { Predicate removedPredicate = getPredicate(removede); obdamodel.deletePredicate(removedPredicate); } }
@Override protected void writeDataPropertyComment(OWLDataProperty prop) { writeComment(prop.getIRI().toString()); }