-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo.py
62 lines (54 loc) · 2.21 KB
/
demo.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
62
import json
import searcher
import fuzzle
import sys
from datetime import datetime
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
games = list()
with open("../data/games/games.json", encoding="utf8") as f:
games = json.loads(f.read())
print("{} games".format(len(games)))
movies = list()
with open("../data/movies/movies.json", encoding="utf8") as f:
movies = json.loads(f.read())
print("{} movies".format(len(movies)))
companies = list()
with open("../data/economy/companies.json", encoding="utf8") as f:
companies = json.loads(f.read())
print("{} companies".format(len(companies)))
countries = list()
with open("../data/places/countries.json", encoding="utf8") as f:
countries = json.loads(f.read())
print("{} countries".format(len(countries)))
while True:
try:
category = input("What would you like to search through? [games, movies, companies, countries] ")
data = list()
if category.startswith("game"):
data = games
elif category.startswith("movie"):
data = movies
elif category.startswith("compan"):
data = companies
else:
data = countries
search = input("Enter search query: ")
if search != "":
time_started = datetime.now()
data_old = [d["key"] if isinstance(d, dict) else d for d in data]
results = searcher.find(data_old, search)
max_results = min(len(results), 20)
time_ended = datetime.now()
## for result in results[:max_results]:
## print(result["key"])
print("Searcher: {} results | {}\n".format(len(results), time_ended - time_started))
time_started = datetime.now()
results = fuzzle.find(data, search, return_all=True, coverage_multiplier=0.05)
max_results = min(len(results), 50)
time_ended = datetime.now()
for result in results[:max_results]:
print(result["key"].translate(non_bmp_map))
# if "tags" in result: print(result["tags"])
print("New Searcher: {} results | {}".format(len(results), time_ended - time_started))
except KeyboardInterrupt:
exit(0)