zhiminy commited on
Commit
09c7026
·
verified ·
1 Parent(s): d482b19

add normalization

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import requests
2
  import streamlit as st
 
3
 
4
  # Constants for citation information
5
  CITATION_BUTTON_LABEL = "📙 Citation"
@@ -38,7 +39,7 @@ class SearchApplication:
38
  st.write("#")
39
 
40
  self.show_search_results()
41
- self.show_citation_panel() # Add the citation panel here
42
 
43
  def set_page_config(self):
44
  st.set_page_config(
@@ -47,6 +48,10 @@ class SearchApplication:
47
  layout="centered",
48
  )
49
 
 
 
 
 
50
  def show_search_results(self):
51
  if self.query:
52
  st.write("#")
@@ -56,8 +61,11 @@ class SearchApplication:
56
  if readme_content:
57
  search_results = []
58
  lines = readme_content.split("\n")
 
 
59
  for line in lines:
60
- if self.query.lower() in line.lower():
 
61
  search_results.append(line)
62
 
63
  num_search_results = len(search_results)
 
1
  import requests
2
  import streamlit as st
3
+ import re # For string normalization
4
 
5
  # Constants for citation information
6
  CITATION_BUTTON_LABEL = "📙 Citation"
 
39
  st.write("#")
40
 
41
  self.show_search_results()
42
+ self.show_citation_panel()
43
 
44
  def set_page_config(self):
45
  st.set_page_config(
 
48
  layout="centered",
49
  )
50
 
51
+ def normalize_string(self, input_string):
52
+ """Normalize a string by removing spaces, converting to lowercase, and stripping special characters."""
53
+ return re.sub(r'\s+', '', input_string.lower())
54
+
55
  def show_search_results(self):
56
  if self.query:
57
  st.write("#")
 
61
  if readme_content:
62
  search_results = []
63
  lines = readme_content.split("\n")
64
+ normalized_query = self.normalize_string(self.query) # Normalize user query
65
+
66
  for line in lines:
67
+ normalized_line = self.normalize_string(line) # Normalize each line
68
+ if normalized_query in normalized_line:
69
  search_results.append(line)
70
 
71
  num_search_results = len(search_results)