我有以下形式的數據龐大的字符串:無法存儲在內存中的
#@ De
A B C.
#@ dabc
xyz def ghi.
#@ <MyName_1>
Here is example.
#@ Df
A B C.
#@ <MyName_2>
De another one.
#@ <MyName_3>
Df next one.
#@ dabc1
xyz def ghi.
#@ <MyName_4>
dabc this one.
轉換成以下形式:
A B#1 C. //step 1 -- 1 assigned to the first occurrence of A B C.
xyz def#1 ghi. //1 assigned to first occurrence of xyz def ghi
Here is example
A B#2 C. //step 1 -- 2 assigned in increasing order
B#1 another one. //step 2
B#2 next one.
xyz def ghi.
def#1 this one.
//這裏代表的意見,並且不爲輸出的一部分。
該算法如下。
- 如果重複##後面的第二行。然後,附加到中間詞#number的 ,其中number是一個數字標識符,並且是以第二行的重複次序遞增的順序分配的 。
- 將#@ ...替換爲出現的單詞#編號。
- 刪除所有#@,其中第二行不重複。
爲了達到這個目的,我存儲了所有的三元組,然後查找它們的出現次序,以便按遞增順序分配數字。有沒有其他的方式來實現python中的相同。實際上,我的文件是500GB,並且不可能將所有三元組存儲在內存中以查找它們的出現。
第二行如何從'A B C.'轉換爲'A B#1 C.'? (我猜'''評論不是輸出的一部分?)我不明白應該做到這一點的三條規則中的任何一條。 – abarnert 2014-09-23 21:46:45
@JoranBeasley好的。你能說明如何使用數據庫做同樣的事情嗎?因爲我是在python中使用數據庫的新手 – user3809749 2014-09-23 21:46:44
@abamert是的,你是正確的//是評論。我正在使用它們來說明這一點。 – user3809749 2014-09-23 21:47:25