DINGOLANI commited on
Commit
7efa999
·
verified ·
1 Parent(s): 5c291e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -34,16 +34,20 @@ autocomplete_embeddings = model.encode(autocomplete_data, convert_to_tensor=True
34
  def find_synonym(word, top_n=1):
35
  query_embedding = model.encode(word, convert_to_tensor=True)
36
  results = util.semantic_search(query_embedding, autocomplete_embeddings, top_k=top_n)
37
- return [autocomplete_data[result['corpus_id']] for result in results[0]]
 
 
 
38
 
39
  # Function to correct spellings
40
  def correct_spelling(word):
41
- matches = process.extract(word, autocomplete_data, scorer=fuzz.ratio, limit=1)
42
- if matches: # Ensure a match exists
43
- best_match = matches[0][0] # Extract the best match string
44
- score = matches[0][1] # Extract the match score
45
- return best_match if score > 80 else word # Only correct if confidence > 80%
46
- return word # Return the original word if no match found
 
47
 
48
  # Autocomplete function with tracking
49
  def autocomplete(query):
 
34
  def find_synonym(word, top_n=1):
35
  query_embedding = model.encode(word, convert_to_tensor=True)
36
  results = util.semantic_search(query_embedding, autocomplete_embeddings, top_k=top_n)
37
+
38
+ if results[0]:
39
+ return [autocomplete_data[result['corpus_id']] for result in results[0] if result['score'] > 0.6] # Only return synonyms with good confidence
40
+ return [word] # Return original word if no synonym is found
41
 
42
  # Function to correct spellings
43
  def correct_spelling(word):
44
+ matches = process.extract(word, autocomplete_data, scorer=fuzz.partial_ratio, limit=3)
45
+
46
+ if matches:
47
+ best_match, score, _ = matches[0] # Extract the best match string & score
48
+ if score > 70: # Lowered threshold to allow for more typo tolerance
49
+ return best_match
50
+ return word # Return the original word if no good match is found
51
 
52
  # Autocomplete function with tracking
53
  def autocomplete(query):