0
讓我們說我有文字這樣檢索特定文本中游離鹼/ WEX蟒蛇重新
This is something before any tag, today's date is 09-06-2012 blah blah
<firsttag> content of first tag </firsttag> <sentence> This is the
first sentence in my paragraph that needs to be <bold> displayed.
</bold> </sentence> <secondtag> blah blah blah <italics> another blah
</italics></secondtag> <sentence> This is the second sentence in my
paragraph that needs to be displayed and it has some weird contents
like \n\n\n and inbetween reference tags like <link> http://google.com
</link></sentence> <thirdtag>blah blah </thirdtag><sentence>Tennis is
a great sport, I'm really sad that <link
synthetic="True"><target>Roger Federer </link></target>Roger Federer
lost yesterday.</sentence>
輸出/字符串應該是這樣的
這是我的一段第一句需要被 顯示。這是我的段落中的第二句話,需要顯示 ,它有一些奇怪的內容,如中間和參考 標籤像網球是一項偉大的運動,我真的很傷心,羅傑費德勒 失去了yest erday。
我正則表達式解析後輸出應該只有我們裏面的內容和標籤。所有標籤,奇怪的\ n \ n字符以及所有垃圾內容都需要刪除,就像「羅傑·費德勒」那樣,鏈接僅僅指向羅傑·費德勒的頁面,因爲這是一個Freebase-wiki(WEX)我正在處理的數據集。一個簡單的python re代碼來幫助我解決這個問題將是非常有用的。我正在嘗試的代碼是這樣的。
for line in fileinput.input():
p = re.sub('<[^>]*>', '', line)
p = re.sub('\n','',p)
print p
因爲我處理龐大的文件,如果你能幫助我用的map-reduce(Hadoop的)代碼,它也將是非常有益的。在此先感謝:)