Package: dated-translator
dated-translatorA Python package that helps translate from one term to another, depending on a passed date, from a CSV that contains some verified information.Getting startedInstallationYou can install this package usingpip:$pipinstalldated_translatorFirst lookupSet up the lookup object first. In this case, we have adata_file.csvwhich contains (at least) four required columns:Term 1,Term 2,Start Date, andEnd 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 datelookup.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 dateAdvanced setupThis 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.ipynbnotebook.Say that we have a list of newspaper titles with different abbreviations, and we need to check which identification number,NLPthat each abbreviation is associated with, within a certain date range.The file that we'd pass to the setup of theLookupobject, in this example calledJISC-papers.csv, would look something like this:Newspaper TitleNLPNormalised TitleAbbrStartDStartMStartYEndDEndMEndYAberdeen Journal and general advertiser for the north of Scotland, The31Aberdeen JournalANJO1Jan180023Aug1876Aberdeen Weekly Journal and general advertiser for the north of Scotland32Aberdeen JournalANJO30Aug187631Dec1900In this example, we want to get the resultingNLP31for any ANJO abbreviations (Abbr) between 1881-01-01 and 1876-08-23, and32for 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 ourleft_translateandright_translatemethods 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 (aStart DateandEnd Datecolumn 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 theleft_translatemethod to check what theNLPis 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 theright_translatemethod to check what theAbbris for a givenNLP(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.