无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

百度LAC分詞(python3實現(xiàn))

2023-02-24 17:32 作者:trisyp  | 我要投稿

對應(yīng)數(shù)據(jù)的鏈接放這里(https://download.csdn.net/download/Trisyp/87486282)了

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 stopwords


def extract_important_word(content: str):
? ?"""
? ?LAC分詞
? ?:param content: str
? ?:return: str
? ?"""

? ?# 運行l(wèi)ac
? ?lac_result = lac.run(content)

? ?# 將分詞和詞性轉(zhuǎn)為dataframe
? ?lac_result_df = pd.DataFrame(data=zip(lac_result[1], lac_result[0]), columns=['char', 'word'])

? ?# 選取重要詞性的dataframe
? ?seg_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)

? ?# 獲取重要詞語,不在停用詞內(nèi)
? ?docu_process = ','.join([word for word in seg_data if len(word) >= 2 and word not in load_stopwords()])
? ?return docu_process


if __name__ == "__main__":
? ?sentence = "小區(qū)物業(yè)沒人管,垃圾也沒人處理"
? ?sentence = extract_important_word(sentence)
? ?print(sentence)

百度LAC分詞(python3實現(xiàn))的評論 (共 條)

分享到微博請遵守國家法律
航空| 黄大仙区| 鄂托克前旗| 龙海市| 璧山县| 尼玛县| 喜德县| 盐边县| 巴南区| 柯坪县| 加查县| 宜良县| 上林县| 肇东市| 方山县| 无极县| 雅安市| 新密市| 山西省| 洛扎县| 清徐县| 光泽县| 屯门区| 沅江市| 涞水县| 东兴市| 方山县| 东台市| 咸阳市| 开化县| 鲁甸县| 四子王旗| 平和县| 长沙县| 渝北区| 思南县| 巴林右旗| 义马市| 日土县| 九台市| 南昌县|