예제 #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;
  }
예제 #2
0
 /**
  * Choose a graph from a DatasetGraph. If it's the union, provide a union graph (not always the
  * best way to deal with union).
  *
  * @param dataset
  * @param graphNode
  * @return Graph
  */
 protected static Graph chooseGraph(DatasetGraph dataset, Node graphNode) {
   if (graphNode == null) return dataset.getDefaultGraph();
   else if (Var.isVar(graphNode))
     throw new NotImplemented("Choosing a graph OpExecutorStage.executeBlockFilter[Variable]");
   else if (graphNode == Node.ANY)
     throw new NotImplemented("OpExecutorMain.executeBlockFilter[Node.ANY]");
   else if (Quad.isUnionGraph(graphNode)) {
     // TODO Check this!  Work needed here to consolidate union graph handling.
     List<Node> graphs = Iter.toList(dataset.listGraphNodes());
     return new GraphUnionRead(dataset, graphs);
   } else return dataset.getGraph(graphNode);
 }
예제 #3
0
  @Override
  public QueryIterator exec(
      Binding binding,
      PropFuncArg argSubject,
      Node predicate,
      PropFuncArg argObject,
      ExecutionContext execCxt) {
    if (textIndex == null) {
      if (!warningIssued) {
        Log.warn(getClass(), "No text index - no text search performed");
        warningIssued = true;
      }
      // Not a text dataset - no-op
      return IterLib.result(binding, execCxt);
    }

    DatasetGraph dsg = execCxt.getDataset();

    argSubject = Substitute.substitute(argSubject, binding);
    argObject = Substitute.substitute(argObject, binding);

    Node s = null;
    Node score = null;
    Node literal = null;

    if (argSubject.isList()) {
      // Length checked in build()
      s = argSubject.getArg(0);
      score = argSubject.getArg(1);

      if (!score.isVariable())
        throw new QueryExecException("Hit score is not a variable: " + argSubject);

      if (argSubject.getArgListSize() > 2) {
        literal = argSubject.getArg(2);
        if (!literal.isVariable())
          throw new QueryExecException("Hit literal is not a variable: " + argSubject);
      }
    } else {
      s = argSubject.getArg();
    }

    if (s.isLiteral())
      // Does not match
      return IterLib.noResults(execCxt);

    StrMatch match = objectToStruct(argObject, true);
    if (match == null) {
      // can't match
      return IterLib.noResults(execCxt);
    }

    // ----

    QueryIterator qIter =
        (Var.isVar(s))
            ? variableSubject(binding, s, score, literal, match, execCxt)
            : concreteSubject(binding, s, score, literal, match, execCxt);
    if (match.getLimit() >= 0) qIter = new QueryIterSlice(qIter, 0, match.getLimit(), execCxt);
    return qIter;
  }