Package org.terrier.structures.postings

Examples of org.terrier.structures.postings.IterablePosting


    // and the corresponding query term array index (low byte)
        final LongPriorityQueue postingHeap = new LongHeapPriorityQueue();
   
    final int queryLength = queryTermsToMatchList.size();
    // The posting list iterator array (one per term) and initialization
    IterablePosting postingListArray[] = new IterablePosting[queryLength];
        for (int i = 0; i < queryLength; i++) {
      LexiconEntry           lexiconEntry = queryTermsToMatchList.get(i).getValue();
      if(logger.isDebugEnabled()) logger.debug((i + 1) + ": " + queryTermStrings[i].trim() + " with " + lexiconEntry.getDocumentFrequency() + " documents (TF is " + lexiconEntry.getFrequency() + ").");
      postingListArray[i] = invertedIndex.getPostings((BitIndexPointer)lexiconEntry);
      postingListArray[i].next();
      long docid = postingListArray[i].getId();
      assert(docid != -1);
      postingHeap.enqueue((docid << 32) + i);
    }
        boolean targetResultSetSizeReached = false;
        final Queue<CandidateResult> candidateResultList = new PriorityQueue<CandidateResult>();
        int currentDocId = selectMinimumDocId(postingHeap);
        IterablePosting currentPosting = null;
        double threshold = 0.0d;
        //int scored = 0;
       
        //while not end of all posting lists
        while (currentDocId != -1)  {
View Full Code Here


      {
        BitIndexPointer pointer = pointerList.get(Integer.parseInt(args[argC]));
        if (pointer.getNumberOfEntries() == 0)
          continue;
        System.out.print(args[argC] + " ");
        IterablePosting ip = bpi.getPostings(pointer);
        while(ip.next() != IterablePosting.EOL)
        {
          System.out.print(ip.toString());
          System.out.print(" ");
        }
        System.out.println();
      }
    }
View Full Code Here

   * Adds the feedback document from the index given a docid
   */
  public void insertDocument(int docid, int rank, double score) throws IOException
  {
    totalDocumentLength += documentIndex.getDocumentLength(docid);
    final IterablePosting ip = directIndex.getPostings((BitIndexPointer)documentIndex.getDocumentEntry(docid));
    if (ip == null)
    {
      //logger.warn("document id "+docid+" not found");
      return;
    }
    while(ip.next() != IterablePosting.EOL)
    {
      this.insertTerm(ip.getId(), ip.getFrequency());
    }
    feedbackDocumentCount++;
  }
View Full Code Here

  }
 
  @Override
  public IterablePosting getPostings(BitIndexPointer pointer) throws IOException {
    final BitIn _file = this.file[pointer.getFileNumber()].readReset(pointer.getOffset(), pointer.getOffsetBits());
    IterablePosting rtr = null;
    try{
      rtr = (fieldCount > 0)
        ? postingConstructor.newInstance(_file, pointer.getNumberOfEntries(), doi, fieldCount)
        : postingConstructor.newInstance(_file, pointer.getNumberOfEntries(), doi);
    } catch (Exception e) {
View Full Code Here

            lee2 = lexInStream2.next();
        } else {
          //write to postings for a term that occurs in both indices
         
          //1. postings from the first index are unchanged
          IterablePosting ip1 = inverted1.getPostings(lee1.getValue());
          BitIndexPointer newPointer1 = invOS.writePostings(ip1);
         
          //2. postings from the 2nd index have their docids transformed
          IterablePosting ip2 = inverted2.getPostings(lee2.getValue());
          BitIndexPointer newPointer2 = invOS.writePostings(ip2, ip1.getId() - numberOfDocs1);
         
          numberOfPointers+= newPointer1.getNumberOfEntries() + newPointer2.getNumberOfEntries();
           
          //don't set numberOfEntries, as LexiconEntry.add() will take care of this.
View Full Code Here

        DocumentIndexEntry die = docidInput2.next();
     
        BitIndexPointer pointerDF = emptyPointer;
        if (die.getDocumentLength() > 0)
        {
          final IterablePosting postings = dfInput2.next();
         
          List<Posting> postingList = new ArrayList<Posting>();
          while(postings.next() != IterablePosting.EOL)
          {
            final Posting p = postings.asWritablePosting();
            p.setId(termcodeHashmap.get(postings.getId()));
            postingList.add(p);
          }
          Collections.sort(postingList, new PostingIdComparator());
          pointerDF = dfOutput.writePostings(postingList.iterator());
        }
View Full Code Here

        IntObjectWrapper<IterablePosting> value = rr.createValue();
        while(rr.next(key, value))
        {
          docid = key.get();
          int doclen = 0int docpointers = 0;
          IterablePosting ip = value.getObject();
          assertEquals("Number of pointers for docid " + docid + " is incorrect", documentPointers[docid], value.getInt());
          while(ip.next() != IterablePosting.EOL)
          {
            //System.err.println("termid" +ip.getId() + " f=" + ip.getFrequency());
            termIds.add(ip.getId());
            tokens += ip.getFrequency();
            doclen += ip.getFrequency();
            pointers++; docpointers++;
            if (numberOfTerms > 0)
              assertTrue("Got too big a termid ("+ip.getId()+") from direct index input stream, numTerms=" + numberOfTerms, ip.getId() < maxTermId);
          }
          if (documentPointers.length > 0)
            assertEquals("Number of pointers for docid " + docid + " is incorrect", documentPointers[docid], docpointers);
          assertEquals("Document length for docid "+docid+" is incorrect", documentLengths[docid], doclen);
        }
View Full Code Here

     
     
     
      //now check correct type of all structures
      BitPostingIndexInputStream bpiis;
      IterablePosting ip;
      BitPostingIndex bpi;
     
      //check stream structures
      bpiis = (BitPostingIndexInputStream) index.getIndexStructureInputStream("direct");
      ip = bpiis.next();
View Full Code Here

    MetaIndex meta = index.getMetaIndex();
    assertNotNull(meta);
    assertEquals("doc1", index.getMetaIndex().getItem("filename", 0));
    assertEquals("doc2", index.getMetaIndex().getItem("filename", 1));
   
    IterablePosting ip = null;
    BitPostingIndexInputStream bpiis = null;
   
    /** INVERTED FILE */   
   
    Lexicon<String> lexicon = index.getLexicon();
   
    /**
     * Test {@link IterablePosting} entries from a {@link InvertedIndex}
     */
    InvertedIndex invertedIndex = index.getInvertedIndex();
    assertNotNull(invertedIndex);
    // for each term
    for (int t = 0; t < termStrings.length; t++) {
      LexiconEntry le = lexicon.getLexiconEntry(termStrings[t]);
      assertNotNull(le);
      ip = invertedIndex.getPostings((BitIndexPointer) le);
      // for each document
      int d = 0;
      while (ip.next() != IterablePosting.EOL) {
        assertEquals(invIds[t][d], ip.getId());
        assertEquals(invTfs[t][d], ip.getFrequency());
        assertEquals(doclens[invIds[t][d]], ip.getDocumentLength());
        if (fieldsExpected) {
          assertEquals(2, invFfs[t][d].length);
          for (int f = 0; f < 2; f++) {
            assertEquals(invFfs[t][d][f], ((FieldIterablePosting) ip).getFieldFrequencies()[f]);
          }
        }
        d++;
      }
      ip.close();
    }
    // post-check
    assertEquals(IterablePosting.EOL, ip.next());

    /**
     * Test {@link IterablePosting} entries from a {@link InvertedIndexInputStream}
     */
    bpiis = (BitPostingIndexInputStream) index.getIndexStructureInputStream("inverted");
    assertNotNull(bpiis);
    // for each term
    for (int t = 0; t < invIds.length; t++) {
      assertTrue(bpiis.hasNext());
      ip = bpiis.next();
      assertNotNull(ip);
      // for each document
      int d = 0;
      while (ip.next() != IterablePosting.EOL) {
        assertEquals(invIds[t][d], ip.getId());
        assertEquals(invTfs[t][d], ip.getFrequency());
        assertEquals(doclens[invIds[t][d]], ip.getDocumentLength());
        if (fieldsExpected) {
          assertEquals(2, invFfs[t][d].length);
          for (int f = 0; f < 2; f++) {
            assertEquals(invFfs[t][d][f], ((FieldIterablePosting) ip).getFieldFrequencies()[f]);
          }
        }
        d++;
      }
    }
    // post-check
    assertFalse(bpiis.hasNext());

    /**
     * Test posting array entries from a {@link InvertedIndex}
     */
    // for each term
    for (int t = 0; t < termStrings.length; t++) {
      LexiconEntry le = lexicon.getLexiconEntry(termStrings[t]);
      assertNotNull(le);
     
      int[][] documents = invertedIndex.getDocuments(le);
     
      if (!fieldsExpected) {
        assertTrue(documents.length >= 2);
      }
      else {
        // array should have length at least 4: 1 for the id, 1 for the
        // frequency, 2 for the fields (optionally more for the blocks)
        assertTrue(documents.length >= 4);
      }
     
      // check number of terms
      assertEquals(invIds[t].length, documents[0].length);
      assertEquals(invTfs[t].length, documents[1].length);
     
      // for each document
      for (int d = 0; d < documents[0].length; d++) {
        // test document id
        assertEquals(invIds[t][d], documents[0][d]);
        // test document frequency
        assertEquals(invTfs[t][d], documents[1][d]);
        if (fieldsExpected) {
          // test number of indexed fields
          assertEquals(2, invFfs[t][d].length);
          // test field frequency
          for (int f = 0; f < 2; f++) {
            assertEquals(invFfs[t][d][f], documents[2+f][d]);
          }
        }
      }
    }   
           
    /** DIRECT FILE */
   
    if (directExpected) {
      DocumentIndex documentIndex = index.getDocumentIndex();

      /**
       * Test {@link IterablePosting} entries from a {@link DirectIndex}
       */
      DirectIndex directIndex = index.getDirectIndex();
      assertNotNull(directIndex);
      // for each document
      for (int d = 0; d < dirTfs.length; d++) {
        DocumentIndexEntry de = documentIndex.getDocumentEntry(d);
        assertNotNull(de);
        ip = directIndex.getPostings((BitIndexPointer) de);
        FieldPosting fp = fieldsExpected ? (FieldPosting)ip : null;
        // for each term
        int t = 0;
        int countFoundTerms = 0;
        while (ip.next() != IterablePosting.EOL) {
          int termid = ip.getId();
          assertTrue(termid >= 0);
          String term = lexicon.getLexiconEntry(termid).getKey();
          assertNotNull(term);
          countFoundTerms++;
          assertTrue(dirTfs[d].containsKey(term));
          assertEquals(dirTfs[d].get(term), ip.getFrequency());
          assertEquals(doclens[d], ip.getDocumentLength());         
         
          if (fieldsExpected) {
            assertEquals(2, fp.getFieldFrequencies().length);
            for (int f = 0; f < 2; f++) {
              assertEquals(dirFfs[d].get(term)[f], fp.getFieldFrequencies()[f]);
            }
          }
          t++;
        }
        assertEquals(dirTfs[d].size() ,countFoundTerms);
        ip.close();
      }
      // post-check
      assertEquals(IterablePosting.EOL, ip.next());

      /**
       * Test {@link IterablePosting} entries from a {@link DirectIndexInputStream}
       */
      bpiis = (BitPostingIndexInputStream) index.getIndexStructureInputStream("direct");
      assertNotNull(bpiis);
      // for each document
      for (int d = 0; d < dirTfs.length; d++) {
        assertTrue(bpiis.hasNext());
        ip = bpiis.next();
        assertNotNull(ip);
        FieldPosting fp = fieldsExpected ? (FieldPosting)ip : null;
        // for each term
        int t = 0;
        int countFoundTerms = 0;
        while (ip.next() != IterablePosting.EOL) {
          int termid = ip.getId();
          assertTrue(termid >= 0);
          String term = lexicon.getLexiconEntry(termid).getKey();
          assertNotNull(term);
          countFoundTerms++;
          assertTrue(dirTfs[d].containsKey(term));
          assertEquals(dirTfs[d].get(term), ip.getFrequency());
          assertEquals(doclens[d], ip.getDocumentLength());         
         
          if (fieldsExpected) {
            assertEquals(2, fp.getFieldFrequencies().length);
            for (int f = 0; f < 2; f++) {
              assertEquals(dirFfs[d].get(term)[f], fp.getFieldFrequencies()[f]);
View Full Code Here

        BitFilePosition bp = new FilePosition(byteOffset, bitOffset);
        startOffsets.add(bp);
        //System.err.println(_tmp.length + "@{"+byteOffset+","+bitOffset+"}");
       
        List<Posting> postingList = new ArrayList<Posting>();
        IterablePosting ip = new ArrayOfIdsIterablePosting(_tmp);
        while(ip.next() != IterablePosting.EOL)
        {
          postingList.add(ip.asWritablePosting());
        }
        BitIndexPointer diosPointer = dios.writePostings(postingList.iterator());
       
        IDS.add(_tmp);
        ids.clear();
View Full Code Here

TOP

Related Classes of org.terrier.structures.postings.IterablePosting

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.