/** * 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) { return Collections.singleton(rdfBackend.createLiteral(constant)); }
/** * 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; } }
@Override public Duration transform(RDFBackend<Node> backend, Node node, Map<String, String> configuration) throws IllegalArgumentException { if(backend.isLiteral(node)) { return toDuration(backend.stringValue(node), false); } else { throw new IllegalArgumentException("cannot transform node of type "+ node.getClass().getCanonicalName()+" to byte"); } }
private Collection<Node> getFromContainer(RDFBackend<Node> backend, Node node, int index) { return backend.listObjects(node, backend.createURI(RDF + "_" + (index + 1))); }
@Override public BigDecimal transform(RDFBackend<Node> backend, Node node, Map<String, String> configuration) throws IllegalArgumentException { if(backend.isLiteral(node)) { return backend.decimalValue(node); } else { throw new IllegalArgumentException("cannot transform node of type "+node.getClass().getCanonicalName()+" to BigDecimal"); } } }
@Override public BigInteger transform(RDFBackend<Node> backend, Node node, Map<String, String> configuration) throws IllegalArgumentException { if(backend.isLiteral(node)) { return backend.integerValue(node); } else { throw new IllegalArgumentException("cannot transform node of type "+node.getClass().getCanonicalName()+" to BigInteger"); } } }
@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)); result.add(rdfBackend.createLiteral(r));
@SafeVarargs @Override public final Collection<Node> apply(RDFBackend<Node> backend, Node context, Collection<Node>... args) throws IllegalArgumentException { try { if (args.length != 2) { throw new IllegalArgumentException("LdPath function " + getLocalName() + " requires 2 arguments"); } if (args[1].size() != 1) { throw new IllegalArgumentException("len argument must be a single literal for function " + getLocalName()); } final Collection<Node> nodes = args[0]; final int length = Math.max(backend.intValue(args[1].iterator().next()), 0); final Collection<Node> result = new LinkedList<>(); for (Node node : nodes) { final String str = backend.stringValue(node); result.add(backend.createLiteral(str.substring(Math.max(0, str.length() - length)))); } return result; } catch (NumberFormatException | ArithmeticException nfe) { throw new IllegalArgumentException(nfe); } }
@SafeVarargs @Override public final Collection<Node> apply(RDFBackend<Node> backend, Node context, Collection<Node>... args) throws IllegalArgumentException { Preconditions.checkArgument(args.length == 1, "Check usage: " + getSignature()); LinkedList<Node> result = new LinkedList<>(); for (Node node : args[0]) { final String stringValue = backend.stringValue(node); final int c = stringValue.length(); result.add(backend.createLiteral(String.valueOf(c), null, dataType)); } 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(); } }
/** * 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(); } }
/** * Transform the KiWiNode node into the datatype T. In case the node cannot be transformed to * the respective datatype, throws an IllegalArgumentException that needs to be caught by the class * carrying out the transformation. * * * @param backend * @param node * @return */ @Override public String transform(RDFBackend<Node> backend, Node node, Map<String, String> configuration) throws IllegalArgumentException { return backend.stringValue(node); } }
/** * 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 node) throws IllegalArgumentException { if(rdfBackend.isLiteral(node)) { if(lang != null && !lang.toLowerCase().equals("none")) { return new Locale(lang).equals(rdfBackend.getLiteralLanguage(node)); } else { return rdfBackend.getLiteralLanguage(node) == null; } } 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 node) throws IllegalArgumentException { if(rdfBackend.isLiteral(node)) { if(typeUri != null) { return typeUri.equals(rdfBackend.getLiteralType(node)); } else { // FIXME: MARMOTTA-39 return null == rdfBackend.getLiteralType(node); } } else { return false; } }
/** * Transform the KiWiNode node into the datatype T. In case the node cannot be transformed to * the respective datatype, throws an IllegalArgumentException that needs to be caught by the class * carrying out the transformation. * * * @param rdfBackend * @param node * @return */ @Override public Double transform(RDFBackend<Node> rdfBackend, Node node, Map<String, String> configuration) throws IllegalArgumentException { if(rdfBackend.isLiteral(node)) { return rdfBackend.doubleValue(node); } else { throw new IllegalArgumentException("cannot transform node of type "+node.getClass().getCanonicalName()+" to double"); } } }
/** * Transform the KiWiNode node into the datatype T. In case the node cannot be transformed to * the respective datatype, throws an IllegalArgumentException that needs to be caught by the class * carrying out the transformation. * * * @param rdfBackend * @param node * @return */ @Override public Integer transform(RDFBackend<Node> rdfBackend, Node node, Map<String, String> configuration) throws IllegalArgumentException { if(rdfBackend.isLiteral(node)) { return rdfBackend.intValue(node); } else { throw new IllegalArgumentException("cannot transform node of type "+node.getClass().getCanonicalName()+" to integer"); } } }
contexts = new ArrayList<RDFTerm>(); for(RDFTerm r : args[0]){ if(backend.isURI(r)){ contexts.add(r); paramIndex = 1;
/** * Transform the KiWiNode node into the datatype T. In case the node cannot be transformed to * the respective datatype, throws an IllegalArgumentException that needs to be caught by the class * carrying out the transformation. * * * @param rdfBackend * @param node * @return */ @Override public Long transform(RDFBackend<Node> rdfBackend, Node node, Map<String, String> configuration) throws IllegalArgumentException { if(rdfBackend.isLiteral(node)) { return rdfBackend.longValue(node); } else { throw new IllegalArgumentException("cannot transform node of type "+node.getClass().getCanonicalName()+" to long"); } } }
/** * Transform the KiWiNode node into the datatype T. In case the node cannot be transformed to * the respective datatype, throws an IllegalArgumentException that needs to be caught by the class * carrying out the transformation. * * * @param rdfBackend * @param node * @return */ @Override public Date transform(RDFBackend<Node> rdfBackend, Node node, Map<String, String> configuration) throws IllegalArgumentException { if(rdfBackend.isLiteral(node)) { return rdfBackend.dateTimeValue(node); } else { throw new IllegalArgumentException("could not parse node, because it is not a literal"); } } }