diff --git a/Example_Dutch.xlsx b/Example_Dutch.xlsx new file mode 100644 index 0000000..2fe5ea2 Binary files /dev/null and b/Example_Dutch.xlsx differ diff --git a/Example_English.xlsx b/Example_English.xlsx new file mode 100644 index 0000000..b58f6f0 Binary files /dev/null and b/Example_English.xlsx differ diff --git a/README.md b/README.md index c4f8bc5..42d0fbd 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,76 @@ -# A script to make you proud - -This repository contains a small Python program that shows that I have learned Python in this semester. - -The code has been developed by Mariana Montes. - -## Installation and usage - -Clone this repository with the following git command in the console (or download the ZIP file via GitHub): - -```sh -git clone git@github.com:montesmariana/intro_machine_learning_using_python -``` - -You can import the script as a module by adding the repository to your path in a Python script or interactive notebook and then calling `import`. - -```python -import sys -sys.path.append('/path/to/intro_machine_learning_using_python') -import script as s -``` - -Check out `tutorial.md` to see an example of the different functionalities of the script! - -You can also run the script directly with the following code in a console: - -```sh -python script.py -``` - -Or in Jupyter notebook with: - -```python -%run script.py -``` - -In both cases `example.json` stands for the `filename` argument that the script needs. You can use [the file in this repository](example.json) or a similar file of yours. Find more information on how this script works with: - -```sh -python script.py --help -``` - -If you run this script, you become proud of yourself. +# Script: Translation Vendor Database + +## The repository +This repository has been created by Elmo Geeraerts for the final assignment of an introductory class on python. + +The repository contains: +- The `README.md` file which describes the repository and illustrates how to use the code as a module and by running the script; +- The `tutorial.md` and `tutorial.ipynb` files which show how to actually use the code and the different functionalities; +- The `Example_English.xlsx` and `Example_Dutch.xlsx` files you can use during the tutorial when you import the code. You could also write and use your own file. How to write your own file using the script is also explained in the tutorial; +- The `vendor_data.py` file, i.e. the actual python script that can be run or imported as a module. + +## Installation and usage + +### As a module +Clone this repository with the following git command in the console (or download the ZIP file via GitHub): + +```sh +git clone https://github.com/ElmoGeeraerts/intro_machine_learning_using_python.git +``` + +You can import the script as a module by adding the repository to your path in a Python script or interactive notebook and then calling `import`. + +```python +import sys +sys.path.append('/path/to/intro_machine_learning_using_python') +import vendor_data as vd +``` + +Check out `tutorial.md` to see an example of the different functionalities of the script! + +### Running the script +You can also run the script directly with the following code in a console: + +```sh +python vendor_data.py -a/--add +``` +to add a vendor. You will be prompted with some questions to input the data. Or you can run: + +```sh +python vendor_data.py -m/--modify +``` +to modify a vendor. Again you will be prompted with some questions to input the data. + +Or in Jupyter notebook with: + +```python +%run vendor_data.py -a/--add +``` +OR +```python +%run vendor_data.py -m/--modify +``` + +For more information you can run the command below, or check in the notebook tuturial.ipynb in this repository under "Running `vendor_data.py`". + +```sh +python vendor_data.py --help +``` + +## What this script CAN do + +This script is supposed to help translation project managers with keeping a clear overview of the vendors working on the a particular project. +The script allows the project manager to: +1. Easily create an excel file with the project name and the source language as filename; +2. Write the following data to the excel file: the target language and the translator's name, e-mail, word rate, preferred CAT tool and the status of the translator; +3. Modify the following data for the vendors already in the excel file: e-mail, word rate, preferred CAT tool and status. +The main advantage of this script is that it limits the posibilities of CAT tools and statuses and that it validates e-mail and word rate (betw. 0.01 and 0.15). This prevents the excel file from becoming messy when different people are working on the project. + +## What this script CANNOT do +There are limits to this script that - with more practice, knowledge and time - might be resolved in the form of new functionalities. +With this script you CANNOT: +- Look up vendors or information for vendors in the excel file +- Read other excel files and instantiating the class VendorData based on the information in those excel files +- Check if a vendor already exists in the excel file when the method ToExcel() is called multiple times +- Delete vendors from the file +- Modify multiple keys in a dictionary if the script is imported as a module. diff --git a/example.json b/example.json deleted file mode 100644 index e69de29..0000000 diff --git a/script.py b/script.py deleted file mode 100644 index ac747da..0000000 --- a/script.py +++ /dev/null @@ -1,13 +0,0 @@ -#! /usr/bin/python - -"""Brief description of the script. -""" -import argparse - -# write here your function and class definitions -# don't forget to properly document them with docstrings!! - -if __name__ == "__main": - # write here what happens if the code is run instead of imported - # include argparse code! - \ No newline at end of file diff --git a/tutorial.ipynb b/tutorial.ipynb new file mode 100644 index 0000000..a04913c --- /dev/null +++ b/tutorial.ipynb @@ -0,0 +1,1766 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "b251afbe", + "metadata": {}, + "source": [ + "# Tutorial: how to use `vendor_data.py`\n", + "\n", + "## Using `vendor_data.py` as a module\n", + "\n", + "This interactive notebook shows how to use the class and the different functions in the script `vendor_data.py`.\n", + "\n", + "To use the script in this code, we can import the script as a module or run it directly.\n", + "We'll begin with importing the code as module:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "b3611132", + "metadata": {}, + "outputs": [], + "source": [ + "import sys\n", + "sys.path.append ('..\\Final_Assignment1') #this is the relative path to where the script lives. If the file where the script lives has a different name than 'Final_Assignment1' you should change this.\n", + "import vendor_data as vd # 'as vd' is not necessary but makes it shorter." + ] + }, + { + "cell_type": "markdown", + "id": "b9df49cf", + "metadata": {}, + "source": [ + "### Instantiating an instance of `VendorData`\n", + "We'll start with instantiating some instances of the class VendorData.\n", + "The class takes four positional arguments: `ProjectName`, `SourceLang`, `TargetLang` and `VendorName`.\n", + "It also takes four optional arguments: `VendorMail`, `WordRate`, `CatTool`, and `Preferred`." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "4ab17746", + "metadata": {}, + "outputs": [], + "source": [ + "VendorNL = vd.VendorData(\"Tutorial\", \"English\", \"Dutch\", \"Elmo Geeraerts\") #An instance with only the positional arguments provided\n", + "VendorFR = vd.VendorData(\"Tutorial\", \"English\", \"French\", \"Jean Lefèvre\", \"j.lefevre@hotmail.com\", 0.10, \"Trados Studio\", True) #An instance with all the arguments provided\n", + "VendorES = vd.VendorData(\"Tutorial\", \"English\", \"Spanish\", \"Emilio De La Banda\", WordRate = 0.09, Preferred = False) #An instance with some of the optional arguments" + ] + }, + { + "cell_type": "markdown", + "id": "4c856f67", + "metadata": {}, + "source": [ + "We can check the values of the arguments for the three vendors as follows:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "c6675ef0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Elmo Geeraerts'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorNL.VendorName" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "23b52971", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'j.lefevre@hotmail.com'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorFR.VendorMail" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "69659b86", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.09" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorES.WordRate" + ] + }, + { + "cell_type": "raw", + "id": "c737f228", + "metadata": {}, + "source": [ + "Some arguments have default values or empty values. When we check the e-mail for VendorNL, for which we didn't provide one, we'll see that it returns an empty string:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "cb2ca64c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "''" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorNL.VendorMail" + ] + }, + { + "cell_type": "markdown", + "id": "5254d93d", + "metadata": {}, + "source": [ + "When we check the CAT tool for the Spanish vendor, we'll get \"XTM\". We did not provide any argument, but in the class it is set to default since that is the main CAT tool used in the particular agency. This can be changed in the actual code." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "c7180a19", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'XTM'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorES.CatTool" + ] + }, + { + "cell_type": "markdown", + "id": "fc86e138", + "metadata": {}, + "source": [ + "The value for the argument Preferred can be True, False or None. This has an influence of the vendor's status.\n", + "If Preferred is True, the vendor gets the status Preferred. If it is False, the vendor gets the status Back-up. If it is None, the vendor gets the status Potential." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "e26d1539", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorFR.Preferred" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "935c0a38", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Preferred'" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorFR.Status" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "9ebc7f07", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorES.Preferred" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "1158b1de", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Back-up'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorES.Status" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "ab5e5f54", + "metadata": {}, + "outputs": [], + "source": [ + "VendorNL.Preferred #Will not return anything since value is None" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "50cd8967", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Potential'" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorNL.Status" + ] + }, + { + "cell_type": "markdown", + "id": "47936f2c", + "metadata": {}, + "source": [ + "### Methods\n", + "The class also contains a couple of methods:\n", + "- `SetVendorMail` to set an e-mail address for a specific vendor\n", + "- `SetWordRate` to add a word rate in EUR/word for a specific vendor\n", + "- `ChangeTool` to change the preferred CAT tool\n", + "- `SetStatus` to change the vendor's status\n", + "- `ToExcel` to write the data to an excel file\n", + "- `ReadExcel` to print the data in the excel file to a dictionary, if the excel file exists\n", + "- `ModExcel` to modify certain values for a vendor in the excel file, if the excel file exists\n", + "\n", + "We did not provide an e-mail for the Spanish vendor so we'll start with that:" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "90cb5c10", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'e.dlbanda@outlook.com'" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorES.SetVendorMail(\"e.dlbanda@outlook.com\")\n", + "VendorES.VendorMail" + ] + }, + { + "cell_type": "markdown", + "id": "f9d73186", + "metadata": {}, + "source": [ + "We did not set a word rate for the Dutch vendor, so now we can add one:" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "730b35ca", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.08" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorNL.SetWordRate(0.08)\n", + "VendorNL.WordRate" + ] + }, + { + "cell_type": "markdown", + "id": "006d6aa9", + "metadata": {}, + "source": [ + "Say, we did not yet know which CAT Tool the Spanish Vendor was going to use, but now we know that they will use Trados Studio. First it was set to 'XTM', we can change this as follows:" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "391e7c5d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Trados Studio'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorES.ChangeTool(\"Trados Studio\")\n", + "VendorES.CatTool" + ] + }, + { + "cell_type": "markdown", + "id": "574ef338", + "metadata": {}, + "source": [ + "Because we set the value for preferred to True for the French vendor, they got the status \"Preferred\". If for some reason this changes, we can change the status easily, by changing the value for Preferred to False or None:" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "96819356", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorFR.SetStatus(False)\n", + "VendorFR.Preferred" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "e8335217", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Back-up'" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorFR.Status" + ] + }, + { + "cell_type": "markdown", + "id": "0bf8e1d0", + "metadata": {}, + "source": [ + "We can now write the data for the vendors to an excel file. Since every vendor has the same value for the argument `ProjectName` and `SourceLang`, they will be written to the same excel file.\n", + "
\n", + "If you run `.toExcel()` multiple times on the same vendor, it will generate multiple entries!\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "aeafcb32", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The file Tutorial_English.xlsx is correctly created and the vendor Elmo Geeraerts was added.\n", + "The vendor Jean Lefèvre was added to Tutorial_English.xlsx.\n", + "The vendor Emilio De La Banda was added to Tutorial_English.xlsx.\n" + ] + } + ], + "source": [ + "VendorNL.ToExcel()\n", + "VendorFR.ToExcel()\n", + "VendorES.ToExcel()" + ] + }, + { + "cell_type": "markdown", + "id": "8ec6866a", + "metadata": {}, + "source": [ + "An excel file named `Tutorial_English.xlsx` should appear in the same folder where you stored this tutorial notebook.\n", + "We can now read the entire excel file by calling the method ReadExcel for any vendor in the excel file. We'll get the information for every vendor in the excel file, no matter what vendor we pick:" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "37124f32", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Target Language': {0: 'Dutch', 1: 'French', 2: 'Spanish'},\n", + " 'Vendor': {0: 'Elmo Geeraerts', 1: 'Jean Lefèvre', 2: 'Emilio De La Banda'},\n", + " 'E-mail': {0: nan, 1: 'j.lefevre@hotmail.com', 2: 'e.dlbanda@outlook.com'},\n", + " 'CAT Tool': {0: 'XTM', 1: 'Trados Studio', 2: 'Trados Studio'},\n", + " 'Word Rate': {0: 0.08, 1: 0.1, 2: 0.09},\n", + " 'Status': {0: 'Potential', 1: 'Back-up', 2: 'Back-up'}}" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorNL.ReadExcel()" + ] + }, + { + "cell_type": "markdown", + "id": "ac3269a9", + "metadata": {}, + "source": [ + "If we create another vendor that works on a different project or translates from another source language and call the same method without writing the data to an excel file first, we'll get an error message saying that a file for the project in the given source language does not exist." + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "10dc02d2", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "There is no file for Tutorial in German", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\1804978508.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mVendorBG\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Tutorial\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"German\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Bulgarian\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Bulgarian Jacob\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mVendorBG\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mReadExcel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mReadExcel\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 255\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mVendorDict\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 256\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 257\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34mf\"There is no file for {self.ProjectName} in {self.SourceLang}\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 258\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 259\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mModExcel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mKey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mNewValue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: There is no file for Tutorial in German" + ] + } + ], + "source": [ + "VendorBG = vd.VendorData(\"Tutorial\", \"German\", \"Bulgarian\", \"Bulgarian Jacob\")\n", + "VendorBG.ReadExcel()" + ] + }, + { + "cell_type": "markdown", + "id": "e0592b3d", + "metadata": {}, + "source": [ + "We can also modify the excel file by running the `ModExcel` method.\n", + "
\n", + "You can only modify one value for one key at a time.\n", + "
\n", + "\n", + "This method takes 2 arguments:\n", + "1. The `Key` which represents the arguments you can change the values for. You can check the modifiable keys by running vd.VendorData.Keys\n", + "3. The `NewValue`, the new value for the index in a key.\n", + "\n", + "First we'll run `vd.VendorData.Keys` to see the modifiable keys:" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "17292d31", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['E-mail', 'CAT Tool', 'Word Rate', 'Status']" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vd.VendorData.Keys" + ] + }, + { + "cell_type": "markdown", + "id": "52d39227", + "metadata": {}, + "source": [ + "Now we'll again read the excel file for the project \"Tutorial\" with source language \"English\". Again, it does not matter which vendor you do this for:" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "abf2dc40", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Target Language': {0: 'Dutch', 1: 'French', 2: 'Spanish'},\n", + " 'Vendor': {0: 'Elmo Geeraerts', 1: 'Jean Lefèvre', 2: 'Emilio De La Banda'},\n", + " 'E-mail': {0: nan, 1: 'j.lefevre@hotmail.com', 2: 'e.dlbanda@outlook.com'},\n", + " 'CAT Tool': {0: 'XTM', 1: 'Trados Studio', 2: 'Trados Studio'},\n", + " 'Word Rate': {0: 0.08, 1: 0.1, 2: 0.09},\n", + " 'Status': {0: 'Potential', 1: 'Back-up', 2: 'Back-up'}}" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorNL.ReadExcel()" + ] + }, + { + "cell_type": "markdown", + "id": "1ecca948", + "metadata": {}, + "source": [ + "Now we can choose for which index in which key we want to change the value for. We can for example change the CAT Tool the Spanish vendor will use like this:" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "52e91ff2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The vendor was correctly modified.\n" + ] + } + ], + "source": [ + "VendorES.ModExcel(\"CAT Tool\", \"MemoQ\")" + ] + }, + { + "cell_type": "markdown", + "id": "cfec5fae", + "metadata": {}, + "source": [ + "If you check this by running `.CatTool`, the value will be changed." + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "f4e539d4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'MemoQ'" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorES.CatTool" + ] + }, + { + "cell_type": "markdown", + "id": "6539e2b4", + "metadata": {}, + "source": [ + "The script knows which vendor you want to change the value for because of the instance you call the method for. If you want to change information for the Dutch vendor, you should call the method for that vendor" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "055d1046", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The vendor was correctly modified.\n" + ] + } + ], + "source": [ + "VendorNL.ModExcel(\"Status\", \"Preferred\")" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "7c7d3af1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Preferred'" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorNL.Status" + ] + }, + { + "cell_type": "markdown", + "id": "83fd2f6e", + "metadata": {}, + "source": [ + "If we read the excel (`ReadExcel()`), we'll see that the values for the correct vendors are changed. Here it does not matter for which vendor we call the method:" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "256e78dd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Target Language': {0: 'Dutch', 1: 'French', 2: 'Spanish'},\n", + " 'Vendor': {0: 'Elmo Geeraerts', 1: 'Jean Lefèvre', 2: 'Emilio De La Banda'},\n", + " 'E-mail': {0: nan, 1: 'j.lefevre@hotmail.com', 2: 'e.dlbanda@outlook.com'},\n", + " 'CAT Tool': {0: 'XTM', 1: 'Trados Studio', 2: 'MemoQ'},\n", + " 'Word Rate': {0: 0.08, 1: 0.1, 2: 0.09},\n", + " 'Status': {0: 'Preferred', 1: 'Back-up', 2: 'Back-up'}}" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorNL.ReadExcel()" + ] + }, + { + "cell_type": "markdown", + "id": "c6e675e6", + "metadata": {}, + "source": [ + "### Validation\n", + "\n", + "This script also uses some functions to validate the user input anytime when user interaction is necessary.\n", + "That is:\n", + "- upon instantiating an instance of VendorData\n", + "- upon changing a value using one of the functions illustrated above\n", + "- upon modifying the excel file\n", + "\n", + "The examples below illustrate what happens when wrong user input is provided. We'll start with the simple TypeErrors.\n", + "TypeErrors are raised when:\n", + "- `ProjectName` is not a string\n", + "- `SourceLang` is not a string\n", + "- `TargLang` is not a string\n", + "- `VendorName` is not a string\n", + "- `VendorMail` is not a string\n", + "- `WordRate` is not a float\n", + "- `CatTool` is not a string\n", + "- `Preferred` is not None or one of the Boolean operators, True or False" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "854ef143", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "ProjectName should be a string!", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\3042631035.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0.1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"English\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"German\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Thomas Zwiebel\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred)\u001b[0m\n\u001b[0;32m 113\u001b[0m \"\"\"\n\u001b[0;32m 114\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mProjectName\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 115\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"ProjectName should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 116\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mSourceLang\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 117\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"SourceLang should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: ProjectName should be a string!" + ] + } + ], + "source": [ + "VendorDE = vd.VendorData(0.1, \"English\", \"German\", \"Thomas Zwiebel\")" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "cd524417", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "SourceLang should be a string!", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\2835384243.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Tutorial\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"German\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Thomas Zwiebel\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred)\u001b[0m\n\u001b[0;32m 115\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"ProjectName should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 116\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mSourceLang\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 117\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"SourceLang should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 118\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mTargLang\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 119\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"TargLang should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: SourceLang should be a string!" + ] + } + ], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", 1, \"German\", \"Thomas Zwiebel\")" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "d6497db2", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "TargLang should be a string!", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\2057797999.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Tutorial\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"English\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Thomas Zwiebel\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred)\u001b[0m\n\u001b[0;32m 117\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"SourceLang should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 118\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mTargLang\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 119\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"TargLang should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 120\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorName\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 121\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"VendorName should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: TargLang should be a string!" + ] + } + ], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", True, \"Thomas Zwiebel\")" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "8b01bfed", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "VendorName should be a string!", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\1683973233.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Tutorial\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"English\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"German\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred)\u001b[0m\n\u001b[0;32m 119\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"TargLang should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 120\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorName\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 121\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"VendorName should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 122\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mVendorMail\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate e-mail address if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 123\u001b[0m \u001b[0mCheckVendorMail\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorMail\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: VendorName should be a string!" + ] + } + ], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", None)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "20b5cc03", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "VendorMail should be a string!", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\2269134755.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Tutorial\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"English\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"German\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Thomas Zwiebel\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m3\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred)\u001b[0m\n\u001b[0;32m 121\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"VendorName should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 122\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mVendorMail\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate e-mail address if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 123\u001b[1;33m \u001b[0mCheckVendorMail\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorMail\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 124\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate word rate if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 125\u001b[0m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mWordRate\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mCheckVendorMail\u001b[1;34m(VendorMail)\u001b[0m\n\u001b[0;32m 44\u001b[0m \u001b[0mregex_mail\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$\"\u001b[0m \u001b[1;31m#regex used to validate email\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 45\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorMail\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 46\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m\"VendorMail should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 47\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mre\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msearch\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mregex_mail\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mVendorMail\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 48\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Please insert a valid email address.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: VendorMail should be a string!" + ] + } + ], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", 3)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "7c32d39f", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "WordRate should be a float!", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\2028391605.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Tutorial\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"English\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"German\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Thomas Zwiebel\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"0.15\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred)\u001b[0m\n\u001b[0;32m 123\u001b[0m \u001b[0mCheckVendorMail\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorMail\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 124\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate word rate if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 125\u001b[1;33m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mWordRate\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 126\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mCatTool\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate CAT Tool if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 127\u001b[0m \u001b[0mCheckCatTool\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mCatTool\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mCheckWordRate\u001b[1;34m(WordRate)\u001b[0m\n\u001b[0;32m 60\u001b[0m \"\"\"\n\u001b[0;32m 61\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mWordRate\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mfloat\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 62\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"WordRate should be a float!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 63\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m0.15\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 64\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"This vendor is too expensive, pick another one.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: WordRate should be a float!" + ] + } + ], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = \"0.15\")" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "32715f64", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "Preferred should either be True, False or None.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\1300272076.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Tutorial\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"English\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"German\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Thomas Zwiebel\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mPreferred\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"Test\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred)\u001b[0m\n\u001b[0;32m 128\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mPreferred\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 129\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mPreferred\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mbool\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 130\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Preferred should either be True, False or None.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 131\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mPreferred\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#if Preferred is set to True, status will be preferred, if set to False, back-up and if neither \"Potential\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 132\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mPreferred\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: Preferred should either be True, False or None." + ] + } + ], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", Preferred = \"Test\")" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "8b74ce10", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "CatTool should be a string!", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\2908856665.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Tutorial\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"English\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"German\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Thomas Zwiebel\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mCatTool\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred)\u001b[0m\n\u001b[0;32m 125\u001b[0m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mWordRate\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 126\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mCatTool\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate CAT Tool if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 127\u001b[1;33m \u001b[0mCheckCatTool\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mCatTool\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 128\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mPreferred\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 129\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mPreferred\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mbool\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mCheckCatTool\u001b[1;34m(CatTool)\u001b[0m\n\u001b[0;32m 78\u001b[0m \"\"\"\n\u001b[0;32m 79\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mCatTool\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 80\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"CatTool should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 81\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mCatTool\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mVendorData\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mCatTools\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 82\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"This CAT tool is not valid. Run 'VendorData.CatTools' to check options.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: CatTool should be a string!" + ] + } + ], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", CatTool = True)" + ] + }, + { + "cell_type": "markdown", + "id": "e7658f35", + "metadata": {}, + "source": [ + "There are also some functions that ensure that:\n", + "- `VendorMail` is a valid e-mail address by checking it against a regex string;\n", + "- `WordRate` is not 0.00 or more than 0.15 and not negative;\n", + "- `CatTool` is one of the following: XTM, Trados Studio, MemoQ or Memsource." + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "14d9561a", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Please insert a valid email address.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\2329585938.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Tutorial\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"English\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"German\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Thomas Zwiebel\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mVendorMail\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"thomas.zw\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred)\u001b[0m\n\u001b[0;32m 121\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"VendorName should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 122\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mVendorMail\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate e-mail address if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 123\u001b[1;33m \u001b[0mCheckVendorMail\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorMail\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 124\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate word rate if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 125\u001b[0m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mWordRate\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mCheckVendorMail\u001b[1;34m(VendorMail)\u001b[0m\n\u001b[0;32m 46\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m\"VendorMail should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 47\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mre\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msearch\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mregex_mail\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mVendorMail\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 48\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Please insert a valid email address.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 49\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mWordRate\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 50\u001b[0m \"\"\"Function to validate the word rate\n", + "\u001b[1;31mValueError\u001b[0m: Please insert a valid email address." + ] + } + ], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", VendorMail = \"thomas.zw\")" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "689a0133", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "This vendor is too expensive, pick another one.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\389829205.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Tutorial\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"English\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"German\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Thomas Zwiebel\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0.19\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred)\u001b[0m\n\u001b[0;32m 123\u001b[0m \u001b[0mCheckVendorMail\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorMail\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 124\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate word rate if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 125\u001b[1;33m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mWordRate\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 126\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mCatTool\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate CAT Tool if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 127\u001b[0m \u001b[0mCheckCatTool\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mCatTool\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mCheckWordRate\u001b[1;34m(WordRate)\u001b[0m\n\u001b[0;32m 62\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"WordRate should be a float!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 63\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m0.15\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 64\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"This vendor is too expensive, pick another one.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 65\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m0.00\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 66\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Word rate cannot be 0.00.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: This vendor is too expensive, pick another one." + ] + } + ], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = 0.19)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "a5a88daf", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Word rate cannot be 0.00.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\2186391260.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Tutorial\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"English\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"German\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Thomas Zwiebel\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0.00\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred)\u001b[0m\n\u001b[0;32m 123\u001b[0m \u001b[0mCheckVendorMail\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorMail\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 124\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate word rate if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 125\u001b[1;33m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mWordRate\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 126\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mCatTool\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate CAT Tool if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 127\u001b[0m \u001b[0mCheckCatTool\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mCatTool\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mCheckWordRate\u001b[1;34m(WordRate)\u001b[0m\n\u001b[0;32m 64\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"This vendor is too expensive, pick another one.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 65\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m0.00\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 66\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Word rate cannot be 0.00.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 67\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m<\u001b[0m \u001b[1;36m0.00\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 68\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Word rate cannot be negative.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: Word rate cannot be 0.00." + ] + } + ], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = 0.00)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "87ad7fb4", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Word rate cannot be negative.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\251048835.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Tutorial\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"English\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"German\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Thomas Zwiebel\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m-\u001b[0m\u001b[1;36m0.04\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred)\u001b[0m\n\u001b[0;32m 123\u001b[0m \u001b[0mCheckVendorMail\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorMail\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 124\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate word rate if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 125\u001b[1;33m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mWordRate\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 126\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mCatTool\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate CAT Tool if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 127\u001b[0m \u001b[0mCheckCatTool\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mCatTool\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mCheckWordRate\u001b[1;34m(WordRate)\u001b[0m\n\u001b[0;32m 66\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Word rate cannot be 0.00.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 67\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m<\u001b[0m \u001b[1;36m0.00\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 68\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Word rate cannot be negative.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 69\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mCheckCatTool\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mCatTool\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 70\u001b[0m \"\"\"Function to validate the chosen CAT Tool\n", + "\u001b[1;31mValueError\u001b[0m: Word rate cannot be negative." + ] + } + ], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = -0.04)" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "a6506797", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "This CAT tool is not valid. Run 'VendorData.CatTools' to check options.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\153109120.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorData\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Tutorial\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"English\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"German\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Thomas Zwiebel\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mCatTool\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"SDL Trados Studio\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred)\u001b[0m\n\u001b[0;32m 125\u001b[0m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mWordRate\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 126\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mCatTool\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate CAT Tool if one is provided\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 127\u001b[1;33m \u001b[0mCheckCatTool\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mCatTool\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 128\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mPreferred\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 129\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mPreferred\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mbool\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mCheckCatTool\u001b[1;34m(CatTool)\u001b[0m\n\u001b[0;32m 80\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"CatTool should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 81\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mCatTool\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mVendorData\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mCatTools\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 82\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"This CAT tool is not valid. Run 'VendorData.CatTools' to check options.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 83\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 84\u001b[0m \u001b[1;32mclass\u001b[0m \u001b[0mVendorData\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: This CAT tool is not valid. Run 'VendorData.CatTools' to check options." + ] + } + ], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", CatTool = \"SDL Trados Studio\")" + ] + }, + { + "cell_type": "markdown", + "id": "35f4617f", + "metadata": {}, + "source": [ + "As already mentioned, this kind of validation is done anytime user input is required, not only upon instantiating.\n", + "More precisely, validation is done when:\n", + "- One of the methods to set a value is run\n", + "- The excel is modified using the `ModExcel` method" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "adb90ded", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\") #for illustration we instantiate a new instance of VendorData" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "0e5da23b", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Please insert a valid email address.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\4282007076.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSetVendorMail\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"thomas.zw@\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mSetVendorMail\u001b[1;34m(self, NewMail)\u001b[0m\n\u001b[0;32m 157\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mthe\u001b[0m \u001b[0maddress\u001b[0m \u001b[0mprovided\u001b[0m \u001b[0mdoes\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mconform\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0mthe\u001b[0m \u001b[0mregex\u001b[0m \u001b[0mstring\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m`\u001b[0m\u001b[0mregex_mail\u001b[0m\u001b[0;31m`\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m \u001b[0mValueError\u001b[0m \u001b[1;32mis\u001b[0m \u001b[0mraised\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 158\u001b[0m \"\"\"\n\u001b[1;32m--> 159\u001b[1;33m \u001b[0mCheckVendorMail\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNewMail\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#validate e-mail address\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 160\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorMail\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mNewMail\u001b[0m \u001b[1;31m#value of VendorMail is changed\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 161\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mCheckVendorMail\u001b[1;34m(VendorMail)\u001b[0m\n\u001b[0;32m 46\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m\"VendorMail should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 47\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mre\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msearch\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mregex_mail\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mVendorMail\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 48\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Please insert a valid email address.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 49\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mWordRate\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 50\u001b[0m \"\"\"Function to validate the word rate\n", + "\u001b[1;31mValueError\u001b[0m: Please insert a valid email address." + ] + } + ], + "source": [ + "VendorDE.SetVendorMail(\"thomas.zw@\")" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "e2f58285", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "This vendor is too expensive, pick another one.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\1677043638.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSetWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0.18\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mSetWordRate\u001b[1;34m(self, NewRate)\u001b[0m\n\u001b[0;32m 173\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mthe\u001b[0m \u001b[0margument\u001b[0m \u001b[0mprovided\u001b[0m \u001b[0mshould\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mbe\u001b[0m \u001b[0mnegative\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 174\u001b[0m \"\"\"\n\u001b[1;32m--> 175\u001b[1;33m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNewRate\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#validate new word rate\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 176\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mWordRate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mNewRate\u001b[0m \u001b[1;31m#value of WordRate is changed\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 177\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mCheckWordRate\u001b[1;34m(WordRate)\u001b[0m\n\u001b[0;32m 62\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"WordRate should be a float!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 63\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m0.15\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 64\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"This vendor is too expensive, pick another one.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 65\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m0.00\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 66\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Word rate cannot be 0.00.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: This vendor is too expensive, pick another one." + ] + } + ], + "source": [ + "VendorDE.SetWordRate(0.18)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "e03407b2", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Word rate cannot be 0.00.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\2070555766.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSetWordRate\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m0.00\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mSetWordRate\u001b[1;34m(self, NewRate)\u001b[0m\n\u001b[0;32m 173\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mthe\u001b[0m \u001b[0margument\u001b[0m \u001b[0mprovided\u001b[0m \u001b[0mshould\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mbe\u001b[0m \u001b[0mnegative\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 174\u001b[0m \"\"\"\n\u001b[1;32m--> 175\u001b[1;33m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNewRate\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#validate new word rate\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 176\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mWordRate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mNewRate\u001b[0m \u001b[1;31m#value of WordRate is changed\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 177\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mCheckWordRate\u001b[1;34m(WordRate)\u001b[0m\n\u001b[0;32m 64\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"This vendor is too expensive, pick another one.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 65\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m0.00\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 66\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Word rate cannot be 0.00.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 67\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m<\u001b[0m \u001b[1;36m0.00\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 68\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Word rate cannot be negative.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: Word rate cannot be 0.00." + ] + } + ], + "source": [ + "VendorDE.SetWordRate (0.00)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "63dc4cab", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Word rate cannot be negative.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\1645063171.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSetWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m0.04\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mSetWordRate\u001b[1;34m(self, NewRate)\u001b[0m\n\u001b[0;32m 173\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mthe\u001b[0m \u001b[0margument\u001b[0m \u001b[0mprovided\u001b[0m \u001b[0mshould\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mbe\u001b[0m \u001b[0mnegative\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 174\u001b[0m \"\"\"\n\u001b[1;32m--> 175\u001b[1;33m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNewRate\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#validate new word rate\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 176\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mWordRate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mNewRate\u001b[0m \u001b[1;31m#value of WordRate is changed\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 177\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mCheckWordRate\u001b[1;34m(WordRate)\u001b[0m\n\u001b[0;32m 66\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Word rate cannot be 0.00.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 67\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mWordRate\u001b[0m \u001b[1;33m<\u001b[0m \u001b[1;36m0.00\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 68\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Word rate cannot be negative.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 69\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mCheckCatTool\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mCatTool\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 70\u001b[0m \"\"\"Function to validate the chosen CAT Tool\n", + "\u001b[1;31mValueError\u001b[0m: Word rate cannot be negative." + ] + } + ], + "source": [ + "VendorDE.SetWordRate(-0.04)" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "4f984703", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "This CAT tool is not valid. Run 'VendorData.CatTools' to check options.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\3483989379.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mChangeTool\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"SDL Trados Studio\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mChangeTool\u001b[1;34m(self, NewTool)\u001b[0m\n\u001b[0;32m 187\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mthe\u001b[0m \u001b[0margument\u001b[0m \u001b[0mprovided\u001b[0m \u001b[0mshould\u001b[0m \u001b[0mbe\u001b[0m \u001b[0mone\u001b[0m \u001b[0mof\u001b[0m \u001b[0mthe\u001b[0m \u001b[0mfour\u001b[0m \u001b[0mCAT\u001b[0m \u001b[0mTools\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mthe\u001b[0m \u001b[0mlist\u001b[0m \u001b[0mVendorData\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mCatTools\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 188\u001b[0m \"\"\"\n\u001b[1;32m--> 189\u001b[1;33m \u001b[0mCheckCatTool\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNewTool\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#validate new CAT Tool\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 190\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mCatTool\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mNewTool\u001b[0m \u001b[1;31m#value of CatTool is changed\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 191\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mCheckCatTool\u001b[1;34m(CatTool)\u001b[0m\n\u001b[0;32m 80\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"CatTool should be a string!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 81\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mCatTool\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mVendorData\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mCatTools\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 82\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"This CAT tool is not valid. Run 'VendorData.CatTools' to check options.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 83\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 84\u001b[0m \u001b[1;32mclass\u001b[0m \u001b[0mVendorData\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: This CAT tool is not valid. Run 'VendorData.CatTools' to check options." + ] + } + ], + "source": [ + "VendorDE.ChangeTool(\"SDL Trados Studio\")" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "2c570d8f", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "Preferred should either be True, False or None.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\3389852500.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSetStatus\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"None\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mSetStatus\u001b[1;34m(self, PrefVend)\u001b[0m\n\u001b[0;32m 198\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mPrefVend\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 199\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mPrefVend\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mbool\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 200\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Preferred should either be True, False or None.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 201\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mPrefVend\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 202\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mPrefVend\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: Preferred should either be True, False or None." + ] + } + ], + "source": [ + "VendorDE.SetStatus(\"None\")" + ] + }, + { + "cell_type": "markdown", + "id": "0917609e", + "metadata": {}, + "source": [ + "To illustrate that validation is done when running the `ModExcel` method, we first have to write the data to the excel file:\n", + "
\n", + "If you run `.toExcel()` multiple times on the same vendor, it will generate multiple entries!\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "b9e3cd49", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The vendor Thomas Zwiebel was added to Tutorial_English.xlsx.\n" + ] + } + ], + "source": [ + "VendorDE.ToExcel()" + ] + }, + { + "cell_type": "markdown", + "id": "288db7ca", + "metadata": {}, + "source": [ + "Now we can modify the German vendor and the input will be validated:" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "f9d200e7", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "ModExcel() takes 3 positional arguments but 4 were given", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\1589300048.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mModExcel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"E-mail\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m3\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"thomaszw@\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m: ModExcel() takes 3 positional arguments but 4 were given" + ] + } + ], + "source": [ + "VendorDE.ModExcel(\"E-mail\", 3, \"thomaszw@\")" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "3db36ec1", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "ModExcel() takes 3 positional arguments but 4 were given", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\3469975144.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mModExcel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"CAT Tool\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m3\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Trados Studio 2019\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m: ModExcel() takes 3 positional arguments but 4 were given" + ] + } + ], + "source": [ + "VendorDE.ModExcel(\"CAT Tool\", 3, \"Trados Studio 2019\")" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "43492fbd", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "ModExcel() takes 3 positional arguments but 4 were given", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\2651721014.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mModExcel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Word Rate\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m3\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0.18\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m: ModExcel() takes 3 positional arguments but 4 were given" + ] + } + ], + "source": [ + "VendorDE.ModExcel(\"Word Rate\", 3, 0.18)" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "fcc7bf99", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "ModExcel() takes 3 positional arguments but 4 were given", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\3428613633.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mModExcel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Status\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m3\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Busy\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m: ModExcel() takes 3 positional arguments but 4 were given" + ] + } + ], + "source": [ + "VendorDE.ModExcel(\"Status\", 3, \"Busy\")" + ] + }, + { + "cell_type": "markdown", + "id": "120be557", + "metadata": {}, + "source": [ + "For the `ModExcel` method there's an additional validation, namely the validation of keys in order to limit the keys for which you can modify the values. Modifiable keys can be checked by running `vd.VendorData.Keys`\n", + "
\n", + "You can only modify one value for one key.\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "id": "405573dd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['E-mail', 'CAT Tool', 'Word Rate', 'Status']" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vd.VendorData.Keys" + ] + }, + { + "cell_type": "markdown", + "id": "94af9ebd", + "metadata": {}, + "source": [ + "If you try to modify any other key you will get an error message:" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "id": "e37f7571", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Invalid key, run 'VendorData.Keys' to see options.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\1799726010.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mModExcel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Vendor\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"John Doe\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mModExcel\u001b[1;34m(self, Key, NewValue)\u001b[0m\n\u001b[0;32m 273\u001b[0m \u001b[0mExcelRecordsDf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_excel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mFileName\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 274\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mKeys\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 275\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid key, run 'VendorData.Keys' to see options.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 276\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 277\u001b[0m \u001b[0mVendorRow\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mExcelRecordsDf\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mExcelRecordsDf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendor\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorName\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: Invalid key, run 'VendorData.Keys' to see options." + ] + } + ], + "source": [ + "VendorDE.ModExcel(\"Vendor\", \"John Doe\")" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "4a988964", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Invalid key, run 'VendorData.Keys' to see options.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19840\\3386871677.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mVendorDE\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mModExcel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Target Language\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Croatian\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mModExcel\u001b[1;34m(self, Key, NewValue)\u001b[0m\n\u001b[0;32m 273\u001b[0m \u001b[0mExcelRecordsDf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_excel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mFileName\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 274\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mKeys\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 275\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid key, run 'VendorData.Keys' to see options.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 276\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 277\u001b[0m \u001b[0mVendorRow\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mExcelRecordsDf\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mExcelRecordsDf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendor\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mVendorName\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: Invalid key, run 'VendorData.Keys' to see options." + ] + } + ], + "source": [ + "VendorDE.ModExcel(\"Target Language\", \"Croatian\")" + ] + }, + { + "cell_type": "markdown", + "id": "1d9bf4b9", + "metadata": {}, + "source": [ + "We will now delete the file we generated during this tutorial so that when you go through it again, you can have a fresh start." + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "d046edf6", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "os.remove(\".\\Tutorial_English.xlsx\")" + ] + }, + { + "cell_type": "markdown", + "id": "a1f29b57", + "metadata": {}, + "source": [ + "Now you know the different functionalities of the script vendor__data.py and what triggers which error. Hopefully you can use this script in your daily life as a translation project manager. Have fun!" + ] + }, + { + "cell_type": "markdown", + "id": "03b81e7c", + "metadata": {}, + "source": [ + "## Running `vendor_data.py`\n", + "The script can also be run on its own. The script takes two optional arguments:\n", + "- `-a` or `--add` allows the user to add a new vendor to an excel file (existing or new);\n", + "- `-m` or `--modify` allows the user to modify a vendor in an existing excel file;\n", + "The same validation is done as if you would import this script as a module. TypeErrors do not cause the prompts to stop but instead you get asked the same question again, ValueErrors do break off the code.\n", + "\n", + "We'll begin with writing data to a brand new excel file by providing a new project name and source language, i.e. not Example and not English since an excel file already exists for this project." + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "id": "7c4e5ac4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What is the project name? Example\n", + "What is the source language? Dutch\n", + "What's the vendor's name? John Doe\n", + "Into which language will the vendor translate? English\n", + "What is the vendor's email address? \n", + "What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor. \n", + "In which tool will the vendor be working?* XTM\n", + "* Trados Studio\n", + "* MemoQ\n", + "* Memsource\n", + "\n", + "True or False: Is this vendor a preferred vendor? If neither, leave blank. \n", + "Are you done? yes\n", + "Do you want to add this vendor to the excel file? yes\n", + "The file Example_Dutch.xlsx is correctly created and the vendor John Doe was added.\n" + ] + } + ], + "source": [ + "%run vendor_data.py -a" + ] + }, + { + "cell_type": "markdown", + "id": "4212de85", + "metadata": {}, + "source": [ + "You can also append a new vendor to the existing `Example_English.xlsx` file by providing `Example` as the project name and `English` as the source language. Again, the code does not check if a vendor already exists in the excel file, so you should add a vendor only once.\n", + "\n", + "
\n", + "You can only modify one value for one key.\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "id": "a32de96d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What is the project name? Example\n", + "What is the source language? English\n", + "What's the vendor's name? Thomas Zwiebel\n", + "Into which language will the vendor translate? German\n", + "What is the vendor's email address? th.zwiebel@gmail.com\n", + "What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor. 0.08\n", + "In which tool will the vendor be working?* XTM\n", + "* Trados Studio\n", + "* MemoQ\n", + "* Memsource\n", + "MemoQ\n", + "True or False: Is this vendor a preferred vendor? If neither, leave blank. False\n", + "Are you done? yes\n", + "Do you want to add this vendor to the excel file? yes\n", + "The vendor Thomas Zwiebel was added to Example_English.xlsx.\n" + ] + } + ], + "source": [ + "%run vendor_data.py -a" + ] + }, + { + "cell_type": "markdown", + "id": "61141753", + "metadata": {}, + "source": [ + "Just like when importing the script, it is possible to leave the following data blank:\n", + "- The vendor's email address\n", + "- The vendors word rate\n", + "- The tool in which the vendor will be working\n", + "- Whether or not the vendor is a preferred vendor\n", + "\n", + "We'll append another vendor to the `Example_English` file:" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "id": "5fba8692", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What is the project name? Example\n", + "What is the source language? English\n", + "What's the vendor's name? Joao Felix\n", + "Into which language will the vendor translate? Portuguese\n", + "What is the vendor's email address? \n", + "What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor. \n", + "In which tool will the vendor be working?* XTM\n", + "* Trados Studio\n", + "* MemoQ\n", + "* Memsource\n", + "\n", + "True or False: Is this vendor a preferred vendor? If neither, leave blank. \n", + "Are you done? yes\n", + "Do you want to add this vendor to the excel file? yes\n", + "The vendor Joao Felix was added to Example_English.xlsx.\n" + ] + } + ], + "source": [ + "%run vendor_data.py -a" + ] + }, + { + "cell_type": "markdown", + "id": "df0dca70", + "metadata": {}, + "source": [ + "Since we're using pyipinputplus we can already avoid some errors by:\n", + "- using the built in type validation of the package by using `pyip.inputStr` or `pyip.inputFloat`, so that the user is forced to put in a valid data type\n", + "- using the Menu option to limit the choices, for example for the CAT Tools\n", + "In the background the same validation is run as when you import this script as a module. To see which kind of validation is done, please go to `Validation` above.\n", + "\n", + "It is also possible to modify existing vendors. The user has to provide the project name and the source language, and is then further asked some questions regarding the vendor they want to modify:" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "54012864", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What is the name of the project that the vendor you want to modify works on? Example\n", + "What is the source language? English\n", + "These are the vendor's already in the database: \n", + "0: Elmo Geeraerts\n", + "1: Jean De Gaule\n", + "2: Emanuel De la Banda\n", + "3: Thomas Zwiebel\n", + "4: Joao Felix\n", + "Enter the index of the vendor you want to modify: 0\n", + "What is the vendor's e-mail? geeraerts@me.com\n", + "What is the vendor's word rate? Should be between 0.01 and 0.15. If higher, choose another vendor. 0.10\n", + "In which tool will the vendor be working?* XTM\n", + "* Trados Studio\n", + "* MemoQ\n", + "* Memsource\n", + "Trados Studio\n", + "What is the vendor's new status? * Preferred\n", + "* Back-up\n", + "* Potential\n", + "Preferred\n", + "Are you done? yes\n", + "This vendor is modified correctly.\n" + ] + } + ], + "source": [ + "%run vendor_data.py -m" + ] + }, + { + "cell_type": "markdown", + "id": "cce96942", + "metadata": {}, + "source": [ + "The vendor in the excel file should now be modified.\n", + "\n", + "Now you are totally ready to use this script and resolve any issues that might pop up! Hopefully this script makes your life as a translation project manager easier! Have fun!" + ] + }, + { + "cell_type": "markdown", + "id": "594044d3", + "metadata": {}, + "source": [ + "### Docstrings\n", + "The script is completely documented with docstrings in order to ensure that the script is correclty used.\n", + "You can read these docstrings by calling one of the following functions if you have imported the script as a module:\n", + "```python\n", + "help(vd)\n", + "```\n", + "OR\n", + "```python\n", + "?vd\n", + "```\n", + "OR\n", + "```python\n", + "vd.__doc__\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "85e46020", + "metadata": {}, + "source": [ + "You can also read the documentation for the script if you run this code:\n", + "```python\n", + "%run vendor_data.py --help\n", + "```\n", + "OR\n", + "```python\n", + "%run vendor_data.py --h\n", + "```" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/tutorial.md b/tutorial.md index 6add32e..a94fe94 100644 --- a/tutorial.md +++ b/tutorial.md @@ -1,3 +1,1341 @@ -# How to use my script +# Tutorial: how to use `vendor_data.py` -In this notebook you will learn how to use the functions and classes defined in `script.py`. +## Using `vendor_data.py` as a module + +This interactive notebook shows how to use the class and the different functions in the script `vendor_data.py`. + +To use the script in this code, we can import the script as a module or run it directly. +We'll begin with importing the code as module: + + +```python +import sys +sys.path.append ('..\Final_Assignment1') #this is the relative path to where the script lives. If the file where the script lives has a different name than 'Final_Assignment1' you should change this. +import vendor_data as vd # 'as vd' is not necessary but makes it shorter. +``` + +### Instantiating an instance of `VendorData` +We'll start with instantiating some instances of the class VendorData. +The class takes four positional arguments: `ProjectName`, `SourceLang`, `TargetLang` and `VendorName`. +It also takes four optional arguments: `VendorMail`, `WordRate`, `CatTool`, and `Preferred`. + + +```python +VendorNL = vd.VendorData("Tutorial", "English", "Dutch", "Elmo Geeraerts") #An instance with only the positional arguments provided +VendorFR = vd.VendorData("Tutorial", "English", "French", "Jean Lefèvre", "j.lefevre@hotmail.com", 0.10, "Trados Studio", True) #An instance with all the arguments provided +VendorES = vd.VendorData("Tutorial", "English", "Spanish", "Emilio De La Banda", WordRate = 0.09, Preferred = False) #An instance with some of the optional arguments +``` + +We can check the values of the arguments for the three vendors as follows: + + +```python +VendorNL.VendorName +``` + + + + + 'Elmo Geeraerts' + + + + +```python +VendorFR.VendorMail +``` + + + + + 'j.lefevre@hotmail.com' + + + + +```python +VendorES.WordRate +``` + + + + + 0.09 + + +Some arguments have default values or empty values. When we check the e-mail for VendorNL, for which we didn't provide one, we'll see that it returns an empty string: + +```python +VendorNL.VendorMail +``` + + + + + '' + + + +When we check the CAT tool for the Spanish vendor, we'll get "XTM". We did not provide any argument, but in the class it is set to default since that is the main CAT tool used in the particular agency. This can be changed in the actual code. + + +```python +VendorES.CatTool +``` + + + + + 'XTM' + + + +The value for the argument Preferred can be True, False or None. This has an influence of the vendor's status. +If Preferred is True, the vendor gets the status Preferred. If it is False, the vendor gets the status Back-up. If it is None, the vendor gets the status Potential. + + +```python +VendorFR.Preferred +``` + + + + + True + + + + +```python +VendorFR.Status +``` + + + + + 'Preferred' + + + + +```python +VendorES.Preferred +``` + + + + + False + + + + +```python +VendorES.Status +``` + + + + + 'Back-up' + + + + +```python +VendorNL.Preferred #Will not return anything since value is None +``` + + +```python +VendorNL.Status +``` + + + + + 'Potential' + + + +### Methods +The class also contains a couple of methods: +- `SetVendorMail` to set an e-mail address for a specific vendor +- `SetWordRate` to add a word rate in EUR/word for a specific vendor +- `ChangeTool` to change the preferred CAT tool +- `SetStatus` to change the vendor's status +- `ToExcel` to write the data to an excel file +- `ReadExcel` to print the data in the excel file to a dictionary, if the excel file exists +- `ModExcel` to modify certain values for a vendor in the excel file, if the excel file exists + +We did not provide an e-mail for the Spanish vendor so we'll start with that: + + +```python +VendorES.SetVendorMail("e.dlbanda@outlook.com") +VendorES.VendorMail +``` + + + + + 'e.dlbanda@outlook.com' + + + +We did not set a word rate for the Dutch vendor, so now we can add one: + + +```python +VendorNL.SetWordRate(0.08) +VendorNL.WordRate +``` + + + + + 0.08 + + + +Say, we did not yet know which CAT Tool the Spanish Vendor was going to use, but now we know that they will use Trados Studio. First it was set to 'XTM', we can change this as follows: + + +```python +VendorES.ChangeTool("Trados Studio") +VendorES.CatTool +``` + + + + + 'Trados Studio' + + + +Because we set the value for preferred to True for the French vendor, they got the status "Preferred". If for some reason this changes, we can change the status easily, by changing the value for Preferred to False or None: + + +```python +VendorFR.SetStatus(False) +VendorFR.Preferred +``` + + + + + False + + + + +```python +VendorFR.Status +``` + + + + + 'Back-up' + + + +We can now write the data for the vendors to an excel file. Since every vendor has the same value for the argument `ProjectName` and `SourceLang`, they will be written to the same excel file. +
+If you run `.toExcel()` multiple times on the same vendor, it will generate multiple entries! +
+ + +```python +VendorNL.ToExcel() +VendorFR.ToExcel() +VendorES.ToExcel() +``` + + The file Tutorial_English.xlsx is correctly created and the vendor Elmo Geeraerts was added. + The vendor Jean Lefèvre was added to Tutorial_English.xlsx. + The vendor Emilio De La Banda was added to Tutorial_English.xlsx. + + +An excel file named `Tutorial_English.xlsx` should appear in the same folder where you stored this tutorial notebook. +We can now read the entire excel file by calling the method ReadExcel for any vendor in the excel file. We'll get the information for every vendor in the excel file, no matter what vendor we pick: + + +```python +VendorNL.ReadExcel() +``` + + + + + {'Target Language': {0: 'Dutch', 1: 'French', 2: 'Spanish'}, + 'Vendor': {0: 'Elmo Geeraerts', 1: 'Jean Lefèvre', 2: 'Emilio De La Banda'}, + 'E-mail': {0: nan, 1: 'j.lefevre@hotmail.com', 2: 'e.dlbanda@outlook.com'}, + 'CAT Tool': {0: 'XTM', 1: 'Trados Studio', 2: 'Trados Studio'}, + 'Word Rate': {0: 0.08, 1: 0.1, 2: 0.09}, + 'Status': {0: 'Potential', 1: 'Back-up', 2: 'Back-up'}} + + + +If we create another vendor that works on a different project or translates from another source language and call the same method without writing the data to an excel file first, we'll get an error message saying that a file for the project in the given source language does not exist. + + +```python +VendorBG = vd.VendorData("Tutorial", "German", "Bulgarian", "Bulgarian Jacob") +VendorBG.ReadExcel() +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\1804978508.py in + 1 VendorBG = vd.VendorData("Tutorial", "German", "Bulgarian", "Bulgarian Jacob") + ----> 2 VendorBG.ReadExcel() + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ReadExcel(self) + 255 return VendorDict + 256 else: + --> 257 raise ValueError(f"There is no file for {self.ProjectName} in {self.SourceLang}") + 258 + 259 def ModExcel(self, Key, NewValue): + + + ValueError: There is no file for Tutorial in German + + +We can also modify the excel file by running the `ModExcel` method. +
+You can only modify one value for one key at a time. +
+ +This method takes 2 arguments: +1. The `Key` which represents the arguments you can change the values for. You can check the modifiable keys by running vd.VendorData.Keys +3. The `NewValue`, the new value for the index in a key. + +First we'll run `vd.VendorData.Keys` to see the modifiable keys: + + +```python +vd.VendorData.Keys +``` + + + + + ['E-mail', 'CAT Tool', 'Word Rate', 'Status'] + + + +Now we'll again read the excel file for the project "Tutorial" with source language "English". Again, it does not matter which vendor you do this for: + + +```python +VendorNL.ReadExcel() +``` + + + + + {'Target Language': {0: 'Dutch', 1: 'French', 2: 'Spanish'}, + 'Vendor': {0: 'Elmo Geeraerts', 1: 'Jean Lefèvre', 2: 'Emilio De La Banda'}, + 'E-mail': {0: nan, 1: 'j.lefevre@hotmail.com', 2: 'e.dlbanda@outlook.com'}, + 'CAT Tool': {0: 'XTM', 1: 'Trados Studio', 2: 'Trados Studio'}, + 'Word Rate': {0: 0.08, 1: 0.1, 2: 0.09}, + 'Status': {0: 'Potential', 1: 'Back-up', 2: 'Back-up'}} + + + +Now we can choose for which index in which key we want to change the value for. We can for example change the CAT Tool the Spanish vendor will use like this: + + +```python +VendorES.ModExcel("CAT Tool", "MemoQ") +``` + + The vendor was correctly modified. + + +If you check this by running `.CatTool`, the value will be changed. + + +```python +VendorES.CatTool +``` + + + + + 'MemoQ' + + + +The script knows which vendor you want to change the value for because of the instance you call the method for. If you want to change information for the Dutch vendor, you should call the method for that vendor + + +```python +VendorNL.ModExcel("Status", "Preferred") +``` + + The vendor was correctly modified. + + + +```python +VendorNL.Status +``` + + + + + 'Preferred' + + + +If we read the excel (`ReadExcel()`), we'll see that the values for the correct vendors are changed. Here it does not matter for which vendor we call the method: + + +```python +VendorNL.ReadExcel() +``` + + + + + {'Target Language': {0: 'Dutch', 1: 'French', 2: 'Spanish'}, + 'Vendor': {0: 'Elmo Geeraerts', 1: 'Jean Lefèvre', 2: 'Emilio De La Banda'}, + 'E-mail': {0: nan, 1: 'j.lefevre@hotmail.com', 2: 'e.dlbanda@outlook.com'}, + 'CAT Tool': {0: 'XTM', 1: 'Trados Studio', 2: 'MemoQ'}, + 'Word Rate': {0: 0.08, 1: 0.1, 2: 0.09}, + 'Status': {0: 'Preferred', 1: 'Back-up', 2: 'Back-up'}} + + + +### Validation + +This script also uses some functions to validate the user input anytime when user interaction is necessary. +That is: +- upon instantiating an instance of VendorData +- upon changing a value using one of the functions illustrated above +- upon modifying the excel file + +The examples below illustrate what happens when wrong user input is provided. We'll start with the simple TypeErrors. +TypeErrors are raised when: +- `ProjectName` is not a string +- `SourceLang` is not a string +- `TargLang` is not a string +- `VendorName` is not a string +- `VendorMail` is not a string +- `WordRate` is not a float +- `CatTool` is not a string +- `Preferred` is not None or one of the Boolean operators, True or False + + +```python +VendorDE = vd.VendorData(0.1, "English", "German", "Thomas Zwiebel") +``` + + + --------------------------------------------------------------------------- + + TypeError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\3042631035.py in + ----> 1 VendorDE = vd.VendorData(0.1, "English", "German", "Thomas Zwiebel") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + 113 """ + 114 if type(ProjectName) != str: + --> 115 raise TypeError("ProjectName should be a string!") + 116 if type(SourceLang) != str: + 117 raise TypeError("SourceLang should be a string!") + + + TypeError: ProjectName should be a string! + + + +```python +VendorDE = vd.VendorData("Tutorial", 1, "German", "Thomas Zwiebel") +``` + + + --------------------------------------------------------------------------- + + TypeError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\2835384243.py in + ----> 1 VendorDE = vd.VendorData("Tutorial", 1, "German", "Thomas Zwiebel") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + 115 raise TypeError("ProjectName should be a string!") + 116 if type(SourceLang) != str: + --> 117 raise TypeError("SourceLang should be a string!") + 118 if type(TargLang) != str: + 119 raise TypeError("TargLang should be a string!") + + + TypeError: SourceLang should be a string! + + + +```python +VendorDE = vd.VendorData("Tutorial", "English", True, "Thomas Zwiebel") +``` + + + --------------------------------------------------------------------------- + + TypeError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\2057797999.py in + ----> 1 VendorDE = vd.VendorData("Tutorial", "English", True, "Thomas Zwiebel") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + 117 raise TypeError("SourceLang should be a string!") + 118 if type(TargLang) != str: + --> 119 raise TypeError("TargLang should be a string!") + 120 if type(VendorName) !=str: + 121 raise TypeError("VendorName should be a string!") + + + TypeError: TargLang should be a string! + + + +```python +VendorDE = vd.VendorData("Tutorial", "English", "German", None) +``` + + + --------------------------------------------------------------------------- + + TypeError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\1683973233.py in + ----> 1 VendorDE = vd.VendorData("Tutorial", "English", "German", None) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + 119 raise TypeError("TargLang should be a string!") + 120 if type(VendorName) !=str: + --> 121 raise TypeError("VendorName should be a string!") + 122 if VendorMail: #validate e-mail address if one is provided + 123 CheckVendorMail(VendorMail) + + + TypeError: VendorName should be a string! + + + +```python +VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", 3) +``` + + + --------------------------------------------------------------------------- + + TypeError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\2269134755.py in + ----> 1 VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", 3) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + 121 raise TypeError("VendorName should be a string!") + 122 if VendorMail: #validate e-mail address if one is provided + --> 123 CheckVendorMail(VendorMail) + 124 if WordRate != None: #validate word rate if one is provided + 125 CheckWordRate(WordRate) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckVendorMail(VendorMail) + 44 regex_mail = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" #regex used to validate email + 45 if type(VendorMail) != str: + ---> 46 raise TypeError ("VendorMail should be a string!") + 47 if not(re.search(regex_mail,VendorMail)): + 48 raise ValueError("Please insert a valid email address.") + + + TypeError: VendorMail should be a string! + + + +```python +VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", WordRate = "0.15") +``` + + + --------------------------------------------------------------------------- + + TypeError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\2028391605.py in + ----> 1 VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", WordRate = "0.15") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + 123 CheckVendorMail(VendorMail) + 124 if WordRate != None: #validate word rate if one is provided + --> 125 CheckWordRate(WordRate) + 126 if CatTool: #validate CAT Tool if one is provided + 127 CheckCatTool(CatTool) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 60 """ + 61 if type(WordRate) != float: + ---> 62 raise TypeError("WordRate should be a float!") + 63 if WordRate > 0.15: + 64 raise ValueError("This vendor is too expensive, pick another one.") + + + TypeError: WordRate should be a float! + + + +```python +VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", Preferred = "Test") +``` + + + --------------------------------------------------------------------------- + + TypeError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\1300272076.py in + ----> 1 VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", Preferred = "Test") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + 128 if Preferred != None: + 129 if type(Preferred) != bool: + --> 130 raise TypeError("Preferred should either be True, False or None.") + 131 if Preferred != None: #if Preferred is set to True, status will be preferred, if set to False, back-up and if neither "Potential" + 132 if Preferred: + + + TypeError: Preferred should either be True, False or None. + + + +```python +VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", CatTool = True) +``` + + + --------------------------------------------------------------------------- + + TypeError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\2908856665.py in + ----> 1 VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", CatTool = True) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + 125 CheckWordRate(WordRate) + 126 if CatTool: #validate CAT Tool if one is provided + --> 127 CheckCatTool(CatTool) + 128 if Preferred != None: + 129 if type(Preferred) != bool: + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckCatTool(CatTool) + 78 """ + 79 if type(CatTool) != str: + ---> 80 raise TypeError("CatTool should be a string!") + 81 if not CatTool in VendorData.CatTools: + 82 raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") + + + TypeError: CatTool should be a string! + + +There are also some functions that ensure that: +- `VendorMail` is a valid e-mail address by checking it against a regex string; +- `WordRate` is not 0.00 or more than 0.15 and not negative; +- `CatTool` is one of the following: XTM, Trados Studio, MemoQ or Memsource. + + +```python +VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", VendorMail = "thomas.zw") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\2329585938.py in + ----> 1 VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", VendorMail = "thomas.zw") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + 121 raise TypeError("VendorName should be a string!") + 122 if VendorMail: #validate e-mail address if one is provided + --> 123 CheckVendorMail(VendorMail) + 124 if WordRate != None: #validate word rate if one is provided + 125 CheckWordRate(WordRate) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckVendorMail(VendorMail) + 46 raise TypeError ("VendorMail should be a string!") + 47 if not(re.search(regex_mail,VendorMail)): + ---> 48 raise ValueError("Please insert a valid email address.") + 49 def CheckWordRate(WordRate): + 50 """Function to validate the word rate + + + ValueError: Please insert a valid email address. + + + +```python +VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", WordRate = 0.19) +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\389829205.py in + ----> 1 VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", WordRate = 0.19) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + 123 CheckVendorMail(VendorMail) + 124 if WordRate != None: #validate word rate if one is provided + --> 125 CheckWordRate(WordRate) + 126 if CatTool: #validate CAT Tool if one is provided + 127 CheckCatTool(CatTool) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 62 raise TypeError("WordRate should be a float!") + 63 if WordRate > 0.15: + ---> 64 raise ValueError("This vendor is too expensive, pick another one.") + 65 if WordRate == 0.00: + 66 raise ValueError("Word rate cannot be 0.00.") + + + ValueError: This vendor is too expensive, pick another one. + + + +```python +VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", WordRate = 0.00) +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\2186391260.py in + ----> 1 VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", WordRate = 0.00) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + 123 CheckVendorMail(VendorMail) + 124 if WordRate != None: #validate word rate if one is provided + --> 125 CheckWordRate(WordRate) + 126 if CatTool: #validate CAT Tool if one is provided + 127 CheckCatTool(CatTool) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 64 raise ValueError("This vendor is too expensive, pick another one.") + 65 if WordRate == 0.00: + ---> 66 raise ValueError("Word rate cannot be 0.00.") + 67 if WordRate < 0.00: + 68 raise ValueError("Word rate cannot be negative.") + + + ValueError: Word rate cannot be 0.00. + + + +```python +VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", WordRate = -0.04) +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\251048835.py in + ----> 1 VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", WordRate = -0.04) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + 123 CheckVendorMail(VendorMail) + 124 if WordRate != None: #validate word rate if one is provided + --> 125 CheckWordRate(WordRate) + 126 if CatTool: #validate CAT Tool if one is provided + 127 CheckCatTool(CatTool) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 66 raise ValueError("Word rate cannot be 0.00.") + 67 if WordRate < 0.00: + ---> 68 raise ValueError("Word rate cannot be negative.") + 69 def CheckCatTool(CatTool): + 70 """Function to validate the chosen CAT Tool + + + ValueError: Word rate cannot be negative. + + + +```python +VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", CatTool = "SDL Trados Studio") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\153109120.py in + ----> 1 VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", CatTool = "SDL Trados Studio") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + 125 CheckWordRate(WordRate) + 126 if CatTool: #validate CAT Tool if one is provided + --> 127 CheckCatTool(CatTool) + 128 if Preferred != None: + 129 if type(Preferred) != bool: + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckCatTool(CatTool) + 80 raise TypeError("CatTool should be a string!") + 81 if not CatTool in VendorData.CatTools: + ---> 82 raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") + 83 + 84 class VendorData: + + + ValueError: This CAT tool is not valid. Run 'VendorData.CatTools' to check options. + + +As already mentioned, this kind of validation is done anytime user input is required, not only upon instantiating. +More precisely, validation is done when: +- One of the methods to set a value is run +- The excel is modified using the `ModExcel` method + + +```python +VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel") #for illustration we instantiate a new instance of VendorData +``` + + +```python +VendorDE.SetVendorMail("thomas.zw@") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\4282007076.py in + ----> 1 VendorDE.SetVendorMail("thomas.zw@") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in SetVendorMail(self, NewMail) + 157 ValueError: if the address provided does not conform with the regex string `regex_mail`, a ValueError is raised + 158 """ + --> 159 CheckVendorMail(NewMail) #validate e-mail address + 160 self.VendorMail = NewMail #value of VendorMail is changed + 161 + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckVendorMail(VendorMail) + 46 raise TypeError ("VendorMail should be a string!") + 47 if not(re.search(regex_mail,VendorMail)): + ---> 48 raise ValueError("Please insert a valid email address.") + 49 def CheckWordRate(WordRate): + 50 """Function to validate the word rate + + + ValueError: Please insert a valid email address. + + + +```python +VendorDE.SetWordRate(0.18) +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\1677043638.py in + ----> 1 VendorDE.SetWordRate(0.18) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in SetWordRate(self, NewRate) + 173 ValueError: the argument provided should not be negative. + 174 """ + --> 175 CheckWordRate(NewRate) #validate new word rate + 176 self.WordRate = NewRate #value of WordRate is changed + 177 + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 62 raise TypeError("WordRate should be a float!") + 63 if WordRate > 0.15: + ---> 64 raise ValueError("This vendor is too expensive, pick another one.") + 65 if WordRate == 0.00: + 66 raise ValueError("Word rate cannot be 0.00.") + + + ValueError: This vendor is too expensive, pick another one. + + + +```python +VendorDE.SetWordRate (0.00) +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\2070555766.py in + ----> 1 VendorDE.SetWordRate (0.00) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in SetWordRate(self, NewRate) + 173 ValueError: the argument provided should not be negative. + 174 """ + --> 175 CheckWordRate(NewRate) #validate new word rate + 176 self.WordRate = NewRate #value of WordRate is changed + 177 + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 64 raise ValueError("This vendor is too expensive, pick another one.") + 65 if WordRate == 0.00: + ---> 66 raise ValueError("Word rate cannot be 0.00.") + 67 if WordRate < 0.00: + 68 raise ValueError("Word rate cannot be negative.") + + + ValueError: Word rate cannot be 0.00. + + + +```python +VendorDE.SetWordRate(-0.04) +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\1645063171.py in + ----> 1 VendorDE.SetWordRate(-0.04) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in SetWordRate(self, NewRate) + 173 ValueError: the argument provided should not be negative. + 174 """ + --> 175 CheckWordRate(NewRate) #validate new word rate + 176 self.WordRate = NewRate #value of WordRate is changed + 177 + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 66 raise ValueError("Word rate cannot be 0.00.") + 67 if WordRate < 0.00: + ---> 68 raise ValueError("Word rate cannot be negative.") + 69 def CheckCatTool(CatTool): + 70 """Function to validate the chosen CAT Tool + + + ValueError: Word rate cannot be negative. + + + +```python +VendorDE.ChangeTool("SDL Trados Studio") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\3483989379.py in + ----> 1 VendorDE.ChangeTool("SDL Trados Studio") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ChangeTool(self, NewTool) + 187 ValueError: the argument provided should be one of the four CAT Tools in the list VendorData.CatTools + 188 """ + --> 189 CheckCatTool(NewTool) #validate new CAT Tool + 190 self.CatTool = NewTool #value of CatTool is changed + 191 + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckCatTool(CatTool) + 80 raise TypeError("CatTool should be a string!") + 81 if not CatTool in VendorData.CatTools: + ---> 82 raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") + 83 + 84 class VendorData: + + + ValueError: This CAT tool is not valid. Run 'VendorData.CatTools' to check options. + + + +```python +VendorDE.SetStatus("None") +``` + + + --------------------------------------------------------------------------- + + TypeError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\3389852500.py in + ----> 1 VendorDE.SetStatus("None") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in SetStatus(self, PrefVend) + 198 if PrefVend != None: + 199 if type(PrefVend) != bool: + --> 200 raise TypeError("Preferred should either be True, False or None.") + 201 if PrefVend != None: + 202 if PrefVend == True: + + + TypeError: Preferred should either be True, False or None. + + +To illustrate that validation is done when running the `ModExcel` method, we first have to write the data to the excel file: +
+If you run `.toExcel()` multiple times on the same vendor, it will generate multiple entries! +
+ + +```python +VendorDE.ToExcel() +``` + + The vendor Thomas Zwiebel was added to Tutorial_English.xlsx. + + +Now we can modify the German vendor and the input will be validated: + + +```python +VendorDE.ModExcel("E-mail", 3, "thomaszw@") +``` + + + --------------------------------------------------------------------------- + + TypeError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\1589300048.py in + ----> 1 VendorDE.ModExcel("E-mail", 3, "thomaszw@") + + + TypeError: ModExcel() takes 3 positional arguments but 4 were given + + + +```python +VendorDE.ModExcel("CAT Tool", 3, "Trados Studio 2019") +``` + + + --------------------------------------------------------------------------- + + TypeError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\3469975144.py in + ----> 1 VendorDE.ModExcel("CAT Tool", 3, "Trados Studio 2019") + + + TypeError: ModExcel() takes 3 positional arguments but 4 were given + + + +```python +VendorDE.ModExcel("Word Rate", 3, 0.18) +``` + + + --------------------------------------------------------------------------- + + TypeError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\2651721014.py in + ----> 1 VendorDE.ModExcel("Word Rate", 3, 0.18) + + + TypeError: ModExcel() takes 3 positional arguments but 4 were given + + + +```python +VendorDE.ModExcel("Status", 3, "Busy") +``` + + + --------------------------------------------------------------------------- + + TypeError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\3428613633.py in + ----> 1 VendorDE.ModExcel("Status", 3, "Busy") + + + TypeError: ModExcel() takes 3 positional arguments but 4 were given + + +For the `ModExcel` method there's an additional validation, namely the validation of keys in order to limit the keys for which you can modify the values. Modifiable keys can be checked by running `vd.VendorData.Keys` +
+You can only modify one value for one key. +
+ + +```python +vd.VendorData.Keys +``` + + + + + ['E-mail', 'CAT Tool', 'Word Rate', 'Status'] + + + +If you try to modify any other key you will get an error message: + + +```python +VendorDE.ModExcel("Vendor", "John Doe") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\1799726010.py in + ----> 1 VendorDE.ModExcel("Vendor", "John Doe") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, NewValue) + 273 ExcelRecordsDf = pd.read_excel(FileName) + 274 if not Key in self.Keys: + --> 275 raise ValueError("Invalid key, run 'VendorData.Keys' to see options.") + 276 + 277 VendorRow = ExcelRecordsDf[ExcelRecordsDf.Vendor == self.VendorName] + + + ValueError: Invalid key, run 'VendorData.Keys' to see options. + + + +```python +VendorDE.ModExcel("Target Language", "Croatian") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_19840\3386871677.py in + ----> 1 VendorDE.ModExcel("Target Language", "Croatian") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, NewValue) + 273 ExcelRecordsDf = pd.read_excel(FileName) + 274 if not Key in self.Keys: + --> 275 raise ValueError("Invalid key, run 'VendorData.Keys' to see options.") + 276 + 277 VendorRow = ExcelRecordsDf[ExcelRecordsDf.Vendor == self.VendorName] + + + ValueError: Invalid key, run 'VendorData.Keys' to see options. + + +We will now delete the file we generated during this tutorial so that when you go through it again, you can have a fresh start. + + +```python +import os +os.remove(".\Tutorial_English.xlsx") +``` + +Now you know the different functionalities of the script vendor__data.py and what triggers which error. Hopefully you can use this script in your daily life as a translation project manager. Have fun! + +## Running `vendor_data.py` +The script can also be run on its own. The script takes two optional arguments: +- `-a` or `--add` allows the user to add a new vendor to an excel file (existing or new); +- `-m` or `--modify` allows the user to modify a vendor in an existing excel file; +The same validation is done as if you would import this script as a module. TypeErrors do not cause the prompts to stop but instead you get asked the same question again, ValueErrors do break off the code. + +We'll begin with writing data to a brand new excel file by providing a new project name and source language, i.e. not Example and not English since an excel file already exists for this project. + + +```python +%run vendor_data.py -a +``` + + What is the project name? Example + What is the source language? Dutch + What's the vendor's name? John Doe + Into which language will the vendor translate? English + What is the vendor's email address? + What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor. + In which tool will the vendor be working?* XTM + * Trados Studio + * MemoQ + * Memsource + + True or False: Is this vendor a preferred vendor? If neither, leave blank. + Are you done? yes + Do you want to add this vendor to the excel file? yes + The file Example_Dutch.xlsx is correctly created and the vendor John Doe was added. + + +You can also append a new vendor to the existing `Example_English.xlsx` file by providing `Example` as the project name and `English` as the source language. Again, the code does not check if a vendor already exists in the excel file, so you should add a vendor only once. + +
+You can only modify one value for one key. +
+ + +```python +%run vendor_data.py -a +``` + + What is the project name? Example + What is the source language? English + What's the vendor's name? Thomas Zwiebel + Into which language will the vendor translate? German + What is the vendor's email address? th.zwiebel@gmail.com + What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor. 0.08 + In which tool will the vendor be working?* XTM + * Trados Studio + * MemoQ + * Memsource + MemoQ + True or False: Is this vendor a preferred vendor? If neither, leave blank. False + Are you done? yes + Do you want to add this vendor to the excel file? yes + The vendor Thomas Zwiebel was added to Example_English.xlsx. + + +Just like when importing the script, it is possible to leave the following data blank: +- The vendor's email address +- The vendors word rate +- The tool in which the vendor will be working +- Whether or not the vendor is a preferred vendor + +We'll append another vendor to the `Example_English` file: + + +```python +%run vendor_data.py -a +``` + + What is the project name? Example + What is the source language? English + What's the vendor's name? Joao Felix + Into which language will the vendor translate? Portuguese + What is the vendor's email address? + What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor. + In which tool will the vendor be working?* XTM + * Trados Studio + * MemoQ + * Memsource + + True or False: Is this vendor a preferred vendor? If neither, leave blank. + Are you done? yes + Do you want to add this vendor to the excel file? yes + The vendor Joao Felix was added to Example_English.xlsx. + + +Since we're using pyipinputplus we can already avoid some errors by: +- using the built in type validation of the package by using `pyip.inputStr` or `pyip.inputFloat`, so that the user is forced to put in a valid data type +- using the Menu option to limit the choices, for example for the CAT Tools +In the background the same validation is run as when you import this script as a module. To see which kind of validation is done, please go to `Validation` above. + +It is also possible to modify existing vendors. The user has to provide the project name and the source language, and is then further asked some questions regarding the vendor they want to modify: + + +```python +%run vendor_data.py -m +``` + + What is the name of the project that the vendor you want to modify works on? Example + What is the source language? English + These are the vendor's already in the database: + 0: Elmo Geeraerts + 1: Jean De Gaule + 2: Emanuel De la Banda + 3: Thomas Zwiebel + 4: Joao Felix + Enter the index of the vendor you want to modify: 0 + What is the vendor's e-mail? geeraerts@me.com + What is the vendor's word rate? Should be between 0.01 and 0.15. If higher, choose another vendor. 0.10 + In which tool will the vendor be working?* XTM + * Trados Studio + * MemoQ + * Memsource + Trados Studio + What is the vendor's new status? * Preferred + * Back-up + * Potential + Preferred + Are you done? yes + This vendor is modified correctly. + + +The vendor in the excel file should now be modified. + +Now you are totally ready to use this script and resolve any issues that might pop up! Hopefully this script makes your life as a translation project manager easier! Have fun! + +### Docstrings +The script is completely documented with docstrings in order to ensure that the script is correclty used. +You can read these docstrings by calling one of the following functions if you have imported the script as a module: +```python +help(vd) +``` +OR +```python +?vd +``` +OR +```python +vd.__doc__ +``` + +You can also read the documentation for the script if you run this code: +```python +%run vendor_data.py --help +``` +OR +```python +%run vendor_data.py --h +``` diff --git a/vendor_data.py b/vendor_data.py new file mode 100644 index 0000000..206b513 --- /dev/null +++ b/vendor_data.py @@ -0,0 +1,402 @@ +#! /usr/bin/python +"""This is a python script to help Translation Project Managers keep a clean overview of the vendors for a particular project by narrowing down the data in the excel. + + It contains: + - 4 functions: + `ChangeDictionaryValue` to easily change values in a certain dictionary. + `CheckVendorMail` to easily check if an e-mail address is valid. + `CheckWordRate` to check if a word rate falls between EUR 0.01 and EUR 0.15 per word. + `CheckCatTool` to validate the CAT tool provided. + - 1 class, `VendorData` that has 3 class attributes: `CatTools`, the CAT Tools that can be used for the project, + `Keys`, the keys of the dictionary that can be modified, and `Statuses`, the possible statuses a vendor can have. + The class takes 4 positional arguments and 4 optional arguments. + - `Argparse` inside `if __name__ == "__main__":` statement to receive arguments when the script is run + """ +#Import some python packages that will be needed: +import argparse +import re #regular expression package to validate e-mail +import pandas as pd #pandas package to write excel file +import os #os package to check if files exists +import pyinputplus as pyip #pyinputplus package to facilitate providing arguments + +#4 functions to make validation easier +def ChangeDictionaryValue(Dictionary, Key, Index, NewValue): + """Function to change the value of a certain key in a certain dictionary. + + Args: + Dictionary (dict): name of the dictionary that will be read + Key (str): the key for which the value will be changed + Index (int): the index of the value that will be changed + NewValue: new value for the chosen index, type depends on the key + """ + if Key in Dictionary and Index in Dictionary[Key]: + Dictionary[Key][Index] = NewValue +def CheckVendorMail(VendorMail): + """Function to validate the e-mail address. + + Args: + VendorMail (str): an e-mail address + + Raises: + TypeError: if the argument provided is not a string, a TypeError is raised + ValueError: if the address provided does not conform with the regex string `regex_mail`, a ValueError is raised + """ + regex_mail = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" #regex used to validate email + if type(VendorMail) != str: + raise TypeError ("VendorMail should be a string!") + if not(re.search(regex_mail,VendorMail)): + raise ValueError("Please insert a valid email address.") +def CheckWordRate(WordRate): + """Function to validate the word rate + + Args: + WordRate (float): a word rate in EUR/word + + Raises: + TypeError: if the argument provided is not a float, a TypeError is raised + ValueError: the argument provided should not be higher than 0.15 + ValueError: the argument provided should not be 0.00 + ValueError: the argument provided should not be negative. + """ + if type(WordRate) != float: + raise TypeError("WordRate should be a float!") + if WordRate > 0.15: + raise ValueError("This vendor is too expensive, pick another one.") + if WordRate == 0.00: + raise ValueError("Word rate cannot be 0.00.") + if WordRate < 0.00: + raise ValueError("Word rate cannot be negative.") +def CheckCatTool(CatTool): + """Function to validate the chosen CAT Tool + + Args: + CatTool (str): a CAT Tool + + Raises: + TypeError: if the argument provided is not string, a TypeError is raised + ValueError: the argument provided should be one of the four CAT Tools in the list VendorData.CatTools + """ + if type(CatTool) != str: + raise TypeError("CatTool should be a string!") + if not CatTool in VendorData.CatTools: + raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") + +class VendorData: + + CatTools = ["XTM", "Trados Studio", "MemoQ", "Memsource"] + Keys = ["E-mail", "CAT Tool", "Word Rate", "Status"] + Statuses = ["Preferred", "Back-up", "Potential"] + + def __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail = "", WordRate = None, CatTool = "XTM", Preferred = None): + """Instantiate + + Class Attributes: + CatTools (list) : + Keys (list) : + Statuses (list) : + + Args: + ProjectName (str): the name of the translation project + SourceLang (str): the source language, i.e. the language the translator will translate from + TargLang (str): the target language, i.e. the language the translator will translate into + VendorName (str): the translator's/vendor's name + VendorMail (str, optional): the vendor's e-mail address, by default empty + WordRate (float, optional): the vendor's word rate in EUR/word, by default set to "None" + CatTool (str, optional): the CAT Tool the translator will use, by default set to "XTM" + Preferred (bool, optional): indicates if a vendor is a preferred vendor or not, by default set to "None". + + Raises: + TypeError: ProjectName should be a string + TypeError: SourceLang should be a string + TypeError: TargLang should be a string + TypeError: VendorName should be a string + """ + if type(ProjectName) != str: + raise TypeError("ProjectName should be a string!") + if type(SourceLang) != str: + raise TypeError("SourceLang should be a string!") + if type(TargLang) != str: + raise TypeError("TargLang should be a string!") + if type(VendorName) !=str: + raise TypeError("VendorName should be a string!") + if VendorMail: #validate e-mail address if one is provided + CheckVendorMail(VendorMail) + if WordRate != None: #validate word rate if one is provided + CheckWordRate(WordRate) + if CatTool: #validate CAT Tool if one is provided + CheckCatTool(CatTool) + if Preferred != None: + if type(Preferred) != bool: + raise TypeError("Preferred should either be True, False or None.") + if Preferred != None: #if Preferred is set to True, status will be preferred, if set to False, back-up and if neither "Potential" + if Preferred: + self.Status = "Preferred" + elif Preferred == False: + self.Status = "Back-up" + else: + self.Status = "Potential" + + self.ProjectName = ProjectName + self.SourceLang = SourceLang + self.VendorName = VendorName + self.TargLang = TargLang + self.WordRate = WordRate + self.VendorMail = VendorMail + self.CatTool = CatTool + self.Preferred = Preferred + + def SetVendorMail(self, NewMail): + """Method to set new vendor mail + + Args: + NewMail (str): a new e-mail address for a certain vendor + Function called: + CheckVendorMail(VendorMail) + Raises: + TypeError: if the argument provided is not a string, a TypeError is raised + ValueError: if the address provided does not conform with the regex string `regex_mail`, a ValueError is raised + """ + CheckVendorMail(NewMail) #validate e-mail address + self.VendorMail = NewMail #value of VendorMail is changed + + def SetWordRate(self, NewRate): + """Method to set new word rate + + Args: + NewRate (float): a new word rate for a certain vendor + Function called: + CheckWordRate(WordRate) + Raises: + TypeError: if the argument provided is not a float, a TypeError is raised + ValueError: the argument provided should not be higher than 0.15 + ValueError: the argument provided should not be 0.00 + ValueError: the argument provided should not be negative. + """ + CheckWordRate(NewRate) #validate new word rate + self.WordRate = NewRate #value of WordRate is changed + + def ChangeTool (self, NewTool): + """Method to change the chosen CAT Tool + + Args: + NewTool (str): a new tool for a certain vendor + Function called: + CheckCatTool(CatTool) + Raises: + TypeError: if the argument provided is not string, a TypeError is raised + ValueError: the argument provided should be one of the four CAT Tools in the list VendorData.CatTools + """ + CheckCatTool(NewTool) #validate new CAT Tool + self.CatTool = NewTool #value of CatTool is changed + + def SetStatus(self, PrefVend): + """Method to set a new value for self.Preferred and self.Status + + Args: + PrefVend (bool or None): new value for Preferred, has an influence on status + """ + if PrefVend != None: + if type(PrefVend) != bool: + raise TypeError("Preferred should either be True, False or None.") + if PrefVend != None: + if PrefVend == True: + self.Preferred = True + self.Status = "Preferred" + elif PrefVend == False: + self.Preferred = False + self.Status = "Back-up" + else: + self.Preferred = None + self.Status = "Potential" + + def ToExcel(self): + """Method to write data of an instance of the class VendorData to an excel file + + How it works: + 1. The arguments provided are dumped into a dictionary called `Data`, + 2. A variable `FileName` is created, the name will be the value for `self.ProjectName` and `self.SourceLang` joined by an underscore (_). + 3. The dictionary `Data` is turned into pandas. + 4. The code checks if the file with the name created in the variable `FileName` exists. + 4.1 If the file exists, the provided data is appended to the existing file. + 4.2 if the file does not exist the provided data is written to a new file under the name created in the variable `FileName`. + """ + Data = { + "Target Language": [self.TargLang], + "Vendor": [self.VendorName], + "E-mail": [self.VendorMail], + "CAT Tool": [self.CatTool], + "Word Rate": [self.WordRate], + "Status": [self.Status] + } + FileName = "_".join([str(self.ProjectName), str(self.SourceLang)]) + ".xlsx" + df = pd.DataFrame(Data) + if not os.path.exists(FileName): + df.to_excel(FileName, index=False, sheet_name="VendorData") + print(f"The file {FileName} is correctly created and the vendor {self.VendorName} was added.") + else: + with pd.ExcelWriter(FileName, mode="a", engine="openpyxl", if_sheet_exists="overlay") as writer: + df.to_excel(writer, sheet_name = "VendorData", startrow=writer.sheets["VendorData"].max_row, header = None, index=False) + print(f"The vendor {self.VendorName} was added to {FileName}.") + + def ReadExcel(self): + """Method to read an existing excel file + + Raises: + ValueError: if the file with the filename created in the variable `FileName` does not exist, you get a message saying a file for that project in that language does not exist. + + Returns: + Dict: a dictionary containing the data in the excel file. + """ + FileName = "_".join([str(self.ProjectName), str(self.SourceLang)]) + ".xlsx" + if os.path.exists(FileName): + ExcelRecords = pd.read_excel(FileName) + ExcelRecordsDf = ExcelRecords.loc[:, ~ExcelRecords.columns.str.contains('^Unnamed')] + VendorDict = ExcelRecordsDf.to_dict() + return VendorDict + else: + raise ValueError(f"There is no file for {self.ProjectName} in {self.SourceLang}") + + def ModExcel(self, Key, NewValue): + """Method to modify existing vendor in excel file + + Args: + Key (str): one of the modifiable keys in VendorData.Keys + NewValue: the new value for the key, type depends on the key, either str or float + + Raises: + ValueError: raised if the key is not one of the keys in VendorData.Keys + ValueError: raised if the provided Status is not in the list VendorData.Statuses + All the errors in the functions `CheckVendorMail`, `CheckWordRate` and `CheckCatTool` + """ + FileName = "_".join([str(self.ProjectName), str(self.SourceLang)]) + ".xlsx" + if os.path.exists(FileName): + ExcelRecordsDf = pd.read_excel(FileName) + if not Key in self.Keys: + raise ValueError("Invalid key, run 'VendorData.Keys' to see options.") + + VendorRow = ExcelRecordsDf[ExcelRecordsDf.Vendor == self.VendorName] + Index = VendorRow.index[0] + + if Key == "E-mail": + CheckVendorMail(NewValue) + self.VendorMail = NewValue + elif Key == "Word Rate": + CheckWordRate(NewValue) + self.WordRate = NewValue + elif Key == "CAT Tool": + CheckCatTool(NewValue) + self.CatTool = NewValue + elif Key == "Status": + if not NewValue in VendorData.Statuses: + raise ValueError("Invalid status, run 'VendorData.Statuses' to see options") + else: + self.Status = NewValue + + ExcelRecordsDf.at[Index, Key] = NewValue + + with pd.ExcelWriter(FileName, engine="openpyxl", mode="w") as writer: + ExcelRecordsDf.to_excel(writer, sheet_name="VendorData", index=False) + + print("The vendor was correctly modified.") + else: + raise ValueError(f"There is no file for {self.ProjectName} in {self.SourceLang}") + +if __name__ == "__main__": + """Parse command line arguments to provide arguments when the code is run + + Args: + --add, -a (flag) : indicating the user wants to add a new vendor + --modify, -m (flag) : indicating the user wants to modify an existing vendor + """ + parser = argparse.ArgumentParser() + parser.add_argument("-a", "--add", action='store_true', help = "Action: add a vendor. Prompts the user with some questions.") + parser.add_argument ("-m", "--modify", action='store_true', help = "Action: modify a vendor. Prompts the user with some questions.") + args = parser.parse_args() + + + if args.add and args.modify: + raise ValueError("Cannot run '--add/-a' and '--modify/-m' at the same time, provide one or the other.") + elif args.add: + done = "no" + WordRate = None + Preferred = None + VendorMail = "" + CatTool = "XTM" + while done.lower() != "yes": #Code underneath is run unless value for done is changed to "no" + ProjectName = pyip.inputStr("What is the project name? ") + SourceLang = pyip.inputStr("What is the source language? ") + VendorName = pyip.inputStr("What's the vendor's name? ") + TargLang = pyip.inputStr("Into which language will the vendor translate? ") + NewVendorMail = pyip.inputStr("What is the vendor's email address? ", blank = True, default="") + if NewVendorMail: + CheckVendorMail(NewVendorMail) + VendorMail = NewVendorMail + else: + VendorMail = VendorMail + NewWordRate = pyip.inputFloat("What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor. ", blank = True) + if NewWordRate: + CheckWordRate(NewWordRate) + VendorWordRate = NewWordRate + else: + WordRate = WordRate + NewCatTool= pyip.inputMenu(VendorData.CatTools, prompt = "In which tool will the vendor be working?", blank = True, default = "XTM") + CatTool = NewCatTool if NewCatTool else CatTool + NewPreferred = pyip.inputBool("True or False: Is this vendor a preferred vendor? If neither, leave blank. ", blank = True, default=None) + Preferred = NewPreferred if NewPreferred else Preferred + done = pyip.inputStr("Are you done? ") #user gets the chance to change value for done to "no" + + Vndr=VendorData(ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + Excel = pyip.inputStr("Do you want to add this vendor to the excel file? ") #user gets the chance to write data to excel + if Excel.lower() == "yes": + Vndr.ToExcel() #data written to excel + else: + print ("Action was cancelled.") + elif args.modify: + done = "no" + while done.lower() != "yes": #Code underneath is run as long as value for done = no + """ + """ + ProjectName = pyip.inputStr("What is the name of the project that the vendor you want to modify works on? ") + SourceLang = pyip.inputStr("What is the source language? ") + FileName = "_".join([str(ProjectName), str(SourceLang)]) + ".xlsx" + if os.path.exists(FileName): + ExcelRecords = pd.read_excel(FileName) + ExcelRecordsDf = ExcelRecords.loc[:, ~ExcelRecords.columns.str.contains('^Unnamed')] + VendorDict=ExcelRecordsDf.to_dict() + + Vendors = VendorDict["Vendor"] + print ("These are the vendor's already in the database: ") + for index, VendorName in Vendors.items(): + print(f"{index}: {VendorName}") + + VendorIndex = pyip.inputInt("Enter the index of the vendor you want to modify: ") + if VendorIndex in Vendors: + VendorKey = "Vendor" + EmailKey = "E-mail" + WordRateKey = "Word Rate" + CatToolKey = "CAT Tool" + StatusKey = "Status" + + NewEmail = pyip.inputStr("What is the vendor's e-mail? ", blank = True) + if NewEmail: + CheckVendorMail(NewEmail) + NewWordRate = pyip.inputFloat("What is the vendor's word rate? Should be between 0.01 and 0.15. If higher, choose another vendor. ", blank = True) + if NewWordRate: + CheckWordRate(NewWordRate) + NewCatTool = pyip.inputMenu(VendorData.CatTools, prompt = "In which tool will the vendor be working?", blank = True, default = "XTM") + NewStatus = pyip.inputMenu(VendorData.Statuses, prompt = "What is the vendor's new status? ", blank = True) + done = pyip.inputStr("Are you done? ") + else: + print("A file for this project and this source language does not yet exist. Check the project name and source language.") + if NewEmail: + ChangeDictionaryValue(VendorDict, EmailKey, VendorIndex, NewEmail) + if NewWordRate: + ChangeDictionaryValue(VendorDict, WordRateKey, VendorIndex, NewWordRate) + if NewCatTool: + ChangeDictionaryValue(VendorDict, CatToolKey, VendorIndex, NewCatTool) + if NewStatus: + ChangeDictionaryValue(VendorDict, StatusKey, VendorIndex, NewStatus) + df = pd.DataFrame(VendorDict) #VendorDict dictionary is turned into pandas dataframe + with pd.ExcelWriter(FileName, engine="openpyxl", mode="w") as writer: #Excel file is overwritten with new data + df.to_excel(writer, sheet_name = "VendorData", index=False) + print("This vendor is modified correctly.") \ No newline at end of file