@Override public Binding getBinding(final String bindingName) { return set.getBinding(bindingName); }
private BindingSet removeConstants(BindingSet bs) { QueryBindingSet bSet = new QueryBindingSet(); for (String s : bs.getBindingNames()) { if (!VarNameUtils.isConstant(s)) { bSet.addBinding(bs.getBinding(s)); } } return bSet; }
public RepositoryMusicArtist (final @Nonnull Repository repository, final @Nonnull BindingSet bindingSet) { super(repository, bindingSet, "artist"); type = toInteger(bindingSet.getBinding("artist_type")).orElse(1); }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ public RepositoryEntitySupport (final @Nonnull Repository repository, final @Nonnull BindingSet bindingSet, final @Nonnull String idName) { this(repository, bindingSet, idName, toString(bindingSet.getBinding("label")).orElse("")); }
public RepositoryRecord (final @Nonnull Repository repository, final @Nonnull BindingSet bindingSet) { super(repository, bindingSet, "record"); diskNumber = toInteger(bindingSet.getBinding("disk_number")); diskCount = toInteger(bindingSet.getBinding("disk_count")); trackCount = toInteger(bindingSet.getBinding("track_count")); asin = toString(bindingSet.getBinding("asin")); gtin = toString(bindingSet.getBinding("gtin")); }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ public RepositoryEntitySupport (final @Nonnull Repository repository, final @Nonnull BindingSet bindingSet, final @Nonnull String idName, final @Nonnull String rdfsLabel) { this.repository = repository; this.id = new Id(toString(bindingSet.getBinding(idName)).get()); this.rdfsLabel = rdfsLabel; this.fallback = toId(bindingSet.getBinding("fallback")); this.source = toId(Optional.ofNullable(bindingSet.getBinding("source")) .orElse(bindingSet.getBinding("fallback"))); }
private String formatLine(final BindingSet bs, final List<String> bindings) { final List<String> bindingValues = new ArrayList<>(); for(final String bindingName : bindings) { bindingValues.add(bs.getBinding(bindingName).getValue().toString()); } return Strings.join(bindingValues, ","); } }
public RepositoryMusicPerformer (final @Nonnull Repository repository, final @Nonnull BindingSet bindingSet) { this.musicArtist = new RepositoryMusicArtist(repository, bindingSet); final Optional<String> r = Optional.of(bindingSet.getBinding("role").getValue().stringValue() .replaceAll(BMMO.NS + "performer_", "")); this.role = r.map(RepositoryMusicPerformerRole::new); }
/** * A utility function that helps construct the keys used by {@link KeyValueAggregationStateStore}. * * @param vars - Which variables within the binding set to use for the key's values. (not null) * @param bindingSet - The binding set the key is being constructed from. (not null) * @return A comma delimited list of the binding values, leading with the side. */ private static String makeCommaDelimitedValues(final List<String> vars, final BindingSet bindingSet) { requireNonNull(vars); requireNonNull(bindingSet); // Make a an ordered list of the binding set variables. final List<String> values = new ArrayList<>(); for(final String var : vars) { values.add( bindingSet.hasBinding(var) ? bindingSet.getBinding(var).getValue().toString() : "" ); } // Return a comma delimited list of those values. return Joiner.on(",").join(values); } }
private BindingSet calcKey(BindingSet bindings, Set<String> commonVars) { QueryBindingSet q = new QueryBindingSet(); for (String varName : commonVars) { Binding b = bindings.getBinding(varName); if (b != null) { q.addBinding(b); } } return q; }
private BindingSet calcKey(BindingSet bindings, Set<String> commonVars) { QueryBindingSet q = new QueryBindingSet(); for (String varName : commonVars) { Binding b = bindings.getBinding(varName); if (b != null) { q.addBinding(b); } } return q; }
public RepositoryAudioFile (final @Nonnull Repository repository, final @Nonnull BindingSet bindingSet) { super(repository, bindingSet, "audioFile", rdfsLabelOf(bindingSet.getBinding("path").getValue().stringValue())); this.path = toPath(bindingSet.getBinding("path")); this.duration = toDuration(bindingSet.getBinding("duration")); this.fileSize = toLong(bindingSet.getBinding("fileSize")); this.trackId = toId(bindingSet.getBinding("track")); this.metadata = new MetadataSupport(path).with(TITLE, rdfsLabel) .with(DURATION, duration) .with(FILE_SIZE, fileSize) .withFallback(key -> fallbackMetadata.get(this::loadFallbackMetadata)); }
@Override protected boolean accept(BindingSet bindings) throws QueryEvaluationException { Binding b = bindings.getBinding(TIMESTAMP_BINDING_NAME); //push back actual time if the timestamp binding is not provided timestampBinding.v = b == null ? SimpleValueFactory.getInstance().createLiteral(System.currentTimeMillis()) : b.getValue(); return true; } };
public RepositoryTrack (final @Nonnull Repository repository, final @Nonnull BindingSet bindingSet) { super(repository, bindingSet, "track"); audioFilePath = toPath(bindingSet.getBinding("path")); duration = toDuration(bindingSet.getBinding("duration")); trackNumber = toInteger(bindingSet.getBinding("track_number")); diskNumber = toInteger(bindingSet.getBinding("disk_number")); diskCount = toInteger(bindingSet.getBinding("disk_count")); // this.recordRdfsLabel = toString(bindingSet.getBinding("record_label")); metadata = new MetadataSupport(audioFilePath).with(DURATION, duration) .with(TRACK_NUMBER, trackNumber) .with(DISK_NUMBER, diskNumber) .with(DISK_COUNT, diskCount); audioFile = new Memoize<>(() -> new RepositoryAudioFile(repository, bindingSet)); }
@Override public String convert(final BindingSet bindingSet, final VariableOrder varOrder) { requireNonNull(bindingSet); requireNonNull(varOrder); // Convert each Binding to a String. final List<String> bindingStrings = new ArrayList<>(); for(final String varName : varOrder) { if(bindingSet.hasBinding(varName)) { // Add a value to the binding set. final Value value = bindingSet.getBinding(varName).getValue(); final RyaType ryaValue = RdfToRyaConversions.convertValue(value); final String bindingString = ryaValue.getData() + TYPE_DELIM + ryaValue.getDataType(); bindingStrings.add(bindingString); } else { // Add a null value to the binding set. bindingStrings.add(NULL_VALUE_STRING); } } // Join the bindings using the binding delim. return Joiner.on(BINDING_DELIM).join(bindingStrings); }
/** * Create a new {@link BindingSet} that only includes the bindings whose names appear within the {@code variableOrder}. * If no binding is found for a variable, then that binding is just omitted from the resulting object. * * @param variableOrder - Defines which bindings will be kept. (not null) * @param bindingSet - Contains the source {@link Binding}s. (not null) * @return A new {@link BindingSet} containing only the specified bindings. */ public static BindingSet keepBindings(final VariableOrder variableOrder, final BindingSet bindingSet) { requireNonNull(variableOrder); requireNonNull(bindingSet); final MapBindingSet result = new MapBindingSet(); for(final String bindingName : variableOrder) { if(bindingSet.hasBinding(bindingName)) { final Binding binding = bindingSet.getBinding(bindingName); result.addBinding(binding); } } return result; } }
static Value value(BindingSet s, String bindingName) { Binding b = s.getBinding(bindingName); return b == null ? null : b.getValue(); }
@Override public void addStatement(UpdateContext op, Resource subj, IRI pred, Value obj, Resource... contexts) throws SailException { BindingSet bs; Binding b; Value v; long timestamp = (op != null && (bs = op.getBindingSet()) != null && (b = bs.getBinding(TIMESTAMP_CALLBACK_BINDING_NAME)) != null) ? longValueOfTimeStamp((Literal) b.getValue()) : System.currentTimeMillis(); for (Resource ctx : normalizeContexts(contexts)) { addStatementInternal(subj, pred, obj, ctx, timestamp); } }
@Override public void removeStatement(UpdateContext op, Resource subj, IRI pred, Value obj, Resource... contexts) throws SailException { BindingSet bs; Binding b; Value v; long timestamp = (op != null && (bs = op.getBindingSet()) != null && (b = bs.getBinding(TIMESTAMP_CALLBACK_BINDING_NAME)) != null) ? longValueOfTimeStamp((Literal) b.getValue()) : System.currentTimeMillis(); try { for (Resource ctx : normalizeContexts(contexts)) { for (KeyValue kv : HalyardTableUtils.toKeyValues(subj, pred, obj, ctx, true, timestamp)) { //calculate the kv's corresponding to the quad (or triple) delete(kv); } } } catch (IOException e) { throw new SailException(e); } }
@Test @Category(TestSuites.Prepush.class) public void tripleIds_rfe10177() throws Exception { BNode bnode = vf.createBNode(); IRI foo = vf.createIRI("http://Foo"); conn.add(bnode, RDF.TYPE, foo); conn.add(foo, foo, foo); String queryString = "(select (?id) (q ?s !rdf:type ?o ?g ?id))"; AGTupleQuery q = conn.prepareTupleQuery(AGQueryLanguage.PROLOG, queryString); TupleQueryResult r = q.evaluate(); Assert.assertTrue("Expected a result", r.hasNext()); Value id = r.next().getBinding("id").getValue(); Assert.assertFalse("Unexpected second result", r.hasNext()); RepositoryResult<Statement> stmts = conn.getStatements(id.stringValue()); Assert.assertTrue("Expected a match", stmts.hasNext()); Assert.assertEquals("Expected rdf:type", RDF.TYPE, stmts.next().getPredicate()); Assert.assertFalse("Unexpected second match", stmts.hasNext()); }