当前位置: 首页 > news >正文

百度LAC分词

对应数据的链接放这里了
import pandas as pd
from util.logger import Log
import os
from util.data_dir import root_dir
from LAC import LAC
os_file_name = os.path.split(os.path.realpath(__file__))[-1]# 加载LAC模型
lac = LAC(mode="lac")
# 载入自定义词典
lac.load_customization(f'{root_dir}/data/lac_data/lac_define_dict.txt')def load_stopwords():"""加载停用词:return: list"""stopwords_path = f'{root_dir}/data/lac_data/stop_words.txt'stopwords_increase_path = f'{root_dir}/data/lac_data/stop_words_increase.txt'if stopwords_path:with open(stopwords_path, 'r', encoding='utf-8-sig') as f:stopwords = [line.strip() for line in f]else:Log().info(os_file_name, '《热点事件》|没有停用词表|')stopwords = []if stopwords_increase_path:with open(stopwords_increase_path, 'r', encoding='utf-8-sig') as f:stopwords_increase = [line.strip() for line in f]stopwords.extend(stopwords_increase)else:Log().info(os_file_name, '《热点事件》|没有停用词增加表|')return stopwordsdef extract_important_word(content: str):"""LAC分词:param content: str:return: str"""# 运行laclac_result = lac.run(content)# 将分词和词性转为dataframelac_result_df = pd.DataFrame(data=zip(lac_result[1], lac_result[0]), columns=['char', 'word'])# 选取重要词性的dataframeseg_data = list(lac_result_df[(lac_result_df['char'] == 'n') | (lac_result_df['char'] == 'vn')| (lac_result_df['char'] == 'an') | (lac_result_df['char'] == 'nz')| (lac_result_df['char'] == 'ORG') | (lac_result_df['char'] == 'v')| (lac_result_df['char'] == 'LOC')].word)# 获取重要词语,不在停用词内docu_process = ','.join([word for word in seg_data if len(word) >= 2 and word not in load_stopwords()])return docu_processif __name__ == "__main__":sentence = "小区物业没人管,垃圾也没人处理"sentence = extract_important_word(sentence)print(sentence)
http://www.lryc.cn/news/17305.html

相关文章:

  • 软件测试面试题 —— 整理与解析(1)
  • 深入浅出C++ ——红黑树模拟实现STL中的set与map
  • 自动化测试框架设计
  • 【虚拟仿真】Unity3D中实现鼠标的单击、双击、拖动的不同状态判断
  • 【2023】Prometheus-相关知识点(面试点)
  • 英语二-电子邮件邀请短文写作
  • 如何快速一次性通过pmp考试?
  • 1-Linux 保存kernel panic信息到flash
  • linux基本功系列-top命令实战
  • 6.5 拓展:如何实现 Web API 版本控制,同时兼容无版本控制的原始接口?
  • Springboot依赖注入Bean的三种方式,final+构造器注入Bean
  • 【java】Spring Cloud --Spring Cloud Alibaba 微服务解决方案
  • CSS 6种选择器(超详细)
  • mysql8.0.32-手动配置安装-具体流程步骤
  • 【项目】Vue3+TS 退出登录 menu header搭建
  • LoRaWAN模块在车辆跟踪定位中的应用
  • 软件测试分类
  • 外置的媒体查询,对性能又一次的优化提升
  • 【Galois工具开发之路】关于IDEA的gradle工程执行两次premain的bug~
  • 云计算 概念与技术
  • 基于追踪标记的WAF设计思路
  • Java StringBuffer StringBuilder,超详细整理,适合新手入门
  • 数据结构—堆(完全解析)
  • 深度卷积对抗神经网络 进阶 第三部分 GANs Unpaired Translation with Cycle GAN 模型
  • 常见的排序算法 | 直接插入排序 | 希尔排序 | 选择排序 | 堆排序 | 冒泡排序 | 快速排序 | 归并排序 |(详解,附动图,代码)
  • 深入浅出 MySQL 索引(一)
  • FinClip 的 2022 与 2023
  • Python 泛型 - 如何在实例方法中获取泛型参数T的类型?
  • Shell语法基础总结
  • 架构基本概念和架构本质