コード例 #1
0
ファイル: TextQueryPF.java プロジェクト: enderunal/jena
  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
ファイル: listLength.java プロジェクト: hmottestad/jena
 private QueryIterator length(
     Binding binding, Graph graph, Node listNode, Var varLength, ExecutionContext execCxt) {
   int x = GraphList.length(new GNode(graph, listNode));
   if (x < 0) return IterLib.noResults(execCxt);
   Node n = NodeFactoryExtra.intToNode(x);
   return IterLib.oneResult(binding, varLength, n, execCxt);
 }
コード例 #3
0
ファイル: listLength.java プロジェクト: hmottestad/jena
  private QueryIterator verify(
      Binding binding, Graph graph, Node listNode, Node length, ExecutionContext execCxt) {
    int x = GraphList.length(new GNode(graph, listNode));
    int len = NodeFactoryExtra.nodeToInt(length);

    if (x == len) return IterLib.result(binding, execCxt);
    return IterLib.noResults(execCxt);
  }
コード例 #4
0
ファイル: TextQueryPF.java プロジェクト: enderunal/jena
  /**
   * Deconstruct the node or list object argument and make a StrMatch The 'executionTime' flag
   * indciates whether this is for a build time static check, or for runtime execution.
   */
  private StrMatch objectToStruct(PropFuncArg argObject, boolean executionTime) {
    EntityDefinition docDef = textIndex.getDocDef();
    if (argObject.isNode()) {
      Node o = argObject.getArg();
      if (!o.isLiteral()) {
        if (executionTime) log.warn("Object to text query is not a literal");
        return null;
      }

      RDFDatatype dt = o.getLiteralDatatype();
      if (dt != null && dt != XSDDatatype.XSDstring) {
        log.warn("Object to text query is not a string");
        return null;
      }

      String qs = o.getLiteralLexicalForm();
      return new StrMatch(null, qs, -1, 0);
    }

    List<Node> list = argObject.getArgList();
    if (list.size() == 0 || list.size() > 3)
      throw new TextIndexException("Change in object list size");

    Node predicate = null;
    String field = null; // Do not prepend the field name - rely on default field
    int idx = 0;
    Node x = list.get(0);
    // Property?
    if (x.isURI()) {
      predicate = x;
      idx++;
      if (idx >= list.size())
        throw new TextIndexException("Property specificed but no query string : " + list);
      x = list.get(idx);
      field = docDef.getField(predicate);
      if (field == null) {
        log.warn("Predicate not indexed: " + predicate);
        return null;
      }
    }

    // String!
    if (!x.isLiteral()) {
      if (executionTime) log.warn("Text query string is not a literal " + list);
      return null;
    }

    if (x.getLiteralDatatype() != null && !x.getLiteralDatatype().equals(XSDDatatype.XSDstring)) {
      log.warn("Text query is not a string " + list);
      return null;
    }
    String queryString = x.getLiteralLexicalForm();
    idx++;

    int limit = -1;
    float score = 0;

    if (idx < list.size()) {
      // Limit?
      x = list.get(idx);
      idx++;
      if (!x.isLiteral()) {
        if (executionTime) log.warn("Text query limit is not an integer " + x);
        return null;
      }

      int v = NodeFactoryExtra.nodeToInt(x);
      limit = (v < 0) ? -1 : v;
    }

    String qs = queryString;
    if (field != null) qs = field + ":" + qs;

    return new StrMatch(predicate, qs, limit, score);
  }