forked from shibing624/python-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcut_file.py
More file actions
35 lines (27 loc) · 837 Bytes
/
cut_file.py
File metadata and controls
35 lines (27 loc) · 837 Bytes
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
# -*- coding: utf-8 -*-
"""
@author:XuMing([email protected])
@description:
"""
import jieba
text = "哈尔滨工业大学迎来100年华诞,周华主持了会议。乐视赞助了会议"
print(jieba.lcut(text))
import jieba.posseg
print(jieba.posseg.lcut(text))
from fastHan import FastHan
model = FastHan()
sentence = "郭靖是金庸笔下的一名男主。"
answer = model(sentence, target="NER")
print(answer)
with open("dynamic_samples.txt", 'r', encoding='utf-8') as f:
for line in f:
line = line.strip('\n')
if line.startswith('#'):
continue
parts = line.split('\t')
idea = parts[0]
brand = parts[1] if len(parts) == 2 else ''
words = jieba.posseg.lcut(idea)
ners = model(idea, target='NER')
if brand:
print(brand, ners, words)