In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use Python to extract the name of the person in the sentence, the article is very detailed, has a certain reference value, interested friends must read it!
Environmental dependence
Need to install two libraries, in fact, one is fine, but I have prepared two libraries to make a comparison.
The installation commands are as follows:
Pip install LAC-I https://pypi.douban.com/simplepip install ltp-I https://pypi.douban.com/simple code
No nonsense, go to the code.
#! / user/bin/env python# coding=utf-8 "" @ project: csdn@author: swordsman A Liang _ ALiang@file: extract_sentence_name_tool.py@ide: PyCharm@time: 2022-01-25 11:11:43 "" from LAC import LACfrom ltp import LTPimport time lac = LAC (mode= "lac") ltp = LTP () # sentence extraction name def extract_name (sentence: str Type='lac'): user_name_lis = [] if type= = 'lac': _ result = lac.run (sentence) for _ index, _ label in enumerate (_ result [1]): if _ label = = "PER": user_name_lis.append (_ result [0] [_ index]) elif type= =' ltp': _ seg _ hidden = ltp.seg ([sentence]) _ pos_hidden = ltp.pos (_ hidden) for _ seg_i, _ seg_v in enumerate (_ seg): _ hidden_v = _ pos_ hidden[ _ seg_i] for _ hudi _ seg_ v in enumerate (_ hidden_v): if _ hudv = = "nh": user_name_lis.append (_ seg_ v [_ hudi]) else: raise Exception ('type not suppose') return user_name_lis if _ _ name__ = =' _ _ main__': _ start_lac = time.time () lis1 = extract_name ("just because I watched the trump card show of Shen Teng and Jia Ling. So Yang Di must have stolen the topic. " , 'lac') _ end_lac = time.time () print ("LAC: {}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.