Skip to content
Snippets Groups Projects
Commit 20c68aa6 authored by Michele Nottoli's avatar Michele Nottoli
Browse files

Merge branch 'localization' into 'main'

Localization

See merge request !6
parents 6465b8f1 a7eebaa1
Branches
No related tags found
1 merge request!6Localization
%% Cell type:markdown id:31ac33c0-18a9-4cfa-8e04-3ee1a0c909eb tags:
# Installation und Einrichtung
Bitte befolge die in README.md beschriebenen Schritte 1-3, um Julia herunterzuladen und zu installieren, und das Notebook 0_Installation.ipynb in einen Jupyter-notebook zu öffnen.
%% Cell type:markdown id:ff3c6951-2bc8-42b9-b2f4-acbb473300c6 tags:
## Informationen zu Notebooks
Notebooks sind Werkzeuge, um interaktiven Code auszuführen und die Ausgabe anzuzeigen. Sie sind sehr praktisch, um mit Code zu experimentieren und eine Programmiersprache neu zu lernen.
Die Julia-Befehle werden in einer separaten Julia-Instanz im Hintergrund ausgeführt, der Browser ermöglicht die Interaktion mit den Notebooks (das Erstellen neuer Notebooks, das Ausführen und Modifizieren von ihnen). Beachte dass der Browser-Editor nicht mehr funktioniert wenn das Backend-Programm geschlossen wird.
Wenn jedoch der Browser geschlossen wird, läuft das Backend weiter. Du kannst darauf zugreifen, indem Du die Adresse öffnest:
[http://localhost:8888](http://localhost:8888)
%% Cell type:markdown id:c974b7c0-119c-4223-ad80-dce5a3ceead3 tags:
### Notebooks
Notebooks sind Dateien, die durch die Erweiterung `.ipynb` gekennzeichnet sind. Mit dem interaktiven Datei-Explorer kannst Du sie öffnen.
Die Notebooks enthalten Code, die Ausgabe des Codes und können zusätzliche Kommentare enthalten (wie diese hier). Das gesamte Material des Kurses enthält noch nicht die Ausgabe des Codes, Du erhälst sie, indem Du den Code zuerst ausführst.
Die Notebooks werden automatisch alle paar Minuten gespeichert, um jedoch sicherzustellen, dass sie gespeichert sind, kannst Du "Strg + S" drücken.
%% Cell type:markdown id:8c98e5f5-5a92-415a-b9ec-865972d45b6f tags:
### Zellen
Notebooks bestehen aus **Zellen**. Es gibt zwei Hauptarten: **Code** und **Markdown**. Dies ist eine Markdown-Zelle und wird verwendet, um Text auf eine formatierte Weise anzuzeigen.
Die nächste ist eine Code-Zelle und wird verwendet, um Code auszuführen und dessen Ausgabe anzuzeigen. Um sie auszuführen, klicken Sie darauf und drücken Sie Shift + Enter.
%% Cell type:code id:8074a659-e100-49db-b83c-f0738b25cf28 tags:
``` julia
println("Hello World!")
```
%% Cell type:markdown id:192dac00-072c-4699-bd06-9af6ae4e3055 tags:
Wenn Du auf eine Code-Zelle klickst, kannst Du auch deren Inhalt ändern. Um eine Markdown-Zelle zu ändern, musst Du darauf doppelklicken (dies ist jedoch für diesen Kurs nicht erforderlich).
Es ist auch möglich, eine Code-Zelle in eine Markdown-Zelle oder umgekehrt zu ändern. Gehe dazu im oberen Menü auf Ausführen, Zellentyp.
Schließlich können neue Zellen hinzugefügt werden, indem Du das `+`-Symbol im oberen Menü verwendest.
Jedes Mal, wenn es eine Übung für den Leser gibt, haben wir eine leere Code-Zelle hinzugefügt.
%% Cell type:markdown id:e7730114-5064-46d1-b724-e92277ff2f90 tags:
## Überprüfen, ob alles funktioniert
Um zu überprüfen, ob die Installation erfolgreich war, führe die folgende Zelle aus.
%% Cell type:code id:7bb04662 tags:
``` julia
using Plots
p = plot(1, xlim=(0, 3π), ylim=(-1.5, 1.5), title="Sine", marker=2)
N = 100
@gif for i=1:N
x = (i-1) * 3π / N
push!(p, x, sin(x))
end
```
%% Cell type:code id:c7d2870e tags:
``` julia
```
%% Cell type:markdown id:16b28ead tags:
# Installation and Setup
Please follow the steps 1-3 outlined in README.md to download and install Julia, and to open the notebook 0_Installation.ipynb in a Jupyter notebook.
%% Cell type:markdown id:9161160b-87ff-4b12-bd5a-bca54228672d tags:
## Information about notebooks
Notebooks are tools to interactively run code and display output. They are quite convenient for experimenting with code.
The julia commands are run in a backend julia instance, the browser let's you interact with the notebooks (create new ones, run them, modify them). If the backend program is closed, the browser editor will stop working.
However, if the browser is closed, the backend will keep running. You can get back to it by opening the address:
[http://localhost:8888](http://localhost:8888)
%% Cell type:markdown id:a915cd2f-dc38-4679-8d79-c2204e2073cf tags:
### Notebooks
Notebooks are files characterized by the extension `.ipynb`. Using the interactive file explorer you can open them.
The notebooks contain code, the output of the code, and can contain additional comments (like these ones). All the material of the course does not contain yet the output of the code, you will get it by running the code first.
The notebooks are automatically saved every now and then, however to make sure they are saved, you can press "Ctrl + S".
%% Cell type:markdown id:93606623-16a4-4263-9906-a79dd3fae22f tags:
### Cells
Notebooks are made up of **cells**. There are two main types: **code** and **markdown**. This is a markdown cell, it is used to display text in a formatted way.
The next is a code cell, it is used to run code and display its output. To run it, click on it and press "Shift + Enter".
%% Cell type:code id:8074a659-e100-49db-b83c-f0738b25cf28 tags:
``` julia
println("Hello World!")
```
%% Cell type:markdown id:5fc38ba1-65d0-490f-8c06-4136a7ff1372 tags:
When you click on a code cell, you can also modify its content.
To modify a markdown cell, you need to double click on it (however this is not required by this course).
It is also possible to transform a code cell in a markdown cell, or the other way around. To do so, go in the top menu, Run, Cell Type.
Finally, new cells can be added by using the `+` symbol in the top menu.
Every time there is an exercise left to the reader, we added an empty code cell.
%% Cell type:markdown id:d3d75953 tags:
## Verifying that everything works
To check if the installation was successfull, run the following cell.
%% Cell type:code id:7bb04662 tags:
``` julia
using Plots
p = plot(1, xlim=(0, 3π), ylim=(-1.5, 1.5), title="Sine", marker=2)
N = 100
@gif for i=1:N
x = (i-1) * 3π / N
push!(p, x, sin(x))
end
```
%% Cell type:code id:c7d2870e tags:
``` julia
```
This diff is collapsed.
This diff is collapsed.
File moved
File moved
#!/usr/bin/python3
import copy
import json
import os
import sys
import langid
def detect_language(text):
return langid.classify(text)
def load(path):
with open(path, encoding="utf-8") as file:
notebook = json.load(file)
return notebook
def human_intervention(language, probability, text):
print(
f"I classified this text:\n`{text}`\nas {language} with a non normalized probability of {probability}.\n"
)
while True:
print(
"Can you help me identifying it? write one among 'en', 'de', 'eq' (for equations), then press enter"
)
language = input()
if language in ["en", "de", "eq"]:
print("\n\n")
return language
def write(path, notebook):
with open(path, "w", encoding="utf-8") as file:
json.dump(notebook, file, indent=4)
def assign_languages(notebook):
cells = notebook["cells"]
for i, cell in enumerate(cells):
if cell["cell_type"] == "markdown":
text = str(cell["source"]).strip("\n# []'")
language, probability = detect_language(text)
if probability >= -10 or language not in ["en", "de"]:
# langid is doing something strange, we need to intervene
language = human_intervention(language, probability, text)
notebook["cells"][i]["metadata"]["natural_language"] = language
def select_language(notebook, language):
cells = notebook["cells"]
selected_cells = []
for cell in cells:
if cell["cell_type"] == "markdown":
if cell["metadata"]["natural_language"] == language:
selected_cells.append(cell)
elif cell["metadata"]["natural_language"] == "eq":
selected_cells.append(cell)
else:
selected_cells.append(cell)
new_notebook = copy.deepcopy(notebook)
new_notebook["cells"] = selected_cells
return new_notebook
if __name__ == "__main__":
PATH = sys.argv[1]
BASENAME = os.path.splitext(os.path.basename(PATH))[0]
NOTEBOOK = load(PATH)
assign_languages(NOTEBOOK)
NOTEBOOK_EN = select_language(NOTEBOOK, "en")
NOTEBOOK_DE = select_language(NOTEBOOK, "de")
write(f"{BASENAME}_en.ipynb", NOTEBOOK_EN)
write(f"{BASENAME}_de.ipynb", NOTEBOOK_DE)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment