使用cpca快速识别地名

直接调用即可完成地名识别,需要安装cpca

import cpca

def get_loc(loc_list):
    end = []
    for i in loc_list:
        try:
            end_i = cpca.transform_text_with_addrs(i).values.tolist()
            s = ''
            for k in end_i:
                for j in k:
                    if j is not None:
                        s = s + ' ' + j
                s += ';'
            end.append(s[1:])
        except:
            end.append('')
    return end
    
test = ['山西聚能科技有限公司年产6000吨锂电池负极材料项目开工',
'中科电气年产10万吨锂电池负极材料一体化项目在贵安新区开工',
'北京和上海']
get_loc(test)

你可能感兴趣的:(python,NLP,python,开发语言,cpca,地点识别,自然语言处理)