ola13 commited on
Commit
ca93234
·
1 Parent(s): 7e70097

capitalization variants

Browse files
Files changed (1) hide show
  1. app.py +34 -5
app.py CHANGED
@@ -103,11 +103,40 @@ def format_result(result, highlight_terms, exact_search, datasets_filter=None):
103
  return ""
104
 
105
  if exact_search:
106
- query_start = text.find(highlight_terms)
107
- query_end = query_start + len(highlight_terms)
108
- tokens_html = text[0:query_start]
109
- tokens_html += "<b>{}</b>".format(text[query_start:query_end])
110
- tokens_html += text[query_end:]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  else:
112
  tokens = text.split()
113
  tokens_html = []
 
103
  return ""
104
 
105
  if exact_search:
106
+ query_variants = [highlight_terms]
107
+
108
+ # lower
109
+ query_variant = highlight_terms.lower()
110
+ if query_variant not in query_variants:
111
+ query_variants.append(query_variant)
112
+
113
+ # upper
114
+ query_variant = highlight_terms.upper()
115
+ if query_variant not in query_variants:
116
+ query_variants.append(query_variant)
117
+
118
+ # first capital
119
+ query_variant = highlight_terms.lower()
120
+ query_variant = query_variant[0].upper() + query_variant[1:].lower()
121
+ if query_variant not in query_variants:
122
+ query_variants.append(query_variant)
123
+
124
+ # camel case
125
+ query_tokens = highlight_terms.split()
126
+ query_variant = " ".join(
127
+ [token[0].upper() + token[1:].lower() for token in query_tokens]
128
+ )
129
+ if query_variant not in query_variants:
130
+ query_variants.append(query_variant)
131
+
132
+ for query_variant in query_variants:
133
+ query_start = text.find(query_variant)
134
+ if query_start >= 0:
135
+ query_end = query_start + len(query_variant)
136
+ tokens_html = text[0:query_start]
137
+ tokens_html += "<b>{}</b>".format(text[query_start:query_end])
138
+ tokens_html += text[query_end:]
139
+ break
140
  else:
141
  tokens = text.split()
142
  tokens_html = []