From 9a3d25dac160fb3c1abc7d53d78cacfacbf6e782 Mon Sep 17 00:00:00 2001 From: Kamil Kubiak Date: Sat, 20 Apr 2024 16:54:31 +0200 Subject: [PATCH] 'labs2' --- lab/lab_02.ipynb | 66 ++++++++++++++++++++++++++++++++++++++++++------ lab/lab_03.ipynb | 4 +-- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/lab/lab_02.ipynb b/lab/lab_02.ipynb index 10c2003..b8883e1 100644 --- a/lab/lab_02.ipynb +++ b/lab/lab_02.ipynb @@ -223,17 +223,17 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 7, "id": "secondary-wrist", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "2" + "3" ] }, - "execution_count": 5, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -344,21 +344,71 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 18, "id": "genetic-cradle", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Wciśnij przycisk Enter -> Wciśnij przycisk Enter [ SCORE = 1.0 ]\n", + "Wciśnij przycisk Enter -> Wciśnij przycisk ENTER [ SCORE = 0.8181818181818181 ]\n", + "Wciśnij przycisk Enter -> Wciśnij przycisk Enter! [ SCORE = 0.9565217391304348 ]\n", + "Wciśnij przycisk Enter -> Wciśnij przycisk Enter [ SCORE = 1.0 ]\n" + ] + } + ], "source": [ + "#!pip3 install python-Levenshtein\n", + "from Levenshtein import distance as levenshtein_distance\n", + "\n", + "translation_memory = [\n", + " ('Wciśnij przycisk Enter', 'Press the ENTER button'),\n", + " ('Wciśnij przycisk ENTER', 'Press the ENTER button'), \n", + " ('Wciśnij przycisk Enter!', 'Press the ENTER button!'), \n", + " ('Wciśnij przycisk', 'Press the button'), \n", + " ('Wciśnij Enter', 'Press the ENTER'), \n", + " ('Sprawdź ustawienia sieciowe', 'Check the network settings'),\n", + " ('Drukarka jest wyłączona', 'The printer is switched off'),\n", + " ('Wymagane ponowne uruchomienie komputera', 'System restart required')\n", + " ]\n", + "\n", + "def levenshtein_similarity(x,y):\n", + " return 1 - levenshtein_distance(x,y) / max(len(x), len(y))\n", + "\n", "def fuzzy_lookup(sentence, threshold):\n", - " return []" + " for entry in translation_memory:\n", + " part1 = entry[0]\n", + " score = levenshtein_similarity(sentence, part1)\n", + " if score >= threshold:\n", + " print(sentence + ' -> ' + part1 + ' [ SCORE = ' + str(score) + ' ]')\n", + "\n", + "fuzzy_lookup('Wciśnij przycisk Enter', 0.8)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b7bb6aa-5aaf-4f49-84ab-edbe6797d568", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3b095fff-71a8-44a9-b809-d872ee9a7b62", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "author": "Rafał Jaworski", "email": "rjawor@amu.edu.pl", "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -373,7 +423,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.9.2" }, "subtitle": "2. Zaawansowane użycie pamięci tłumaczeń", "title": "Komputerowe wspomaganie tłumaczenia", diff --git a/lab/lab_03.ipynb b/lab/lab_03.ipynb index 5707f0d..1067d98 100644 --- a/lab/lab_03.ipynb +++ b/lab/lab_03.ipynb @@ -407,7 +407,7 @@ "author": "Rafał Jaworski", "email": "rjawor@amu.edu.pl", "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -422,7 +422,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.9.2" }, "subtitle": "3. Terminologia", "title": "Komputerowe wspomaganie tłumaczenia",