Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

your_name_here

Project description

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for correspondentia, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size correspondentia-0.1-py3-none-any.whl (5.4 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size correspondentia-0.1.tar.gz (5.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page