Skip to content

Commit

Permalink
Fix of induced bag for search
Browse files Browse the repository at this point in the history
  • Loading branch information
M1Al3x authored Aug 31, 2023
1 parent 7e654c5 commit 089e45e
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions src/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def word_details_api(request, slug: str):
if matched_recs:
recordings.extend(matched_recs)
print("here we go")
if paradigm is not None:
if paradigm is not None:
FST_DIR = settings.BASE_DIR / "res" / "fst"
paradigm_manager = ParadigmManager(
layout_directory=settings.LAYOUTS_DIR,
Expand All @@ -154,6 +154,7 @@ def word_details_api(request, slug: str):
}
}


return Response(content)


Expand Down Expand Up @@ -193,6 +194,7 @@ def search_api(request):
:param request:
:return:
"""


query_string = request.GET.get("name")
rw_index = request.GET.get("rw_index")
Expand Down Expand Up @@ -231,14 +233,18 @@ def search_api(request):
context["verbose_messages"] = json.dumps(
search_run.verbose_messages, indent=2, ensure_ascii=False
)
context["search_results"] = recordings(context["search_results"], request)

start = time.time()
context["search_results"] = recordings(
context["search_results"], request
)
end = time.time()
print(end-start)
for result in context["search_results"]:

result["wordform_text"] = wordform_orth_text(result["wordform_text"])
result["lemma_wordform"]["wordform_text"] = wordform_orth_text(
result["lemma_wordform"]["text"]
)
end = time.time()
if "inflectional_category" in result["lemma_wordform"]:
result["lemma_wordform"][
"inflectional_category_relabelled"
Expand All @@ -252,6 +258,7 @@ def search_api(request):
return Response(context)



def make_wordnet_format(wn_class):
"""
Accepts: wn_class of format (n) bear 1
Expand Down Expand Up @@ -301,7 +308,6 @@ def wordnet_api(request, classification):

return Response(context)


def recordings(results, request):
query_terms = []
for result in results:
Expand All @@ -316,33 +322,22 @@ def recordings(results, request):
for search_terms in divide_chunks(query_terms, 30):
for source in speech_db_eq:
temp.append(None)
query_terms = [
query_terms[0],
query_terms[1],
query_terms[2],
query_terms[3],
query_terms[4],
]
index = 0
size_query = len(query_terms)
terms = []
for index in range(min(size_query, 5)):
terms.append(query_terms[index])
query_terms = terms
for search_terms in divide_chunks(query_terms, 30):
for source in speech_db_eq:
url = f"https://speech-db.altlab.app/{source}/api/bulk_search"
x = threading.Thread(
target=get_recordings_from_url,
args=(
search_terms,
url,
temp,
index,
),
)
x = threading.Thread(target=get_recordings_from_url, args=(search_terms, url, temp, index,))
threads.append(x)
x.start()
index += 1
print("here we go")
for i in range(len(threads)):
threads[i].join()
print(temp)

for item in temp:
if item is not None:
matched_recordings.update(item)
Expand All @@ -355,7 +350,6 @@ def recordings(results, request):
result["recording"] = ""
return results


def relabelInflectionalCategory(ic):
with open(Path(settings.RESOURCES_DIR / "altlabel.tsv")) as f:
labels = Relabelling.from_tsv(f)
Expand Down

0 comments on commit 089e45e

Please sign in to comment.