Skip to content

Commit

Permalink
修改pagerank
Browse files Browse the repository at this point in the history
  • Loading branch information
letiantian committed Dec 1, 2014
1 parent 1b4508b commit 5ba83e1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ tr4w = TextRank4Keyword(stop_words_file='./stopword.data') # 导入停止词
tr4w.train(text=text, speech_tag_filter=True, lower=True, window=2)
print '关键词:'
# 10个关键词且每个的长度最小为2
print '/'.join(tr4w.get_keywords(10, word_min_len=2))
# 20个关键词且每个的长度最小为1
print '/'.join(tr4w.get_keywords(20, word_min_len=1))
print '关键短语:'
# 20个关键词去构造短语,短语在原文本中出现次数最少为2
Expand All @@ -134,15 +134,18 @@ print '\n'.join(tr4s.get_key_sentences(num=3)) # 重要性最高的三个句子

得到的关键词:
```
媒体/高圆圆/宾客/新人/记者/北京/赵又廷/谢娜/现身/答谢
媒体/高圆圆/微/宾客/赵又廷/答谢/谢娜/现身/记者/新人/北京/博/展示/捧场/礼物/张杰/当晚/戴/酒店/外套
```
得到的关键短语:
```
微博
```
没有关键短语。

得到的摘要:
```
中新网北京12月1日电(记者 张曦) 30日晚,高圆圆和赵又廷在京举行答谢宴,诸多明星现身捧场,其中包括张杰(微博)、谢娜(微博)夫妇、何炅(微博)、蔡康永(微博)、徐克、张凯丽、黄轩(微博)等
高圆圆身穿粉色外套,看到大批记者在场露出娇羞神色,赵又廷则戴着鸭舌帽,十分淡定,两人快步走进电梯,未接受媒体采访
30日中午,有媒体曝光高圆圆和赵又廷现身台北桃园机场的照片,照片中两人小动作不断,尽显恩爱
记者了解到,出席高圆圆、赵又廷答谢宴的宾客近百人,其中不少都是女方的高中同学
```

##使用说明
Expand Down
4 changes: 2 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
tr4w.train(text=text, speech_tag_filter=True, lower=True, window=2)

print '关键词:'
# 10个关键词且每个的长度最小为2
print '/'.join(tr4w.get_keywords(10, word_min_len=2))
# 20个关键词且每个的长度最小为1
print '/'.join(tr4w.get_keywords(20, word_min_len=1))

print '关键短语:'
# 20个关键词去构造短语,短语在原文本中出现次数最少为2
Expand Down
8 changes: 4 additions & 4 deletions textrank4zh/TextRank4Keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def train(self, text, window = 2, lower = False, speech_tag_filter=True,
self.graph[index1][index2] = 1.0
self.graph[index2][index1] = 1.0

for x in xrange(words_number):
row_sum = np.sum(self.graph[x, :])
if row_sum > 0:
self.graph[x, :] = self.graph[x, :] / row_sum
# for x in xrange(words_number):
# row_sum = np.sum(self.graph[x, :])
# if row_sum > 0:
# self.graph[x, :] = self.graph[x, :] / row_sum

nx_graph = nx.from_numpy_matrix(self.graph)
scores = nx.pagerank(nx_graph) # this is a dict
Expand Down
8 changes: 4 additions & 4 deletions textrank4zh/TextRank4Sentence.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def train(self, text, lower = False, speech_tag_filter=True,
self.graph[x, y] = similarity
self.graph[y, x] = similarity

for x in xrange(sentences_num):
row_sum = np.sum(self.graph[x, :])
if row_sum > 0:
self.graph[x, :] = self.graph[x, :] / row_sum
# for x in xrange(sentences_num):
# row_sum = np.sum(self.graph[x, :])
# if row_sum > 0:
# self.graph[x, :] = self.graph[x, :] / row_sum

# print self.graph

Expand Down

0 comments on commit 5ba83e1

Please sign in to comment.