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 Thingy1 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.txt2 en acroniemen.txt3 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.