/** * Constructor to start the parser from an RDF Model * @param model - the sesame Model containing mappings */ public R2RMLManager(Model model){ myModel = model; r2rmlParser = new R2RMLParser(); }
/** * method to read the mappings from the graph * @return list of obdaMappingAxioms */ public ArrayList<OBDAMappingAxiom> readMappings(){ return manager.getMappings(m); }
/** * Pre-pends the passed resource string with a default prefix in order * to make it into a valid URI. * * @param resource * @return */ public static final String prefixUri(String resource) { if ( !isResourceString(resource)) { return "http://example.com/base/" + resource; } else { return resource; } }
public static void main(String args[]) { String file = "/Users/mindaugas/r2rml/test2.ttl"; try { R2RMLReader reader = new R2RMLReader(file); OWLOntology ontology = null; R2RMLWriter writer = new R2RMLWriter(reader.readModel(URI.create("test")),URI.create("test"), ontology); File out = new File("/Users/mindaugas/r2rml/out.ttl"); // Graph g = writer.getGraph(); // Iterator<Statement> st = g.iterator(); // while (st.hasNext()) // System.out.println(st.next()); writer.write(out); } catch (Exception e) { e.printStackTrace(); } } }
public Collection <TriplesMap> getTripleMaps() { OBDAMappingTransformer transformer = new OBDAMappingTransformer(); transformer.setOntology(ontology); return splitMappingAxioms(this.mappings).stream() .map(a -> transformer.getTripleMap(a, prefixmng)) .collect(Collectors.toList()); }
public static void main(String args[]) { String file = "/Users/mindaugas/r2rml/test26.ttl"; R2RMLReader reader = null; try { reader = new R2RMLReader(file); } catch (Exception e) { e.printStackTrace(); } ArrayList<OBDAMappingAxiom> axioms = reader.readMappings(); for (OBDAMappingAxiom ax : axioms) System.out.println(ax); }
/** * get a typed atom of a specific type * * @param type * - iri, blanknode or literal * @param string * - the atom as string * @return the contructed Function atom */ private Function getTermTypeAtom(String string, Object type, String joinCond) { if (type.equals(R2RMLVocabulary.iri)) { return getURIFunction(string, joinCond); } else if (type.equals(R2RMLVocabulary.blankNode)) { return getTypedFunction(string, 2, joinCond); } else if (type.equals(R2RMLVocabulary.literal)) { return getTypedFunction(trim(string), 3, joinCond); } return null; }
public R2RMLReader(File file) throws Exception { manager = new R2RMLManager(file); m = manager.getModel(); }
/** * Get OBDA mapping axiom from R2RML TriplesMap * @param tm * @return * @throws Exception */ private OBDAMappingAxiom getMapping(TriplesMap tm) throws Exception { String sourceQuery = r2rmlParser.getSQLQuery(tm).trim(); List<Function> body = getMappingTripleAtoms(tm); //Function head = getHeadAtom(body); //CQIE targetQuery = fac.getCQIE(head, body); OBDAMappingAxiom mapping = fac.getRDBMSMappingAxiom("mapping-"+tm.hashCode(), fac.getSQLQuery(sourceQuery), body); if (body.isEmpty()){ //we do not have a target query System.out.println("WARNING a mapping without target query will not be introduced : "+ mapping.toString()); return null; } return mapping; }
private Function getURIFunction(String string) { return getTypedFunction(string, 1); }
public R2RMLReader(Model m) { manager = new R2RMLManager(m); this.m = m; }
public Term getSubjectAtom(TriplesMap tm) throws Exception { return getSubjectAtom(tm, ""); }
public Term getObjectAtom(PredicateObjectMap pom) { return getObjectAtom(pom, ""); }
@Deprecated public List<Resource> getJoinNodes(TriplesMap tm) { List<Resource> joinPredObjNodes = new ArrayList<Resource>(); // get predicate-object nodes Set<Resource> predicateObjectNodes = getPredicateObjects(tm); return joinPredObjNodes; }
/** * the method to write the R2RML mappings * from an rdf Model to a file * @param file the ttl file to write to */ public void write(File file) throws Exception { try { FileOutputStream fos = new FileOutputStream(file); write(fos); } catch (Exception e) { e.printStackTrace(); throw e; } }
@Deprecated private Term getConstantObject(String objectString) { if (objectString.startsWith("http:")) return getURIFunction(objectString); else { // literal Constant constt = fac.getConstantLiteral(objectString); return fac.getTypedTerm(constt, COL_TYPE.LITERAL); } }
/** * method to get the parent column in a join condition * * @param myModel * - the Model of mappings * @param predobjNode * - the pred obj node containing the join condition * @return the parent column condition as a string */ public String getParentColumn(Model myModel, Resource predobjNode) { // process OBJECTMAP Model m = myModel.filter(predobjNode, R2RMLVocabulary.objectMap, null); if (!m.isEmpty()) { Resource object = m.objectResource(); // look for joincondition declaration m = myModel.filter(object, R2RMLVocabulary.joinCondition, null); if (!m.isEmpty()) { Resource objectt = m.objectResource(); // look for parent declaration m = myModel.filter(objectt, R2RMLVocabulary.parent, null); if (!m.isEmpty()) { return trimTo1(m.objectString()); } } } return null; }
public Function getTypedFunction(String parsedString, int type) { return getTypedFunction(parsedString, type, ""); }
/** * the method that gives the obda model based on the given graph * @param sourceUri - the uri of the datasource of the model * @return the read obda model */ public OBDAModel readModel(URI sourceUri){ try { //add to the model the mappings retrieved from the manager obdaModel.addMappings(sourceUri, manager.getMappings(m)); } catch (DuplicateMappingException e) { e.printStackTrace(); } return obdaModel; }
private Function getURIFunction(String string, String joinCond) { return getTypedFunction(string, 1, joinCond); }