Skip to main content

dated-translator

A Python package that helps translate from one term to another, depending on a passed date, from a CSV that contains some verified information.

Getting started

Installation

You can install this package using pip:

$ pip install dated_translator

First lookup

Set up the lookup object first. In this case, we have a data_file.csv which contains (at least) four required columns: Term 1, Term 2, Start Date, and End Date. For a more advanced setup, see below.

lookup = Lookup(dataset="data_file.csv")

lookup.left_translate("Term 1", "1800-01-01") # Will return a list with the values of term 2 that exist in any given span of start and end date

lookup.right_translate("Term 2", "1800-01-01") # Will return a list with the values of term 1 that exist in any given span of start and end date

Advanced setup

This example is a real-world example from the Living with Machines project, and if you want to test it yourself (after installing the package), you can clone this repository and check out the example/Example.ipynb notebook.

Say that we have a list of newspaper titles with different abbreviations, and we need to check which identification number, NLP that each abbreviation is associated with, within a certain date range.

The file that we'd pass to the setup of the Lookup object, in this example called JISC-papers.csv, would look something like this:

Newspaper Title NLP Normalised Title Abbr StartD StartM StartY EndD EndM EndY
Aberdeen Journal and general advertiser for the north of Scotland, The 31 Aberdeen Journal ANJO 1 Jan 1800 23 Aug 1876
Aberdeen Weekly Journal and general advertiser for the north of Scotland 32 Aberdeen Journal ANJO 30 Aug 1876 31 Dec 1900

In this example, we want to get the resulting NLP 31 for any ANJO abbreviations (Abbr) between 1881-01-01 and 1876-08-23, and 32 for any of the same abbreviation between 1876-08-30 and 1900-12-31.

To set this up, we need to pass the dataset's name, and specify the names of the lookup's term 1 (Abbr) and term 2 (NLP). Note: It doesn't matter in which order you pass them, but which one is considered term 1 and 2 will affect our left_translate and right_translate methods further down the line.

We also need to specify the particular date column format in our file. Since we're not using the standard setup here (a Start Date and End Date column respectively), we can pass a dictionary which requires three items, specifying the name of the year, month, and day columns, and their date formatting. We do so for both the start date and end date columns:

lookup = Lookup(
    dataset="JISC-papers.csv",
    term_1_column = "Abbr",
    term_2_column = "NLP",
    start_date_column = {
        "StartY": "%Y",
        "StartM": "%b",
        "StartD": "%d"
    },
    end_date_column = {
        "EndY": "%Y",
        "EndM": "%b",
        "EndD": "%d"
    }
)

After this setup, we can run the left_translate method to check what the NLP is for the abbreviation "ANJO" on the date 1800-01-01:

lookup.left_translate("ANJO", "1800-01-01")

This should return the value: [31], that is, a list of the possible NLPs for this abbreviation on this particular date.

Similarly, we can run the right_translate method to check what the Abbr is for a given NLP (31) on the date 1800-01-01:

lookup.right_translate(31, "1800-01-01")

The result should, in a reverse of the result above, be ['ANJO'], that is, a list of the possible abbreviations for this NLP in on this particular date.

Metadata

Release files for dated-translator 0.1.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 dated-translator 0.1.1
File Size Uploaded
dated-translator-0.1.1.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dated-translator 0.1.1
File Interpreter ABI Platform
dated_translator-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.9 kB

Release files / dated-translator-0.1.1.tar.gz

Download URL dated-translator-0.1.1.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
08e4f7ef1bcdf895a0127a3071dc6e373ecf378e0d663f956cbeaef558d10679
BLAKE2b-256 checksum
How to use checksums
c5eac1b6c924e730198e9bb9e32aa313c5a5d54243a6c2bd176632b41e6a5547
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.9.12 Darwin/21.6.0

Release files / dated_translator-0.1.1-py3-none-any.whl

Download URL dated_translator-0.1.1-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16c1d520cc26de7f16821bfcfb926149868b8c8c7aaecfeac1ca906ee716bb91
BLAKE2b-256 checksum
How to use checksums
1f746d678ce1643d18127322234e26168f6f5e185432a928ad7581d4a2148bcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.9.12 Darwin/21.6.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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