Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api2 #102

Open
wants to merge 23 commits into
base: api-client-integration
Choose a base branch
from
Open

Api2 #102

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
062039d
Merge pull request #2 from lbs-iitkgp/flask-api
divyang-mittal Mar 27, 2019
613708b
Added Spelling Correction module
halloTheCoder Mar 27, 2019
ed9aa28
Merge pull request #3 from lbs-iitkgp/master
divyang-mittal Mar 28, 2019
f70a54a
Updates in endpoints to make integration easier
divyang-mittal Mar 28, 2019
0aac98b
Slight improvement in acts.py
divyang-mittal Mar 28, 2019
55234c4
Addition of fetch by acts function
divyang-mittal Mar 28, 2019
78e3a9d
Merge pull request #93 from divyang-mittal/master
Shankusu993 Mar 28, 2019
9d30c2e
Add fetch_subgraph_with_acts
divyang-mittal Mar 28, 2019
1660bbe
Merge pull request #94 from thebhatman/spacy-acts-sections
thebhatman Mar 28, 2019
8656b03
Update act.py
divyang-mittal Mar 28, 2019
c8e868a
Update case.py
divyang-mittal Mar 28, 2019
0633d4c
Applying cors and adding acts query
divyang-mittal Mar 28, 2019
e035c8a
Merge pull request #96 from divyang-mittal/master
divyang-mittal Mar 28, 2019
d23d36f
Script for obtaining text of a section of an act
thebhatman Mar 28, 2019
4cba76c
Made sure section number is only integer
thebhatman Mar 28, 2019
493e6ba
Removed unnecessary stuff
thebhatman Mar 28, 2019
c0d9648
Merge pull request #95 from thebhatman/spacy-acts-sections
thebhatman Mar 28, 2019
6cd2a9f
mmm
rakaar Mar 29, 2019
9749f13
emplty search pres fix
rakaar Mar 29, 2019
d57a436
Resolving conflicts
rakaar Mar 29, 2019
a3cbeac
no msg
rakaar Mar 30, 2019
c8a36ba
updated
rakaar Mar 30, 2019
f122dd9
axios put in baic search only check it carefullt
rakaar Mar 30, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions api/backend/graph_formation/base/subgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ def fetch_subgraph_with_judgements(graph, judgements=set()):
def fetch_subgraph_with_keywords(graph, keywords=set()):
return(fetch_subgraph_from_meta_nodes(graph, keywords))

def fetch_subgraph_with_acts(graph, acts=set()):
return(fetch_subgraph_from_meta_nodes(graph, acts))

# For extracting subgraphs of **only** some particular types like acts & judges etc...
def fetch_subgraph_with_types(graph, node_types=set()):
if not node_types:
Expand All @@ -120,8 +123,9 @@ def graph_query(G, **query_params):
gph_with_keywords = fetch_subgraph_with_keywords(G, query_params['keywords'])
gph_with_year_range = fetch_subgraph_with_year_range(G, query_params['year_range'])
gph_with_types = fetch_subgraph_with_types(G, query_params['types'])
gph_with_acts = fetch_subgraph_with_types(G, query_params['acts'])

result = merge_graphs_by_intersection(G, [gph_with_judges, gph_with_judgements, gph_with_subjects, gph_with_keywords, gph_with_year_range, gph_with_types])
result = merge_graphs_by_intersection(G, [gph_with_judges, gph_with_judgements, gph_with_subjects, gph_with_keywords, gph_with_year_range, gph_with_types, gph_with_acts])

return(result)

Expand Down Expand Up @@ -154,7 +158,7 @@ def prepare_corpus_dist_file(graph, query_type):
graph_2 = import_graph("{}.json".format(filename))

# result = graph_query(graph, judges=[], subjects=[], keywords=[], judgements=[], types=['judge', 'case'], year_range=list(range(2002, 2005)))
result = graph_query(graph_2, judges=[], subjects=[], keywords=[], judgements=[], types=['judge', 'keyword'], year_range=[])
result = graph_query(graph_2, judges=[], subjects=[], keywords=[], judgements=[], types=['judge', 'keyword'], year_range=[], acts=[])

print(result.nodes())
print("Criminal" in result.nodes())
Expand Down
52 changes: 40 additions & 12 deletions api/endpoints/act.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from endpoints import *

@app.route('/act/<act_id>', methods=['GET'])
@cross_origin(origin='localhost',headers=["Content- Type","Authorization"])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def act_metadata(act_id):
#act = mydb.mytable.find({"act_id":act_id})
act = {"name":"Aadi","year":1990,"type":"Criminal","recent_version_name":"190","recent_version_id":"Aadi05","abbreviation":"CRM"}
Expand All @@ -18,10 +18,10 @@ def act_metadata(act_id):
return jsonify(result)

@app.route('/act/<act_id>/sections', methods=['GET'])
@cross_origin(origin='localhost',headers=["Content- Type","Authorization"])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def act_sections(act_id):
result = []
for section in mydb.mytable.find({"act_id":act_id}):
for section in mongo_db.find("act_id",act_id):
section = {
'section_id': section['section_id'],
'section_text': section['section_text']
Expand All @@ -30,30 +30,58 @@ def act_sections(act_id):
return jsonify(result)

@app.route('/act/<act_id>/section/<section_id>', methods=['GET'])
@cross_origin(origin='localhost',headers=["Content- Type","Authorization"])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def act_section(act_id, section_id):
sections = mydb.mytable.find({"act_id":act_id})
section = mydb.sections[section_id].find({"section_id":section_id})
sections = mongo_db.find("act_id", act_id)
section = mongo_db.find("section_id", section_id)
result = {
'section_id': section_id,
'section_text': section['section_text']
'section_id': section_id,
'section_text': section['section_text']
# 'section_text': "hiya"
}
return jsonify(result)


@app.route('/act/<act_id>/plot_line', methods=['GET'])
@cross_origin(origin='localhost',headers=["Content- Type","Authorization"])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def act_line_distribution(act_id):
# Iterate through each citer in neo4j
# Iterateacts=[act_id] through each citer in neo4j
# Find citer's year from mongo
#
#
result = { 1934: 19,1936: 7,1940: 42,1943: 5, 1935: 19,1937: 7,1941: 42,1944: 5}
return jsonify(result)

# catchword = fetch_from_mongo(catchword_id)

for i in range(1947,2020):
result[i] = 0
subgraph = lkg.query(judges =[],subjects=[], keywords=[] , judgements = [], types =[], year_range=[], acts =[act_id])
data = lkg.nodes(data=True)
such_cases = subgraph[act_id]
for case in such_cases:
all_metas = lkg.in_edges(case)
for meta, _ in all_metas:
if data[meta]['type'] == 'year':
year = meta
result[int(year)] += 1
return jsonify(result)

@app.route('/act/<act_id>/cases', methods=['GET'])
@cross_origin(origin='localhost',headers=["Content- Type","Authorization"])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def act_citations(act_id):
# Fetch list of cases that cite this act from neo4j and return their details from mongodb as json
return('Hello')
result = []
for i in range (1947,2020):
result[i] = 0
subgraph = lkg.query(judges =[],subjects=[], keywords=[] , judgements = [], types =[], year_range=[], acts =[act_id])

data = lkg.nodes(data=True)
such_cases = subgraph[act_id]
for case in such_cases:
all_metas = lkg.in_edges(case)
for meta, _ in all_metas:
if data[meta]['type'] == 'year':
year = meta
result[int(year)] += 1
return jsonify(result)
54 changes: 26 additions & 28 deletions api/endpoints/case.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
from endpoints import *

@app.route('/case/<case_id>', methods=['GET'])
@cross_origin(origin='localhost',headers=["Content- Type","Authorization"])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def case_metadata(case_id):
# case = mydb.mytable.find( {"case_id":case_id} )
case = { 'case_name': "hi",
'case_indlawid': 42,
'case_judge': 'some',
'case_judgement': 'win',
'case_date': '23',
'case_year': 1969
}
#case = mongo_db.find("case_id",case_id)
# case = { 'case_name': "hi",
# 'case_indlawid': 42,
# 'case_judges': 'some',
# 'case_judgements': 'win',
# 'case_date': '23',
# 'case_year': 1969
# }
result = {
"case_id": case_id,
"case_name": case['case_name'],
"case_indlaw_id": case['case_indlawid'],
"case_judge": case['case_judge'],
"case_judgement": case['case_judgement'],
"case_judges": case['judge'],
"case_judgement": case['judgement'],
"case_date": case['case_date'],
"case_year": case['case_year']
}
return jsonify(result)

@app.route('/case/<case_id>/plot_line', methods=['GET'])
@cross_origin(origin='localhost',headers=["Content- Type","Authorization"])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def case_line_distribution(case_id):
# result = {}
# for i in range (1947,2020):
# result[i] = 0
# subgraph = lkg.query(judges =[],subjects=[], keywords=[] , judgements = [], types =[], year_range=[])

# data = lkg.nodes(data=True)
# such_cases = subgraph[judge_id]
# for case in such_cases:
# all_metas = lkg.in_edges(case)
# for meta, _ in all_metas:
# if data[meta]['type'] == 'year':
# year = meta
# result[int(year)] += 1
result = { 1934: 19,1936: 7,1940: 42,1943: 5, 1935: 15,1937: 20,1941: 32,1944: 15}
result = {}
for i in range (1947 ,2020):
result[i] = 0
subgraph = lkg.query(judges =[],subjects=[], keywords=[] , judgements = [], types =[], year_range=[], acts =[])
data = lkg.nodes(data=True)
such_cases = subgraph[case_id]
for case in such_cases:
all_metas = lkg.in_edges(case)
for meta, _ in all_metas:
if data[meta]['type'] == 'year':
year = meta
result[int(year)] += 1
return jsonify(result)


@app.route('/case/<case_id>/timeline', methods=['GET'])
@cross_origin(origin='localhost',headers=["Content- Type","Authorization"])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def case_timeline(case_id):
# Timeline function w/ sections parser
# # [
Expand Down Expand Up @@ -97,4 +95,4 @@ def case_citations(case_id):
# ]
# }
result = { "cited_acts": [{'1':"Criminal"},{'2':"Land"}], "cited_cases": [{'1':"Criminal"},{'2':"Land"}], "cited_by_cases": [{'1':"Criminal"},{'2':"Land"}] }
return jsonify(result)
return jsonify(result)
47 changes: 25 additions & 22 deletions api/endpoints/catchword.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from endpoints import *

@app.route('/catchword/<catchword_id>', methods=['GET'])
@cross_origin(origin='localhost',headers=["Content- Type","Authorization"])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def catchword_metadata(catchword_id):
# Just return catchword name, # of cases and precentile among catchwords maybe?
#catchword = mydb.mytable.find({"catchword_id":catchword_id})
Expand All @@ -15,6 +15,7 @@ def catchword_metadata(catchword_id):


@app.route('/catchword/<catchword_id>/plot_line', methods=['GET'])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def catchword_cases(catchword_id):
# Iterate through each citer in neo4j
# Find citer's year from mongo
Expand All @@ -25,8 +26,7 @@ def catchword_cases(catchword_id):

for i in range(1947,2020):
result[i] = 0
subgraph = lkg.query(judges=[], subjects=[catchword_id], keywords=[], judgements=[], types=[], year_range=[])

subgraph = lkg.query(judges=[], subjects=[catchword_id], keywords=[], judgements=[], types=[], year_range=[],acts = [])
data = lkg.nodes(data=True)
such_cases = subgraph[catchword_id]
for case in such_cases:
Expand All @@ -37,25 +37,28 @@ def catchword_cases(catchword_id):
result[int(year)] += 1
return jsonify(result)

# @app.route('/catchword/<catchword_id>/cases', methods=['GET'])
# def catchword_cases(catchword_id):
@app.route('/catchword/<catchword_id>/cases', methods=['GET'])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def catchword_cases(catchword_id):
# # Fetch list of cases that cite this catchword from neo4j and return their details from mongodb as json
# # nx_graph = export_neo4j()
# # result = []
# # subgraph = fetch_subgraph_with_subjects(nx_graph , set(catchword_id))

# such_cases = subgraph[catchword_id]
# for node in subgraph['nodes']:
# case = mydb.mytable.find({"keyword":node['keyword']})
# point = {
# "case_id": case['case_id'],
# "case_name": case['case_name'],
# "case_indlaw_id": case['case_indlawid'],
# "case_judges": case['judge'],
# "case_judgement": case['judgement'],
# "case_date": case['case_date'],
# "case_year": case['case_year']
# }
# result.append(point)
# return jsonify(result)
result = []
for i in range (1947,2020):
result[i] = 0
subgraph = lkg.query(judges =[], subjects=[catchword_id], keywords=[], judgements = [], types =[], year_range=[], acts = [])

for node in subgraph['nodes']:
case = mongo_db.find("case_id",node['case_id'])
point = {
"case_id": case['case_id'],
"case_name": case['case_name'],
"case_indlaw_id": case['case_indlawid'],
"case_judges": case['judge'],
"case_judgement": case['judgement'],
"case_date": case['case_date'],
"case_year": case['case_year']
}
result.append(point)
return jsonify(result)


11 changes: 5 additions & 6 deletions api/endpoints/common.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

from endpoints import *
from base_class.subgraph import graph_query
from base_class.neo4j_to_networkx_graph import export_neo4j

def provide_line_distribution(judges,judgements,subjects,keywords,years,types,nx_grap):

def provide_line_distribution(judges,judgements,subjects,keywords,years,types,nx_graph):
params = {
'judges' : judges,
'judgements' : judgements,
Expand All @@ -17,7 +16,7 @@ def provide_line_distribution(judges,judgements,subjects,keywords,years,types,nx
for i in range (1947,2020):
result.append({i: 0})
for node in subgraph['nodes']:
case = mydb.mytable.find({"case_id":node['case_id']})
case = mongo_db.find({"case_id":node['case_id']})
result[int(case['year'])] = result[int(case['year'])]+1
return jsonify(result)

Expand All @@ -33,7 +32,7 @@ def provide_cases(judges,judgements,subjects,keywords,years,types,nx_graph):
subgraph = graph_query(nx_graph, params)
result = []
for node in subgraph['nodes']:
case = mydb.mytable.find({"keyword":node['keyword']})
case = mongo_db.find({"keyword":node['keyword']})
point = {
"case_id": case['case_id'],
"case_name": case['case_name'],
Expand All @@ -51,5 +50,5 @@ def provide_cases(judges,judgements,subjects,keywords,years,types,nx_graph):
def provide_metadata(judge,judgement,subject,keyword,year,type,nx_graph):
# gives union of all the required values
result = []
query = mydb.mytable.find({"keyword_id":keyword_id})
query = mongo_db.find({"keyword_id":keyword_id})

53 changes: 28 additions & 25 deletions api/endpoints/judge.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
from endpoints import *

@app.route('/judge/<judge_id>', methods=['GET'])
@cross_origin(origin='localhost',headers=["Content- Type","Authorization"])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def judge_metadata(judge_id):
# judge = mydb.mytable.find({"judge_id":judge_id})
judge ={'name': "Divyang",'number_of_cases':10}
judge = mongo_db.find({"judge_id":judge_id})
result = {
"name": judge['name'],
"number_of_cases": judge['number_of_cases'],
"percentile": 90
# mydb.mytable.find({"judge_id":judge_id}).count()*100.0/mydb.mytable.count()
"percentile": mongo_db.find("judge_id",judge_id).count()*100.0/mongo_db.count()
# 90
}
return jsonify(result)

@app.route('/judge/<judge_id>/plot_line', methods=['GET'])
@cross_origin(origin='localhost',headers=["Content- Type","Authorization"])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def judge_line_distribution(judge_id):
# Iterate through each case of judge in neo4j
# Find case's year from mongo
Expand All @@ -35,23 +34,27 @@ def judge_line_distribution(judge_id):
return jsonify(result)

@app.route('/judge/<judge_id>/cases', methods=['GET'])
@cross_origin(origin='localhost',headers=["Content- Type","Authorization"])
@cross_origin(origin='localhost', headers=['Content- Type', 'Authorization'])
def judge_cases(judge_id):
# Fetch list of cases that relate to this judge from neo4j,
# and return their details from mongodb as json
#nx_graph = export_neo4j()
result = [{"case_id":1,"case_name":"Babajan","case_indlawid":"Kakajan","case_judges":"Papajan","case_judgement":"no","case_date":"dada","case_year":2018}]
#subgraph = fetch_subgraph_with_judges(nx_graph , set(judge_id))
# for node in subgraph['nodes']:
# case = mydb.mytable.find({"case_id":node['case_id']})
# point = {
# "case_id": case['case_id'],
# "case_name": case['case_name'],
# "case_indlaw_id": case['case_indlawid'],
# "case_judges": case['judge'],
# "case_judgement": case['judgement'],
# "case_date": case['case_date'],
# "case_year": case['case_year']
# }
# result.append(point)
return jsonify(result)
# # Fetch list of cases that relate to this judge from neo4j,
# # and return their details from mongodb as json
# nx_graph = export_neo4j()
result = []
for i in range (1947,2020):
result[i] = 0
subgraph = lkg.query(judges =[judge_id], subjects=[], keywords=[], judgements = [], types =[], year_range=[],acts =[])

for node in subgraph['nodes']:
case = mongo_db.find("case_id", node['case_id'])
point = {
"case_id": case['case_id'],
"case_name": case['case_name'],
"case_indlaw_id": case['case_indlawid'],
"case_judges": case['judge'],
"case_judgement": case['judgement'],
"case_date": case['case_date'],
"case_year": case['case_year']
}
result.append(point)
return jsonify(result)

Loading