Translating only the relevant parts of a Mathematica notebook: NotebookTranslate
Translating only the relevant parts of a Mathematica notebook: NotebookTranslate
Thomas Colignatus
http://thomascool.eu
April 2 2018
http://thomascool.eu
April 2 2018
Abstract
Many fine Mathematica notebooks in English are inaccessible to users of other languages, especially to young people growing up in other languages. Translating a Mathematica notebook - conventionally from English into another language - involves mainly text. It better does not involve Input and Output cells that should remain in English. One obvious reason is that the program uses English. The other obvious reason is that we want students to learn to use the program (in English). The routine NotebookTranslate distinguishes what to translate and what not. Since translation comes with a cost, the routine also supports the prudent use of Service Credits. Educators are advised to create repositories per language for such translated notebooks, to reduce costs and to allow ease of access and version management, e.g. also when an automated translation is improved upon manually.
Keywords
Education, Translation, Mathematica, Wolfram language, Service Credits, Programming, Linguistic Enhancement, Package
JEL
A20 Economic Education and Teaching of Economics: General,C87 Econometric SoftwareC88 Other Computer SoftwareI29 Education and Research Institutions: Other
MSC2010
97M70 Mathematics education. Behavioral and social sciences
Cloud
This paper is also available at:
Contents
Contents
Introduction
Introduction
Cost accounting
Cost accounting
Routines
Routines
The routine NotebookTranslate
The routine NotebookTranslate
Conclusions
Conclusions
Appendix: Example translation
Appendix: Example translation
Literature
Literature
Start (subsection for the initialisation packages)
Start (subsection for the initialisation packages)
Introduction
Introduction
Notebooks in English cannot be used in education in other languages when students still do not master English. This applies especially to elementary school.
This notebook provides a routine to translate the relevant parts of English notebooks, while keeping the Input and Output cells in English.
The latter cells must remain in English since the engine works like that. It is a key objective that students learn to use Mathematica in English.
Example of interesting notebooks that are still in English
Example of interesting notebooks that are still in English
There is a large collection of notebooks in English that are inaccessible to most students in the world.
◼
An obvious example is the discussion by Stephen Wolfram himself “An Elementary Introduction to the Wolfram Language” (2015-12-08) http://blog.wolfram.com/2015/12/08/i-wrote-a-book-to-teach-the-wolfram-language and http://www.wolfram.com/language/elementary-introduction/2nd-ed.
◼
From that discussion: Neidinger, Swallow, Will, Davis, “Programming Paradigms via Mathematica (A First Course)”, 2001-02-16, http://library.wolfram.com/infocenter/MathSource/1847/
What to translate - what not to translate
What to translate - what not to translate
For translation of a Mathematica notebook from English into another language it suffices that Titles, Section heads and Text cells are translated while the Input and Output cells can remain in English:
◼
since the engine is in English anyway
◼
since it is a learning objective that students learn to use Mathematica in English.
There now is also the feature of a linguistic enhancement of the code. Use the Menu: Edit, Preferences, Interface.
◼
http://www.wolfram.com/language/11/user-interface-enhancements/multilingual-code-captions.html
Service Credits costs of translation
Service Credits costs of translation
Automated translation uses services from Google or Microsoft, and then comes with Service Credits costs.
?$ServiceCreditsAvailable
$ServiceCreditsAvailable gives the available Service Credits in the user's account.
The routine supports a prudent use of funds.
Limits to automatic translation
Limits to automatic translation
There are many obvious limits to automatic translation. It is often advisable to consider manual corrections.
Mathematica is versatile with inline editing options e.g. with the TextData object. Google and Microsoft can only handle plain text.
?TextData
TextData[exprs] is a low-level representation of the contents of a textual cell.
The routine converts Mathematica text - in the relevant cells - into the InputText format, before submitting to translation.
The routine allows you to fully replace such translated cells, but, it also allows you to keep the original cell in English and put the translated cell below it, so that you may improve on the translation, and, so that students can benefit both from the translation and the original text in English.
Translated cells will be be given the CellTag “Translated” automatically, and one may adapt that tag for improvements on the automated translation.
A test run before committing to a costly translation
A test run before committing to a costly translation
Because of these costs and limitations, the routine allows the user to first run a test, that shows that the relevant files can found, that relevant options have been chosen, and that the relevant cells have been selected. The test file will be deleted automatically when a new test is performed.
When the command has been given to make an actual translation, and thus to commit the Service Credits, then a new file is created. If such a translated file already exists then the routine will stop, preventing the overwriting of a costly file. Translated files must be managed manually (relocated, renamed, deleted).
This notebook
This notebook
We will look at cost accounting first, then the routines, then apply an example translation, and close with conclusions.
Cost accounting
Cost accounting
The routine
The routine
This routine allows some cost accounting.
?TranslationCostAccount
TranslationCostAccount["text"] estimates the cost of translating "text"TranslationCostAccount["text", n] compares this estimate with the actual cost of n Service CreditsTranslationCostAccount[nchar, n:0] has integer input for the number of characters and number of Service CreditsOptions are (with defaults):"ServiceCreditsPerCharacter" -> N[10 / 1000]"DollarCentsPerServiceCredit" -> N[500 / 1000 ]N -> 1, for the number of calls to the translation service, e.g. the number of cells translated
Translating 100 characters currently costs 1 Service Credit.
TranslationCostAccount[100]
, ,
NumberOfCharacters | 100 |
NumberOfCalls | 1 |
AverageNCharPerCall | 100. |
EstimatedCost | ActualCost | |
ServiceCredits | 1. | 0 |
$Cents | 0.5 | 0. |
Options[TranslationCostAccount]
{ServiceCreditsPerCharacter0.01,DollarCentsPerServiceCredit0.5,N1}
Using it
Using it
The following text has 26 characters with spaces and 22 without spaces. The convention is to count a space as a character.
TranslationCostAccount["The book was very popular."]
, ,
NumberOfCharacters | 26 |
NumberOfCalls | 1 |
AverageNCharPerCall | 26. |
EstimatedCost | ActualCost | |
ServiceCredits | 0.26 | 0 |
$Cents | 0.13 | 0. |
An A4 page may have 1000 words and 5000 characters without spaces, thus 5 characters per word. Thus it has 6000 characters with spaces. Translating it would cost 60 Service Credits.
TranslationCostAccount[6000]
, ,
NumberOfCharacters | 6000 |
NumberOfCalls | 1 |
AverageNCharPerCall | 6000. |
EstimatedCost | ActualCost | |
ServiceCredits | 60. | 0 |
$Cents | 30. | 0. |
Wolfram’s An Elementary Introduction to the Wolfram Language has 324 pages in the printed version. Let us assume a smaller page with 550 words per page, and let us assume that 150 are plain text because there will be much input and output from Mathematica. Translating it would cost $14.58.
TranslationCostAccount[324*150*(5+1)]
, ,
NumberOfCharacters | 291600 |
NumberOfCalls | 1 |
AverageNCharPerCall | 291600. |
EstimatedCost | ActualCost | |
ServiceCredits | 2916. | 0 |
$Cents | 1458. | 0. |
Routines
Routines
Routines in Mathematica
Routines in Mathematica
Mathematica already has many features for languages and translations.
?*Language*
?WordTranslation
WordTranslation["word",lang] gives translations for word into the language lang.WordTranslation["word",] gives translations for word from to .
lang
1
lang
2
lang
1
lang
2
Remarkable, TextTranslation doesn’t have options to set the input and output language. For this reason, the present package defines its own TextTranslator routine with a particular setting for the case at hand.
Routines in this notebook / package
Routines in this notebook / package
The Initialisation cell in this notebook contains the following package that defines the following routines.
The subroutines are:
The routine NotebookTranslate
The routine NotebookTranslate
Use, format and options
Use, format and options
The routine finds the source file via directory and name, with default the working directory and name “Source.nb”.
Subsequently, the routine is steered by the options.
Example Test
Example Test
We copied Hw01.nb from http://library.wolfram.com/infocenter/MathSource/1847/ to this particular directory.
There is no need of confirmation that the file has been written, since the translation is done in an open notebook that the user can see.
The routine has set the following TextTranslator.
Example Translation 1
Example Translation 1
The translation can be generated.
For the record, the generated “Dutch translation” of Hw01.nb is in the Appendix. The file is small and contains only text. For limited purposes it seems that one can live with it.
Example Translation 2
Example Translation 2
Since the former run already created a translated file, the routine stops, saving Service Credits. We may delete, relocate or rename this earlier translation to make room for a new one.
The routine now has defined a TextTranslator that will cost Service Credits when used.
Conclusions
Conclusions
The special structure of Mathematica notebooks causes that we cannot translate all in one go, yet the special structure also allows us to identify what cells are most relevant to translate.
Translation of tidbits may seem cheap, but translation of whole notebooks, and collections of them that form a book or course, quickly becomes expensive.
Results of automated translation are best stored at some common repository per language.
◼
The number of translated notebooks may be limited since these would focus on students who are too young to command English.
◼
Yet it would be dubious to extend MathSource with all the languages in the world. Thus educators best create a repository per language.
◼
These repositories would also take care of copyrights and intellectual rights of the original authors.
◼
Translated versions would require version management. The automated translators improve over time, and after a while one may venture on a new automated version, if it is worth the cost. If a translation has been improved manually, then one might forgo such an update though. The latter is more likely for Mathematica with its special inline formats.
The present routine removes all inline formats and uses InputText. WRI stands for the choice to develop a translation engine that can also handle these special formats. Perhaps though this is not needed when “natural language input” becomes dominant. The advantage of structured input remains that one can be much more precise, but, students who reach that stage may already command English.
Appendix: Example translation
Appendix: Example translation
1. Rekenen: syntaxis, gegevenstypen, operators en expressies
1. Rekenen: syntaxis, gegevenstypen, operators en expressies
Laatste herziening: 15 januari 1998
Persoonlijke informatie
Persoonlijke informatie
Naam:
E-mail:
Webadres?:
Studentenkamer #:
Telefoon: 896-
adviseur:
E-mail:
Webadres?:
Studentenkamer #:
Telefoon: 896-
adviseur:
Welke rol speelt deze cursus in uw academische plannen?
Wat was je laatste wiskundecursus? ... wanneer heb je het genomen?
Wat is je belangrijkste prestatie in een wiskunde- of computeropleiding?
Oefening
Oefening
Je eerste oefening is om te beslissen over de volgorde (d.w.z. x <y <z) tussen de drie cijfers Pi, 22/7 en 355/113, zodat we weten welke de kleinste is, welke de grootste.
Gebruik voor uw eerste poging de functie "N []" om voor elk getal een decimale benadering te vinden. Klik tussen deze cel en die erboven (je zou een horizontale lijn moeten zien); begin dan met typen om een invoercel te maken (vergeet niet om enter te gebruiken, of shift-return om een invoercel uit te voeren). U kunt op deze manier meerdere invoercellen maken en, zeker, u kunt teruggaan en een cel wijzigen en het opnieuw proberen. Kijk of je de volgorde van deze nummers kunt onderscheiden door gewoon de "N []" -functie te gebruiken. Voer vervolgens het probleem opnieuw uit met behulp van de symbolen <en> om nummers te vergelijken, zoals beschreven in les 1.
Als je klaar bent, zorg er dan voor dat je instructeur een kopie van je voltooide werk heeft. Sla een kopie op onder een bestandsnaam die zowel de toewijzing als de auteur (u) identificeert (bijvoorbeeld HW01-MyName.nb). Sleep een kopie van dit bestand naar het vervolgkeuzemenu van uw instructeur op het netwerk en breng een gedrukt exemplaar naar onze volgende klas.
Literature
Literature
Since 2004, Thomas Colignatus is the scientific name of Thomas Cool, econometrician and teacher of mathematics, Scheveningen, Holland.
Cool, Th. (2003), Some Update Notes on The Economics Pack, https://econpapers.repec.org/software/wpawuwppr/0303001.htm (website of The Economics Pack relocated to http://thomascool.eu/TheEconomicsPack/index.html)
Neidinger, Swallow, Will, Davis (2001), Programming Paradigms via Mathematica (A First Course), 2001-02-16, http://library.wolfram.com/infocenter/MathSource/1847/
Wolfram, S. (2015), I Wrote a Book—To Teach the Wolfram Language, http://blog.wolfram.com/2015/12/08/i-wrote-a-book-to-teach-the-wolfram-language
Wolfram, S. (2017), An Elementary Introduction to the Wolfram Language, 2nd ed., Wolfram Media, Inc., http://www.wolfram.com/language/elementary-introduction/2nd-ed