コード例 #1
0
 public StructuredRetrieval(StructuredIndex index, Parameters factoryParameters) {
   this.index = index;
   Parameters featureParameters = factoryParameters.clone();
   featureParameters.add("collectionLength", Long.toString(index.getCollectionLength()));
   featureParameters.add("documentCount", Long.toString(index.getDocumentCount()));
   featureFactory = new FeatureFactory(featureParameters);
 }
コード例 #2
0
  /**
   * Evaluates a query.
   *
   * @param queryTree A query tree that has been already transformed with
   *     StructuredRetrieval.transformQuery.
   * @param requested The number of documents to retrieve, at most.
   * @return
   * @throws java.lang.Exception
   */
  public ScoredDocument[] runQuery(Node queryTree, int requested) throws Exception {

    // my addition
    queryTree = this.transformQuery(queryTree);

    // System.out.println("runQuery: " + queryTree.toString());

    // construct the query iterators
    ScoreIterator iterator = (ScoreIterator) createIterator(queryTree);

    // now there should be an iterator at the root of this tree
    PriorityQueue<ScoredDocument> queue = new PriorityQueue<ScoredDocument>();

    while (!iterator.isDone()) {
      int document = iterator.nextCandidate();
      int length = index.getLength(document);
      double score = iterator.score(document, length);

      if (queue.size() <= requested || queue.peek().score < score) {
        ScoredDocument scoredDocument = new ScoredDocument(document, score);
        queue.add(scoredDocument);

        if (queue.size() > requested) {
          queue.poll();
        }
      }

      iterator.movePast(document);
    }

    return getArrayResults(queue);
  }
コード例 #3
0
 public NodeType getNodeType(Node node) throws Exception {
   NodeType nodeType = index.getNodeType(node);
   if (nodeType == null) {
     nodeType = featureFactory.getNodeType(node);
   }
   return nodeType;
 }
コード例 #4
0
  public StructuredIterator createIterator(Node node) throws Exception {
    ArrayList<StructuredIterator> internalIterators = new ArrayList<StructuredIterator>();

    for (Node internalNode : node.getInternalNodes()) {
      StructuredIterator internalIterator = createIterator(internalNode);
      internalIterators.add(internalIterator);
    }

    StructuredIterator iterator = index.getIterator(node);
    if (iterator == null) {
      iterator = featureFactory.getIterator(node, internalIterators);
    }

    return iterator;
  }
コード例 #5
0
 public void close() throws IOException {
   index.close();
 }
コード例 #6
0
 public String getDocumentName(int document) {
   return index.getDocumentName(document);
 }