-
Notifications
You must be signed in to change notification settings - Fork 3
/
articleprocessor.py
51 lines (38 loc) · 1.85 KB
/
articleprocessor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pysolr
import requests
class ArticleProcessor:
def __init__(self):
self.art_solr = pysolr.Solr('http://librairy.linkeddata.es/data/covid', timeout=10)
def _get_articles_by_query(self,query,num):
results = self.art_solr.search(query,rows=num)
articles = []
for result in results:
article = {}
if ('name_s' in result):
article['name'] = result['name_s']
if ('id' in result):
article['id'] = result['id']
if ('abstract_t' in result):
article['abstract'] = result['abstract_t']
if ('url_s' in result):
article['url'] = result['url_s']
articles.append(article)
return articles
def get_articles(self, num):
return self._get_articles_by_query("*:*",num)
def get_articles_by_disease(self, keyword, num):
return self._get_articles_by_query("scispacy_diseases_t:"+keyword,num)
def get_articles_by_drug(self, keyword, num):
query = " or ".join(["labels"+str(i)+"_t:"+keyword for i in range(1,6)])
print(query)
return self._get_articles_by_query(query,num)
def get_articles_by_keyword(self, keyword, num):
return self._get_articles_by_query("id:"+keyword + " or name_s:\""+keyword+"\" or abstract_t:\""+keyword + "\" or txt_t:\""+keyword+"\"",num)
def get_articles_by_id(self, keyword, num=1):
return self._get_articles_by_query("id:"+keyword,num)
def get_articles_by_name(self, keyword, num):
return self._get_articles_by_query("name_s:\""+keyword+"\"",num)
def get_articles_by_abstract(self, keyword, num):
return self._get_articles_by_query("abstract_t:\""+keyword+"\"",num)
def get_articles_by_text(self, keyword, num):
return self._get_articles_by_query("txt_t:\""+keyword+"\"",num)