private CountQuery(final String name, final Properties properties, @Nullable final Template condition) { super(name, properties, condition.getVariables(), ImmutableList.of("size")); this.layer = (URI) Statements.parseValue(properties.getProperty("layer")); this.condition = condition; }
private LookupQuery(final String name, final Properties properties, @Nullable final Template id) { super(name, properties, id.getVariables(), ImmutableList.of("size")); List<URI> props = null; if (properties.containsKey("properties")) { props = Lists.newArrayList(); for (final String token : Splitter.onPattern("[ ,;]").omitEmptyStrings() .trimResults().split(properties.getProperty("properties"))) { props.add((URI) Statements.parseValue(token)); } } this.layer = (URI) Statements.parseValue(properties.getProperty("layer"), Namespaces.DEFAULT); this.id = id; this.properties = props; }
private RetrieveQuery(final String name, final Properties properties, @Nullable final Template condition) { super(name, properties, condition.getVariables(), ImmutableList.of("size")); final String offset = properties.getProperty("offset"); final String limit = properties.getProperty("limit"); List<URI> props = null; if (properties.containsKey("properties")) { props = Lists.newArrayList(); for (final String token : Splitter.onPattern("[ ,;]").omitEmptyStrings() .trimResults().split(properties.getProperty("properties"))) { props.add((URI) Statements.parseValue(token)); } } this.layer = (URI) Statements.parseValue(properties.getProperty("layer"), Namespaces.DEFAULT); this.condition = condition; this.offset = offset == null ? null : Long.parseLong(offset); this.limit = limit == null ? null : Long.parseLong(limit); this.properties = props; }
public static BindingSet decode(final List<String> variables, final String line) { final String[] tokens = line.split("\t"); Preconditions.checkArgument(tokens.length == variables.size(), "Wrong number of values (" + tokens.length + " found, " + variables.size() + " expected) in line: " + line); try { final MapBindingSet bindings = new MapBindingSet(); for (int i = 0; i < tokens.length; ++i) { String token = tokens[i]; if (!Strings.isNullOrEmpty(token)) { final char ch = token.charAt(0); token = ch == '\'' || ch == '"' || ch == '<' || ch == '_' ? token : "\"" + token + "\""; final Value value = Statements.parseValue(token, Namespaces.DEFAULT); bindings.addBinding(variables.get(i), value); } } return bindings; } catch (final Throwable ex) { throw new IllegalArgumentException("Could not parse variable values.\nVariables: " + variables + "\nLine: " + line, ex); } }
final int end = parseURI(string, i); if (end >= 0) { final URI u = (URI) Statements.parseValue(string.substring(i, end)); builder.append("__iri(").append(counter.getAndIncrement()) .append(", \"").append(u.stringValue()).append("\")"); final int end = parseQName(string, i); if (end >= 0) { final URI u = (URI) Statements.parseValue(string.substring(i, end), Namespaces.DEFAULT); builder.append("__iri(").append(counter.getAndIncrement())
base = base == null ? null : Statements.parseValue(base.contains(":") ? base : base + ":", Namespaces.DEFAULT).stringValue(); final int index = token.indexOf('='); if (index >= 0) { bindings.addBinding(token.substring(0, index).trim(), Statements.parseValue(token .substring(index + 1).trim(), Namespaces.DEFAULT)); if (options.hasOption("G")) { final String u = options.getOptionArg("G", String.class); globalURI = (URI) Statements.parseValue(u.contains(":") ? u // : u + ":", Namespaces.DEFAULT); emitStatic = true; final String ctx = options.getOptionArg("c", String.class); staticContext = (URI) Statements.parseValue(ctx.contains(":") ? ctx // : ctx + ":", Namespaces.DEFAULT);
@Override void doEvaluate(final Session session, final BindingSet input, final MapBindingSet output) throws Throwable { final URI id = (URI) Statements.parseValue(this.id.instantiate(input), Namespaces.DEFAULT); long size = 0L; try (final Representation representation = session.download(id) .caching(this.caching).timeout(getTimeout()).exec()) { if (representation != null) { size = representation.writeToByteArray().length; } else { LOGGER.warn("No results for DOWNLOAD request, id " + id); } } catch (final Throwable ex) { throw new RuntimeException("Failed DOWNLOAD, id " + TestUtil.format(id) + ", caching " + this.caching, ex); } finally { output.addBinding("size", FACTORY.createLiteral(size)); } } }
@Override void doEvaluate(final Session session, final BindingSet input, final MapBindingSet output) throws Throwable { final URI id = (URI) Statements.parseValue(this.id.instantiate(input), Namespaces.DEFAULT); long numTriples = 0L; try { final Stream<Record> stream = session.retrieve(this.layer).ids(id) .properties(this.properties).exec(); numTriples = Record.encode(stream, ImmutableList.of(this.layer)).count(); if (numTriples == 0) { LOGGER.warn("No results for LOOKUP request, layer " + TestUtil.format(this.layer) + ", id " + id); } } catch (final Throwable ex) { throw new RuntimeException("Failed LOOKUP " + TestUtil.format(this.layer) + ", id " + TestUtil.format(id) + ", properties " + this.properties, ex); } finally { output.addBinding("size", FACTORY.createLiteral(numTriples)); } }
@Override void doEvaluate(final Session session, final BindingSet input, final MapBindingSet output) throws Throwable { final URI id = (URI) Statements.parseValue(this.id.instantiate(input), Namespaces.DEFAULT); long numTriples = 0L; try { numTriples += Record.encode(session.retrieve(KS.RESOURCE).ids(id).exec(), ImmutableList.of(KS.RESOURCE)).count(); numTriples += Record.encode( session.retrieve(KS.MENTION).condition("ks:mentionOf = $$", id) .limit(100000L).exec(), ImmutableList.of(KS.MENTION)).count(); if (numTriples == 0) { LOGGER.warn("No results for LOOKUP ALL request, id " + id); } } catch (final Throwable ex) { throw new RuntimeException("Failed LOOKUP ALL, id " + TestUtil.format(id), ex); } finally { output.addBinding("size", FACTORY.createLiteral(numTriples)); } } }