@@ -118,22 +118,20 @@ def __init__(self, content):
118
118
# 명사 추출
119
119
nouns = SentenceTokenizer .get_nouns (self .sentences )
120
120
121
- # 가중치 그래프 객체 생성
122
- matrix = GraphMatrix (nouns )
123
- # 문장별 가중치 그래프 [문장수, 문장수], {index: 문장} 사전
124
- # sent_graph, sent_vocab = matrix.get_sent_graph_vocab()
125
- # 단어별 가중치 그래프 [단어수, 단어수], {index: 단어} 사전
126
- words_graph , word_vocab = matrix .get_words_graph_vocab ()
127
-
128
- # (문장, index, 가중치) 리스트 생성
129
- # sent_rank = [(sent_vocab[index], index, weight) for index, weight in (Rank.get_ranks(sent_graph).items())]
130
- # weight 기준으로 정렬
131
- # self.sorted_sent_rank = sorted(sent_rank, key=lambda k: k[2], reverse=True)
132
-
133
- # (단어, index, 가중치) 리스트 생성
134
- word_rank_idx = [(word_vocab [index ], index , weight ) for index , weight in Rank .get_ranks (words_graph ).items ()]
135
- # weight 기준으로 정렬
136
- self .sorted_word_rank = sorted (word_rank_idx , key = lambda k : k [2 ], reverse = True )
121
+ if nouns :
122
+ # 가중치 그래프 객체 생성
123
+ matrix = GraphMatrix (nouns )
124
+ # 문장별 가중치 그래프 [문장수, 문장수], {index: 문장} 사전
125
+ # sent_graph, sent_vocab = matrix.get_sent_graph_vocab()
126
+ # 단어별 가중치 그래프 [단어수, 단어수], {index: 단어} 사전
127
+ words_graph , word_vocab = matrix .get_words_graph_vocab ()
128
+
129
+ # (단어, index, 가중치) 리스트 생성
130
+ word_rank_idx = [(word_vocab [index ], index , weight ) for index , weight in Rank .get_ranks (words_graph ).items ()]
131
+ # weight 기준으로 정렬
132
+ self .sorted_word_rank = sorted (word_rank_idx , key = lambda k : k [2 ], reverse = True )
133
+ else :
134
+ self .sorted_word_rank = []
137
135
138
136
# sent_size 개의 문장 요약
139
137
# def summarize(self, sent_size=3):
0 commit comments