Search code examples
stringpython-3.xsummarize

Combining multiple sentences into one text string in Python


I am trying to join separate sentences into one text object so that I can run it through the Gensim generator. In order for it to work, there need to be at least 2 sentences. According to my output, it looks as though I have more than two sentences but it says that my input is less than 2 sentences.

I have tried so many string methods and it seems as though the Gensim Summarizer doesn't pick up it is entire joined text but rather it looks at each sentence by itself.

MY CODE:

if w in ws:
 bc= ''.join([w for w in background_corpora])
#print(bc)
if len(bc.split('. '))<= 4:
bc_text= '.'.join(bc.split('\n'))
print(bc_text)
print("Background Content: {} ".format(summarize(bc_text))

ERROR MESSAGE:

`raise ValueError("input must have more than one sentence")
ValueError: input must have more than one sentence

Solution

  • Remove this line

    bc_text= '.'.join(bc.split('\n'))
    

    The summarize function expects a list of sentences.