protected Concept getParentConcept( OWLOntology o, OWLClass ontologyClass, File inDir, Authorizations authorizations) throws IOException { Set<OWLClassExpression> superClasses = ontologyClass.getSuperClasses(o); if (superClasses.size() == 0) { return getEntityConcept(); } else if (superClasses.size() == 1) { OWLClassExpression superClassExpr = superClasses.iterator().next(); OWLClass superClass = superClassExpr.asOWLClass(); String superClassUri = superClass.getIRI().toString(); Concept parent = getConceptByIRI(superClassUri); if (parent != null) { return parent; } parent = importOntologyClass(o, superClass, inDir, authorizations); if (parent == null) { throw new LumifyException("Could not find or create parent: " + superClass); } return parent; } else { throw new LumifyException( "Unhandled multiple super classes. Found " + superClasses.size() + ", expected 0 or 1."); } }
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); } }
public boolean contains(OWLClass cls) { if (cls.equals(owlOntologyManager.getOWLDataFactory().getOWLThing())) { return true; } else if (cls.equals(owlOntologyManager.getOWLDataFactory().getOWLNothing())) { return true; } return owlClass2ClassPointerMap.containsKey(cls); }
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(); } }
/** * filters the result of e.g. getSubclasses which is Set<Set<OWLClass>> To Set<OWLClass> * * @param original * @return * @throws OWLReasonerException */ protected Set<OWLClass> filterClasses(Set<Set<OWLClass>> original) throws OWLReasonerException { Set<OWLClass> result = new HashSet<OWLClass>(); for (Set<OWLClass> set : original) { for (Iterator<OWLClass> it = set.iterator(); it.hasNext(); ) { OWLClass cls = it.next(); if (cls.getURI().equals(OWLRDFVocabulary.OWL_NOTHING)) { it.remove(); } else { result.add(cls); } } } return result; }
private Iterable<Concept> getDomainsConcepts(OWLOntology o, OWLObjectProperty objectProperty) { String uri = objectProperty.getIRI().toString(); if (objectProperty.getDomains(o).size() == 0) { throw new LumifyException("Invalid number of domain properties on " + uri); } List<Concept> domains = new ArrayList<Concept>(); for (OWLClassExpression rangeClassExpr : objectProperty.getDomains(o)) { OWLClass rangeClass = rangeClassExpr.asOWLClass(); String rangeClassUri = rangeClass.getIRI().toString(); Concept ontologyClass = getConceptByIRI(rangeClassUri); checkNotNull(ontologyClass, "Could not find class with uri: " + rangeClassUri); domains.add(ontologyClass); } return domains; }
public void visit(OWLClass owlClass) { try { lastClassPointer = owlClass2ClassPointerMap.get(owlClass); // Cache if not in map if (lastClassPointer == null) { if (owlClass.getURI().equals(OWLRDFVocabulary.OWL_THING.getURI())) { lastClassPointer = faCTPlusPlus.getThing(); } else if (owlClass.getURI().equals(OWLRDFVocabulary.OWL_NOTHING.getURI())) { lastClassPointer = faCTPlusPlus.getNothing(); } else { lastClassPointer = faCTPlusPlus.getNamedClass(owlClass.getURI().toString()); } classPointerMap.put(lastClassPointer, owlClass); owlClass2ClassPointerMap.put(owlClass, lastClassPointer); } } catch (Exception e) { throw new FaCTPlusPlusRuntimeException(e); } }
/** * 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; }
protected Concept importOntologyClass( OWLOntology o, OWLClass ontologyClass, File inDir, Authorizations authorizations) throws IOException { String uri = ontologyClass.getIRI().toString(); if ("http://www.w3.org/2002/07/owl#Thing".equals(uri)) { return getEntityConcept(); } String label = getLabel(o, ontologyClass); checkNotNull(label, "label cannot be null or empty: " + uri); LOGGER.info("Importing ontology class " + uri + " (label: " + label + ")"); Concept parent = getParentConcept(o, ontologyClass, inDir, authorizations); Concept result = getOrCreateConcept(parent, uri, label); String color = getColor(o, ontologyClass); if (color != null) { result.setProperty( OntologyLumifyProperties.COLOR.getPropertyName(), color, OntologyRepository.VISIBILITY.getVisibility(), authorizations); } String displayType = getDisplayType(o, ontologyClass); if (displayType != null) { result.setProperty( OntologyLumifyProperties.DISPLAY_TYPE.getPropertyName(), displayType, OntologyRepository.VISIBILITY.getVisibility(), authorizations); } String titleFormula = getTitleFormula(o, ontologyClass); if (titleFormula != null) { result.setProperty( OntologyLumifyProperties.TITLE_FORMULA.getPropertyName(), titleFormula, OntologyRepository.VISIBILITY.getVisibility(), authorizations); } String subtitleFormula = getSubtitleFormula(o, ontologyClass); if (subtitleFormula != null) { result.setProperty( OntologyLumifyProperties.SUBTITLE_FORMULA.getPropertyName(), subtitleFormula, OntologyRepository.VISIBILITY.getVisibility(), authorizations); } String timeFormula = getTimeFormula(o, ontologyClass); if (timeFormula != null) { result.setProperty( OntologyLumifyProperties.TIME_FORMULA.getPropertyName(), timeFormula, OntologyRepository.VISIBILITY.getVisibility(), authorizations); } boolean userVisible = getUserVisible(o, ontologyClass); result.setProperty( OntologyLumifyProperties.USER_VISIBLE.getPropertyName(), userVisible, OntologyRepository.VISIBILITY.getVisibility(), authorizations); String glyphIconFileName = getGlyphIconFileName(o, ontologyClass); setIconProperty( result, inDir, glyphIconFileName, LumifyProperties.GLYPH_ICON.getPropertyName(), authorizations); String mapGlyphIconFileName = getMapGlyphIconFileName(o, ontologyClass); setIconProperty( result, inDir, mapGlyphIconFileName, LumifyProperties.MAP_GLYPH_ICON.getPropertyName(), authorizations); return result; }
/** * Gets the main temperature categories. This actually returns the direct named subclasses of the * Temperature class. * * @return A <code>Collection</code> of <code>OWLNamedClasses</code> */ public Collection getTemperatureCategories() throws OWLReasonerException { OWLClass temperatureCls = this.getNamedClass(PREFERENCES.getTemperatureClassName()); return temperatureCls.getSubClasses(ontology); }
/** * Gets the main base categories. This actually returns the direct named subclasses of the Bases * class. * * @return A <code>Collection</code> of <code>OWLNamedClasses</code> */ public Collection getCoffeeBasesCategories() throws OWLReasonerException { OWLClass basesCls = this.getNamedClass(PREFERENCES.getBaseClassName()); return basesCls.getSubClasses(ontology); }