private void flattenContainer(RDFBackend<Node> backend, Node node, Collection<Node> result) { for (int i = 1; /* exit via break */; i++) { final Collection<Node> objects = backend.listObjects(node, backend.createURI(RDF + "_" + i)); if (objects.size() > 0) { result.addAll(objects); } else { break; } } }
private Collection<? extends Node> subListFromContainer(RDFBackend<Node> backend, Node node, int start, int end) { List<Node> result = new LinkedList<>(); for (int i = start; i < end; i++) { final Collection<Node> objects = backend.listObjects(node, backend.createURI(RDF + "_" + (i + 1))); if (objects.size() > 0) { result.addAll(objects); } else { break; } } return result; }
private void flattenContainer(RDFBackend<Node> backend, Node node, Collection<Node> result) { for (int i = 1; /* exit via break */; i++) { final Collection<Node> objects = backend.listObjects(node, backend.createURI(RDF + "_" + i)); if (objects.size() > 0) { result.addAll(objects); } else { break; } } }
private Collection<? extends Node> subListFromContainer(RDFBackend<Node> backend, Node node, int start, int end) { List<Node> result = new LinkedList<>(); for (int i = start; i < end; i++) { final Collection<Node> objects = backend.listObjects(node, backend.createURI(RDF + "_" + (i + 1))); if (objects.size() > 0) { result.addAll(objects); } else { break; } } return result; }
private Collection<Node> getFromContainer(RDFBackend<Node> backend, Node node, int index) { return backend.listObjects(node, backend.createURI(RDF + "_" + (index + 1))); }
private Collection<Node> getFromContainer(RDFBackend<Node> backend, Node node, int index) { return backend.listObjects(node, backend.createURI(RDF + "_" + (index + 1))); }
private Collection<Node> getFromCollection(RDFBackend<Node> backend, Node node, int index) { if (index < 0 || isNil(backend, node)) { return Collections.emptySet(); } else if (index == 0) { return backend.listObjects(node, backend.createURI(RDF + "first")); } else { HashSet<Node> result = new HashSet<>(); for (Node n : backend.listObjects(node, backend.createURI(RDF + "rest"))) { result.addAll(getFromCollection(backend, n, index - 1)); } return result; } }
private Collection<Node> getFromCollection(RDFBackend<Node> backend, Node node, int index) { if (index < 0 || isNil(backend, node)) { return Collections.emptySet(); } else if (index == 0) { return backend.listObjects(node, backend.createURI(RDF + "first")); } else { HashSet<Node> result = new HashSet<>(); for (Node n : backend.listObjects(node, backend.createURI(RDF + "rest"))) { result.addAll(getFromCollection(backend, n, index - 1)); } return result; } }
/** * Apply the selector to the context node passed as argument and return the collection * of selected nodes in appropriate order. * * @param context the node where to start the selection * @param path the path leading to but not including the context node in the current evaluation of LDPath; may be null, * in which case path tracking is disabled * @param resultPaths a map where each of the result nodes maps to a path leading to the result node in the LDPath evaluation; * if null, path tracking is disabled and the path argument is ignored * @return the collection of selected nodes */ @Override public Collection<Node> select(RDFBackend<Node> rdfBackend, Node context, List<Node> path, Map<Node, List<Node>> resultPaths) { if(rdfBackend.isURI(context) || rdfBackend.isBlank(context)) { if(path != null && resultPaths != null) { Collection<Node> results = rdfBackend.listObjects(context,property); for(Node n : results) { resultPaths.put(n, new ImmutableList.Builder<Node>().addAll(path).add(context).add(n).build()); } return results; } else { return rdfBackend.listObjects(context,property); } } else { return Collections.emptyList(); } }
private void subListFromCollection(RDFBackend<Node> backend, Node node, int start, int end, List<Node> result) { if (isNil(backend, node)) { return; } if (end > 0) { if (start <= 0) { result.addAll(backend.listObjects(node, backend.createURI(RDF + "first"))); } for (Node n : backend.listObjects(node, backend.createURI(RDF + "rest"))) { subListFromCollection(backend, n, start - 1, end - 1, result); } } }
/** * Apply the selector to the context node passed as argument and return the collection * of selected nodes in appropriate order. * * @param context the node where to start the selection * @param path the path leading to but not including the context node in the current evaluation of LDPath; may be null, * in which case path tracking is disabled * @param resultPaths a map where each of the result nodes maps to a path leading to the result node in the LDPath evaluation; * if null, path tracking is disabled and the path argument is ignored * @return the collection of selected nodes */ @Override public Collection<Node> select(RDFBackend<Node> rdfBackend, Node context, List<Node> path, Map<Node, List<Node>> resultPaths) { if(rdfBackend.isURI(context) || rdfBackend.isBlank(context)) { if(path != null && resultPaths != null) { Collection<Node> results = rdfBackend.listObjects(context,property); for(Node n : results) { resultPaths.put(n, new ImmutableList.Builder<Node>().addAll(path).add(context).add(n).build()); } return results; } else { return rdfBackend.listObjects(context,property); } } else { return Collections.emptyList(); } }
private void subListFromCollection(RDFBackend<Node> backend, Node node, int start, int end, List<Node> result) { if (isNil(backend, node)) { return; } if (end > 0) { if (start <= 0) { result.addAll(backend.listObjects(node, backend.createURI(RDF + "first"))); } for (Node n : backend.listObjects(node, backend.createURI(RDF + "rest"))) { subListFromCollection(backend, n, start - 1, end - 1, result); } } }
protected boolean hasType(RDFBackend<Node> backend, Node node, String type) { return backend.listObjects(node, backend.createURI(RDF + "type")).contains(backend.createURI(type)); }
protected boolean hasType(RDFBackend<Node> backend, Node node, String type) { return backend.listObjects(node, backend.createURI(RDF + "type")).contains(backend.createURI(type)); }
private void flattenCollection(RDFBackend<Node> backend, Node node, Collection<Node> result, Collection<Node> backtrace) { if (isNil(backend, node)) { return; } // Stop if we detect a cycle. if (!backtrace.add(node)) { return; } // Add the (all) firsts result.addAll(backend.listObjects(node, backend.createURI(RDF + "first"))); // Recursively add the rest final Collection<Node> rest = backend.listObjects(node, backend.createURI(RDF + "rest")); for (Node r : rest) { flattenCollection(backend, r, result, backtrace); } }
private void flattenCollection(RDFBackend<Node> backend, Node node, Collection<Node> result, Collection<Node> backtrace) { if (isNil(backend, node)) { return; } // Stop if we detect a cycle. if (!backtrace.add(node)) { return; } // Add the (all) firsts result.addAll(backend.listObjects(node, backend.createURI(RDF + "first"))); // Recursively add the rest final Collection<Node> rest = backend.listObjects(node, backend.createURI(RDF + "rest")); for (Node r : rest) { flattenCollection(backend, r, result, backtrace); } }