0

I wrote a code for reading article and self-learning AI. First, I read the article with URL and download it.Then I parse the article and use it for my AI's learning text.But now I want to read text from txt file.How can I assign txt file's text to Article object ? (Please check code to clear my wish ) Thanks all.

article = Article('URL for article')
article.download()
article.parse()
article.nlp()
corpus = article.text

text= corpus
sentence_list = nltk.sent_tokenize(text)

PS:I want to use txt file instead of URL. But I do not remove article from code because it will be necessary again.

  • You probably want to write a base class with your common funcionalities. Then inherit from it and create your article and file class. – Tin Nguyen Jun 18 '20 at 11:49
  • `f = open("your file"); article.text = f.read(); f.close()` Or change `corpus` or `text` as they seem to be the same. – Banana Jun 18 '20 at 12:25

1 Answers1

0

I tried many options but only way is that not using Article.So I remove Article parts and change like this :

f = open("visp.txt", "r",encoding="utf8")

#article = Article('visp.txt')
#article.download()
#article.parse()
#article.nlp()
#corpus = article.text


f = open("demo.txt", "r",encoding="utf8")
corpus = f.read()
print(corpus)

PS: Do not forget encoding while open the .txt file.