def test_links_to_network_invalid():
    """
    These are invalid eclis so we should get an error

    """
    links = [{'source': 'NONEXISTENT_A',
              'target': 'NONEXISTENT_B'}]
    with pytest.raises(Exception):
        nodes, links = caselawnet.links_to_network(links)
def test_links_to_network_unfound():
    """
    These are valid eclis that are not in rechtspraak.nl

    """
    links = [{'source': 'ECLI:PT:TRP:2017:671.14.0GAMCN.P1',
              'target': 'ECLI:EU:C:2017:497'}]
    nodes, links = caselawnet.links_to_network(links)
    assert len(nodes) == 2
    assert len(links) == 1
Beispiel #3
0
def query_links():
    try:
        nodes_file = None
        links_file = None
        network_file = None
        warning = None
        if('links' in request.form):
            links_csv = request.form['links']
            title = request.form.get('title', 'Network')
            links_df, eclis = read_csv(io.StringIO(links_csv),
                                                     sep=',', header=None)
            links_dict = links_df.to_dict(orient='records')
            nodes, links = caselawnet.links_to_network(links_dict, db_session=get_db())
            if len(nodes) < len(eclis):
                existing_eclis = [node['ecli'] for node in nodes]
                difference = set(eclis) - set(existing_eclis)
                warning = "The following ECLI cases were not found: " + \
                    str(difference)
            if len(nodes) == 0:
                return render_template("links.html",
                                       error="No resulting matches!")
            nodes_csv = caselawnet.to_csv(nodes)
            nodes_file = save_result(nodes_csv, 'csv')
            links_csv = pd.DataFrame(links).to_csv(index=False)
            links_file = save_result(links_csv, 'csv')
            network_json = caselawnet.to_sigma_json(nodes, links, title)
            network_file = save_result(network_json, 'json')
        return render_template("links.html",
                               network_file=network_file,
                               nodes_file=nodes_file,
                               links_file=links_file,
                               warning=warning)
    except caselawnet.utils.InvalidECLIError as error:
        return render_template("links.html",
                               error="Invalid ecli: "+str(error))
    except Exception as error:
        print(error)
        traceback.print_exc()
        return render_template("links.html",
                               error="Sorry, something went wrong!")
def test_links_to_network_empty():
    links = []
    nodes, links = caselawnet.links_to_network(links)
    assert len(nodes) == 0
    assert len(links) == 0
def test_links_to_network():
    links = [{'source': 'ECLI:NL:HR:2009:BF0003',
              'target': 'ECLI:NL:HR:2008:BD3129'}]
    nodes, links = caselawnet.links_to_network(links)
    assert len(nodes) == 2
    assert len(links) == 1