Skip to main content

Correspondentia

Build Status Build status

Python library to map correspondence tables in different formats to data structures.

A quick example:

from correspondentia import match_fields

numbers_to_names = {
    1: [{"value": "one", "type": "exact"}],
    2: [{"value": "two", "weight": 0.5, "type": "disaggregation"},
        {"value": "deux", "weight": 0.5, "type": "disaggregation"}],
}

my_data = [{
    'count': 1,
    'name': 'foo'
}, {
    'count': 2,
    'name': 'bar'
}]

list(match_fields(my_data, numbers_to_names, "count"))
> [{'count': 'one', 'name': 'foo'},
   {'count': 'two', 'name': 'bar', 'correspondentia_allocation': 0.5},
   {'count': 'deux', 'name': 'bar', 'correspondentia_allocation': 0.5}]

match_fields return a generator.

Input data

Input data should be an iterable of objects supporting the dictionary interface.

Input tables

correspondentia currently can import the following formats:

  • CSVs following the simple schema

We plan to also eventually support the following:

  • RDF (Turtle) correspondence tables following the BONSAI spec
  • CSVs with BONSAI ontology predicates

You can also write custom importers, or define correspondence tables manually. In either case, the correspondence table data should include at least the following fields (additional fields are also allowed):

{
    "label in origin schema (usually str, but can be int or float)": {
        "value": "label in destination schema (usually str, but can be int or float)",
        "type": one of ["exact", "disaggregation"],
        "weight": float, # optional
    }
}

Simple CSV schema for input tables

A CSV with two required and one optional columns.

  • First column: Label in origin schema
  • Second column: Label in destination schema
  • Third column (optional): Weight used for disaggregation.

If matching is 1-N or N-1, just use multiple rows with redundant labels.

CSVs should follow the Open Knowledge CSV spec. Do not use column headers.

Installation

Installation via normal pathways; currently has no dependencies.

Contributing

Follow standard fork/pull-request procedure.

Metadata

Release files for correspondentia 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for correspondentia 0.1
File Size Uploaded
correspondentia-0.1.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for correspondentia 0.1
File Interpreter ABI Platform
correspondentia-0.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.4 kB

Release files / correspondentia-0.1.tar.gz

Download URL correspondentia-0.1.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
86a2163b1108c3a59312b7d0f99eac4dd4a6137b73aa400d607667bf1e40ec21
BLAKE2b-256 checksum
How to use checksums
a5b54b3a385c92c791522283157537527feb00652fc48807a427a5cd9253fc21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / correspondentia-0.1-py3-none-any.whl

Download URL correspondentia-0.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c83ba0dda802b7203f5a10b413ed06759f1316d9c6170ee46c7a9dadbe760b3
BLAKE2b-256 checksum
How to use checksums
b550001a45927b2ff6ec3fba7e90bd491c1f36054bf85eee1f4cf3ef52668f5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page