Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preventing query as recommendation, and checking that the same questions are in the query and the recommendations #10

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions api/cbrcycle/custom_reuse_scripts/_isee.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,22 @@ def nlg_subtree(q_nodes, s_nodes):
print(s_nodes)
return ""

def filter_same_question(bt1, bt2):
"""
bt1, bt2 -> graph format
Function to check if the questions in two BTs are exactly the same (returns true).
If the questions are not exactly the same, returns false
"""
question_isee = [question for intent in INTENTS.values() for question in intent]
questions_bt1 = sorted([x for x in bt1["nodes"] if x in question_isee])
questions_bt2 = sorted([x for x in bt2["nodes"] if x in question_isee])

if questions_bt1 == questions_bt2:
return True
else:
return False


def replace_subtree(data):
if data is None:
return {}
Expand Down Expand Up @@ -1076,9 +1092,13 @@ def replace_subtree(data):
solution = {}
for bt in tree_dict_filtered:
tree_case = tree_dict_filtered[bt]['tree_graph']
if query_subtree_graph != tree_case:
solution[bt] = edit_distance(
# here we are checking if the case has the same questions than the query
# we should comment "and filter_same_question(tree_case, query_subtree_graph)" if we dont want to consider the questions
if query_subtree_graph != tree_case and filter_same_question(tree_case, query_subtree_graph):
edit_distance_value = edit_distance(
query_subtree_graph, tree_case, semantic_delta_parent(similarities))
if edit_distance_value != 0:
solution[bt] = edit_distance_value

sorted_BTs = sorted(solution.items(), key=lambda x: x[1])
results = []
Expand Down