Skip to content

Commit

Permalink
inscription method copy-orphans
Browse files Browse the repository at this point in the history
  • Loading branch information
thvitt committed Oct 16, 2019
1 parent cd4e5bc commit d03486a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/macrogen/graph.py
Expand Up @@ -10,14 +10,16 @@
from io import TextIOWrapper
from operator import itemgetter
from pathlib import Path
from typing import List, Any, Dict, Tuple, Union, Sequence, Optional, Set, Iterable, FrozenSet
from typing import List, Any, Dict, Tuple, Union, Sequence, Optional, Set, Iterable
from warnings import warn
from zipfile import ZipFile, ZIP_DEFLATED

import networkx as nx
import pandas as pd
from dataclasses import dataclass

from macrogen.graphutils import is_orphan

from .graphutils import mark_edges_to_delete, remove_edges, in_path, first
from .bibliography import BiblSource
from .config import config
Expand Down Expand Up @@ -87,6 +89,8 @@ def handle_inscriptions(base):
inscriptions_inline(base)
if 'copy' in methods:
datings_from_inscriptions(base)
if 'copy-orphans' in methods:
datings_from_inscriptions(base, orphans_only=True)
if 'orphans' in methods:
adopt_orphans(base)

Expand Down Expand Up @@ -797,7 +801,7 @@ def resolve_ambiguities(graph: nx.MultiDiGraph):
graph.remove_node(ambiguity)


def datings_from_inscriptions(base: nx.MultiDiGraph):
def datings_from_inscriptions(base: nx.MultiDiGraph, orphans_only=False):
"""
Copy datings from inscriptions to witnesses.
Expand All @@ -817,10 +821,10 @@ def datings_from_inscriptions(base: nx.MultiDiGraph):
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)):
if before and not any(isinstance(pred, date) for pred in base.predecessors(witness)) and not (orphans_only and not is_orphan(witness, base)):
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)):
if after and not any(isinstance(succ, date) for succ in base.successors(witness)) and not (orphans_only and not is_orphan(witness, base)):
for i, d, k, attr in after:
base.add_edge(witness, d, copy=(d, i, k), **attr)

Expand Down
4 changes: 4 additions & 0 deletions src/macrogen/graphutils.py
Expand Up @@ -277,3 +277,7 @@ def base_n(number: int, base: int = 10, neg: Optional[str] = '-') -> str:
digits.append(neg)

return "".join(reversed(digits))


def is_orphan(node, graph: nx.DiGraph):
return node not in graph.nodes or graph.in_degree[node] == 0 and graph.out_degree[node] == 0
2 changes: 2 additions & 0 deletions src/macrogen/report.py
Expand Up @@ -1434,6 +1434,8 @@ def report_config(info: MacrogenesisInfo):
'Inskription <var>w<sub>i</sub></var> von <var>w</var>, so wird für jede Inskription von <var>w</var>'
'eine Kante <var>w<sub>i</sub> → w</var> eingezogen.',
'copy': 'Alle Aussagen über Inskriptionen werden auf die zugehörigen Zeugen kopiert.',
'copy-orphans': 'Alle Aussagen über Inskriptionen werden auf die zugehörigen Zeugen kopiert, wenn'
'für die Zeugen keine eigenen Aussagen vorliegen.',
'inline': 'Eine Inskription <var>w<sub>i</sub></var> eines Zeugen <var>w</var> wird so eingebunden, dass '
'sie nach dem Beginn von <var>w</var> beginnt und vor dem Ende von <var>w</var> endet.',
}
Expand Down

0 comments on commit d03486a

Please sign in to comment.