protected String makeFragment( StringBuilder buffer, int[] index, Field[] values, WeightedFragInfo fragInfo, String[] preTags, String[] postTags, Encoder encoder ){ StringBuilder fragment = new StringBuilder(); final int s = fragInfo.getStartOffset(); int[] modifiedStartOffset = { s }; String src = getFragmentSourceMSO( buffer, index, values, s, fragInfo.getEndOffset(), modifiedStartOffset ); int srcIndex = 0; for( SubInfo subInfo : fragInfo.getSubInfos() ){ for( Toffs to : subInfo.getTermsOffsets() ){ fragment .append( encoder.encodeText( src.substring( srcIndex, to.getStartOffset() - modifiedStartOffset[0] ) ) ) .append( getPreTag( preTags, subInfo.getSeqnum() ) ) .append( encoder.encodeText( src.substring( to.getStartOffset() - modifiedStartOffset[0], to.getEndOffset() - modifiedStartOffset[0] ) ) ) .append( getPostTag( postTags, subInfo.getSeqnum() ) ); srcIndex = to.getEndOffset() - modifiedStartOffset[0]; } } fragment.append( encoder.encodeText( src.substring( srcIndex ) ) ); return fragment.toString(); }
public void testToffsComparisonConsistency() { Toffs a = new Toffs( 0, 0 ); Toffs b = new Toffs( 1, 2 ); Toffs c = new Toffs( 2, 3 ); Toffs d = new Toffs( 0, 0 ); assertConsistentEquals( a, a ); assertConsistentEquals( b, b ); assertConsistentEquals( c, c ); assertConsistentEquals( d, d ); assertConsistentEquals( a, d ); assertConsistentLessThan( a, b ); assertConsistentLessThan( b, c ); assertConsistentLessThan( a, c ); assertConsistentLessThan( d, b ); assertConsistentLessThan( d, c ); }
@Override public String toString(){ StringBuilder sb = new StringBuilder(); sb.append( text ).append( '(' ); for( Toffs to : termsOffsets ) sb.append( to.toString() ); sb.append( ')' ); return sb.toString(); }
public SubInfo( String text, List<Toffs> termsOffsets, int seqnum, float boost ){ this.text = text; this.termsOffsets = termsOffsets; this.seqnum = seqnum; this.boost = boost; }
public List<Toffs> getTermsOffsets(){ return termsOffsets; }
public SubInfo( String text, List<Toffs> termsOffsets, int seqnum ){ this.text = text; this.termsOffsets = termsOffsets; this.seqnum = seqnum; }