import re SEPARATOR reg_arr re compile фейсбук facebook linkedin vkont

 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
import re
SEPARATOR = "|"
reg_arr = [ re.compile(u'фейсбук|facebook|linkedin|vkontakt|вконтакт',re.IGNORECASE | re.UNICODE),
re.compile(u'соц.{1,10}сет', re.UNICODE)]
re.compile(u'скайп[^у]|skype', re.IGNORECASE | re.UNICODE),
re.compile(u'скайпу', re.IGNORECASE | re.UNICODE),
re.compile(u'[йцукенгшщздлорпавифячсмітьбю].*\s[a-zZ-Z]', re.IGNORECASE | re.UNICODE),
re.compile('\d{3}[-\.\s]??\d{3}[-\.\s]??\d{4}|\(\d{3}\)\s*\d{3}[-\.\s]??\d{4}|\d{3}[-\.\s]??\d{4}'),
...
re.compile('http|www|\.com', re.IGNORECASE),
re.compile(u'мой|my', re.IGNORECASE | re.UNICODE),
re.compile(u'найдите|find', re.IGNORECASE | re.UNICODE),
re.compile(u'добавь|add', re.IGNORECASE | re.UNICODE),
...
re.compile('\w+@\w+', re.IGNORECASE),
re.compile('.{0,50}', re.IGNORECASE),
re.compile('.{50,200}', re.IGNORECASE),
....
]
def feature_vector(text):
return map(lambda x: 1 if x.search(text) else 0, reg_arr)
fi=open('db_machine.csv', 'r')
fo=open('db_machine_result.csv', 'w')
for line in fi:
[text, result] = line.split(SEPARATOR)
output = feature_vector(text).append(result)
fo.write(",".join(map(lambda x: str(x), output )) + "\n")
fo.close()
fi.close()