Skip to content

Commit

Permalink
Merge pull request jupyter-naas#1254 from jupyter-naas/display-word-d…
Browse files Browse the repository at this point in the history
…efinition

Added: Display word definiton
  • Loading branch information
FlorentLvr authored Oct 18, 2022
2 parents 3bc2f29 + a6f4125 commit 3d506b2
Showing 1 changed file with 211 additions and 0 deletions.
211 changes: 211 additions & 0 deletions Python/Python_Get_Word_Definition_and_Translation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "5a8150cb-480c-469f-8aff-4ea7c2b26963",
"metadata": {},
"source": [
"<img width=\"10%\" alt=\"Naas\" src=\"https://landen.imgix.net/jtci2pxwjczr/assets/5ice39g4.png?w=160\"/>"
]
},
{
"cell_type": "markdown",
"id": "10371288-b489-41bc-8460-9b07c689da06",
"metadata": {},
"source": [
"# Python - Get word definition and translation"
]
},
{
"cell_type": "markdown",
"id": "be58437b-49b9-4813-a1fc-1b244b4989b9",
"metadata": {},
"source": [
"**Tags:** #python #dictionary #project #word #snippet"
]
},
{
"cell_type": "markdown",
"id": "a09fa493-3a7d-40c6-a486-f9c95380d2f2",
"metadata": {},
"source": [
"**Author:** [Sriniketh Jayasendil](https://twitter.com/srini047/)"
]
},
{
"cell_type": "markdown",
"id": "87abccf3-290d-4e3e-96a2-eb5373f27002",
"metadata": {},
"source": [
"**Description:** This notebook get world definition and translation from English using PyDictionary."
]
},
{
"cell_type": "markdown",
"id": "3691d70b-39e6-4ed9-9c37-cab39f47cfdb",
"metadata": {},
"source": [
"## Input"
]
},
{
"cell_type": "markdown",
"id": "116fb801-86da-488d-896f-3841353c55b8",
"metadata": {},
"source": [
"### Import libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "83d9b261-4e73-4b10-820e-0f21db738fd0",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"try:\n",
" from PyDictionary import PyDictionary\n",
"except ModuleNotFoundError:\n",
" !pip install PyDictionary\n",
" from PyDictionary import PyDictionary"
]
},
{
"cell_type": "markdown",
"id": "eda2461b-0583-4942-8304-0afd6f6fd9af",
"metadata": {},
"source": [
"### Setup Variables\n",
"- Enter the word in English\n",
"- Check the available language codes [here](https://developers.google.com/admin-sdk/directory/v1/languages)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6615bf49-3f2c-4025-93a1-ec65dd64646b",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"word = input('-> Enter the word to get all details: ') # Get the word from the user\n",
"lang_code = input('-> Enter the language that needs to be translated: ') # Available language codes: https://developers.google.com/admin-sdk/directory/v1/languages [EN, FR, ES]"
]
},
{
"cell_type": "markdown",
"id": "5aeb981c-1813-4675-81cc-ea9ff89636ae",
"metadata": {},
"source": [
"## Model"
]
},
{
"cell_type": "markdown",
"id": "41471a07-0fb7-4692-913b-e2c71780f178",
"metadata": {},
"source": [
"### Set PyDictionary"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7967f2ff-d54a-4f1e-8efb-ed3edc0eba4c",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"dictionary = PyDictionary() # Create a PyDictionary Model"
]
},
{
"cell_type": "markdown",
"id": "00ebed91-a193-4fa7-a208-7a845395563b",
"metadata": {},
"source": [
"## Output"
]
},
{
"cell_type": "markdown",
"id": "3af29764-42ad-418b-9c5f-51595e6f3ffa",
"metadata": {
"execution": {
"iopub.execute_input": "2022-10-13T17:46:27.193763Z",
"iopub.status.busy": "2022-10-13T17:46:27.193530Z",
"iopub.status.idle": "2022-10-13T17:46:27.196566Z",
"shell.execute_reply": "2022-10-13T17:46:27.195853Z",
"shell.execute_reply.started": "2022-10-13T17:46:27.193737Z"
}
},
"source": [
"### Meaning"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f71f6935-c93d-4643-8145-c1b0326929a3",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"print(word + \" : \", end=\"\")\n",
"meaning = dictionary.meaning(word)\n",
"print(meaning) # replace \"earth\" with any other word of your choice"
]
},
{
"cell_type": "markdown",
"id": "e702e23e-f75f-4dba-a9c2-d12e4c99c6ef",
"metadata": {},
"source": [
"### Translate"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "44f7485b-664b-4cf9-8161-38596984dabb",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"print(word + \" => \" + dictionary.translate(word, lang_code))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
},
"vscode": {
"interpreter": {
"hash": "1a98dfdbf5f4dedf5e8d8f4bfd1359a63aa6179b015a1f011f140876f85c4cf3"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 3d506b2

Please sign in to comment.