-
Notifications
You must be signed in to change notification settings - Fork 1
/
cases.py
38 lines (30 loc) · 1.16 KB
/
cases.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
from keybert import KeyBERT
#from flair.embeddings import TransformerDocumentEmbeddings
import requests
#roberta = TransformerDocumentEmbeddings('roberta-base')
kw_model = KeyBERT()
def get_query(ques):
topn = 4
keys = kw_model.extract_keywords(ques, keyphrase_ngram_range=(1,1), stop_words='english', top_n=topn)
query = ""
for i in range(len(keys)):
query += keys[i][0]
query += " "
return query
def get_cases(ques, topn):
URL = "https://api.case.law/v1/cases/?search=" + get_query(ques)
response = requests.get(URL)
res = response.json()["results"][:topn]
cases = []
keys = ["id", "name", "court", "jurisdiction", "web", "pdf"]
for i in range(len(res)):
casedata = dict.fromkeys(keys, "")
idurl = res[i]["url"]
casedata["id"] = res[i]["id"]
casedata["name"] = res[i]["name"]
casedata["court"] = res[i]["court"]["name"]
casedata["jurisdiction"] = res[i]["jurisdiction"]["name_long"]
casedata["web"] = res[i]["frontend_url"]
casedata["pdf"] = res[i]["frontend_pdf_url"]
cases.append(casedata)
return cases