知識圖譜數據預處理筆記
- 0. 引言
- 1. 筆記
- 1-1. `\`的轉義
- 1-2. 特殊符號的清理
- 1-3. 檢查結尾是否正常
- 1-4. 檢查`<>`是否存在
- 1-5. 兩端空格的清理
- 1-6. 檢查object內容長時是否以`<`開始
0. 引言
最近學習知識圖譜,發現數據有很多問題,這篇筆記記錄遇到的一些問題。
1. 筆記
1-1. \
的轉義
line = line.replace('\\', '\\\\')
1-2. 特殊符號的清理
line.replace('特殊符號', '')
由于特殊符號在文章上無法粘貼顯示,所以采取截圖的形式
1-3. 檢查結尾是否正常
for line in input_file:last_four = line[-4:]last_three = line[-3:]if last_four == '> .\n' or last_four == '" .\n':output_file1.write(line)elif last_three == '>.\n' or last_three == '".\n':output_file1.write(line)else:output_file2.write(line)
1-4. 檢查<>
是否存在
if '<>' in line:output_file3.write(line)
1-5. 兩端空格的清理
line = line.strip()
1-6. 檢查object內容長時是否以<
開始
if len(object) > 10 and object[0] == '<':output_file3.write(line)continue
未完待續!!!