File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -199,11 +199,20 @@ def segment(text: str) -> List[str]:
199
199
labs = _tagger .tag (feat )
200
200
labs [- 1 ] = "E" # make sure it cuts the last sentence
201
201
202
+ # To ensure splitting of sentences using Terminal Punctuation
203
+ for idx , _ in enumerate (toks ):
204
+ if toks [idx ].strip ().endswith (("!" , "." , "?" )):
205
+ labs [idx ] = "E"
206
+ # Spaces or empty strings would no longer be treated as end of sentence.
207
+ elif (idx == 0 or labs [idx - 1 ] == "E" ) and toks [idx ].strip () == "" :
208
+ labs [idx ] = "I"
209
+
202
210
sentences = []
203
211
sentence = ""
204
212
for i , w in enumerate (toks ):
205
213
sentence = sentence + w
206
- if labs [i ] == "E" :
214
+ # Empty strings should not be part of output.
215
+ if labs [i ] == "E" and sentence != "" :
207
216
sentences .append (sentence )
208
217
sentence = ""
209
218
You can’t perform that action at this time.
0 commit comments