-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystems.py
38 lines (29 loc) · 1002 Bytes
/
systems.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
import json
import random
import logging
import jsonlines
logging.basicConfig(level=logging.INFO)
class Recommender(object):
def __init__(self):
self.idx = None
def index(self):
self.idx = []
with jsonlines.open('./data/relish_text.jsonl') as reader:
for obj in reader:
self.idx.append(obj.get('pmid'))
def recommend_publications(self, item_id, page, rpp):
filename = '../data/relish_recoms.jsonl'
recommendations = []
with open(filename, 'r') as file:
for line in file:
record = json.loads(line)
if int(record['pmid']) == int(item_id):
recommendations.append(record)
itemlist = sorted([int(record['target_pmid']) for record in recommendations[:rpp]])
return {
'page': page,
'rpp': rpp,
'item_id': item_id,
'itemlist': itemlist,
'num_found': len(itemlist)
}