forked from bfijalkowski/KWT-2024
'labs2'
This commit is contained in:
parent
1f7c4d72ad
commit
9a3d25dac1
@ -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": [],
|
||||
"source": [
|
||||
"def fuzzy_lookup(sentence, threshold):\n",
|
||||
" return []"
|
||||
"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",
|
||||
" 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",
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user