1. 程式人生 > >論文翻譯第二彈--用python(或Markdown)對論文復制文本進行處理

論文翻譯第二彈--用python(或Markdown)對論文復制文本進行處理

dem 有一個 tab and http -- png 處理 pen

技術分享圖片

圖中這種論文你想進行文本復制放入翻譯軟件進行翻譯時,會發現是這種形式:

技術分享圖片

句子之間是斷開的,這時普遍的方法,也是我之前一直用的方法就是打開一個文檔編輯器,復制上去後一行行地繼續調整。昨天不想這樣了,就打算寫個批量處理的函數完成這項工作。
python小白在重復了一個小時的工作之後,總是有奇怪的問題出現,打算放棄時突然搞好了。之前的函數編寫邏輯出現了問題,想在每一行後面加空格然後把第二行的數據增加到第一行上,不熟悉的操作使得字符串數據變成了list數據而不知如何下手。最後刪代碼時突然發現,只需要把每一行後面的換行符
\n刪除掉再加空格即可。

ff = open('b.txt','w')  #打開一個文件,可寫模式
with open('a.txt','r') as f:  #打開一個文件只讀模式
    line = f.readlines()
    for line_list in line:
        line_new =line_list.replace('\n','')
        line_new =line_new+' '  #行末尾加上" "
        ff.write(line_new)

不過該程序也有一個問題,在結果文件中沒有換行符的存在,也就是分段不明顯。嘗試在段首加入\t進行分隔,但google在翻譯的時候會忽視tab的存在而照樣看不出分段的模樣。有些遺憾但能基本功能可以使用了。

Abstract〞Autonomous feeding is challenging because it requires manipulation of food items with various compliance, sizes, and shapes. To understand how humans manipulate food items during feeding and to explore ways to adapt their strategies to robots, we collected a rich dataset of human trajectories by asking them to pick up food and feed it to a mannequin. From the analysis of the collected haptic and motion signals, we demonstrate that humans adapt their control policies to

P.S.在編輯的時候突然發現一個更簡單的方法,把文字復制到markdown編輯器中,比如有道雲筆記,可以利用markdown特殊的語法得到相同的結果。

論文翻譯第二彈--用python(或Markdown)對論文復制文本進行處理