use of de.uni_koblenz.aggrimm.icp.crypto.sign.graph.Prefix in project webofneeds by researchstudio-sat.
the class ModelConverter method namedGraphToModel.
private static Model namedGraphToModel(NamedGraph graph, List<Prefix> prefixes) throws Exception {
// Here, the simplest, but probably not the most efficient, approach is
// applied: Signingframework's reader and Jena's writer are used to
// transform data from one data structure to another. Works fine.
ByteArrayOutputStream os = new ByteArrayOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os));
String dfPref = "";
// write prefixes
for (Prefix p : prefixes) {
writer.write(p.toString());
if (p.getPrefix().equals(":")) {
dfPref = p.getIriContent();
}
}
// write NamedGraph
TriGPlusWriter.writeGraph(writer, graph, 3);
writer.close();
String content = os.toString();
// read the result with Jena as Dataset
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
Dataset dataset = DatasetFactory.createGeneral();
RDFDataMgr.read(dataset, is, RDFFormat.TRIG.getLang());
// extract the Model that corresponds to the NamedGraph
String modelName = graphNameToModelName(graph.getName(), dfPref);
Model model = dataset.getNamedModel(modelName);
for (Prefix pref : prefixes) {
model.setNsPrefix(pref.getPrefix().replace(":", ""), pref.getIriContent());
}
return model;
}
use of de.uni_koblenz.aggrimm.icp.crypto.sign.graph.Prefix in project webofneeds by researchstudio-sat.
the class ModelConverter method modelToGraphCollection.
private static GraphCollection modelToGraphCollection(String name, Model model, Map<String, String> pm) {
// Convert each subj pred obj in Jena Statement into String and add to
// SigningFramework's NamedGraph.
// The simpler approach with just using Jena's writer and Signingframework's
// reader to transform data between data structures won't work since
// Signingframework has problems with recognizing the [] structure
GraphCollection graphc = new GraphCollection();
NamedGraph namedGraph = new NamedGraph(enclose(name, "<", ">"), 0, null);
StmtIterator iterator = model.listStatements();
while (iterator.hasNext()) {
Statement stmt = iterator.nextStatement();
String subjString = rdfNodeAsString(stmt.getSubject());
String objString = rdfNodeAsString(stmt.getObject());
String predString = enclose(stmt.getPredicate().asResource().getURI(), "<", ">");
Triple gcTriple = new Triple(subjString, predString, objString);
namedGraph.addTriple(gcTriple);
}
graphc.addGraph(namedGraph);
for (String prefix : pm.keySet()) {
graphc.addPrefix(new Prefix(prefix + ":", "<" + pm.get(prefix) + ">"));
}
return graphc;
}
Aggregations