Page 1 of 1

***PYTHON QUESTION*** I'm not sure where I am going wrong in my code: def sentence_segmentation(document): """segmen

Posted: Fri Apr 29, 2022 6:38 am
by answerhappygod
***PYTHON QUESTION***
I'm not sure where I am going wrong in my code:
def sentence_segmentation(document):
"""segments words on full stops"""
if document == " " :
return []
list_time = []
i = 0
while( i < len(document) ):
j = i + 1
while( j < len(document) ):
if document[j] == '
':
break
j += 1
str_time = document[i:j]
i = j + 1
list_time.append(str_time)
return list_time
Python Question I M Not Sure Where I Am Going Wrong In My Code Def Sentence Segmentation Document Segmen 1
Python Question I M Not Sure Where I Am Going Wrong In My Code Def Sentence Segmentation Document Segmen 1 (32.24 KiB) Viewed 101 times
Could someone please provide an alternative solution or
debug?
In Q2, you found a way to tokenize words from a sentence. It would also be useful if we had a way to tokenize individual sentences from a string of sentences (which we will refer to as a document). A sentence will be any sequence of words that is terminated by a full stop and including the full stop itself). Test Case 2 should illustrate this. Write a function sentence_segmentation (document) that takes an input parameter document (type string) and returns a list of sentences from the given document. If no sentences could be segmented (think about the cases), then it simply returns an empty list. NB: You are guaranteed that a document will not begin with the full stop character. For example: Test Result ['senti.', 'sent2.', 'sent3.', document = "senti. sent2. sent3. sent4. sent." sentences = sentence_segmentation (document) print (sentences) document = "sent 1. sent 2... sent 3.... sent 4. sent 5.." ['sent 1.', 'sent 2...', 'sent 3. sentences = sentence_segmentation (document) print( sentences) ['sent1.sent2. sent3. sent4.sent5. document = "senti. sent2.sent3.sent4.sents." sentences = sentence_segmentation (document) print (sentences)