-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader.py
43 lines (31 loc) · 1.01 KB
/
reader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
"""
from bs4 import BeautifulSoup
from xml.etree import ElementTree
import codecs
from .utils import normalize_sentence
__author__ = ["Clément Besnier <[email protected]>", ]
def read_moses():
with open('texts/moses.html', 'r') as f:
b = BeautifulSoup(f.read(), 'html5lib')
print(b.text[1000:2100])
def read_corpus():
with codecs.open("corpora/fsv-aldrelagar.xml", "r", encoding="utf8") as f:
text = f.read()
root = ElementTree.fromstring(text)
ltext = []
for text in root:
title = text.attrib["title"]
lparagraph = []
for paragraph in text:
sentences = []
for sentence in paragraph:
lsentence = []
for word in sentence:
lsentence.append(word.text)
sentences.append(normalize_sentence(lsentence))
lparagraph.append(" ".join(sentences))
ltext.append("\n\n".join(lparagraph))
return ltext
if __name__ == "__main__":
print(read_corpus())