Package org.apache.lucene.index

Examples of org.apache.lucene.index.TermPositionVector


            }
        } catch (IOException e) {
            // should never happen, we are reading from a string
        }

        return new TermPositionVector() {

            private String[] terms =
                    (String[]) termMap.keySet().toArray(new String[termMap.size()]);

            public int[] getTermPositions(int index) {
View Full Code Here


         {
            LOG.trace("An exception occurred: " + e.getMessage());
         }
      }

      return new TermPositionVector()
      {

         private String[] terms = (String[])termMap.keySet().toArray(new String[termMap.size()]);

         public int[] getTermPositions(int index)
View Full Code Here

        for (int freqVectorIndex = 0; freqVectorIndex < aprioriFreqVectors.length; freqVectorIndex++) {
          assertTrue(Arrays.equals(aprioriFreqVectors[freqVectorIndex].getTermFrequencies(), testFreqVectors[freqVectorIndex].getTermFrequencies()));
          assertTrue(Arrays.equals(aprioriFreqVectors[freqVectorIndex].getTerms(), testFreqVectors[freqVectorIndex].getTerms()));

          if (aprioriFreqVectors[freqVectorIndex] instanceof TermPositionVector) {
            TermPositionVector aprioriTermPositionVector = (TermPositionVector) aprioriFreqVectors[freqVectorIndex];
            TermPositionVector testTermPositionVector = (TermPositionVector) testFreqVectors[freqVectorIndex];

            for (int positionVectorIndex = 0; positionVectorIndex < aprioriFreqVectors[freqVectorIndex].getTerms().length; positionVectorIndex++)
            {
              if (aprioriTermPositionVector.getOffsets(positionVectorIndex) != null) {
                assertTrue(Arrays.equals(aprioriTermPositionVector.getOffsets(positionVectorIndex), testTermPositionVector.getOffsets(positionVectorIndex)));
              }

              if (aprioriTermPositionVector.getTermPositions(positionVectorIndex) != null) {
                assertTrue(Arrays.equals(aprioriTermPositionVector.getTermPositions(positionVectorIndex), testTermPositionVector.getTermPositions(positionVectorIndex)));
              }
            }
          }

        }
View Full Code Here

  public FieldTermStack( IndexReader reader, int docId, String fieldName, final FieldQuery fieldQuery ) throws IOException {
    this.fieldName = fieldName;

    TermFreqVector tfv = reader.getTermFreqVector( docId, fieldName );
    if( tfv == null ) return; // just return to make null snippets
    TermPositionVector tpv = null;
    try{
      tpv = (TermPositionVector)tfv;
    }
    catch( ClassCastException e ){
      return; // just return to make null snippets
    }
   
    Set<String> termSet = fieldQuery.getTermSet( fieldName );
    // just return to make null snippet if un-matched fieldName specified when fieldMatch == true
    if( termSet == null ) return;
   
    for( String term : tpv.getTerms() ){
      if( !termSet.contains( term ) ) continue;
      int index = tpv.indexOf( term );
      TermVectorOffsetInfo[] tvois = tpv.getOffsets( index );
      if( tvois == null ) return; // just return to make null snippets
      int[] poss = tpv.getTermPositions( index );
      if( poss == null ) return; // just return to make null snippets
      for( int i = 0; i < tvois.length; i++ )
        termList.add( new TermInfo( term, tvois[i].getStartOffset(), tvois[i].getEndOffset(), poss[i] ) );
    }
   
View Full Code Here

            ts.close();
        } catch (IOException e) {
            // should never happen, we are reading from a string
        }

        return new TermPositionVector() {

            private String[] terms =
                    (String[]) termMap.keySet().toArray(new String[termMap.size()]);

            public int[] getTermPositions(int index) {
View Full Code Here

 
  private List<TermVectorOffsetInfo> getOffsets(IndexReader ir, int docNo, String fieldName, Collection<String> words) throws Exception {
    List<TermVectorOffsetInfo> results = new ArrayList<TermVectorOffsetInfo>();
    TermFreqVector tfv = ir.getTermFreqVector(docNo, fieldName);
    if(tfv instanceof TermPositionVector) {
      TermPositionVector tpv = (TermPositionVector)tfv;
      String [] terms = tpv.getTerms();
      for(int i=0;i<tpv.getTerms().length;i++) {
        if(words.contains(terms[i])) {
          //System.out.println(terms[i]);
          TermVectorOffsetInfo[] tps = tpv.getOffsets(i);
          int[] positions = tpv.getTermPositions(i);
          for(int j=0;j<tps.length;j++) {
            results.add(tps[j]);
            System.out.println(terms[i] + "\t" + positions[j] + "\t" + tps[j].getStartOffset() + "\t" + tps[j].getEndOffset());
          }         
        }
View Full Code Here

   
    List<TermVectorOffsetInfo> results = new ArrayList<TermVectorOffsetInfo>();
    TermFreqVector tfv = ir.getTermFreqVector(docNo, fieldName);
    Map<String,Integer> termToID = new HashMap<String,Integer>();
    if(tfv instanceof TermPositionVector) {
      TermPositionVector tpv = (TermPositionVector)tfv;
      String [] terms = tpv.getTerms();
      for(int i=0;i<tpv.getTerms().length;i++) {
        if(simpleTerms.contains(new Term(fieldName, terms[i]))) {
          //System.out.println(terms[i]);
          TermVectorOffsetInfo[] tps = tpv.getOffsets(i);
          int[] positions = tpv.getTermPositions(i);
          for(int j=0;j<tps.length;j++) {
            results.add(tps[j]);
            //System.out.println(terms[i] + "\t" + positions[j] + "\t" + tps[j].getStartOffset() + "\t" + tps[j].getEndOffset());
          }         
        }
        if(ptt.contains(terms[i])) {
          termToID.put(terms[i], i);
        }
      }
      for(List<Term> phraseTerm : phraseTerms) {
        String firstWord = phraseTerm.get(0).text();
        if(termToID.containsKey(firstWord)) {
          //System.out.println(firstWord);
          Map<Integer,List<TermVectorOffsetInfo>> phrases = new HashMap<Integer,List<TermVectorOffsetInfo>>();
          int id = termToID.get(firstWord);
          TermVectorOffsetInfo[] tps = tpv.getOffsets(id);
          int[] positions = tpv.getTermPositions(id);
          for(int i=0;i<positions.length;i++) {
            List<TermVectorOffsetInfo> tvoil = new ArrayList<TermVectorOffsetInfo>();
            tvoil.add(tps[i]);
            phrases.put(positions[i], tvoil);
            //System.out.println(firstWord + "\t" + positions[i]);
          }
          for(int i=1;i<phraseTerm.size();i++) {
            String word = phraseTerm.get(i).text();
            if(!termToID.containsKey(word)) {
              phrases = null;
              break;
            }
            int cid = termToID.get(word);
            TermVectorOffsetInfo[] ctps = tpv.getOffsets(cid);
            int[] cpositions = tpv.getTermPositions(cid);
            for(int j=0;j<cpositions.length;j++) {
              //System.out.println(word + "\t" + cpositions[j]);
              if(phrases.containsKey(cpositions[j] - i)) {
                //System.out.println(phrases.get(cpositions[j] - i));
                phrases.get(cpositions[j] - i).add(ctps[j]);
View Full Code Here

            }
        } catch (IOException e) {
            // should never happen, we are reading from a string
        }

        return new TermPositionVector() {

            private String[] terms =
                    (String[]) termMap.keySet().toArray(new String[termMap.size()]);

            public int[] getTermPositions(int index) {
View Full Code Here

            ts.close();
        } catch (IOException e) {
            // should never happen, we are reading from a string
        }

        return new TermPositionVector() {

            private String[] terms =
                    (String[]) termMap.keySet().toArray(new String[termMap.size()]);

            public int[] getTermPositions(int index) {
View Full Code Here

            }
        } catch (IOException e) {
            // should never happen, we are reading from a string
        }

        return new TermPositionVector() {

            private String[] terms =
                    (String[]) termMap.keySet().toArray(new String[termMap.size()]);

            public int[] getTermPositions(int index) {
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.TermPositionVector

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.