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 #101

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

Api2 #101

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
53 changes: 41 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,59 @@ 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)
57 changes: 29 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 @@ -78,6 +76,7 @@ def case_timeline(case_id):
return jsonify(result)

@app.route('/case/<case_id>/citations', methods=['GET'])

@cross_origin(origin='localhost',headers=["Content- Type","Authorization"])
def case_citations(case_id):
# Get citer id's from neo4j, and respective names from mongo
Expand All @@ -96,5 +95,7 @@ def case_citations(case_id):
# ...
# ]
# }
result = { "cited_acts": [{'name':"Criminal"},{'name':"Land"}], "cited_cases": [{'name':"Criminal"},{'name':"Land"}], "cited_by_cases": [{'name':"Criminal"},{'name':"Land"}] }
return jsonify(result)
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})

Loading