/** * Return an iterator of Triples for versions. * * @param graph the graph * @param subject the subject * @return iterator */ public Iterator<Node> getVersions(final Graph graph, final Node subject) { // Mementos should be ordered by date so use the getOrderedVersions. return getOrderedVersions(graph, subject, CONTAINS.asResource()); }
public static void createQueryBackward(Model model, Node node, Resource res, Set<Triple> result) { Node n; if(node.isVariable()) { n = createVarUri((Var)node); } else { n = node; } Resource r = model.asRDFNode(n).asResource(); Set<Statement> preds = model.listStatements(null, null, r).toSet(); for(Statement stmt : preds) { Resource s = stmt.getSubject(); Property p = stmt.getPredicate(); //Triple t = new Triple(p.asNode(), VocabPath.joinsWith.asNode(), node); Triple t = new Triple(node, VocabPath.joinsWith.asNode(), p.asNode()); if(!result.contains(t)) { result.add(t); createQueryBackward(model, s.asNode(), p.asResource(), result); } } }
public static void createQueryForward(Model model, Node node, Resource res, Set<Triple> result) { Node n; if(node.isVariable()) { n = createVarUri((Var)node); } else { n = node; } Resource r = model.asRDFNode(n).asResource(); Set<Statement> succs = model.listStatements(r, null, (RDFNode)null).toSet(); for(Statement stmt : succs) { RDFNode oo = stmt.getObject(); if(!oo.isURIResource()) { continue; } Property p = stmt.getPredicate(); Resource o = oo.asResource(); Triple t = new Triple(node, VocabPath.joinsWith.asNode(), p.asNode()); if(!result.contains(t)) { result.add(t); createQueryForward(model, o.asNode(), p.asResource(), result); } } }
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) + ">")); } // don't apply prefixes since it can result in funny things like: // pref:/connections/, and also the collision on the prefix uris // that starts the same. E.g. having prefixes below in need rdf // would cause errors // @prefix : <http://www.example.com/resource/need/12#> . // @prefix need: <http://www.example.com/resource/need/12> . //graphc.applyPrefixes(); return graphc; }