Skip to content

Commit 73606cc

Browse files
committed
add entity_type node attr, support node attrs in dynamic Gephi export
1 parent 2410cc9 commit 73606cc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

renard/graph_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ def dynamic_graph_to_gephi_graph(graphs: List[nx.Graph]) -> nx.Graph:
124124
G = nx.Graph()
125125

126126
for H_i, H in enumerate(graphs):
127+
128+
# update node attributes
129+
for u in H.nodes:
130+
G.add_node(u)
131+
for key, value in H.nodes[u].items():
132+
# format : (VALUE, START, END)
133+
series = G.nodes[u].get(key, [])
134+
G.nodes[u][key] = series + [(value, H_i, H_i + 1)]
135+
127136
for u, v in H.edges:
128137
# create a new edge between two characters if it doesn't
129138
# exist yet

renard/pipeline/graph_extraction.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,11 @@ def _extract_graph(
306306

307307
# * Construct graph from co-occurence matrix
308308
G = nx.Graph()
309-
for character, _ in mentions:
310-
G.add_node(character)
309+
for character, mention in mentions:
310+
# NOTE: we add an 'entity_type' attribute. This is useful
311+
# when using the 'additional_ner_classes' option, to
312+
# differentiate between different entity types.
313+
G.add_node(character, entity_type=mention.tag)
311314

312315
for i, (char1, mention1) in enumerate(mentions):
313316
for j, (char2, mention2) in enumerate(mentions):

0 commit comments

Comments
 (0)