PROG0166 - TMA

no tags 

acroniem

On the Internet, acronyms are often used as an abbreviation. Examples are ASAP (as soon as possible), FAQ (frequently asked questions) and WYSIWYG (what you see is what you get). In informatics recursive acronyms are sometimes used: acronyms of which the combined parts are the same as the acronym: GNU (GNU is not Unix) or PNG (PNG is not GIF). Many can be used in all sorts of cases. The reason for the use of abbreviations is to make a text clearer. However, in the case of overuse, the text becomes harder to understand.

In the Monty Python sketch Tax on Thingy John Cleese plays a politician that says this to his three colleagues:

Gentlemen, our MP saw the PM this AM and the PM wants more LSD from the PIB by tomorrow AM or PM at the latest. I told the PM's PPS that AM was NBG so tomorrow PM it is for the PM nem. con. Give us a fag or I'll go spare. Now, the fiscal deficit with regard to the monetary balance, the current financial year excluding invisible exports, but adjusted of course for seasonal variations and the incremental statistics of the fiscal and revenue arrangements for the forthcoming annual budgetary period terminating in April.

Try figuring that one out. In an other Monty Python sketch we can hear Eric Idle saying:

In a nutshell, the problem of the CFJ has arisen from a dispute amongst the members of the PBFC who have decided to appeal to the NTSU for permission to take action against the LSM in their dispute with the NFOR. The NFO itself has come out firmly against the CYP, accusing the BFO of not listening to the KY or the more moderate CSI and rejecting the report of the BACON on AK achievements during the current BFP in favor of the SDSCP. This dispute, which arose last MAY, has spread to the TFO, which itself is appealing a BRN ruling to the GRM against the PYB elements of the NPU. Well, will it be McGumby's FNP, or can Harkham's DNY provide last minute support to the FDO to bolster the failing appeal of the BFN FUCK YOU. Or is it simply too late to understand just what is going on here? This is Robert Allison in MANC... (whisper "Manchester") Thank you.

The acronym TMA in the title of this assignment stand for Too Many Acronyms, a series of cartoons of Yu-San Moon in which the conversations are held exclusively in acronyms.

too many acronyms

Assignment

Write a function TMA that takes the locations of two text files as its arguments. The first text file contains a number of lines of text in which several acronyms occur. The second text file contains an acronym on every line, followed by an tab character and the meaning of the acronym. The function should print the lines of the first text file, and replace the first occurrence of acronym $A$ with its meaning $B$ that is defined in the second text file, followed by a space and then the acronym $A$ between brackets. If the acronym $A$ is repeated thereafter, then the acronym can remain.

Example

In the following example session we assume that the files taxonthingy.txt and acronyms.txt are located in the current directory.

>>> TMA('taxonthingy.txt', 'acronyms.txt')
Gentlemen, our Member of Parliament (MP) saw the Prime Minister (PM) this
Ante Meridiem (AM) and the PM wants more Pounds, Shillings and Pence (LSD)
from the Publishers' Information Bureau (PIB) by tomorrow AM or PM at the
latest. I told the PM's Principal Private Secretary (PPS) that AM was
No Bloody Good (NBG) so tomorrow PM it is for the PM nem. con.
Give us a fag or I'll go spare.
acroniem

Op het Internet worden acroniemen vaak als afkorting gebruikt. Voorbeelden zijn ASAP (as soon as possible) dat in het Nederlands als woord wordt uitgesproken, FAQ (frequently asked questions) en WYSIWYG (what you see is what you get). In informaticamiddens worden soms ook recursieve acroniemen gebruikt: acroniemen waarvan één van de samenstellende delen weer hetzelfde acroniem is: GNU (GNU is not Unix) of PNG (spreek uit: ping; PNG is not GIF). Heel veel zaken kunnen te pas en te onpas gebruikt worden, en dat geldt zeker voor het gebruik van afkortingen. De achterliggende reden achter het gebruik van afkortingen is om een tekst duidelijker te maken. Met overmatig of verkeerd gebruik van afkortingen bekomt men echter vaak het omgekeerde effect.

In de Monty Python sketch Tax on Thingy speelt John Cleese bijvoorbeeld een politicus die het volgende zegt tegen drie collega's:

Gentlemen, our MP saw the PM this AM and the PM wants more LSD from the PIB by tomorrow AM or PM at the latest. I told the PM's PPS that AM was NBG so tomorrow PM it is for the PM nem. con. Give us a fag or I'll go spare. Now, the fiscal deficit with regard to the monetary balance, the current financial year excluding invisible exports, but adjusted of course for seasonal variations and the incremental statistics of the fiscal and revenue arrangements for the forthcoming annual budgetary period terminating in April.

Probeer daar maar eens aan uit te raken. In een andere Monty Python sketch horen we Eric Idle het volgende zeggen:

In a nutshell, the problem of the CFJ has arisen from a dispute amongst the members of the PBFC who have decided to appeal to the NTSU for permission to take action against the LSM in their dispute with the NFOR. The NFO itself has come out firmly against the CYP, accusing the BFO of not listening to the KY or the more moderate CSI and rejecting the report of the BACON on AK achievements during the current BFP in favor of the SDSCP. This dispute, which arose last MAY, has spread to the TFO, which itself is appealing a BRN ruling to the GRM against the PYB elements of the NPU. Well, will it be McGumby's FNP, or can Harkham's DNY provide last minute support to the FDO to bolster the failing appeal of the BFN FUCK YOU. Or is it simply too late to understand just what is going on here? This is Robert Allison in MANC... (whisper "Manchester") Thank you.

Het acroniem TMA uit de titel van deze opgave slaat trouwens op Too Many Acronyms, een reeks cartoons van Yu-San Moon waarin de dialogen uitsluitend in acroniemen gevoerd worden.

too many acroyms

Opgave

Schrijf een functie TMA waaraan de locaties van twee tekstbestanden moeten doorgegeven worden. Het eerste tekstbestand bevat een aantal regels tekst waarin verschillende acroniemen voorkomen. Het tweede tekstbestand bevat op elke regel een acroniem, gevolgd door een tab karakter en de betekenis van het acroniem. De functie moet de regels uit het eerste tekstbestand uitschrijven, en moet daarbij telkens het eerste voorkomen van acroniem $A$ waarvan de betekenis $B$ gedefinieerd wordt in het tweede tekstbestand vervangen door de betekenis $B$, gevolgd door een spatie en dan tussen ronde haakjes het acroniem $A$ zelf. Indien het acroniem $A$ daarna nog herhaald wordt in de tekst, dan mag het daar gewoon blijven staan.

Voorbeeld

Bij onderstaand voorbeeld gaan we ervan uit dat de bestanden taxonthingy.txt en acroniemen.txt zich in dezelfde folder bevinden als het Python script.

>>> TMA('taxonthingy.txt', 'acroniemen.txt')
Gentlemen, our Member of Parliament (MP) saw the Prime Minister (PM) this
Ante Meridiem (AM) and the PM wants more Pounds, Shillings and Pence (LSD)
from the Publishers' Information Bureau (PIB) by tomorrow AM or PM at the
latest. I told the PM's Principal Private Secretary (PPS) that AM was
No Bloody Good (NBG) so tomorrow PM it is for the PM nem. con.
Give us a fag or I'll go spare.


Added by:Peter Dawyndt
Date:2011-08-31
Time limit:5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:PY_NBC
Resource:None