private void writeModel(Workspace workspace, OntologyManager ontMgr, KR2RMLMappingGenerator mappingGen, Worksheet worksheet, String modelFileLocalPath) throws RepositoryException, FileNotFoundException, UnsupportedEncodingException, JSONException { File f = new File(modelFileLocalPath); File parentDir = f.getParentFile(); parentDir.mkdirs(); PrintWriter writer = new PrintWriter(f, "UTF-8"); KR2RMLMappingWriter mappingWriter = new KR2RMLMappingWriter(); mappingWriter.addR2RMLMapping(mappingGen.getKR2RMLMapping(), worksheet, workspace); mappingWriter.writeR2RMLMapping(writer); mappingWriter.close(); writer.flush(); writer.close(); if(OSUtils.isWindows()) System.gc(); //Invoke gc for windows, else it gives error: The requested operation cannot be performed on a file with a user-mapped section open //when the model is republished, and the original model is earlier open }
public boolean addR2RMLMapping(KR2RMLMapping mapping, Worksheet worksheet, Workspace workspace) throws RepositoryException, JSONException { try { Resource mappingRes = addKR2RMLMappingResource(worksheet, mapping); addTripleMaps(mapping, mappingRes, worksheet, workspace); addPrefixes(mapping); } catch (OpenRDFException e) { logger.error("Error occured while generating RDF representation of R2RML data " + "structures.", e); } return true; }
private void addPredicateObjectMaps( KR2RMLMapping mapping, Resource mappingRes, TriplesMap trMap, URI trMapUri, Workspace workspace, Worksheet worksheet) throws RepositoryException { // Add the predicate object maps for (PredicateObjectMap pom:trMap.getPredicateObjectMaps()) { addPredicateObjectMap(mapping, mappingRes, trMapUri, workspace, pom, worksheet); } }
private void addTripleMap(KR2RMLMapping mapping, Resource mappingRes, Worksheet worksheet, Workspace workspace, TriplesMap trMap) throws RepositoryException { URI trMapUri = f.createURI(Namespaces.KARMA_DEV + trMap.getId()); addTripleMapMetadata(mapping, mappingRes, worksheet, trMap, trMapUri); addSubjectMap(mapping, mappingRes, trMap, trMapUri, workspace); addPredicateObjectMaps(mapping, mappingRes, trMap, trMapUri, workspace, worksheet); }
private void addPredicateObjectMap(KR2RMLMapping mapping, Resource mappingRes, URI trMapUri, Workspace workspace, PredicateObjectMap pom, Worksheet worksheet) throws RepositoryException { KR2RMLColumnNameFormatter columnNameFormatter = mapping.getColumnNameFormatter(); RepFactory factory = workspace.getFactory(); URI pomUri = f.createURI(Namespaces.KARMA_DEV + pom.getId()); //BNode pomBlankNode = f.createBNode(); boolean usablePredicate = addPredicate(pom, columnNameFormatter, factory, pomUri); if(!usablePredicate) { return; } addObject(mappingRes, pom, columnNameFormatter, factory, pomUri, worksheet); con.add(trMapUri, repoURIs.get(Uris.RR_PRED_OBJ_MAP_URI), pomUri); // Add the predicate object map type statement con.add(pomUri, RDF.TYPE, repoURIs.get(Uris.RR_PREDICATEOBJECTMAP_CLASS_URI)); con.add(pomUri, repoURIs.get(Uris.KM_IS_PART_OF_MAPPING_URI), mappingRes); con.add(mappingRes, repoURIs.get(Uris.KM_HAS_PREDICATE_OBJECT_MAP_URI), pomUri); }
if (oldHistory != null && !oldHistory.trim().isEmpty()) con.add(mappingRes, repoURIs.get(Uris.KM_HAS_OLDHISTORY), f.createLiteral(oldHistory)); addWorksheetProperties(worksheet, mappingRes); addCompleteWorksheetHistory(mapping, mappingRes); return mappingRes;
private void addTripleMapMetadata(KR2RMLMapping mapping, Resource mappingRes, Worksheet worksheet, TriplesMap trMap, URI trMapUri) throws RepositoryException { // Add the triples map type statement con.add(trMapUri, RDF.TYPE, repoURIs.get(Uris.RR_TRIPLESMAP_CLASS_URI)); // Associate it with the source mapping URI con.add(mappingRes, repoURIs.get(Uris.KM_HAS_TRIPLES_MAP_URI), trMapUri); con.add(trMapUri, repoURIs.get(Uris.KM_IS_PART_OF_MAPPING_URI), mappingRes); addLogicalSource(mapping, worksheet, mappingRes, trMapUri); }
StringWriter string = new StringWriter(); PrintWriter pw = new PrintWriter(string); writer = new KR2RMLMappingWriter(); writer.addR2RMLMapping(mapping, worksheet, workspace); writer.writeR2RMLMapping(pw); writer.close(); pw.flush(); pw.close();