Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 通过nltk将元组组件作为pos标记添加到元组列表中_Python_List_Tags_Tuples_Nltk - Fatal编程技术网

Python 通过nltk将元组组件作为pos标记添加到元组列表中

Python 通过nltk将元组组件作为pos标记添加到元组列表中,python,list,tags,tuples,nltk,Python,List,Tags,Tuples,Nltk,我正在研究一种名称实体识别(NER),用于识别文本的一些标签 我想使用nltk,问题是我有这种格式的数据(元组列表),基本上看起来像这样(4个示例): 我想在不改变数据结构的情况下添加到每个元组pos_标记 期望的结果应该是这样的 [[('Appendix','CS', 'None'), ('B', 'NC', 'None')], [('On', 'NC', 'None'), ('the', 'NC', 'None'), ('Table', 'NC', 'None'),

我正在研究一种名称实体识别(NER),用于识别文本的一些标签

我想使用
nltk
,问题是我有这种格式的数据(元组列表),基本上看起来像这样(4个示例):

我想在不改变数据结构的情况下添加到每个元组pos_标记

期望的结果应该是这样的

[[('Appendix','CS', 'None'), ('B',  'NC', 'None')],
 [('On',  'NC',  'None'),
  ('the',  'NC',  'None'),
  ('Table',  'NC',  'None'),
  ('of', 'Fp' 'None'),
  ('Oppositions','Fp',  'None'),
  ('in', 'Fp' 'None'),
  ('Chapter', 'Fp', 'None'),
  ('15', 'Fp', 'NUM')],
 [('by', 'None'),
  ('Yaakov', 'Fp', 'None'),
  ('Zik', 'None'),
  ('Table', 'Fp', 'None'),
  ('i', 'Fp', 'None')],
 [('Initial', 'Fp', 'None'),
  ('positions', 'Fp', 'None'),
  ('of', 'Fp', 'None'),
  ('Mars', 'Fp', 'None'),
  ('in', 'Fp', 'None'),
  ('Chapter 15 ', 'Z', 'None'),
  ('computed', 'Fp', 'None'),
  ('with', 'Fp', 'None'),
  ('Guide 9 ', 'Fp', 'None'),
  ('using', 'None'),
  ('JPL', 'Fp', 'GEOM'),
  ('DE430', 'Fp', 'GEOM')],
 [('General', 'Z', 'None'), ('notes', ''Fp' 'None')]] 
如上所述,我想通过nltk.pos_标记(sent)在每个元组中添加pos标记


一般来说,我如何将一个组件添加到元组列表中,以使结果再次与元组列表相同?

您的问题有点模糊,但根据我的理解,这里有一个快速解决方案。假设您希望保持顺序不变,并希望将项插入元组的某个位置:

to_add = '*' # Replace this value with the actual data you want to insert such as pos_tag
position_to_add = 1 # Replace this value with the actual position to insert into

result = []
for lst in df:
    ret_li = []
    for tpl in lst:
        # new_tpl = [*tpl]
        # new_tpl.append('None')
        new_tpl = tuple([*tpl[0:position_to_add]] + [to_add] + [*tpl[position_to_add:]])
        ret_li.append(new_tpl)

    result.append(ret_li)

这对于一个不断增加的值来说是完美的!非常感谢。现在,我正在将此项添加到每个元组中。我有。我更新了结果,只有最后一个问题,用nltk标记一个单词而不是一个句子不会影响标记的质量?
to_add = '*' # Replace this value with the actual data you want to insert such as pos_tag
position_to_add = 1 # Replace this value with the actual position to insert into

result = []
for lst in df:
    ret_li = []
    for tpl in lst:
        # new_tpl = [*tpl]
        # new_tpl.append('None')
        new_tpl = tuple([*tpl[0:position_to_add]] + [to_add] + [*tpl[position_to_add:]])
        ret_li.append(new_tpl)

    result.append(ret_li)