python笑傲江湖
时间: 2023-11-21 13:58:58 浏览: 96
python
笑傲江湖是金庸先生创作的武侠小说,讲述了主人公令狐冲在江湖中的传奇经历。如果您想提取小说中的人名,可以使用Python进行处理。以下是一个示例代码:
```python
import jieba.posseg as poss
from gensim.models import Word2Vec
# 读取笑傲江湖小说文本
with open('笑傲江湖.txt', 'r', encoding='utf-8') as f:
text = f.read()
# 使用结巴分词提取人名
temp = [poss.lcut(i) for i in text]
people = [[i.word for i in x if i.flag =='nr'] for x in temp]
temp2 = [' '.join(x) for x in people]
people2 = list(set(' '.join(temp2).split()))
# 使用Word2Vec模型获取人名的向量表示
my_wv = Word2Vec.load('my_word2vec.model')
data = []
newpeo = []
for i in people2:
try:
data.append(my_wv.wv[i])
newpeo.append(i)
except KeyError:
pass
```
阅读全文