-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextractFutureWorks.py~
65 lines (49 loc) · 1.65 KB
/
extractFutureWorks.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from bs4 import BeautifulSoup
from bs4 import BeautifulStoneSoup
import nltk.data
import re
sent_detector = nltk.data.load('tokenizers/punkt/english.pickle')
def main():
xmlFile="cleanXMLdataV2/W11-0707.out"
with open(xmlFile, 'r') as f:
xmlData = f.read();
#soup = BeautifulStoneSoup(xmlData, selfClosingTags=['sectionHeader','bodyText'])
soup = BeautifulSoup(xmlData, 'html5lib')
print soup.prettify()
bodiesAWK = []
# gets all of the lines after conclusion and before acknowledgement
limit = 5 #assuming that there are not many seperations between conclusion and acknowledgement
for i, header in enumerate(soup.findAll('sectionHeader')):
#print header
if header['genericHeader'] == 'conclusions':
bodiesCON = header.find_all_next('bodyText')
#print bodiesCON
#print bodiesCON
if header['genericHeader'] == 'acknowledgments':
bodiesAWK = header.find_all_previous('bodyText', limit=limit)
bodyConText = ""
print bodiesAWK
for awkbody in reversed(bodiesAWK):
if awkbody in bodiesCON:
bodyConText += awkbody.get_text()
get_futureWork(bodyConText)
#bodiesCON = header.find_next('bodyText').find_next('bodyText')
def get_futureWork(all_text):
ret = ""
#for body in textBodies:
# all_text += body.get_text()
#print all_text
pattern = re.compile("future")
for sent in sent_detector.tokenize(all_text.strip()):
clean_sent = sent.lower().replace('\n', ' ').strip()
clean_sent = clean_sent.replace("- ", "")
#print clean_sent
#print "------------------"
if pattern.search(clean_sent):
print ' >>> there was a match <<< '
ret = sent
print clean_sent
print
return ret
if __name__=="__main__":
main();