亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用Python怎么把如下文件中的中文詞條提取出來,并把這些中文做成json文件?

用Python怎么把如下文件中的中文詞條提取出來,并把這些中文做成json文件?

收到一只叮咚 2019-03-18 17:18:50
-------------------------------------------------------------------------------File:D:\svn\aCenter\windows\dap\store\vdidc\web\vue-ui\src\components\datetime_range.vuecontent:? ? ? ? ? ? ? ? 'default': '至'Line: 24Time: 2018-03-26 08:46:13-------------------------------------------------------------------------------File:D:\svn\aCenter\windows\dap\store\vdidc\web\vue-ui\src\components\piece.vuecontent:? ? ? ? ? ? ? ? <div><span class="branch-num">{{checkBranchNum}}</span><lang>個</lang><Line: 6Time: 2018-03-26 08:46:13-------------------------------------------------------------------------------File:D:\svn\aCenter\windows\dap\store\vdidc\web\vue-ui\src\components\piece.vuecontent:? ? ? ? ? ? ? ? <div class="branch"><lang>分支</lang></div>Line: 7Time: 2018-03-26 0........比如文本中的,“至”,“個”,“分支”,做成json:{“至”:“至”,“個”:“個”,“分支”:“分支”},各位有什么騷代碼都甩出來把。。。
查看完整描述

2 回答

?
絕地無雙

TA貢獻1946條經驗 獲得超4個贊

import re


s = '''File:D:\svn\aCenter\windows\dap\store\vdidc\web\vue-ui\src\components\datetime_range.vue

content:                'default': '至'

Line: 24

Time: 2018-03-26 08:46:13


-------------------------------------------------------------------------------

File:D:\svn\aCenter\windows\dap\store\vdidc\web\vue-ui\src\components\piece.vue

content:                <div><span class="branch-num">{{checkBranchNum}}</span><lang>個</lang><

Line: 6

Time: 2018-03-26 08:46:13


-------------------------------------------------------------------------------

File:D:\svn\aCenter\windows\dap\store\vdidc\web\vue-ui\src\components\piece.vue

content:                <div class="branch"><lang>分支</lang></div>

Line: 7

Time: 2018-03-26 0'''



p2 = re.compile(r'[^\u4e00-\u9fa5]')

result = {i: i for i in " ".join(p2.split(s)).strip().split()}


# {'個': '個', '至': '至', '分支': '分支'}

優雅的寫在本地,比如你的文件是1.txt


import re

p2 = re.compile(r'[^\u4e00-\u9fa5]')

with open('1.txt', 'r') as r:

    result = {i: i for i in ' '.join(p2.split(''.join(r.readlines()))).strip().split()}


print(result) # {'個': '個', '分支': '分支', '至': '至'}


查看完整回答
反對 回復 2019-03-23
?
紫衣仙女

TA貢獻1839條經驗 獲得超15個贊

用規制式啊,字符編碼在中文范圍內的。
這個關鍵是提取,用go語言好像比較方便,因為其內的規制式有中文標簽 go處理中文

查看完整回答
反對 回復 2019-03-23
  • 2 回答
  • 0 關注
  • 735 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號