public void setUp() throws Exception { pm = new SimplePrefixManager(); OBDADataFactory pfac = OBDADataFactoryImpl.getInstance(); OBDADataFactory tfac = OBDADataFactoryImpl.getInstance(); query = tfac.getDatalogProgram(); LinkedList<Term> innerterms = new LinkedList<Term>(); innerterms.add(tfac.getVariable("id")); // IRIFactory fact = new IRIFactory(); List<Term> terms = new LinkedList<Term>(); terms.add( tfac.getFunction( pfac.getPredicate("http://obda.org/onto.owl#person-individual", 1), innerterms)); Function body = tfac.getFunction(pfac.getClassPredicate("http://obda.org/onto.owl#Person"), terms); terms = new LinkedList<Term>(); terms.add(tfac.getVariable("id")); Function head = tfac.getFunction(pfac.getPredicate("http://obda.org/predicates#q", 1), terms); rule1 = tfac.getCQIE(head, Collections.singletonList(body)); query.appendRule(rule1); }
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 static Predicate getPredicate(OWLEntity entity) { Predicate p = null; if (entity instanceof OWLClass) { /* We ignore TOP and BOTTOM (Thing and Nothing) */ if (((OWLClass) entity).isOWLThing() || ((OWLClass) entity).isOWLNothing()) { return null; } String uri = entity.getIRI().toString(); p = dfac.getClassPredicate(uri); } else if (entity instanceof OWLObjectProperty) { String uri = entity.getIRI().toString(); p = dfac.getObjectPropertyPredicate(uri); } else if (entity instanceof OWLDataProperty) { String uri = entity.getIRI().toString(); p = dfac.getDataPropertyPredicate(uri); } return p; }