@@ -909,17 +909,17 @@ func writeAligments(combinedAlignments *CombinedAlignments, sourceDocID *string,
909
909
910
910
// Returns three passages: the context before, the match itself, and the context after
911
911
func alignmentToText (alignment * position , filename string , config * matchingParams ) []string {
912
- beforeContext := getText (& filename , alignment .startByte - int32 (config .contextSize ), alignment .startByte )
912
+ beforeContext := getText (& filename , alignment .startByte - int32 (config .contextSize ), alignment .startByte , "before" )
913
913
beforeContext = cleanStart .ReplaceAllString (beforeContext , "" ) // avoid truncation at beginning
914
- matchingPassage := getText (& filename , alignment .startByte , alignment .endByte )
915
- afterContext := getText (& filename , alignment .endByte , alignment .endByte + int32 (config .contextSize ))
914
+ matchingPassage := getText (& filename , alignment .startByte , alignment .endByte , "match" )
915
+ afterContext := getText (& filename , alignment .endByte , alignment .endByte + int32 (config .contextSize ), "after" )
916
916
afterContext = cleanEnd .ReplaceAllString (afterContext , "" ) // avoid truncation at the end
917
917
passages := []string {beforeContext , matchingPassage , afterContext }
918
918
return passages
919
919
}
920
920
921
921
// Get text passages using file location and start and end byte
922
- func getText (fileLocation * string , startByte int32 , endByte int32 ) string {
922
+ func getText (fileLocation * string , startByte int32 , endByte int32 , passageType string ) string {
923
923
f , err := os .Open (* fileLocation )
924
924
checkErr (err , fmt .Sprintf ("getText (opening %s)" , * fileLocation ))
925
925
if startByte < 0 {
@@ -935,8 +935,10 @@ func getText(fileLocation *string, startByte int32, endByte int32) string {
935
935
passage = bytes .Replace (passage , []byte ("\xc2 \xa0 " ), []byte (" " ), - 1 ) // remove non-breaking spaces
936
936
text := string (passage )
937
937
text = tags .ReplaceAllString (text , "" )
938
- text = brokenBeginTags .ReplaceAllString (text , "" )
939
- text = brokenEndTags .ReplaceAllString (text , "" )
938
+ if passageType != "match" {
939
+ text = brokenBeginTags .ReplaceAllString (text , "" )
940
+ text = brokenEndTags .ReplaceAllString (text , "" )
941
+ }
940
942
text = html .UnescapeString (text )
941
943
text = strings .Replace (text , "\\ n" , "\n " , - 1 )
942
944
text = strings .Replace (text , "\\ t" , "\t " , - 1 )
0 commit comments