|
|
@ -179,46 +179,6 @@ def request_results(query): |
|
|
|
|
|
|
|
return filenames, results, analytics |
|
|
|
|
|
|
|
def get_tfidflistings(): |
|
|
|
index = load_index() |
|
|
|
languages = set([index[document]['language'] for document in index.keys()]) |
|
|
|
tfidflistings = {} |
|
|
|
for language in languages: |
|
|
|
tfidflistings[language] = [] |
|
|
|
for document in index.keys(): |
|
|
|
if index[document]['language'] == language: |
|
|
|
for word, value in index[document]['tfidf'].items(): |
|
|
|
tfidflistings[language].append([value, word]) |
|
|
|
tfidflistings[language].sort(reverse=True) |
|
|
|
|
|
|
|
# pp.pprint(tfidflistings) |
|
|
|
print('*tfidflistings returned*') |
|
|
|
return tfidflistings |
|
|
|
|
|
|
|
def get_tfidfcontext(query): |
|
|
|
tfidflistings = get_tfidflistings() |
|
|
|
tfidfcontext = {} |
|
|
|
context_reach = 3 |
|
|
|
for language in tfidflistings.keys(): |
|
|
|
index = 0 |
|
|
|
tfidfcontext[language] = [] |
|
|
|
for value, word in tfidflistings[language]: |
|
|
|
if word.lower() == query.lower(): |
|
|
|
for x in range(1, context_reach): |
|
|
|
cprev = tfidflistings[language][index - x] |
|
|
|
cnext = tfidflistings[language][index + x] |
|
|
|
tfidfcontext[language].append(cprev) |
|
|
|
if x == 1: |
|
|
|
tfidfcontext[language].append([value, word]) |
|
|
|
tfidfcontext[language].append(cnext) |
|
|
|
break |
|
|
|
index += 1 |
|
|
|
tfidfcontext[language].sort(reverse=True) |
|
|
|
|
|
|
|
# pp.pprint(tfidfcontext) |
|
|
|
print('*tfidfcontext returned*') |
|
|
|
return tfidfcontext |
|
|
|
|
|
|
|
def request_mappings(mapping_type): |
|
|
|
index = load_index() |
|
|
|
filenames = [document for document, _ in index.items()] |
|
|
|