# ekq/genealogy architecture

> Architecture diagram of the GitHub repository ekq/genealogy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ekq/genealogy
- Repository: https://github.com/ekq/genealogy

## Overview

1. **Repository purpose**
   This project implements two related historical-demography workflows:  
   - **genealogical network inference** from the HisKi church-record database, and  
   - **assortative mating analysis** on the inferred family links.  
   The code is organized as a data-processing pipeline rather than a service or interactive application.

2. **Top-level flow**
   The main pipeline starts with raw HisKi records in `data/`, runs record-linking and parent inference in `src/`, writes intermediate reconstructed relationships into `src/reconstructions/`, and then uses those derived links for downstream statistical analysis.

3. **Core inference subsystem**
   `compute_burial_matches.py` and `compute_matches.py` are the two main batch jobs.  
   - The burial-matching step links burial records to corresponding birth records.  
   - The parent-matching step infers parent-child edges for birth events.  
   Both scripts are designed to run in batches over event-id lists (`birth_event_ids.txt`, `burial_event_ids.txt`) so the workload can be parallelized.

4. **Persistence and reconstruction boundary**
   `src/reconstructions/` is the output boundary for generated genealogy artifacts. The README indicates burial-birth links are first produced there, then written back into the HisKi database via `serial_burial_db_write.sh`, after which parent inference is rerun. This shows a two-stage loop: infer links externally, persist them, then use the enriched database for the next inference pass.

5. **Matching model subsystem**
   The inference logic is concentrated in `person_matching_model.py` and `hiski_models.py`. These likely implement scoring, feature extraction, and model evaluation for candidate matches. The presence of serialized models in `src/estimated_models/` indicates the system depends on precomputed likelihood tables and trained classifiers rather than training everything from scratch at runtime.

6. **Feature and knowledge inputs**
   `src/estimated_models/` contains pickled probability tables and model artifacts such as age likelihoods, name-based ratios, geographic distance maps, and XGBoost models. These are the main statistical priors/features used by the matching pipeline. The architecture is therefore “feature lookup + probabilistic/classifier scoring” over candidate relationships.

7. **Geographic and normalization utilities**
   Several support modules handle domain normalization:  
   - `etrs2lonlat.py` converts coordinate systems,  
   - `parish_distances.py` supports location-based matching,  
   - `normalize_occupations.py` standardizes historical occupations, and  
   - `populate_normalized_names.py` fills normalized-name fields.  
   These utilities feed cleaner features into the matching model and reduce ambiguity in historical records.

8. **Historical name normalization boundary**
   The `historical_name_normalizer/` submodule and the files under `src/assortative_mating/` for normalized occupations and occupation-to-status mappings indicate a separate normalization layer. Its role is to transform messy historical text into canonical forms before those values are used in inference or social-status analysis.

9. **Assortative mating analysis subsystem**
   `src/assortative_mating/assortative_mating_analysis.py` consumes reconstructed family links plus occupation/status metadata to analyze partner similarity over time. The package includes curated occupational datasets (`historismi_ammatit.tsv`, `historismi_lyhenteet_filtered.tsv`, `occupation2status.json`) and a cached status model (`data/status_data_p0.90.pckl`), showing that the analysis depends on precomputed semantic mapping from occupation to social status.

10. **Data and generated-artifact split**
    The repo distinguishes between:  
    - **raw or externally obtained data** in `data/`,  
    - **bundled reference tables and model artifacts** in `src/estimated_models/` and `src/assortative_mating/data/`, and  
    - **generated outputs** in `src/reconstructions/` and `src/assortative_mating/plots/`.  
    This separation is important for the diagram: source code operates on curated inputs and emits reconstruction/analysis artifacts.

11. **Execution model**
    The project is primarily Python-based, with a small shell orchestration step. Batch processing is central: the same scripts are run repeatedly over slices of event IDs, allowing parallel execution and incremental reconstruction. There is no evidence of a server, web UI, or message queue; the architecture is offline, file-driven, and model-centric.

12. **Diagram takeaway**
    A good architecture diagram would show: raw HisKi data and normalization tables on the left; candidate-generation and matching models in the middle; reconstructed births/burials/parent edges written to output stores; and assortative-mating analysis consuming the reconstructed genealogy plus occupation/status mappings on the right.

Main entry points: [`src/reconstructions`](https://github.com/ekq/genealogy/tree/master/src/reconstructions) (Reconstructions), [`src/compute_matches.py`](https://github.com/ekq/genealogy/blob/master/src/compute_matches.py) (Parent matches), [`src/compute_burial_matches.py`](https://github.com/ekq/genealogy/blob/master/src/compute_burial_matches.py) (Burial matches), [`src/hiski_models.py`](https://github.com/ekq/genealogy/blob/master/src/hiski_models.py) (HisKi models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Inputs"]
  node_data[("HisKi data<br/>raw dataset")]
  node_birth_ids["Birth IDs<br/>batch list"]
  node_burial_ids["Burial IDs<br/>batch list"]
end

subgraph group_matching["Matching pipeline"]
  node_estimated_models[("Model priors<br/>serialized models")]
  node_compute_burial_matches["Burial matches<br/>batch job"]
  node_compute_matches["Parent matches<br/>batch job<br/>[compute_matches.py]"]
  node_person_matching_model["Match model<br/>scoring logic"]
  node_hiski_models["HisKi models<br/>feature models<br/>[hiski_models.py]"]
  node_etrs2lonlat["Coords<br/>geo utility<br/>[etrs2lonlat.py]"]
  node_parish_distances["Parish distance<br/>geo utility"]
  node_populate_normalized_names["Name norms<br/>normalization"]
  node_historical_name_normalizer["Name normalizer<br/>normalization module"]
end

subgraph group_outputs["Outputs"]
  node_reconstructions[("Reconstructions<br/>derived outputs")]
  node_serial_burial_db_write["DB write<br/>orchestration script"]
end

subgraph group_assortative["Assortative mating"]
  node_occupation_normalize["Occ norms<br/>normalization"]
  node_assortative_data[("Status data<br/>reference data")]
  node_assortative_analysis["Mating analysis<br/>analysis job"]
  node_plots["Plots<br/>analysis output"]
end

node_data -->|"records"| node_compute_burial_matches
node_data -->|"records"| node_compute_matches
node_birth_ids -->|"batch"| node_compute_matches
node_burial_ids -->|"batch"| node_compute_burial_matches
node_estimated_models -->|"priors"| node_person_matching_model
node_estimated_models -->|"features"| node_hiski_models
node_etrs2lonlat -->|"geo"| node_parish_distances
node_parish_distances -->|"location"| node_hiski_models
node_historical_name_normalizer -->|"names"| node_populate_normalized_names
node_populate_normalized_names -->|"clean names"| node_person_matching_model
node_hiski_models -->|"domain features"| node_person_matching_model
node_compute_burial_matches -->|"burial links"| node_reconstructions
node_compute_matches -->|"parent edges"| node_reconstructions
node_reconstructions -->|"persist"| node_serial_burial_db_write
node_serial_burial_db_write -.->|"enriched db"| node_compute_matches
node_reconstructions -->|"family links"| node_assortative_analysis
node_assortative_data -->|"status refs"| node_occupation_normalize
node_occupation_normalize -->|"occupation status"| node_assortative_analysis
node_assortative_analysis -->|"figures"| node_plots

click node_data "https://github.com/ekq/genealogy/tree/master/data"
click node_birth_ids "https://github.com/ekq/genealogy/blob/master/src/birth_event_ids.txt"
click node_burial_ids "https://github.com/ekq/genealogy/blob/master/src/burial_event_ids.txt"
click node_estimated_models "https://github.com/ekq/genealogy/tree/master/src/estimated_models"
click node_compute_burial_matches "https://github.com/ekq/genealogy/blob/master/src/compute_burial_matches.py"
click node_compute_matches "https://github.com/ekq/genealogy/blob/master/src/compute_matches.py"
click node_person_matching_model "https://github.com/ekq/genealogy/blob/master/src/person_matching_model.py"
click node_hiski_models "https://github.com/ekq/genealogy/blob/master/src/hiski_models.py"
click node_etrs2lonlat "https://github.com/ekq/genealogy/blob/master/src/etrs2lonlat.py"
click node_parish_distances "https://github.com/ekq/genealogy/blob/master/src/parish_distances.py"
click node_populate_normalized_names "https://github.com/ekq/genealogy/blob/master/src/populate_normalized_names.py"
click node_historical_name_normalizer "https://github.com/ekq/genealogy/tree/master/src/historical_name_normalizer"
click node_reconstructions "https://github.com/ekq/genealogy/tree/master/src/reconstructions"
click node_serial_burial_db_write "https://github.com/ekq/genealogy/blob/master/src/serial_burial_db_write.sh"
click node_occupation_normalize "https://github.com/ekq/genealogy/blob/master/src/assortative_mating/normalize_occupations.py"
click node_assortative_data "https://github.com/ekq/genealogy/tree/master/src/assortative_mating/data"
click node_assortative_analysis "https://github.com/ekq/genealogy/blob/master/src/assortative_mating/assortative_mating_analysis.py"
click node_plots "https://github.com/ekq/genealogy/tree/master/src/assortative_mating/plots"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_data,node_birth_ids,node_burial_ids toneBlue
class node_estimated_models,node_compute_burial_matches,node_compute_matches,node_person_matching_model,node_hiski_models,node_etrs2lonlat,node_parish_distances,node_populate_normalized_names,node_historical_name_normalizer toneAmber
class node_reconstructions,node_serial_burial_db_write toneMint
class node_occupation_normalize,node_assortative_data,node_assortative_analysis,node_plots toneRose
```

## Components

### Inputs

Raw HisKi records, batch ID lists, and bundled lookup tables.

- [HisKi data](https://github.com/ekq/genealogy/tree/master/data): raw dataset · Source church-record data consumed by the reconstruction pipeline. · `data`
- [Birth IDs](https://github.com/ekq/genealogy/blob/master/src/birth_event_ids.txt): batch list · Event IDs that partition the birth-matching workload. · `src/birth_event_ids.txt`
- [Burial IDs](https://github.com/ekq/genealogy/blob/master/src/burial_event_ids.txt): batch list · Event IDs that partition the burial-matching workload. · `src/burial_event_ids.txt`

### Matching pipeline

Batch inference, scoring models, and normalization helpers for genealogy reconstruction.

- [Model priors](https://github.com/ekq/genealogy/tree/master/src/estimated_models): serialized models · Probability tables and trained classifiers used by matching. · `src/estimated_models`
- [Burial matches](https://github.com/ekq/genealogy/blob/master/src/compute_burial_matches.py): batch job · Links burial records to corresponding birth records. · `src/compute_burial_matches.py`
- [Parent matches](https://github.com/ekq/genealogy/blob/master/src/compute_matches.py): batch job · Infers parent-child edges for birth events. · `src/compute_matches.py`
- [Match model](https://github.com/ekq/genealogy/blob/master/src/person_matching_model.py): scoring logic · Core candidate scoring and feature combination for person matches. · `src/person_matching_model.py`
- [HisKi models](https://github.com/ekq/genealogy/blob/master/src/hiski_models.py): feature models · Domain-specific feature extraction and model support for HisKi records. · `src/hiski_models.py`
- [Coords](https://github.com/ekq/genealogy/blob/master/src/etrs2lonlat.py): geo utility · Converts coordinates for location-based matching. · `src/etrs2lonlat.py`
- [Parish distance](https://github.com/ekq/genealogy/blob/master/src/parish_distances.py): geo utility · Distance support for parish-aware candidate matching. · `src/parish_distances.py`
- [Name norms](https://github.com/ekq/genealogy/blob/master/src/populate_normalized_names.py): normalization · Populates normalized-name fields used by matching. · `src/populate_normalized_names.py`
- [Name normalizer](https://github.com/ekq/genealogy/tree/master/src/historical_name_normalizer): normalization module · Historical name normalization layer shared by the pipeline. · `src/historical_name_normalizer`

### Outputs

Reconstructed links and downstream analysis artifacts.

- [Reconstructions](https://github.com/ekq/genealogy/tree/master/src/reconstructions): derived outputs · Generated genealogy artifacts such as burial-birth links and parent edges. · `src/reconstructions`
- [DB write](https://github.com/ekq/genealogy/blob/master/src/serial_burial_db_write.sh): orchestration script · Writes burial-birth links back to the HisKi database for the next pass. · `src/serial_burial_db_write.sh`

### Assortative mating

Occupation normalization and partner-similarity analysis.

- [Occ norms](https://github.com/ekq/genealogy/blob/master/src/assortative_mating/normalize_occupations.py): normalization · Normalizes occupations for downstream status analysis. · `src/assortative_mating/normalize_occupations.py`
- [Status data](https://github.com/ekq/genealogy/tree/master/src/assortative_mating/data): reference data · Occupation-to-status mappings and cached status model artifacts. · `src/assortative_mating/data`
- [Mating analysis](https://github.com/ekq/genealogy/blob/master/src/assortative_mating/assortative_mating_analysis.py): analysis job · Analyzes partner similarity using reconstructed links and occupation/status data. · `src/assortative_mating/assortative_mating_analysis.py`
- [Plots](https://github.com/ekq/genealogy/tree/master/src/assortative_mating/plots): analysis output · Generated figures from assortative mating analysis. · `src/assortative_mating/plots`

## Connections

- HisKi data → Burial matches: records · Raw burial and birth records are matched in batch.
- HisKi data → Parent matches: records · Raw HisKi records feed parent inference.
- Birth IDs → Parent matches: batch · Birth event slices drive parallel execution.
- Burial IDs → Burial matches: batch · Burial event slices drive parallel execution.
- Model priors → Match model: priors · Serialized likelihood tables and classifiers inform scoring.
- Model priors → HisKi models: features · Precomputed model artifacts support matching features.
- Coords → Parish distance: geo · Coordinate conversion supports parish distance calculations.
- Parish distance → HisKi models: location · Geographic similarity is used in feature generation.
- Name normalizer → Name norms: names · Normalization routines standardize names before matching.
- Name norms → Match model: clean names · Normalized name fields improve candidate scoring.
- HisKi models → Match model: domain features · HisKi-specific features feed the scoring model.
- Burial matches → Reconstructions: burial links · Burial-birth links are written to the reconstruction boundary.
- Parent matches → Reconstructions: parent edges · Parent-child relationships are emitted as derived artifacts.
- Reconstructions → DB write: persist · Generated burial links are written back to the HisKi database.
- DB write → Parent matches: enriched db · The second inference pass uses the updated database.
- Reconstructions → Mating analysis: family links · Reconstructed genealogy links feed the mating analysis.
- Status data → Occ norms: status refs · Occupation and status reference tables support normalization.
- Occ norms → Mating analysis: occupation status · Normalized occupation/status mappings are analyzed over time.
- Mating analysis → Plots: figures · Analysis outputs are rendered as plots.
