Skip to content

Commit

Permalink
Copy dating links from inscriptions to witnesses
Browse files Browse the repository at this point in the history
Cf. #5
  • Loading branch information
thvitt committed Sep 27, 2018
1 parent c4b6496 commit 2d24b18
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
24 changes: 23 additions & 1 deletion graph.py
Expand Up @@ -2,7 +2,7 @@
from collections import defaultdict
from datetime import date, timedelta
from pathlib import Path
from typing import List, Callable, Any, Dict, Tuple, Union
from typing import List, Callable, Any, Dict, Tuple, Union, Hashable, Set

import dateutil
import networkx as nx
Expand Down Expand Up @@ -271,6 +271,27 @@ def resolve_ambiguities(graph: nx.MultiDiGraph):
graph.remove_node(ambiguity)


def datings_from_inscriptions(base: nx.MultiDiGraph):
logger.info('Copying datings from inscriptions to witnesses')
inscriptions_by_wit: Dict[Witness, List[Inscription]] = defaultdict(list)
for inscription in [node for node in base.nodes if isinstance(node, Inscription)]:
if inscription.witness in base.nodes:
inscriptions_by_wit[inscription.witness].append(inscription)
for witness, inscriptions in inscriptions_by_wit.items():
iin = [edge for i in inscriptions for edge in base.in_edges(i, data=True, keys=True)]
before = [edge for edge in iin if isinstance(edge[0], date)]
iout = [edge for i in inscriptions for edge in base.out_edges(i, data=True, keys=True)]
after = [edge for edge in iout if isinstance(edge[1], date)]
if before and not any(isinstance(pred, date) for pred in base.predecessors(witness)):
for d, i, k, attr in before:
base.add_edge(d, witness, copy=(d, i, k), **attr)
if after and not any(isinstance(succ, date) for succ in base.successors(witness)):
for i, d, k, attr in after:
base.add_edge(witness, d, copy=(d, i, k), **attr)




def adopt_orphans(graph: nx.MultiDiGraph):
"""
Introduces auxilliary edges to witnesses that are referenced by an inscription or ambiguous ref, but are not
Expand Down Expand Up @@ -313,6 +334,7 @@ def macrogenesis_graphs() -> MacrogenesisInfo:
"""
base = base_graph()
datings_from_inscriptions(base)
adopt_orphans(base)
add_edge_weights(base)
resolve_ambiguities(base)
Expand Down
3 changes: 2 additions & 1 deletion styles.yaml
Expand Up @@ -31,10 +31,11 @@ edge:
style: dashed
color: gray
inscription:
dir: none
color: gray
constraint: false
style: dashed
copy:
color: lightblue

# additional style for conflicting edges
delete:
Expand Down

0 comments on commit 2d24b18

Please sign in to comment.