/** * Apply the function to the list of nodes passed as arguments and return the result as type T. * Throws IllegalArgumentException if the function cannot be applied to the nodes passed as argument * or the number of arguments is not correct. * * @return */ @Override public boolean accept(RDFBackend<Node> rdfBackend, Node context, Node candidate) throws IllegalArgumentException { if (rdfBackend.isURI(candidate) || rdfBackend.isBlank(candidate)) { Collection<Node> testResult = path.select(rdfBackend, candidate,null,null); return testResult.size() > 0; } else { return false; } }
/** * Apply the function to the list of nodes passed as arguments and return the result as type T. * Throws IllegalArgumentException if the function cannot be applied to the nodes passed as argument * or the number of arguments is not correct. * * @return */ @Override public boolean accept(RDFBackend<Node> rdfBackend, Node context, Node candidate) throws IllegalArgumentException { if (rdfBackend.isURI(candidate) || rdfBackend.isBlank(candidate)) { Collection<Node> testResult = path.select(rdfBackend, candidate,null,null); return testResult.size() > 0; } else { return false; } }
/** * 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.listSubjects(property, context); for(Node n :results) { resultPaths.put(n, new ImmutableList.Builder<Node>().addAll(path).add(context).add(n).build()); } return results; } else { return rdfBackend.listSubjects(property, context); } } else { return Collections.emptyList(); } }
/** * 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(); } }
/** * 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.listSubjects(property, context); for(Node n :results) { resultPaths.put(n, new ImmutableList.Builder<Node>().addAll(path).add(context).add(n).build()); } return results; } else { return rdfBackend.listSubjects(property, context); } } else { return Collections.emptyList(); } }
/** * 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(); } }
contexts = new ArrayList<RDFTerm>(); for(RDFTerm r : args[0]){ if(backend.isURI(r)){ contexts.add(r); paramIndex = 1;
@SafeVarargs @Override public final Collection<Node> apply(RDFBackend<Node> backend, Node context, Collection<Node>... args) throws IllegalArgumentException { if (args.length != 3 || args[1].size() != 1 || args[2].size() != 1) { throw new IllegalArgumentException("wrong usage: " + getSignature()); } Collection<Node> nodes = args[0]; String regex = transformer.transform(backend, args[1].iterator().next(), null); String replace = transformer.transform(backend, args[2].iterator().next(), null); try { final Pattern pattern = Pattern.compile(regex); Set<Node> result = new HashSet<>(); for (Node node : nodes) { final String string = backend.stringValue(node); final String replaced = pattern.matcher(string).replaceAll(replace); if (backend.isURI(node)) { result.add(backend.createURI(replaced)); } else if (backend.isLiteral(node)) { final Locale lang = backend.getLiteralLanguage(node); final URI type = backend.getLiteralType(node); result.add(backend.createLiteral(replaced, lang, type)); } } return result; } catch (PatternSyntaxException pex) { throw new IllegalArgumentException("could not parse regex pattern: '" + regex + "'", pex); } catch (IndexOutOfBoundsException iobex) { throw new IllegalArgumentException("invalid replacement string: '" + replace + "'"); } }
final String string = transformer.transform(rdfBackend, n, null); final Document jsoup = Jsoup.parse(string); if (rdfBackend.isURI(context)) { jsoup.setBaseUri(rdfBackend.stringValue(context));
final String string = transformer.transform(rdfBackend, n, null); final Document jsoup = Jsoup.parse(string); if (rdfBackend.isURI(context)) { jsoup.setBaseUri(rdfBackend.stringValue(context));
final String string = transformer.transform(rdfBackend, n, null); final Document jsoup = Jsoup.parse(string); if (rdfBackend.isURI(context)) { jsoup.setBaseUri(rdfBackend.stringValue(context));
if(backend.isURI(value)){ result.addReference(entry.getKey(), backend.stringValue(value)); } else if(backend.isLiteral(value)){ //literal
if(backend.isURI(value)){ result.addReference(entry.getKey(), backend.stringValue(value)); } else if(backend.isLiteral(value)){ //literal