Jan Mühlnikel commited on
Commit
e22c7b1
1 Parent(s): b199e73
Files changed (2) hide show
  1. functions/filter_single.py +15 -2
  2. similarity_page.py +16 -3
functions/filter_single.py CHANGED
@@ -5,5 +5,18 @@ def contains_code(crs_codes, code_list):
5
  codes = str(crs_codes).split(';')
6
  return any(code in code_list for code in codes)
7
 
8
- def filter_projects(df, crs3_list, crs5_list, sdg_str, country_code_list, orga_code_list, query, model, embeddings, TOP_X_PROJECTS=30):
9
- # Check if filters where not all should be selected are empty
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  codes = str(crs_codes).split(';')
6
  return any(code in code_list for code in codes)
7
 
8
+ def filter_projects(df, country_code_list, orga_code_list):
9
+ # FILTER COUNTRY
10
+ if country_code_list != []:
11
+ country_filtered_df = pd.DataFrame()
12
+ for c in country_code_list:
13
+ c_df = df[df["country"].str.contains(c, na=False)]
14
+ country_filtered_df = pd.concat([country_filtered_df, c_df], ignore_index=False)
15
+
16
+ df = country_filtered_df
17
+
18
+ # FILTER ORGANIZATION
19
+ if orga_code_list != []:
20
+ df = df[df['orga_abbreviation'].isin(orga_code_list)]
21
+
22
+ return df
similarity_page.py CHANGED
@@ -13,6 +13,7 @@ from sentence_transformers import SentenceTransformer
13
  from modules.multimatch_result_table import show_multi_table
14
  from modules.singlematch_result_table import show_single_table
15
  from functions.filter_projects import filter_projects
 
16
  from functions.calc_matches import calc_matches
17
  from functions.same_country_filter import same_country_filter
18
  from functions.single_similar import find_similar
@@ -239,7 +240,6 @@ def show_multi_matching_page():
239
  orga_code_list = [option.split("(")[1][:-1].lower() for option in orga_option]
240
 
241
  # FILTER DF WITH SELECTED FILTER OPTIONS
242
-
243
  TOP_X_PROJECTS = 30
244
  filtered_df = filter_projects(projects_df, crs3_list, crs5_list, sdg_str, country_code_list, orga_code_list, query, model, embeddings, TOP_X_PROJECTS)
245
  if isinstance(filtered_df, pd.DataFrame) and len(filtered_df) != 0:
@@ -338,6 +338,19 @@ def show_single_matching_page():
338
  selected_index = search_list.index(project_option)
339
  st.dataframe(projects_df.iloc[selected_index])
340
 
341
- top_projects_df = find_similar(selected_index, sim_matrix, projects_df, 10)
342
- show_single_table(top_projects_df)
 
 
 
 
 
 
 
 
 
 
 
 
 
343
 
 
13
  from modules.multimatch_result_table import show_multi_table
14
  from modules.singlematch_result_table import show_single_table
15
  from functions.filter_projects import filter_projects
16
+ from functions.filter_single import filter_single
17
  from functions.calc_matches import calc_matches
18
  from functions.same_country_filter import same_country_filter
19
  from functions.single_similar import find_similar
 
240
  orga_code_list = [option.split("(")[1][:-1].lower() for option in orga_option]
241
 
242
  # FILTER DF WITH SELECTED FILTER OPTIONS
 
243
  TOP_X_PROJECTS = 30
244
  filtered_df = filter_projects(projects_df, crs3_list, crs5_list, sdg_str, country_code_list, orga_code_list, query, model, embeddings, TOP_X_PROJECTS)
245
  if isinstance(filtered_df, pd.DataFrame) and len(filtered_df) != 0:
 
338
  selected_index = search_list.index(project_option)
339
  st.dataframe(projects_df.iloc[selected_index])
340
 
341
+ # COUNTRY CODES LIST
342
+ country_code_list = [option[-3:-1] for option in country_option_s]
343
+
344
+ # ORGANIZATION CODES LIST
345
+ orga_code_list = [option.split("(")[1][:-1].lower() for option in orga_option_s]
346
+
347
+ TOP_X_PROJECTS = 10
348
+ filtered_df_s = filter_single(projects_df, country_code_list, orga_code_list)
349
+ st.dataframe(filtered_df_s)
350
+
351
+ #if isinstance(filtered_df_s, pd.DataFrame) and len(filtered_df_s) != 0:
352
+
353
+
354
+ #top_projects_df = find_similar(selected_index, sim_matrix, projects_df, 10)
355
+ #show_single_table(top_projects_df)
356