public List<Resource> listOneOfClasses() { GraphThing oneOf = ontClass.getOneOf(); List<Resource> list = new ArrayList<Resource>(); for (Value value : GraphUtils.getContainerMembers(oneOf.resource(), ontGraph)) { if (value instanceof Resource) { //com.ibm.adtech.boca.owl.Class rangeClazz = OWL11Factory.getClass((Resource) value, ontGraph); list.add((Resource) value); } } return list; }
/** * Specify an ontology needed by one of the generation ontologies. One of these * entreis should be added for every import in every ontology to generate. * We have this call because imports in Jena don't work all that well. * @param ontologyFile The InputStream containing the ontology document * @param ontlang The Ontology Language, owl or rdfs. * @param rdflang The seriazation format of the ontology file (N3,RDF/XM,...all Jena formats) * @param ontologyURI The URI of the ontology * @param packagename The Java package that generate classes should be in. */ public void addOntologyDependency(InputStream ontologyFile, String ontLang, String rdflang, String ontologyURI, String packagename) { try { INamedGraph temp = createOntGraph(false, ontLang); if (rdflang != null) GraphUtils.loadGraph(temp, ontologyFile, RDFFormat.valueOf(rdflang),ontologyURI); else GraphUtils.loadGraph(temp, ontologyFile, RDFFormat.RDFXML,ontologyURI); if (ontLang != null && ontLang.equals(ONT_LANG_RDFS)) { temp = Rdfs2Owl.convertToOwl(temp, ontologyURI); } GraphUtils.addGraph(ontGraph, temp); registerOntology(temp, ontologyURI, packagename, false); } catch (Exception e) { throw new RuntimeException(e); } }
public static void loadGraphInDataset(IDataset dataset, URI namedGraphURI, InputStream rdf, RDFFormat format,String baseURI) throws Exception { loadGraphInDataset(dataset, namedGraphURI, rdf, format, baseURI, -1); } public static void loadGraphInDataset(IDataset dataset, URI namedGraphURI, InputStream rdf, RDFFormat format,String baseURI,int batchSize) throws Exception {
private void buildUnionTable() { List<OntologyClass> list = listOntologyClassesToGenerate(); for (int i = 0; i < list.size(); i++) { OntologyClass oc = list.get(i); com.ibm.adtech.boca.owl.Class ontClass = oc.getOntClass(); if (ontClass.resource() instanceof URI) { GraphThing unionOf = ontClass.getUnionOf(); if (unionOf != null) { Iterable<Value> unions = GraphUtils.getCollectionMembers(unionOf.resource(), getOntGraph()); for (Value val : unions) { if(val instanceof Resource) { com.ibm.adtech.boca.owl.Class op = OWL11Factory.getClass((Resource)val,getOntGraph()); if(op!=null) { List<OntologyClass> l = unionTable.get(op.resource()); if (l == null) { l = new ArrayList<OntologyClass>(); unionTable.put(op.resource(), l); } l.add(oc); } } } } } } }
public static void loadGraph(INamedGraph graph, InputStream rdf, RDFFormat format,String baseURI) throws Exception { loadGraph(graph,rdf,format,baseURI,-1); }
/** * Specify an ontology to generate * @param ontGraph A Jena INamedGraph containing the ontology * @param ontologyURI The URI of the ontology * @param packagename The Java package that generate classes should be in. */ public void addOntologyToGenerate(INamedGraph ontGraph, String ontologyURI, String packagename) { GraphUtils.addGraph(this.ontGraph, ontGraph); registerOntology(ontGraph, ontologyURI, packagename, true); }
public static String graphToString(INamedGraph graph) throws Exception { StringWriter sw = new StringWriter(); writeGraph(graph, sw); return sw.getBuffer().toString(); }
for (Value value : GraphUtils.getCollectionMembers(unionOf.resource(), ontGraph)) { if (value instanceof URI) { com.ibm.adtech.boca.owl.Class oc = OWL11Factory.getClass((URI) value, ontGraph);
public static void loadGraph(INamedGraph graph, String rdf, RDFFormat format) throws Exception { loadGraph(graph, new ByteArrayInputStream(rdf.getBytes()), format,""); }
/** * Specify an ontology to generate * @param ontGraph A Jena INamedGraph containing the ontology * @param ontlang The Ontology Language, owl or rdfs. * @param ontologyURI The URI of the ontology * @param packagename The Java package that generate classes should be in. */ public void addOntologyToGenerate(INamedGraph ontGraph, String ontlang, String ontologyURI, String packagename) { if (ontlang != null && ontlang.equals(ONT_LANG_RDFS)) ontGraph = Rdfs2Owl.convertToOwl(ontGraph, ontologyURI); GraphUtils.addGraph(this.ontGraph, ontGraph); registerOntology(ontGraph, ontologyURI, packagename, true); }
public void writeOut() { for (URI ng : getNamedGraphs()) { INamedGraph result = getNamedGraph(ng); try { System.err.println(ng); GraphUtils.writeGraph(result, System.err); } catch (Exception e) { e.printStackTrace(); } } }
/** * Determine if this property has multiple ranges defined in the base declaration of the property. Note, this is different * from multiple ranges via-all values from. */ private void checkForMultipleBaseRanges() { Resource range = getRange(); if (range != null && range instanceof BNode) { com.ibm.adtech.boca.owl.Class clazz = OWL11Factory.getClass(range, ontGraph); GraphThing union = clazz.getUnionOf(); if (union != null) { ranges = new ArrayList<Resource>(); for (Value value : GraphUtils.getContainerMembers(union.resource(), ontGraph)) { if (value instanceof Resource) { //com.ibm.adtech.boca.owl.Class rangeClazz = OWL11Factory.getClass((Resource) value, ontGraph); ranges.add((Resource) value); } } } } }
public static Iterable<Statement> getCollectionMembers(Resource list, IDataset dataset) { ArrayList<Statement> statements = new ArrayList<Statement>(); if (dataset.contains(list, RDF.FIRST, null, null) && dataset.contains(list, RDF.REST, null, null)) { CloseableIterator<Statement> firstStatements = dataset.find(list, RDF.FIRST, null, null); try { if (firstStatements.hasNext()) { Statement first = firstStatements.next(); if (!statements.contains(first.getObject())) { statements.add(first); } } } finally { firstStatements.close(); } CloseableIterator<Statement> restStatements = dataset.find(list, RDF.REST, null, null); try { if (restStatements.hasNext()) { Statement rest = restStatements.next(); if (!statements.contains(rest.getObject()) && rest.getObject() instanceof Resource) { Iterators.addAll(getCollectionMembers((Resource) rest.getObject(), dataset).iterator(), statements); } } } finally { restStatements.close(); } } return statements; }
/** * Specify an ontology to generate * @param ontologyFile The InputStream containing the ontology document * @param ontlang The Ontology Language, owl or rdfs. * @param rdflang The seriazation format of the ontology file (N3,RDF/XM,...all Jena formats) * @param ontologyURI The URI of the ontology * @param packagename The Java package that generate classes should be in. */ public void addOntologyToGenerate(InputStream ontologyFile, String ontLang, String rdflang, String ontologyURI, String packagename) { try { INamedGraph temp = createOntGraph(false, ontLang); if (rdflang != null) GraphUtils.loadGraph(temp, ontologyFile, RDFFormat.valueOf(rdflang),ontologyURI); else GraphUtils.loadGraph(temp, ontologyFile, RDFFormat.RDFXML,ontologyURI); if (ontLang != null && ontLang.equals(ONT_LANG_RDFS)) { temp = Rdfs2Owl.convertToOwl(temp, ontologyURI); } addConcreteEnumClasses(temp); GraphUtils.addGraph(ontGraph, temp); //GraphUtils.writeGraph(temp, System.err); registerOntology(temp, ontologyURI, packagename, true); } catch (Exception e) { throw new RuntimeException(e); } }
public static void loadGraph(INamedGraph graph, File file) throws Exception { RDFFormat format = RDFFormat.forFileName(file.getName()); if (format == null) { if (file.getName().endsWith(".owl")) { format = RDFFormat.RDFXML; } } loadGraph(graph, new FileInputStream(file), format,""); }
private List<OntologyClass> listImmediateIntersectionClasses(List<com.ibm.adtech.boca.owl.Class> visited, boolean includeAnon) { List<OntologyClass> list = new ArrayList<OntologyClass>(); GraphThing intersectionOf = ontClass.getIntersectionOf(); if (intersectionOf != null) { for (Value value : GraphUtils.getContainerMembers(intersectionOf.resource(), ontGraph)) { if (value instanceof Resource) { com.ibm.adtech.boca.owl.Class rangeClazz = OWL11Factory.getClass((Resource) value, ontGraph); if (value instanceof BNode) { if (includeAnon) { list.add(new OntologyClass(rangeClazz, ctx)); } } else { list.add(new OntologyClass(rangeClazz, ctx)); } } } } return list; }
public static Iterable<Value> getCollectionMembers(Resource list, INamedGraph graph) { ArrayList<Value> statements = new ArrayList<Value>(); if (graph.contains(list, RDF.FIRST, null) && graph.contains(list, RDF.REST, null)) { CloseableIterator<Statement> firstStatements = graph.find(list, RDF.FIRST, null); try { if (firstStatements.hasNext()) { Statement first = firstStatements.next(); if (!statements.contains(first.getObject())) { statements.add(first.getObject()); } } } finally { firstStatements.close(); } CloseableIterator<Statement> restStatements = graph.find(list, RDF.REST, null); try { if (restStatements.hasNext()) { Statement rest = restStatements.next(); if (!statements.contains(rest.getObject()) && rest.getObject() instanceof Resource) { Iterators.addAll(getCollectionMembers((Resource) rest.getObject(), graph).iterator(), statements); } } } finally { restStatements.close(); } } return statements; }
private void addUnionOperands(Resource range, List<Resource> list) { CloseableIterator<Statement> union = ontGraph.find(range, com.ibm.adtech.boca.owl.Class.unionOfProperty, null); while (union.hasNext()) { Statement stmt = union.next(); if (stmt.getObject() instanceof Resource) { for (Value value : GraphUtils.getContainerMembers((Resource) stmt.getObject(), ontGraph)) { if (value instanceof Resource) { ranges.add((Resource) value); } } } } }
private void buildOPUnionDomainTable(List<ObjectProperty> it) { for (ObjectProperty prop : it) { OntologyProperty op=new OntologyProperty(prop,this); if (prop.getDomain() != null && (prop.getDomain().resource() instanceof BNode)) { com.ibm.adtech.boca.owl.Class clazz = OWL11Factory.getClass(prop.getDomain().resource(), getOntGraph()); GraphThing union = clazz.getUnionOf(); Iterable<Value> unions = GraphUtils.getCollectionMembers(union.resource(), getOntGraph()); for (Value val : unions) { if(val instanceof Resource) { com.ibm.adtech.boca.owl.Class oc = OWL11Factory.getClass((Resource)val,getOntGraph()); if(oc!=null) { List<OntologyProperty> l = unionDomainTable.get(oc.resource()); if (l == null) { l = new ArrayList<OntologyProperty>(); unionDomainTable.put(oc.resource(), l); } l.add(op); } } } } } }
GraphThing oneOf = dr.getOneOf(); if (oneOf != null) { Iterable<Value> oneOfs = GraphUtils.getContainerMembers(oneOf.resource(), ontGraph); Iterator<Value> it = oneOfs.iterator(); while (it.hasNext()) {