-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.py
49 lines (37 loc) · 1.08 KB
/
query.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
"""
handle queries for data crawled before DRC
"""
import os
import json
import sys
import re
import argparse
import codecs
from collections import Counter
PATH_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),"path.json")
class PreDRCQuery(object):
def __init__(self,query_path=None):
if query_path:
self._query_path = query_path
else:
path_data = json.load(open(PATH_FILE))
self._query_path = path_data["query"]
self._queries = json.load(open(self._query_path))
@property
def queries(self):
return self._queries
def count_top_disaster(self,top=5):
words = {}
for qid in self._queries:
for w in re.findall("\w+",self._queries[qid]):
if w not in words:
words[w] = 0
words[w] += 1
c = Counter(words)
print c.most_common(top)
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("")
args=parser.parse_args()
if __name__=="__main__":
main()