Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
cprog7 committed Oct 18, 2024
1 parent 7cd3372 commit 6396a85
Showing 1 changed file with 15 additions and 49 deletions.
64 changes: 15 additions & 49 deletions Petz_2024_HNA-tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@
"# Add metadata information on nodes and edges:\n",
"\n",
"G.add_node(\"Henry_II_of_England\", age=\"65\")\n",
"G.add_edge(\"Eleonor_of_Aquitaine\", \"Henry_II_of_England\", year=5025)\n",
"G.add_edge(\"Eleonor_of_Aquitaine\", \"Henry_II_of_England\", year=5025) \n",
"# or update info like this:\n",
"G[\"Eleonor_of_Aquitaine\"][\"Henry_II_of_England\"][\"weight\"] = 8\n",
"G[\"Eleonor_of_Aquitaine\"][\"Henry_II_of_England\"][\"weight\"] = 8 # note: we initialized the Graph-object as a basic graph\n",
"# Therefore all added metadata are added as additional metadata of the edge, instead of being added as additional edges (needs a MultiGraph-object)\n",
"G[\"Eleonor_of_Aquitaine\"][\"Richard_I_of_England\"][\"sign\"] = \"positive\"\n",
"\n",
"print(G.nodes(data=True))\n",
Expand All @@ -193,37 +194,6 @@
" print(f'Nodes {e[0]} and {e[1]} are on good terms.')"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "6dcdff7c-f6ea-46ac-95dc-f9a2ef7fa86d",
"metadata": {},
"outputs": [],
"source": [
"G[\"Eleonor_of_Aquitaine\"][\"Henry_II_of_England\"][\"sign\"] = \"negative\" "
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "b31ccd74-c4eb-4bca-aae9-40718b447231",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[('Eleonor_of_Aquitaine', 'Richard_I_of_England', {'sign': 'positive'}), ('Eleonor_of_Aquitaine', 'Henry_II_of_England', {'year': 5025, 'weight': 8, 'sign': 'negative'}), ('Henry_II_of_England', 'Richard_I_of_England', {})]\n",
"Graph with 3 nodes and 3 edges\n"
]
}
],
"source": [
"G[\"Eleonor_of_Aquitaine\"][\"Henry_II_of_England\"][\"sign\"] = \"negative\" \n",
"print(G.edges(data=True))\n",
"print(G)"
]
},
{
"cell_type": "markdown",
"id": "13cee8e2-28df-459e-bc5d-08a7beefa411",
Expand Down Expand Up @@ -266,6 +236,8 @@
"source": [
"## Let's import a sample dataset!\n",
"\n",
"**If you don't have your own data, please use the one mentioned below. If you have your own dataset, please adapt the code below accordingly.**\n",
"\n",
"The sample dataset consists of sender and receivers of scholarly correspondences of early romanticism.\n",
"\n",
"-- The small sample dataset originates from the project [\"Correspondences of Early Romanticism. Edition -- Annotation - Network Research\"](https://gepris-extern.dfg.de/gepris/projekt/470517871?language=en), a cooperation of Universities of Marburg, Mainz, Trier, and Frankfurter Goethe Haus (2022-2025), focusing on the Jena and Berlin early Romanticism as an outstanding intellectual revolution of young German authors and scholars at the epochal threshold around 1800.)"
Expand All @@ -277,9 +249,7 @@
"id": "bf3f9e07-9b1b-4aec-9fc8-412dc5119292",
"metadata": {},
"outputs": [],
"source": [
"## Import a Letter Network"
]
"source": []
},
{
"cell_type": "code",
Expand All @@ -288,8 +258,10 @@
"metadata": {},
"outputs": [],
"source": [
"## Import a Letter Network\n",
"\n",
"data = pd.read_csv(\"sender_receiver.csv\", names=[\"letter_id\", \"date\", \"sender\", \"receiver\"], header=None)\n",
"# names puts in new column-names, which for the original file had been ignored by 'header=None'\n",
"# names puts in new column-names, which for the original file have been ignored by 'header=None'\n",
"print(data)"
]
},
Expand All @@ -300,7 +272,7 @@
"metadata": {},
"outputs": [],
"source": [
"#G2 = nx.DiGraph()\n",
"#L = nx.DiGraph()\n",
"L = nx.MultiDiGraph() # Directed Multigraph, as there might be multiple edges between two nodes"
]
},
Expand Down Expand Up @@ -730,12 +702,6 @@
"### Object-based programming\n"
]
},
{
"cell_type": "markdown",
"id": "e71ab0c2",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -745,9 +711,9 @@
"source": [
"class Fall:\n",
"\n",
" def __init__(self, id):\n",
" self.id = id # about initialised variables above\n",
" self.angeklagter = []\n",
" def __init__(self, id): # initialize class with an id\n",
" self.id = id # this method does not need to be defined\n",
" self.angeklagter = [] # all other methods need to be defined\n",
" self.richter = []\n",
" self.aktennummer = []\n",
" \n",
Expand Down Expand Up @@ -780,10 +746,10 @@
" self.politorientierung.append(p)\n",
"\n",
"\n",
"# Access these:\n",
"# Access these objects:\n",
"Fall.id\n",
"Fall.fallteilnehmer\n",
"getattr(case, fallteilnehmer) \n",
"getattr(running_variable, fallteilnehmer) \n",
"\n",
"# Fill these:\n",
"# ... read in your data, access columns\n",
Expand Down

0 comments on commit 6396a85

Please sign in to comment.