short_Cases1 = ["我们伟大祖国的每一寸领土都绝对不能也绝对不可能从中国分割出去"]
import jieba
import jieba.posseg as pseg
import thulac
from pyhanlp import *
import pkuseg
from ltp import LTP
import nltk
thu1 = thulac.thulac() # 默认模式
seg = pkuseg.pkuseg(postag=True) # 以默认配置加载模型
ltp = LTP() # 默认加载 Small 模型
for sentence in short_Cases:
for sentence in short_Cases1:
seg_list = pseg.cut(sentence)
print('jieba:')
for w in seg_list:
a = w.word + w.flag
print(' ', a, end=' ')
print('\t')
text = thu1.cut(sentence, text=True) # 进行一句话分词
print("thulac:", '\n', text)
print("HanLP:", '\n', HanLP.segment(sentence))
text = seg.cut(sentence)
print("pkuseg:", '\n', text)
seg, hidden = ltp.seg(short_Cases1)
pos = ltp.pos(hidden) # 词性标注
print("ltp:", '\n', seg)
print('', pos)
encoding=utf-8
import jieba
import thulac
from pyhanlp import *
import pkuseg
from ltp import LTP
import time
A = ['刘二狗', '真', '狗', ',', '刘大狗', '比', '他', '还', '狗']
sentence = "刘二狗真狗,刘大狗比他还狗"
t1 = time.time()
jiebajg = list(jieba.cut(sentence))
t2 = time.time()
thu1 = thulac.thulac(seg_only=True)
thulacjg = thu1.cut(sentence, text=True).split()
t3 = time.time()
pyhanlpjg = []
for term in HanLP.segment(sentence):
pyhanlpjg.append(term.word)
t4 = time.time()
se = pkuseg.pkuseg()
pkusegjg = list(se.cut(sentence))
t5 = time.time()
ltp = LTP()
ltpjg, hidden = ltp.seg([sentence])
t6 = time.time()
def jqzhf1(x, y, n):
a = 0
b = 0
c = 0
za = 0
zb = 0
while True:
if za == zb:
if len(x[a]) == len(y[b]):
c += 1
zb += len(y[b])
za += len(x[a])
a += 1
b += 1
else:
zb += len(y[b])
za += len(x[a])
a += 1
b += 1
if za < zb:
za += len(x[a])
a += 1
if za > zb:
zb += len(y[b])
b += 1
if zb == n | za == n:
break
P = c / len(y)
R = c / len(x)
F = 2 * P * R / (P + R)
return P, R, F
precision, recall, F1 = jqzhf1(A, jiebajg, len(sentence))
print("jieba:\n精准率{}:\n召回率:{}\nF1:{}".format(precision, recall, F1))
print("所用时间", t2 - t1)
print(jiebajg)
precision, recall, F1 = jqzhf1(A, thulacjg, len(sentence))
print("thulac:\n精准率{}:\n召回率:{}\nF1:{}".format(precision, recall, F1))
print("所用时间", t3 - t2)
print(thulacjg)
precision, recall, F1 = jqzhf1(A, pyhanlpjg, len(sentence))
print("pyhanlp:\n精准率{}:\n召回率:{}\nF1:{}".format(precision, recall, F1))
print("所用时间", t4 - t3)
print(pyhanlpjg)
precision, recall, F1 = jqzhf1(A, pkusegjg, len(sentence))
print("pkuseg:\n精准率{}:\n召回率:{}\nF1:{}".format(precision, recall, F1))
print("所用时间", t5 - t4)
print(pkusegjg)
precision, recall, F1 = jqzhf1(A, ltpjg[0], len(sentence))
print("ltp:\n精准率{}:\n召回率:{}\nF1:{}".format(precision, recall, F1))
print("所用时间", t6 - t5)
print(ltpjg[0])
哪位可以把这两段代码运行出来给我发个截图呀