Esempio n. 1
0
  private QueryIterator resultsToQueryIterator(
      Binding binding,
      Node s,
      Node score,
      Node literal,
      Collection<TextHit> results,
      ExecutionContext execCxt) {
    Var sVar = Var.isVar(s) ? Var.alloc(s) : null;
    Var scoreVar = (score == null) ? null : Var.alloc(score);
    Var literalVar = (literal == null) ? null : Var.alloc(literal);

    Function<TextHit, Binding> converter =
        (TextHit hit) -> {
          if (score == null && literal == null)
            return sVar != null
                ? BindingFactory.binding(binding, sVar, hit.getNode())
                : BindingFactory.binding(binding);
          BindingMap bmap = BindingFactory.create(binding);
          if (sVar != null) bmap.add(sVar, hit.getNode());
          if (scoreVar != null) bmap.add(scoreVar, NodeFactoryExtra.floatToNode(hit.getScore()));
          if (literalVar != null) bmap.add(literalVar, hit.getLiteral());
          return bmap;
        };

    Iterator<Binding> bIter = Iter.map(results.iterator(), converter);
    QueryIterator qIter = new QueryIterPlainWrapper(bIter, execCxt);
    return qIter;
  }
Esempio n. 2
0
  private Triple resolveTriple(final Triple t, final Binding values) {
    int idx = variables.indexOf(t.getSubject());

    final Node s = idx == -1 ? t.getSubject() : values.get(Var.alloc(variables.get(idx)));

    idx = variables.indexOf(t.getPredicate());
    final Node p = idx == -1 ? t.getPredicate() : values.get(Var.alloc(variables.get(idx)));
    idx = variables.indexOf(t.getObject());
    final Node o = idx == -1 ? t.getObject() : values.get(Var.alloc(variables.get(idx)));
    return new Triple(s, p, o);
  }
Esempio n. 3
0
  @Override
  public QueryIterator execEvaluated(
      final Binding binding,
      PropFuncArg argSubject,
      Node predicate,
      PropFuncArg argObject,
      ExecutionContext execCxt) {
    // check subject is a variable.
    if (!argSubject.getArg().isVariable()) throw new QueryExecException("Subject not a variable");

    final Var var = Var.alloc(argSubject.getArg());

    if (!argObject.getArg().isLiteral()) throw new QueryExecException("Subject not a literal");

    String searchTerm = argObject.getArg().getLiteralLexicalForm();
    Search search = searchEngine();
    Iterator<String> x = search.search(searchTerm);
    Iter<String> iter = Iter.iter(x);
    QueryIterator qIter =
        new QueryIterPlainWrapper(
            iter.map(
                (item) -> {
                  return BindingFactory.binding(binding, var, NodeFactory.createURI(item));
                }));
    return qIter;
  }
Esempio n. 4
0
  @Test
  public void testSetVars() {
    Var v = Var.alloc("v");
    Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v);
    handler.addConstruct(t);
    Template template = query.getConstructTemplate();
    assertNotNull(template);
    List<Triple> lst = template.getTriples();
    assertEquals(1, lst.size());
    assertEquals(t, lst.get(0));

    Map<Var, Node> values = new HashMap<Var, Node>();
    values.put(v, NodeFactory.createURI("three"));
    handler.setVars(values);

    template = query.getConstructTemplate();
    assertNotNull(template);
    lst = template.getTriples();
    assertEquals(1, lst.size());
    t =
        new Triple(
            NodeFactory.createURI("one"),
            NodeFactory.createURI("two"),
            NodeFactory.createURI("three"));
    assertEquals(t, lst.get(0));
  }
Esempio n. 5
0
  @Override
  public QueryIterator execOneList(
      Binding binding, Node listNode, Node predicate, Node length, ExecutionContext execCxt) {
    Graph graph = execCxt.getActiveGraph();
    if (Var.isVar(listNode))
      throw new ARQInternalErrorException("listLength: Subject is a variable");
    // Case : arg 1 (the list) is bound and arg 2 not bound => generate possibilities
    // Case : arg 1 is bound and arg 2 is bound => test for membership.

    if (Var.isVar(length)) return length(binding, graph, listNode, Var.alloc(length), execCxt);
    else return verify(binding, graph, listNode, length, execCxt);
  }
Esempio n. 6
0
 @Override
 protected QueryIterator execObjectBound(
     Binding binding, Var listVar, Node predicate, Node length, ExecutionContext execCxt) {
   Graph graph = execCxt.getActiveGraph();
   return length(binding, graph, listVar, Var.alloc(length), execCxt);
 }