public WeightedPhraseInfo( LinkedList<TermInfo> terms, float boost, int number ){ this.boost = boost; this.seqnum = number; termsOffsets = new ArrayList<Toffs>( terms.size() ); TermInfo ti = terms.get( 0 ); termsOffsets.add( new Toffs( ti.getStartOffset(), ti.getEndOffset() ) ); if( terms.size() == 1 ){ text = ti.getText(); return; } StringBuilder sb = new StringBuilder(); sb.append( ti.getText() ); int pos = ti.getPosition(); for( int i = 1; i < terms.size(); i++ ){ ti = terms.get( i ); sb.append( ti.getText() ); if( ti.getPosition() - pos == 1 ){ Toffs to = termsOffsets.get( termsOffsets.size() - 1 ); to.setEndOffset( ti.getEndOffset() ); } else{ termsOffsets.add( new Toffs( ti.getStartOffset(), ti.getEndOffset() ) ); } pos = ti.getPosition(); } text = sb.toString(); }
return; // no offsets, null snippet termList.add( new TermInfo( term, dpEnum.startOffset(), dpEnum.endOffset(), pos, weight ) ); if (current.position == currentPos) { assert previous != null; previous.setNext(current); previous = current; iterator.remove(); } else { if (previous != null) { previous.setNext(first); previous.setNext(first);
currMap = fieldQuery.getFieldTermMap( field, ti.getText() ); while (currMap == null && ti.getNext() != first) { ti = ti.getNext(); currMap = fieldQuery.getFieldTermMap( field, ti.getText() ); nextMap = null; if( ti != null ) { nextMap = currMap.getTermMap( ti.getText() ); while (nextMap == null && ti.getNext() != first) { ti = ti.getNext(); nextMap = currMap.getTermMap( ti.getText() );
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] ) );
public WeightedPhraseInfo( LinkedList<TermInfo> terms, float boost, int seqnum ){ this.boost = boost; this.seqnum = seqnum; // We keep TermInfos for further operations termsInfos = new ArrayList<>( terms ); termsOffsets = new ArrayList<>( terms.size() ); TermInfo ti = terms.get( 0 ); termsOffsets.add( new Toffs( ti.getStartOffset(), ti.getEndOffset() ) ); if( terms.size() == 1 ){ return; } int pos = ti.getPosition(); for( int i = 1; i < terms.size(); i++ ){ ti = terms.get( i ); if( ti.getPosition() - pos == 1 ){ Toffs to = termsOffsets.get( termsOffsets.size() - 1 ); to.setEndOffset( ti.getEndOffset() ); } else{ termsOffsets.add( new Toffs( ti.getStartOffset(), ti.getEndOffset() ) ); } pos = ti.getPosition(); } }
public boolean isValidTermOrPhrase( final List<TermInfo> phraseCandidate ){ // check terminal if( !terminal ) return false; // if the candidate is a term, it is valid if( phraseCandidate.size() == 1 ) return true; // else check whether the candidate is valid phrase // compare position-gaps between terms to slop int pos = phraseCandidate.get( 0 ).getPosition(); for( int i = 1; i < phraseCandidate.size(); i++ ){ int nextPos = phraseCandidate.get( i ).getPosition(); if( Math.abs( nextPos - pos - 1 ) > slop ) return false; pos = nextPos; } return true; } }
public boolean isValidTermOrPhrase( final List<TermInfo> phraseCandidate ){ // check terminal if( !terminal ) return false; // if the candidate is a term, it is valid if( phraseCandidate.size() == 1 ) return true; // else check whether the candidate is valid phrase // compare position-gaps between terms to slop int pos = phraseCandidate.get( 0 ).getPosition(); for( int i = 1; i < phraseCandidate.size(); i++ ){ int nextPos = phraseCandidate.get( i ).getPosition(); if( Math.abs( nextPos - pos - 1 ) > slop ) return false; pos = nextPos; } return true; } }
/** * Text of the match, calculated on the fly. Use for debugging only. * @return the text */ public String getText() { StringBuilder text = new StringBuilder(); for ( TermInfo ti: termsInfos ) { text.append( ti.getText() ); } return text.toString(); }
public QueryPhraseMap searchPhrase( final List<TermInfo> phraseCandidate ){ QueryPhraseMap currMap = this; for( TermInfo ti : phraseCandidate ){ currMap = currMap.subMap.get( ti.getText() ); if( currMap == null ) return null; } return currMap.isValidTermOrPhrase( phraseCandidate ) ? currMap : null; }
public QueryPhraseMap searchPhrase( final List<TermInfo> phraseCandidate ){ QueryPhraseMap currMap = this; for( TermInfo ti : phraseCandidate ){ currMap = currMap.subMap.get( ti.getText() ); if( currMap == null ) return null; } return currMap.isValidTermOrPhrase( phraseCandidate ) ? currMap : null; }