<jupyter_start><jupyter_text>Table of Contents1&nbsp;&nbsp;Modeling1.1&nbsp;&nbsp;Victims1.2&nbsp;&nbsp;Perpetrators1.3&nbsp;&nbsp;ViolenceEvent<jupyter_code>import sys
sys.version
from pathlib import Path
import pprint
%load_ext cypher
# https://ipython-cypher.readthedocs.io/en/latest/
# used for cell magic
from py2neo import Graph
NEO4J_URI="bolt://localhost:7687"
graph = Graph(NEO4J_URI)
graph
def clear_graph():
    print(graph.run("MATCH (n) DETACH DELETE n").stats())
clear_graph()
graph.run("RETURN apoc.version();").data()
graph.run("call dbms.components() yield name, versions, edition unwind versions as version return name, version, edition;").data()<jupyter_output><empty_output><jupyter_text>Modeling<jupyter_code>import pandas as pd<jupyter_output><empty_output><jupyter_text>We are modeling data from the pinochet dataset, available in https://github.com/danilofreire/pinochet> <NAME>., <NAME>., <NAME>., & <NAME>.. (2019). Deaths and Disappearances in the Pinochet Regime: A New Dataset. https://doi.org/10.31235/osf.io/vqnwu.The dataset has 59 variables with information about the victims, the perpetrators, and geographicalcoordinates of each incident.<jupyter_code>PINOCHET_DATA = "../pinochet/data/pinochet.csv"
pin = pd.read_csv(PINOCHET_DATA)
pin.head()
pin.age.isna().sum()<jupyter_output><empty_output><jupyter_text>The dataset contains informations about perpetrators, victims, violence events and event locations. We will develop models around these concepts, and we will stablish relationships between them later.   Victims- victim_id*: this is not the same as in the dataset.- individual_id- group_id- first_name- last_name- age- minor- male- number_previous_arrests- occupation- occupation_detail- victim_affiliation- victim_affiliation_detail- targeted<jupyter_code>victim_attributes = [
    "individual_id",
    "group_id",
    "first_name",
    "last_name",
    "age",
    "minor",
    "male",
    "number_previous_arrests",
    "occupation",
    "occupation_detail",
    "victim_affiliation",
    "victim_affiliation_detail",
    "targeted",
]

pin_victims = pin[victim_attributes]
pin_victims.head()
# https://neo4j.com/docs/labs/apoc/current/import/load-csv/
PINOCHET_CSV_GITHUB = "https://raw.githubusercontent.com/danilofreire/pinochet/master/data/pinochet.csv"

query = """
WITH $url AS url 
CALL apoc.load.csv(url) 
YIELD lineNo, map, list
RETURN *
LIMIT 1"""

graph.run(query, url = PINOCHET_CSV_GITHUB).data()
%%cypher
CALL apoc.load.csv('pinochet.csv') 
YIELD lineNo, map, list
RETURN *
LIMIT 1<jupyter_output>1 rows affected.<jupyter_text>Perpetrators- perpetrator_affiliation- perpetrator_affiliation_detail- war_tribunal<jupyter_code>perpetrators_attributes = [
    "perpetrator_affiliation",
    "perpetrator_affiliation_detail",
    "war_tribunal",
]

pin_perps = pin[perpetrators_attributes]
pin_perps.head()<jupyter_output><empty_output><jupyter_text>ViolenceEvent<jupyter_code>clear_graph()
query = Path("../services/graph-api/project/queries/load_csv.cql").read_text()
# pprint.pprint(query)
graph.run(query, url = PINOCHET_CSV_GITHUB).stats()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup