Package gnu.trove

Examples of gnu.trove.TIntArrayList


    }
  }
 
  public void computeExpectations(ArrayList<SumLattice> lattices) {
    double[][] gammas;   
    TIntArrayList cache = new TIntArrayList();
    for (int i = 0; i < lattices.size(); i++) {
      if (lattices.get(i) == null) { continue; }
      SumLattice lattice = lattices.get(i);
      FeatureVectorSequence fvs = (FeatureVectorSequence)lattice.getInput();
      gammas = lattice.getGammas();
      for (int ip = 0; ip < fvs.size(); ++ip) {
        cache.resetQuick();
        FeatureVector fv = fvs.getFeatureVector(ip);
        int fi;
        for (int loc = 0; loc < fv.numLocations(); loc++) {
          fi = fv.indexAtLocation(loc);
          // binary constraint features
          if (constraints.containsKey(fi)) {
            cache.add(fi);
          }
        }
        if (constraints.containsKey(fv.getAlphabet().size())) {
          cache.add(fv.getAlphabet().size());
        }
        for (int s = 0; s < map.getNumStates(); ++s) {
          int li = map.getLabelIndex(s);
          if (li != StateLabelMap.START_LABEL) {
            double gammaProb = Math.exp(gammas[ip+1][s]);
            for (int j = 0; j < cache.size(); j++) {
              constraints.get(cache.getQuick(j)).incrementExpectation(li,gammaProb);
            }
          }
        }
      }
    }
View Full Code Here


  public TwoLabelGEConstraints() {
    this.constraintsList = new ArrayList<TwoLabelGEConstraint>();
    this.constraintsMap = new TIntIntHashMap();
    this.map = null;
    this.cache = new TIntArrayList();
  }
View Full Code Here

 
  protected TwoLabelGEConstraints(ArrayList<TwoLabelGEConstraint> constraintsList, TIntIntHashMap constraintsMap, StateLabelMap map) {
    this.constraintsList = constraintsList;
    this.constraintsMap = constraintsMap;
    this.map = map;
    this.cache = new TIntArrayList();
  }
View Full Code Here

    }
  }
 
  public void computeExpectations(ArrayList<SumLattice> lattices) {
    double[][][] xis;
    TIntArrayList cache = new TIntArrayList();
    for (int i = 0; i < lattices.size(); i++) {
      if (lattices.get(i) == null) { continue; }
      FeatureVectorSequence fvs = (FeatureVectorSequence)lattices.get(i).getInput();
      SumLattice lattice = lattices.get(i);
      xis = lattice.getXis();
      for (int ip = 1; ip < fvs.size(); ++ip) {
        cache.resetQuick();
        FeatureVector fv = fvs.getFeatureVector(ip);
        int fi;
        for (int loc = 0; loc < fv.numLocations(); loc++) {
          fi = fv.indexAtLocation(loc);
          // binary constraint features
          if (constraintsMap.containsKey(fi)) {
            cache.add(constraintsMap.get(fi));
          }
        }
        for (int prev = 0; prev < map.getNumStates(); ++prev) {
          int liPrev = map.getLabelIndex(prev);
          if (liPrev != StateLabelMap.START_LABEL) {
            for (int curr = 0; curr < map.getNumStates(); ++curr) {
              int liCurr = map.getLabelIndex(curr);
              if (liCurr != StateLabelMap.START_LABEL) {
                double prob = Math.exp(xis[ip][prev][curr]);
                for (int j = 0; j < cache.size(); j++) {
                  constraintsList.get(cache.getQuick(j)).expectation[liPrev][liCurr] += prob;
                }
              }
            }
          }
        }
View Full Code Here

public class PostingUtil {

  /** Get an array of all the ids in a given IterablePosting stream */
  public static int[] getIds(final IterablePosting ip) throws IOException
  {
    final TIntArrayList ids = new TIntArrayList();
    while(ip.next() != IterablePosting.EOL)
      ids.add(ip.getId());
    return ids.toNativeArray();
  }
View Full Code Here

    final boolean loadTagInformation = fieldCount > 0;
   
    final int[][] documentTerms = new int[fieldCount+4][];
    for(int i=0;i<fieldCount+3;i++)
      documentTerms[i] = new int[df];
    final TIntArrayList blockids = new TIntArrayList(df); //ideally we'd have TF here
 
    if (loadTagInformation) { //if there are tag information to process
      documentTerms[0][0] = file.readGamma() - 1;
      documentTerms[1][0] = file.readUnary();
      for(int fi=0;fi < fieldCount;fi++)
        documentTerms[2+fi][0] = file.readUnary() -1;
      int blockfreq = documentTerms[fieldCount+2][0] = file.readUnary() - DocumentBlockCountDelta;
      int tmpBlocks[] = new int[blockfreq];
      int previousBlockId = -1;
      for(int j=0;j<blockfreq;j++)
      {
        tmpBlocks[j] = previousBlockId = file.readGamma() + previousBlockId;
      }
      blockids.add(tmpBlocks);
     
      for (int i = 1; i < df; i++) {         
        documentTerms[0][i= file.readGamma() + documentTerms[0][i - 1];
        documentTerms[1][i= file.readUnary();
        for(int fi=0;fi < fieldCount;fi++)
          documentTerms[2+fi][i] = file.readUnary() -1;
       
        blockfreq = documentTerms[2+fieldCount][i] = file.readUnary() - DocumentBlockCountDelta;
        tmpBlocks = new int[blockfreq];
        previousBlockId = -1;
        for(int j=0;j<blockfreq;j++)
        {
          tmpBlocks[j] = previousBlockId = file.readGamma() + previousBlockId;
        }
        blockids.add(tmpBlocks);
      }
    } else { //no tag information to process         
     
      documentTerms[0][0] = file.readGamma() - 1;
      documentTerms[1][0] = file.readUnary();
     
      int blockfreq = documentTerms[2][0] = file.readUnary() - DocumentBlockCountDelta;
      int tmpBlocks[] = new int[blockfreq];
      int previousBlockId = -1;
      for(int j=0;j<blockfreq;j++)
      {
        tmpBlocks[j] = previousBlockId = file.readGamma() + previousBlockId;
      }
      blockids.add(tmpBlocks);
     
      for (int i = 1; i < df; i++) {         
        documentTerms[0][i= file.readGamma() + documentTerms[0][i - 1];
        documentTerms[1][i= file.readUnary();

        blockfreq = documentTerms[2][i] = file.readUnary() - DocumentBlockCountDelta;
        tmpBlocks = new int[blockfreq];
        previousBlockId = -1;
        for(int j=0;j<blockfreq;j++)
        {
          tmpBlocks[j] = previousBlockId = file.readGamma() + previousBlockId;
        }
        blockids.add(tmpBlocks);
      }
    }
    documentTerms[documentTerms.length -1] = blockids.toNativeArray();
    return documentTerms;
  }
View Full Code Here

    final boolean loadTagInformation = fieldCount > 0;
   
    final int[][] documentTerms = new int[4+fieldCount][];
    for(int i=0;i<fieldCount+3;i++)
      documentTerms[i] = new int[df];
    final TIntArrayList blockids = new TIntArrayList(df); //ideally we'd have TF here

    try{
      final BitIn file = this.file[pointer.getFileNumber()].readReset(startOffset, startBitOffset);
 
      if (loadTagInformation) { //if there are tag information to process
        //documentTerms[2] = new int[df];
        documentTerms[0][0] = file.readGamma() - 1;       
        documentTerms[1][0] = file.readUnary();
        for(int fi=0;fi < fieldCount;fi++)
          documentTerms[2+fi][0] = file.readUnary() -1;
        int blockfreq = documentTerms[2+fieldCount][0] = file.readUnary() - DocumentBlockCountDelta;
        int tmpBlocks[] = new int[blockfreq];
        int previousBlockId = -1;
        for(int j=0;j<blockfreq;j++)
        {
          tmpBlocks[j] = previousBlockId = file.readGamma() + previousBlockId;
        }
        blockids.add(tmpBlocks);
       
        for (int i = 1; i < df; i++) {         
          documentTerms[0][i= file.readGamma() + documentTerms[0][i - 1];
          documentTerms[1][i= file.readUnary();
          for(int fi=0;fi < fieldCount;fi++)
            documentTerms[2+fi][0] = file.readUnary() -1;
          blockfreq = documentTerms[2+fieldCount][i] = file.readUnary() - DocumentBlockCountDelta;
          tmpBlocks = new int[blockfreq];
          previousBlockId = -1;
          for(int j=0;j<blockfreq;j++)
          {
            tmpBlocks[j] = previousBlockId = file.readGamma() + previousBlockId;
          }
          blockids.add(tmpBlocks);
        }
      } else { //no tag information to process         
       
        documentTerms[0][0] = file.readGamma() - 1;
        documentTerms[1][0] = file.readUnary();
       
        int blockfreq = documentTerms[2][0] = file.readUnary() - DocumentBlockCountDelta;
        int tmpBlocks[] = new int[blockfreq];
        int previousBlockId = -1;
        for(int j=0;j<blockfreq;j++)
        {
          tmpBlocks[j] = previousBlockId = file.readGamma() + previousBlockId;
        }
        blockids.add(tmpBlocks);
       
        for (int i = 1; i < df; i++) {         
          documentTerms[0][i= file.readGamma() + documentTerms[0][i - 1];
          documentTerms[1][i= file.readUnary();

          blockfreq = documentTerms[2][i] = file.readUnary() - DocumentBlockCountDelta;
          tmpBlocks = new int[blockfreq];
          previousBlockId = -1;
          for(int j=0;j<blockfreq;j++)
          {
            tmpBlocks[j] = previousBlockId = file.readGamma() + previousBlockId;
          }
          blockids.add(tmpBlocks);
        }
      }
      documentTerms[documentTerms.length-1] = blockids.toNativeArray();
      return documentTerms;
    } catch (IOException ioe) {
      logger.error("Problem reading block inverted index", ioe);
      return null;
    }
View Full Code Here

    {
      filters[i].new_query(this, srq, results);
    }
   
    int doccount = -1;//doccount is zero-based, so 0 means 1 document
    TIntArrayList docatnumbers = new TIntArrayList();//list of resultset index numbers to keep
    byte docstatus; int thisDocId;
    int[] docids = results.getDocids();
    //int elitesetsize = results.getExactResultSize();
    //the exact result size is the total number of
    //documents that would be retrieved if we
    //didn't do any cropping
    int elitesetsize = results.getResultSize();
    for(int thisdoc = 0; thisdoc < elitesetsize; thisdoc++)
    {
      //run this document through all the filters
      docstatus = PostFilter.FILTER_OK;
      thisDocId = docids[thisdoc];
      //run this doc through the filters
      for(int i=0;i<filters_length; i++)
      {
        if ( ( docstatus = filters[i].filter(this, srq, results, thisdoc, thisDocId) )
          == PostFilter.FILTER_REMOVE
        )
          break;
          //break if the document has to be removed
      }
      //if it's not being removed, then
      if (docstatus != PostFilter.FILTER_REMOVE) //TODO this should always be true
      {
        //success, another real document
        doccount++;
        //check if it's in our results "WINDOW"
        if (doccount >= Start)
        {
          if (doccount <= End)
          {  //add to the list of documents to keep
            docatnumbers.add(thisdoc);
            //System.out.println("Keeping @"+thisdoc);
          }
          else
          {
            //we've now got enough results, break
            break;
          }
        }
      }
      else
      {
        //System.out.println("Removed");
      }
    }
    //since doccount is zero-based, we add one so that it
    //corresponds to the real number of documents.
    doccount++;
    rq.setNumberOfDocumentsAfterFiltering(doccount);
    if (docatnumbers.size() < docids.length)
    {
      //result set is definently shorter, replace with new one
      rq.setResultSet( results.getResultSet(docatnumbers.toNativeArray()));
      rq.getResultSet().setExactResultSize(results.getExactResultSize());
    }
  }
           
        catch(Exception e){}
View Full Code Here

  protected TIntArrayList[] createPointerForTerm(LexiconEntry le)
  {
    TIntArrayList[] tmpArray = new TIntArrayList[4+fieldCount];
    final int tmpNT = le.getDocumentFrequency();
    for(int i = 0; i < fieldCount+3; i++)
      tmpArray[i] = new TIntArrayList(tmpNT);
    if (le instanceof BlockEntryStatistics)
    {
      tmpArray[fieldCount+3] = new TIntArrayList(((BlockEntryStatistics)le).getBlockCount());
    }
    else
    {
      tmpArray[fieldCount+3] = new TIntArrayList(le.getFrequency());
    }
    return tmpArray;
  }
View Full Code Here

  protected TIntArrayList[] createPointerForTerm(LexiconEntry le)
  {
    TIntArrayList[] tmpArray = new TIntArrayList[2 + fieldCount];
    final int tmpNT = le.getDocumentFrequency();
    for(int i = 0; i < fieldCount+2; i++)
      tmpArray[i] = new TIntArrayList(tmpNT);
    return tmpArray;
  }
View Full Code Here

TOP

Related Classes of gnu.trove.TIntArrayList

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.