public SimpleSchemaGenerator(OWLOntology ontology) { super(OwlApiJenaUtils.getModel(ontology)); }
@Override public OWLOntology createOWLOntology(OWLOntologyManager manager) { return OwlApiJenaUtils.getOWLOntology(model); }
/** * Computes the least common subsumer (LCS) of the given entities <code>e1</code> and <code>e2</code> if exists, * otherwise <code>null</code> * * @param reasoner the reasoner used to compute the direct parents * @param n1 first entity * @param n2 second entity * @param entityType the entity type * @param <E> the entity type * @return the LCS if exists */ public static <E extends OWLEntity> Node getLeastCommonSubsumer(AbstractReasonerComponent reasoner, Node n1, Node n2, EntityType<E> entityType) { // trivial case if(n1.equals(n2)) { return n1; } E lcs = getLeastCommonSubsumer(reasoner, OwlApiJenaUtils.asOWLEntity(n1, entityType), OwlApiJenaUtils.asOWLEntity(n2, entityType)); if(lcs != null) { return OwlApiJenaUtils.asNode(lcs); } return null; }
/** * Converts a JENA API literal into an OWL API literal. * @param lit the JENA API literal * @return the OWL API literal */ public static OWLLiteral getOWLLiteral(LiteralLabel lit){ return getOWLLiteral(new LiteralImpl(NodeFactory.createLiteral(lit), null)); }
/** * Add the axioms to the running knowledge base. * @param axioms the axioms */ protected void addToKnowledgebase(Set<OWLAxiom> axioms) { Set<Statement> statements = OwlApiJenaUtils.asStatements(axioms); model.add(new ArrayList<>(statements)); }
private void runBatched() { ParameterizedSparqlString template = strictOWLMode ? CLASS_OVERLAP_BATCH_QUERY_STRICT_OWL : CLASS_OVERLAP_BATCH_QUERY; template.setIri("cls", entityToDescribe.toStringID()); ResultSet rs = executeSelectQuery(template.toString()); while (rs.hasNext()) { QuerySolution qs = rs.next(); RDFNode cls = qs.get("cls_other"); if (!cls.isAnon()) { OWLClass sup = OwlApiJenaUtils.asOWLEntity(cls.asNode(), EntityType.CLASS); int overlap = qs.get("cnt").asLiteral().getInt(); if (!sup.isOWLThing() && !entityToDescribe.equals(sup)) {//omit owl:Thing and the class to describe itself currentlyBestEvaluatedDescriptions.add(new EvaluatedDescription(sup, computeScore(popularity, overlap))); } } else { logger.warn("Ignoring anonymous super class candidate: " + cls); } } }
@Override public Map<OWLIndividual, SortedSet<OWLLiteral>> getDatatypeMembersImpl(OWLDataProperty dataProperty) { Map<OWLIndividual, SortedSet<OWLLiteral>> subject2objects = new HashMap<>(); String query = String.format(SPARQLQueryUtils.SELECT_PROPERTY_RELATIONSHIPS_QUERY, dataProperty.toStringID()); ResultSet rs = executeSelectQuery(query); while(rs.hasNext()){ QuerySolution qs = rs.next(); OWLIndividual sub = df.getOWLNamedIndividual(IRI.create(qs.getResource("var1").getURI())); OWLLiteral obj = OwlApiJenaUtils.getOWLLiteral(qs.getLiteral("var2")); subject2objects.computeIfAbsent(sub, k -> new TreeSet<>()).add(obj); } return subject2objects; }
public RDFSSchemaGenerator(OWLOntology ontology) { super(OwlApiJenaUtils.getModel(ontology)); }
public static OWLOntology readDumpFiles() throws IOException { Model model = ModelFactory.createDefaultModel(); logger.debug("reading main knowledge base (" + kbFilePath + ")..."); try (InputStream is = new FileInputStream(new File(kbFilePath))) { model.read(is, null, Lang.RDFXML.getName()); } logger.debug("reading positive examples data (" + genoDiseaseFilePath + ")..."); try (InputStream is = new FileInputStream(new File(genoDiseaseFilePath))) { model.read(is, null, Lang.TURTLE.getName()); } logger.debug("reading negative examples data (" + genoNotDiseaseFilePath + ")..."); try (InputStream is = new FileInputStream(new File(genoNotDiseaseFilePath))) { model.read(is, null, Lang.TURTLE.getName()); } logger.debug("finished reading files"); //convert JENA model to OWL API ontology logger.debug("converting to OWLApi ontology..."); OWLOntology ontology = OwlApiJenaUtils.getOWLOntology(model); logger.debug("finished conversion"); // sanity check if(containsErrorNamedClasses(ontology)){ System.exit(0); } return ontology; }
RDFResourceTree newTree = new RDFResourceTree(tree.getData()); Consumer<OWLClass> addTypeChild = (cls) -> newTree.addChild(new RDFResourceTree(OwlApiJenaUtils.asNode(cls)), RDF.type.asNode()); types.add(reasoner.getRange(OwlApiJenaUtils.asOWLEntity(edge, EntityType.OBJECT_PROPERTY))); } else { types.add(reasoner.getDomain(OwlApiJenaUtils.asOWLEntity(edge, EntityType.OBJECT_PROPERTY))); Node inEdge = tree.getEdgeToParent(); if(inEdge instanceof NodeInv) { types.add(reasoner.getDomain(OwlApiJenaUtils.asOWLEntity(inEdge, EntityType.OBJECT_PROPERTY))); } else { types.add(reasoner.getRange(OwlApiJenaUtils.asOWLEntity(inEdge, EntityType.OBJECT_PROPERTY))); children.forEach(child -> types.add(OwlApiJenaUtils.asOWLEntity(child.getData(), EntityType.CLASS)));
@Override protected Set<OWLDataPropertyAssertionAxiom> getExamples(ParameterizedSparqlString queryTemplate, EvaluatedAxiom<OWLDataPropertyDomainAxiom> evAxiom) { OWLDataPropertyDomainAxiom axiom = evAxiom.getAxiom(); queryTemplate.setIri("p", entityToDescribe.toStringID()); queryTemplate.setIri("type", axiom.getDomain().asOWLClass().toStringID()); Set<OWLDataPropertyAssertionAxiom> examples = new TreeSet<>(); ResultSet rs = executeSelectQuery(queryTemplate.toString()); while (rs.hasNext()) { QuerySolution qs = rs.next(); OWLIndividual subject = df.getOWLNamedIndividual(IRI.create(qs.getResource("s").getURI())); OWLLiteral object = OwlApiJenaUtils.getOWLLiteral(qs.getLiteral("o")); examples.add(df.getOWLDataPropertyAssertionAxiom(entityToDescribe, subject, object)); } return examples; }
private void printNTriplesSyntax(List<OWLAxiom> axioms){ try { System.out.println("ENRICHMENT["); Model model = OwlApiJenaUtils.getModel(OWLManager.createOWLOntologyManager().createOntology(new HashSet<>(axioms))); model.write(System.out, "N-TRIPLES"); System.out.println("]"); } catch (OWLOntologyCreationException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public static OWLOntology readDumpFiles() throws IOException { Model model = ModelFactory.createDefaultModel(); logger.debug("reading main knowledge base (" + kbFilePath + ")..."); try (InputStream is = new FileInputStream(new File(kbFilePath))) { model.read(is, null, Lang.RDFXML.getName()); } logger.debug("reading positive examples data (" + genoDiseaseFilePath + ")..."); try (InputStream is = new FileInputStream(new File(genoDiseaseFilePath))) { model.read(is, null, Lang.TURTLE.getName()); } logger.debug("reading negative examples data (" + genoNotDiseaseFilePath + ")..."); try (InputStream is = new FileInputStream(new File(genoNotDiseaseFilePath))) { model.read(is, null, Lang.TURTLE.getName()); } logger.debug("finished reading files"); //convert JENA model to OWL API ontology logger.debug("converting to OWLApi ontology..."); OWLOntology ontology = OwlApiJenaUtils.getOWLOntology(model); logger.debug("finished conversion"); // sanity check if(containsErrorNamedClasses(ontology)){ System.exit(0); } return ontology; }
public static RDFResourceTree materializePropertyDomains(RDFResourceTree tree, AbstractReasonerComponent reasoner) { RDFResourceTree newTree = new RDFResourceTree(tree.getData()); Consumer<OWLClass> addTypeChild = (cls) -> newTree.addChild(new RDFResourceTree(OwlApiJenaUtils.asNode(cls)), RDF.type.asNode()); tree.getEdges().forEach(edge -> { List<RDFResourceTree> children = tree.getChildren(edge); // add existing children children.forEach(child -> { RDFResourceTree newChild = materializePropertyDomains(child, reasoner); newTree.addChild(newChild, edge); }); // add the rdf:type statements for the property domain(s) OWLClassExpression dom = reasoner.getDomain(OwlApiJenaUtils.asOWLEntity(edge, EntityType.OBJECT_PROPERTY)); if(!dom.isAnonymous() && !dom.isOWLThing()) { addTypeChild.accept(dom.asOWLClass()); } else { if(dom.getClassExpressionType() == ClassExpressionType.OBJECT_INTERSECTION_OF) { dom.getNestedClassExpressions().stream() .filter(ce -> !ce.isAnonymous()) .map(OWLClassExpression::asOWLClass) .forEach(addTypeChild); } } }); return newTree; }
OWLLiteral value = OwlApiJenaUtils.getOWLLiteral(child.getData().getLiteral()); classExpressions.add(df.getOWLDataHasValue(dp, value));
private static void loadThroughJena(String in, String out) throws OWLOntologyCreationException, FileNotFoundException { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File(in)); Model model = OwlApiJenaUtils.getModel(ontology); System.out.println("ltj; size:"+model.size()); model.write(new FileOutputStream(out)); }
/** * Convert statements from JENA API into OWL API axioms. * @param statements the JENA API statements * @return the set of axioms */ public static Set<OWLAxiom> asOWLAxioms(List<Statement> statements) { Model model = ModelFactory.createDefaultModel(); model.add(statements); OWLOntology ontology = getOWLOntology(model); return ontology.getAxioms(); }
OWLObjectProperty prop2 = OwlApiJenaUtils.asOWLEntity(edge2, EntityType.OBJECT_PROPERTY); SortedSet<OWLObjectProperty> subProperties = reasoner.getSubProperties(prop2); subProperties.add(prop2); Node edge1 = OwlApiJenaUtils.asNode(subProp); List<RDFResourceTree> children1 = tree1.getChildren(edge1);
private void printTurtleSyntax(List<OWLAxiom> axioms){ try { System.out.println("ENRICHMENT["); Model model = OwlApiJenaUtils.getModel(OWLManager.createOWLOntologyManager().createOntology(new HashSet<>(axioms))); model.write(System.out, "TURTLE"); System.out.println("]"); } catch (OWLOntologyCreationException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
return OwlApiJenaUtils.getOWLOntology(sample);