domenicrosati commited on
Commit
a776895
β€’
1 Parent(s): 03de2e8

improve snippet matching

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -64,24 +64,22 @@ def search(term, limit=10, clean=True, strict=True, abstracts=True):
64
  )
65
 
66
 
67
-
68
-
69
-
70
  def find_source(text, docs):
71
  for doc in docs:
72
- if text in remove_html(doc[1][0]['snippet']):
73
- new_text = text
74
- for snip in remove_html(doc[1][0]['snippet']).split('.'):
75
- if text in snip:
76
- new_text = snip
77
- return {
78
- 'citation_statement': doc[1][0]['snippet'].replace('<strong class="highlight">', '').replace('</strong>', ''),
79
- 'text': new_text,
80
- 'from': doc[1][0]['source'],
81
- 'supporting': doc[1][0]['target'],
82
- 'source_title': doc[2],
83
- 'source_link': f"https://scite.ai/reports/{doc[0]}"
84
- }
 
85
  return None
86
 
87
 
 
64
  )
65
 
66
 
 
 
 
67
  def find_source(text, docs):
68
  for doc in docs:
69
+ for snippet in doc[1]:
70
+ if text in remove_html(snippet.get('snippet', '')):
71
+ new_text = text
72
+ for snip in remove_html(snippet.get('snippet', '')).split('.'):
73
+ if text in snip:
74
+ new_text = snip
75
+ return {
76
+ 'citation_statement': snippet['snippet'].replace('<strong class="highlight">', '').replace('</strong>', ''),
77
+ 'text': new_text,
78
+ 'from': snippet['source'],
79
+ 'supporting': snippet['target'],
80
+ 'source_title': doc[2],
81
+ 'source_link': f"https://scite.ai/reports/{doc[0]}"
82
+ }
83
  return None
84
 
85