鍍金池/ 問答/Java  Python  C++  HTML/ 用Python(或者其他語言)怎么把如下文件中的中文詞條提取出來,并把這些中文做

用Python(或者其他語言)怎么把如下文件中的中文詞條提取出來,并把這些中文做成json文件?

-------------------------------------------------------------------------------
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
........

比如文本中的,“至”,“個”,“分支”,做成json:

“至”:“至”,

“個”:“個”,

“分支”:“分支”

},

各位有什么騷代碼都甩出來把。。。

回答
編輯回答
貓館

不是很推薦樓主的方案,不是很適合用中文作為鍵…

2017年4月15日 15:31
編輯回答
不討囍

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

2018年9月10日 22:43
編輯回答
詆毀你
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()}

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

優(yōu)雅的寫在本地,比如你的文件是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) # {'個': '個', '分支': '分支', '至': '至'}
2017年12月26日 12:22