forked from DerwenAI/pytextrank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrub.py
executable file
·42 lines (30 loc) · 992 Bytes
/
scrub.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
#!/usr/bin/env python
# encoding: utf-8
import pytextrank
import sys
import unicodedata
DEBUG = False # True
def cleanup_text (text):
"""
It scrubs the garbled from its stream...
Or it gets the debugger again.
"""
x = " ".join(map(lambda s: s.strip(), text.split("\n"))).strip()
x = x.replace('“', '"').replace('”', '"')
x = x.replace("‘", "'").replace("’", "'").replace("`", "'")
x = x.replace('…', '...').replace('–', '-')
x = str(unicodedata.normalize('NFKD', x).encode('ascii', 'ignore').decode('ascii'))
# some content returns text in bytes rather than as a str ?
try:
assert type(x).__name__ == 'str'
except AssertionError:
print("not a string?", type(line), line)
return x
if __name__ == "__main__":
path = sys.argv[1]
with open(path) as f:
text = f.read()
j = {}
j["id"] = "777"
j["text"] = cleanup_text(text)
print(pytextrank.pretty_print(j))