[python jieba]词性标注 2018年4月16日10:40:07

>>> import jieba

>>> import jieba.posseg
>>> string = '陈晨和林迪是好朋友'
>>> seg = jieba.posseg.cut(string)
>>> print(seg)
<generator object cut at 0x00000145F7601FC0>
>>> l = []
>>> for i in seg:
...   l.append(i.word,i.flag)
...
Building prefix dict from the default dictionary ...
Loading model from cache C:\Users\oil\AppData\Local\Temp\jieba.cache
Loading model cost 0.937 seconds.
Prefix dict has been built succesfully.
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
TypeError: append() takes exactly one argument (2 given)
>>> for i in seg:
...   l.append(i.word,i.flag)
... for element in l:
  File "<stdin>", line 3
    for element in l:
      ^
SyntaxError: invalid syntax
>>> for i in seg:
...   l.append((i.word,i.flag))
...
>>> for element in l:
...   print(element[0],element[1])
...
和 c
林迪 nr
是 v
好 a
朋友 n
>>> print(type(seg))
<class 'generator'>
>>> print(type(element))
<class 'tuple'>
>>> print(type(l))
<class 'list'>
>>> print(list)
<class 'list'>
>>> print(l)

[('和', 'c'), ('林迪', 'nr'), ('是', 'v'), ('好', 'a'), ('朋友', 'n')]

-----------------------------------------------------------------------------------


没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭