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(); } }
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); } }