-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathTextSummarizer.py
58 lines (44 loc) · 1.76 KB
/
TextSummarizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Text Summarizer class for automatic text summary.
# Written by Ed Collins 06 / 07 / 2016
# Global variables and imports
from Summarizers.Summarizer import Summarizer
from Summarizers.SummarizeBySentenceAnalysis import SummarizeBySentenceAnalysis
from Summarizers.SummarizeNoQuotes import SummarizeNoQuotes
from Summarizers.BookSummarizer import BookSummarizer
DEBUG = True
class TextSummarizer(object):
"""Takes a piece of text, for example a news article, and automatically generates a summary of it. Designed according to the strategy design pattern.
Attributes:
article The article to summarize.
summary The summary of the article.
summarizer The object used to summarize the article."""
def __init__(self, article):
self._article = article
self._summary = ""
self._summarizer = SummarizeBySentenceAnalysis(0.1)
@property
def article(self):
return self._article
@article.setter
def article(self, new_article):
self._article = new_article
@property
def summary(self):
return self._summary
@summary.setter
def summary(self, new_summary):
self._summary = new_summary
@property
def summarizer(self):
return self._summarizer
@summarizer.setter
def summarizer(self, new_summarizer):
self._summarizer = new_summarizer
def summarize(self):
"""Takes the article and produces a summary of it."""
if self.summarizer == None:
return "The summarizer has not been initialised"
elif not isinstance(self.summarizer, Summarizer):
raise TypeError("summarizer is not a Summarizer object")
self.summary = self.summarizer.summarize(self.article)
return self.summary