public JSONObject loadContext(ContextIdentifier id) throws IOException { if (contextCache.containsKey(id.getName())) { return contextCache.get(id.getName()); } InputStream jsonStream; if(id.getContent() != null) jsonStream = IOUtils.toInputStream(id.getContent(), "utf-8"); else jsonStream = id.getLocation().openStream(); JSONTokener token = new JSONTokener(new InputStreamReader(jsonStream)); JSONObject obj = new JSONObject(token); this.contextCache.put(id.getName(), obj); return obj; }
private void addContext(String contextURI, String contextContent) { try { contextId = new ContextIdentifier("context", new URL(contextURI), contextContent); generator.addContext(contextId); }catch(Exception e) { } }
private void initializeWriter(R2RMLMappingIdentifier id, ContextIdentifier contextId, List<KR2RMLRDFWriter> writers) { JSONObject contextObj = new JSONObject(); if (contextId != null) { try { JSONTokener token = new JSONTokener(contextId.getLocation().openStream()); contextObj = new JSONObject(token); }catch(Exception e) { } } for (KR2RMLRDFWriter writer : writers) { if (writer instanceof JSONKR2RMLRDFWriter) { JSONKR2RMLRDFWriter t = (JSONKR2RMLRDFWriter)writer; t.setGlobalContext(contextObj, contextId); } writer.setR2RMLMappingIdentifier(id); } }
public void addContext(ContextIdentifier id) { this.contextIdentifiers.put(id.getName(), id); }
public void setGlobalContext(JSONObject context, ContextIdentifier contextId) { if (context.has("@context")) { if (contextId != null) { location = contextId.getLocation(); } JSONObject c = context.getJSONObject("@context"); this.context = c; @SuppressWarnings("rawtypes") Iterator itr = c.keys(); while (itr.hasNext()) { String key = itr.next().toString(); try { if (c.get(key).toString().equals("@id")) { atId = key; } if (c.get(key).toString().equals("@type")) { atType = key; } if (c.getJSONObject(key).has("@id")) { contextInverseAtIdMapping.put(c.getJSONObject(key).getString("@id"), key); } if (c.getJSONObject(key).has("@container") && c.getJSONObject(key).get("@container").equals("@set")) { contextInverseAtContainerMapping.put(key, true); } }catch(Exception e) { } } } }
private void generateRdfFromDatabaseTable() throws Exception { if(!validateDatabaseCommandLineOptions()) { logger.error("Unable to generate RDF from database table!"); return; } DatabaseTableRDFGenerator dbRdfGen = new DatabaseTableRDFGenerator(dbType, hostname, port, username, password, dBorSIDName, encoding, selectionName, contextParameters); ContextIdentifier contextId = null; if (contextURL != null) { contextId = new ContextIdentifier(contextURL.getQuery(), contextURL, null); } if(inputType.equals("DB")) { R2RMLMappingIdentifier id = new R2RMLMappingIdentifier(tablename, modelURL, null); createWriters(); dbRdfGen.generateRDFFromTable(tablename, topkrows, writers, id, contextId, baseURI); } else { String query = loadQueryFromFile(); R2RMLMappingIdentifier id = new R2RMLMappingIdentifier(modelURL.toString(), modelURL, null); createWriters(); dbRdfGen.generateRDFFromSQL(query, writers, id, contextId, baseURI); } }
contextURL = url.toString(); writer.setGlobalContext(context, new ContextIdentifier(context.toString(), new URL(contextURL)));
request.setContextParameters(contextParameters); if (contextURL != null) { ContextIdentifier contextId = new ContextIdentifier(contextURL.getQuery(), contextURL, null); rdfGenerator.addContext(contextId); request.setContextName(contextURL.getQuery());