Пример #1
0
 public Sequence evalQuery(NodeSet nodes, List terms) throws XPathException {
   if (terms == null || terms.size() == 0) return Sequence.EMPTY_SEQUENCE; // no search terms
   double threshold = 0.65;
   if (getArgumentCount() == 3) {
     Sequence thresOpt = getArgument(2).eval(nodes);
     // TODO : get rid of getLength()
     if (!thresOpt.hasOne())
       throw new XPathException(
           getASTNode(), "third argument to " + getName() + "should be a single double value");
     threshold = ((DoubleValue) thresOpt.convertTo(Type.DOUBLE)).getDouble();
   }
   NodeSet hits[] = new NodeSet[terms.size()];
   String term;
   TermMatcher matcher;
   for (int k = 0; k < terms.size(); k++) {
     term = (String) terms.get(k);
     if (term.length() == 0) hits[k] = null;
     else {
       matcher = new FuzzyMatcher(term, threshold);
       hits[k] =
           context
               .getBroker()
               .getTextEngine()
               .getNodes(
                   context,
                   nodes.getDocumentSet(),
                   nodes,
                   NodeSet.ANCESTOR,
                   null,
                   matcher,
                   term.substring(0, 1));
     }
   }
   return mergeResults(hits);
 }
Пример #2
0
  public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
    if (context.getProfiler().isEnabled()) {
      context.getProfiler().start(this);
      context
          .getProfiler()
          .message(
              this,
              Profiler.DEPENDENCIES,
              "DEPENDENCIES",
              Dependency.getDependenciesName(this.getDependencies()));
      if (contextSequence != null)
        context
            .getProfiler()
            .message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
      if (contextItem != null)
        context
            .getProfiler()
            .message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
    }

    if (contextItem != null) contextSequence = contextItem.toSequence();

    Sequence result;
    Sequence arg = null;
    if (getSignature().getArgumentCount() == 1) arg = getArgument(0).eval(contextSequence);
    else arg = contextSequence;

    if (arg == null) throw new XPathException(getASTNode(), "XPDY0002: Undefined context item");

    if (arg.isEmpty()) result = DoubleValue.NaN;
    else {
      try {
        result = arg.convertTo(Type.DOUBLE);
      } catch (XPathException e) {
        result = DoubleValue.NaN;
      }
    }

    if (context.getProfiler().isEnabled()) context.getProfiler().end(this, "", result);

    return result;
  }