From 28f8263b8acb382c6068bcb030d0531d81d551f4 Mon Sep 17 00:00:00 2001 From: Elmo Date: Tue, 2 May 2023 11:33:39 +0200 Subject: [PATCH 01/24] upgrade README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c4f8bc5..30e8bac 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 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. +The code has been developed by Elmo Geeraerts. ## Installation and usage From f4144585bddbc1f41eb3e128ea3e89f1a661c1c4 Mon Sep 17 00:00:00 2001 From: Elmo Date: Tue, 2 May 2023 12:05:13 +0200 Subject: [PATCH 02/24] Update Tutorial --- tutorial.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tutorial.md b/tutorial.md index 6add32e..589872f 100644 --- a/tutorial.md +++ b/tutorial.md @@ -1,3 +1,5 @@ # How to use my script In this notebook you will learn how to use the functions and classes defined in `script.py`. + +This will become a great tutorial. From 1e1b710d7e1777a1ea554157c8bc75f308fd8876 Mon Sep 17 00:00:00 2001 From: ElmoGeeraerts <131765913+ElmoGeeraerts@users.noreply.github.com> Date: Tue, 2 May 2023 12:21:05 +0200 Subject: [PATCH 03/24] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 30e8bac..98ead3e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The code has been developed by Elmo Geeraerts. 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 +git clone https://github.com/ElmoGeeraerts/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`. From 964abfea64d5d50d44f8a0c55dab0b5ad5a092e5 Mon Sep 17 00:00:00 2001 From: ElmoGeeraerts <131765913+ElmoGeeraerts@users.noreply.github.com> Date: Sun, 14 May 2023 15:45:14 +0200 Subject: [PATCH 04/24] Add files via upload --- README.md | 86 +++++++++++++++++++++++++------------------------- vendor_data.py | 76 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 43 deletions(-) create mode 100644 vendor_data.py diff --git a/README.md b/README.md index 98ead3e..3da6bf5 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,43 @@ -# 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 Elmo Geeraerts. - -## Installation and usage - -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 -``` - -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 + +This repository contains a Python program that could help a translation agency to keep track of a vendor database. The idea is to make it easier for project managers to keep track of who the preferred and back-up vendors are for a project, in which languages they work, what their contact details and rates are and other information that might be useful for the PMs. + +The code has been developed by Elmo Geeraerts. + +## Installation and usage + +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 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. diff --git a/vendor_data.py b/vendor_data.py new file mode 100644 index 0000000..3605b94 --- /dev/null +++ b/vendor_data.py @@ -0,0 +1,76 @@ +#! /usr/bin/python + +"""This script is meant to help Translation Project Managers with keeping a clear overview of the vendors participating in a project. + +The script contains three classes: + 1. The main parent class ´VendorData´. This class is meant for a general potential vendor profile, without assigning a status (preferred/back-up). + It has 2 class arguments ´ProjectName´, representing the project name and ´SourceLang´, the source language the translators will be translating from, and takes 5 arguments: + - ´VendorName´: The first and last name of the vendor. + - ´VendorMail´: The vendor's email address. + - ´TargLang´: the language the translators will be translating into. + - ´WordRate´: the translator's word rate in Euro. + - ´CatTool´: the vendor's preferred cat tool. + 2. The subclass ´PrefVendor´, for the preferred vendors. They are assigned the status "Preferred". + 3. The subclass ´BackupVendor´ for the back-up vendors. They are assigned the status "Back-up" +""" +import argparse + +# write here your function and class definitions +class VendorData: + ProjectName = "Toyota MM24" #Class attribute no.1, the project the vendors will be working on + SourceLang = "English" #Class attribute no.2, the source language + + def __init__(self, VendorName, VendorMail, TargLang, WordRate, CatTool): + """ Instantiate + Args: + "VendorName" (str): First and last name of the vendor + "VendorMail" (str): the vendor's email address + "TargLang" (str): Language the vendor will be translating to + "WordRate" (float): Vendor's word rate for new words in Euro + "CatTool" (str): Vendor's preferred CAT-tool + """ + self.VendorName = VendorName + self.VendorMail = VendorMail + self.TargLang = TargLang + self.WordRate = WordRate + self.CatTool = CatTool + + """Exceptions: + VendorName should be a string, if not a TypeError is raised. + VendorMail should be a string, if not a TypeError is raised. + TargLang should be a string, if not a TypeError is raised. + WordRate should be a float, if not a TypeError is raised. + WordRate should be > 0.15, if not a ValueError is raised. + CatTool should be a string, if not a TypeError is raised. + """ + + if type(VendorName) !=str: + raise TypeError("VendorName should be a string!") + if type(VendorMail) != str: + raise TypeError ("VendorMail should be a string!") + if type(TargLang) != str: + raise TypeError("TargLang should be a string!") + if type(WordRate) != float: + raise TypeError("WordRate should be a float!") + if WordRate > 0.15: + raise ValueError("This vendor is too expensive, consider another one.") + if type(CatTool) != str: + raise TypeError("CatTool should be a string!") + +class PrefVendor(VendorData): + Preferred = True #Subclass Attribute set to True by default: indicating these vendors are the preferred vendors + + def __init__(self, VendorName, VendorMail, TargLang, WordRate, CatTool): + super().__init__(VendorName, VendorMail, TargLang, WordRate, CatTool) + +class BackupVendor(VendorData): + Preferred = False #Subclass Attribute set to False by default: indicating these vendors are the back-up vendors + + def __init__(self, VendorName, VendorMail, TargLang, WordRate, CatTool): + super().__init__(VendorName, VendorMail, TargLang, WordRate, CatTool) + +# 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 From 5248266c4ad3943584d801c5fa97eb99683ca197 Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Tue, 16 May 2023 12:36:42 +0200 Subject: [PATCH 05/24] Update vendor_data.py --- script.py | 13 ----------- vendor_data.py | 62 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 35 deletions(-) delete mode 100644 script.py 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/vendor_data.py b/vendor_data.py index 3605b94..2d48aad 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -4,7 +4,8 @@ The script contains three classes: 1. The main parent class ´VendorData´. This class is meant for a general potential vendor profile, without assigning a status (preferred/back-up). - It has 2 class arguments ´ProjectName´, representing the project name and ´SourceLang´, the source language the translators will be translating from, and takes 5 arguments: + It has 3 class arguments ´ProjectName´, representing the project name and ´SourceLang´, the source language the translators will be translating from and ´CatTools´, the possible Cat Tools the translator can use. + It takes 5 arguments: - ´VendorName´: The first and last name of the vendor. - ´VendorMail´: The vendor's email address. - ´TargLang´: the language the translators will be translating into. @@ -14,13 +15,15 @@ 3. The subclass ´BackupVendor´ for the back-up vendors. They are assigned the status "Back-up" """ import argparse +import re # write here your function and class definitions class VendorData: ProjectName = "Toyota MM24" #Class attribute no.1, the project the vendors will be working on SourceLang = "English" #Class attribute no.2, the source language + CatTools = ["XTM", "Trados Studio", "MemoQ", "Memsource"] #Class attribute no.3, the list of possible Cat Tools - def __init__(self, VendorName, VendorMail, TargLang, WordRate, CatTool): + def __init__(self, VendorName, TargLang, WordRate = None, VendorMail = "", CatTool = "XTM"): """ Instantiate Args: "VendorName" (str): First and last name of the vendor @@ -35,42 +38,57 @@ def __init__(self, VendorName, VendorMail, TargLang, WordRate, CatTool): self.WordRate = WordRate self.CatTool = CatTool - """Exceptions: - VendorName should be a string, if not a TypeError is raised. - VendorMail should be a string, if not a TypeError is raised. - TargLang should be a string, if not a TypeError is raised. - WordRate should be a float, if not a TypeError is raised. - WordRate should be > 0.15, if not a ValueError is raised. - CatTool should be a string, if not a TypeError is raised. + regex_mail = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" #regex used to validate email + + """ + Exceptions: + VendorName should be a string, if not a TypeError is raised. + TargLang should be a string, if not a TypeError is raised. + WordRate should be a float, if not a TypeError is raised. + WordRate should NOT be > 0.15, if not a ValueError is raised. + VendorMail should be a string, if not a TypeError is raised. + VendorMail should be an email, if not a ValueError is raised. + CatTool should be a string, if not a TypeError is raised. + CatTool should be one of the options in the list "CatTools", if not a ValueError is raised. """ if type(VendorName) !=str: raise TypeError("VendorName should be a string!") - if type(VendorMail) != str: - raise TypeError ("VendorMail should be a string!") if type(TargLang) != str: raise TypeError("TargLang should be a string!") if type(WordRate) != float: raise TypeError("WordRate should be a float!") - if WordRate > 0.15: - raise ValueError("This vendor is too expensive, consider another one.") + if WordRate: + if WordRate > 0.15: + raise ValueError("This vendor is too expensive, consider another one.") + else: + self.WordRate = WordRate if type(CatTool) != str: raise TypeError("CatTool should be a string!") + if type(VendorMail) != str: + raise TypeError ("VendorMail should be a string!") + if VendorMail: + if(re.search(regex_mail,VendorMail)): + self.VendorMail = VendorMail + else: + raise ValueError("Please insert a valid email address.") + else: + self.VendorMail = VendorMail + if CatTool in VendorData.CatTools: + self.CatTool = CatTool + else: + raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") class PrefVendor(VendorData): - Preferred = True #Subclass Attribute set to True by default: indicating these vendors are the preferred vendors + Preferred = True + """ Class Attribute: + Preffered (bool.) by default set to "True" indicating this is a Preferred Vendor, if "False" it is a back-up vendor.""" def __init__(self, VendorName, VendorMail, TargLang, WordRate, CatTool): super().__init__(VendorName, VendorMail, TargLang, WordRate, CatTool) -class BackupVendor(VendorData): - Preferred = False #Subclass Attribute set to False by default: indicating these vendors are the back-up vendors - - def __init__(self, VendorName, VendorMail, TargLang, WordRate, CatTool): - super().__init__(VendorName, VendorMail, TargLang, WordRate, CatTool) - -# don't forget to properly document them with docstrings!! +# don't forget to properly dcument them with docstrings!! -if __name__ == "__main": +if __name__ == "__main__": # write here what happens if the code is run instead of imported # include argparse code! \ No newline at end of file From f7a2a44b6491031df405001334db13d2ebaee7d0 Mon Sep 17 00:00:00 2001 From: "Elmo.Geeraerts" Date: Sun, 21 May 2023 10:57:41 +0200 Subject: [PATCH 06/24] Update vendor_data --- vendor_data.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/vendor_data.py b/vendor_data.py index 2d48aad..695b40b 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -7,9 +7,9 @@ It has 3 class arguments ´ProjectName´, representing the project name and ´SourceLang´, the source language the translators will be translating from and ´CatTools´, the possible Cat Tools the translator can use. It takes 5 arguments: - ´VendorName´: The first and last name of the vendor. - - ´VendorMail´: The vendor's email address. - ´TargLang´: the language the translators will be translating into. - ´WordRate´: the translator's word rate in Euro. + - ´VendorMail´: The vendor's email address. - ´CatTool´: the vendor's preferred cat tool. 2. The subclass ´PrefVendor´, for the preferred vendors. They are assigned the status "Preferred". 3. The subclass ´BackupVendor´ for the back-up vendors. They are assigned the status "Back-up" @@ -17,7 +17,6 @@ import argparse import re -# write here your function and class definitions class VendorData: ProjectName = "Toyota MM24" #Class attribute no.1, the project the vendors will be working on SourceLang = "English" #Class attribute no.2, the source language @@ -33,13 +32,14 @@ def __init__(self, VendorName, TargLang, WordRate = None, VendorMail = "", CatTo "CatTool" (str): Vendor's preferred CAT-tool """ self.VendorName = VendorName - self.VendorMail = VendorMail self.TargLang = TargLang self.WordRate = WordRate + self.VendorMail = VendorMail self.CatTool = CatTool regex_mail = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" #regex used to validate email - + + """ Exceptions: VendorName should be a string, if not a TypeError is raised. @@ -61,6 +61,8 @@ def __init__(self, VendorName, TargLang, WordRate = None, VendorMail = "", CatTo if WordRate: if WordRate > 0.15: raise ValueError("This vendor is too expensive, consider another one.") + elif WordRate == 0.00: + raise ValueError("Word rate cannot be 0.00.") else: self.WordRate = WordRate if type(CatTool) != str: @@ -78,17 +80,32 @@ def __init__(self, VendorName, TargLang, WordRate = None, VendorMail = "", CatTo self.CatTool = CatTool else: raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") + + def set_mail(self,mail): + regex_mail = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" #regex used to validate email + if (re.search(regex_mail,mail)): + self.VendorMail = mail + else: + raise ValueError("Please insert a valid email address.") + class PrefVendor(VendorData): Preferred = True """ Class Attribute: Preffered (bool.) by default set to "True" indicating this is a Preferred Vendor, if "False" it is a back-up vendor.""" - def __init__(self, VendorName, VendorMail, TargLang, WordRate, CatTool): - super().__init__(VendorName, VendorMail, TargLang, WordRate, CatTool) + def __init__(self, VendorName, TargLang, WordRate, VendorMail, CatTool): + super().__init__(VendorName, TargLang, WordRate, VendorMail, CatTool) + # don't forget to properly dcument 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 + parser = argparse.ArgumentParser("docstring") + parser.add_argument("VendorName", type=str, help="Vendor's name") + parser.add_argument("TargLang", type=str, help="Language the vendor will be translating into") + parser.add_argument("--WordRate", type=float, help="The vendor's word rate in Euro") + parser.add_argument("--VendorMail", type=str, help="The vendor's email address") + parser.add_argument("--CatTool", type=str, help="The CAT-tool the vendor wants to use") + args = parser.parse_args() + Vndr = VendorData(args.VendorName, args.TargLang, args.WordRate, args.VendorMail, args.CatTool) From 9de2efc23817151df63ae617af45d0a9ef0086ad Mon Sep 17 00:00:00 2001 From: "Elmo.Geeraerts" Date: Sun, 21 May 2023 16:23:15 +0200 Subject: [PATCH 07/24] update vendor_data --- vendor_data.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/vendor_data.py b/vendor_data.py index 695b40b..dfd1de9 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -14,15 +14,17 @@ 2. The subclass ´PrefVendor´, for the preferred vendors. They are assigned the status "Preferred". 3. The subclass ´BackupVendor´ for the back-up vendors. They are assigned the status "Back-up" """ + import argparse import re +import pandas as pd class VendorData: ProjectName = "Toyota MM24" #Class attribute no.1, the project the vendors will be working on SourceLang = "English" #Class attribute no.2, the source language CatTools = ["XTM", "Trados Studio", "MemoQ", "Memsource"] #Class attribute no.3, the list of possible Cat Tools - def __init__(self, VendorName, TargLang, WordRate = None, VendorMail = "", CatTool = "XTM"): + def __init__(self, VendorName, TargLang, WordRate, VendorMail = "", CatTool = "XTM"): """ Instantiate Args: "VendorName" (str): First and last name of the vendor @@ -87,6 +89,19 @@ def set_mail(self,mail): self.VendorMail = mail else: raise ValueError("Please insert a valid email address.") + + + def to_excel(self): + data = { + "Target Language": [self.TargLang], + "Vendor": [self.VendorName], + "E-mail": [self.VendorMail], + "Word rate": [self.WordRate], + "CAT-tool": [self.CatTool] + } + filename = "_".join([str(self.ProjectName), str(self.SourceLang)]) + df = pd.DataFrame(data) + df.to_excel(f"{filename}.xlsx", index=False, sheet_name="VendorData") class PrefVendor(VendorData): @@ -98,6 +113,7 @@ def __init__(self, VendorName, TargLang, WordRate, VendorMail, CatTool): super().__init__(VendorName, TargLang, WordRate, VendorMail, CatTool) + # don't forget to properly dcument them with docstrings!! if __name__ == "__main__": From 9694930742960b11340e6ddacb7d1371afb9cb49 Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Sun, 21 May 2023 18:00:29 +0200 Subject: [PATCH 08/24] Update vendor_data --- vendor_data.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/vendor_data.py b/vendor_data.py index dfd1de9..b6350c2 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -18,6 +18,8 @@ import argparse import re import pandas as pd +import os +from openpyxl import load_workbook class VendorData: ProjectName = "Toyota MM24" #Class attribute no.1, the project the vendors will be working on @@ -88,8 +90,7 @@ def set_mail(self,mail): if (re.search(regex_mail,mail)): self.VendorMail = mail else: - raise ValueError("Please insert a valid email address.") - + raise ValueError("Please insert a valid email address.") def to_excel(self): data = { @@ -101,16 +102,34 @@ def to_excel(self): } filename = "_".join([str(self.ProjectName), str(self.SourceLang)]) df = pd.DataFrame(data) - df.to_excel(f"{filename}.xlsx", index=False, sheet_name="VendorData") - - + if os.path.exists(f"{filename}.xlsx") != True: + df.to_excel(f"{filename}.xlsx", index=False, sheet_name="VendorData") + else: + with pd.ExcelWriter(f"{filename}.xlsx", 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) class PrefVendor(VendorData): Preferred = True """ Class Attribute: Preffered (bool.) by default set to "True" indicating this is a Preferred Vendor, if "False" it is a back-up vendor.""" - def __init__(self, VendorName, TargLang, WordRate, VendorMail, CatTool): + def __init__(self, VendorName, TargLang, WordRate, VendorMail="", CatTool = "XTM"): super().__init__(VendorName, TargLang, WordRate, VendorMail, CatTool) + + def to_excel(self): + data = { + "Target Language": [self.TargLang], + "Vendor": [self.VendorName], + "E-mail": [self.VendorMail], + "Word rate": [self.WordRate], + "CAT-tool": [self.CatTool] + } + filename = "_".join([str(self.ProjectName), str(self.SourceLang)]) + df = pd.DataFrame(data) + if os.path.exists(f"{filename}.xlsx") != True: + df.to_excel(f"{filename}.xlsx", index=False, sheet_name="VendorData") + else: + with pd.ExcelWriter(f"{filename}.xlsx", 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) From 4e4212d6abbdfee1e82e5b9825863dae8cf9295d Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Sun, 21 May 2023 18:13:34 +0200 Subject: [PATCH 09/24] Update vendor_data --- vendor_data.py | 1 - 1 file changed, 1 deletion(-) diff --git a/vendor_data.py b/vendor_data.py index b6350c2..6d85c12 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -19,7 +19,6 @@ import re import pandas as pd import os -from openpyxl import load_workbook class VendorData: ProjectName = "Toyota MM24" #Class attribute no.1, the project the vendors will be working on From 1fac65aa610a294277ddc010779999fd394437a0 Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Tue, 23 May 2023 08:43:37 +0200 Subject: [PATCH 10/24] Update vendor_data --- vendor_data.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/vendor_data.py b/vendor_data.py index 6d85c12..2d86382 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -19,11 +19,13 @@ import re import pandas as pd import os +import pyinputplus as pyip class VendorData: ProjectName = "Toyota MM24" #Class attribute no.1, the project the vendors will be working on SourceLang = "English" #Class attribute no.2, the source language CatTools = ["XTM", "Trados Studio", "MemoQ", "Memsource"] #Class attribute no.3, the list of possible Cat Tools + Status = "Potential" def __init__(self, VendorName, TargLang, WordRate, VendorMail = "", CatTool = "XTM"): """ Instantiate @@ -106,8 +108,10 @@ def to_excel(self): else: with pd.ExcelWriter(f"{filename}.xlsx", 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) + class PrefVendor(VendorData): Preferred = True + Status = "Preferred" """ Class Attribute: Preffered (bool.) by default set to "True" indicating this is a Preferred Vendor, if "False" it is a back-up vendor.""" @@ -130,6 +134,13 @@ def to_excel(self): with pd.ExcelWriter(f"{filename}.xlsx", 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) + def change_status(self): + self.Preferred = False + if self.Preferred == True: + self.Status = "Preferred" + else: + self.Status = "Back-Up" + # don't forget to properly dcument them with docstrings!! From 46317bac5032308e9ec83a69128a4876529fbe33 Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Sat, 27 May 2023 16:24:03 +0200 Subject: [PATCH 11/24] Update vendor_data.py --- vendor_data.py | 165 +++++++++++++++++++++++++++++-------------------- 1 file changed, 98 insertions(+), 67 deletions(-) diff --git a/vendor_data.py b/vendor_data.py index 2d86382..bab5df2 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -4,15 +4,16 @@ The script contains three classes: 1. The main parent class ´VendorData´. This class is meant for a general potential vendor profile, without assigning a status (preferred/back-up). - It has 3 class arguments ´ProjectName´, representing the project name and ´SourceLang´, the source language the translators will be translating from and ´CatTools´, the possible Cat Tools the translator can use. + It has 4 class attributes ´ProjectName´, representing the project name and ´SourceLang´, the source language the translators will be translating from (by default set to English), + ´CatTools´, the possible Cat Tools the translator can use and ´Status´ which is by default set to "Potential". It takes 5 arguments: - ´VendorName´: The first and last name of the vendor. - ´TargLang´: the language the translators will be translating into. - ´WordRate´: the translator's word rate in Euro. - ´VendorMail´: The vendor's email address. - ´CatTool´: the vendor's preferred cat tool. - 2. The subclass ´PrefVendor´, for the preferred vendors. They are assigned the status "Preferred". - 3. The subclass ´BackupVendor´ for the back-up vendors. They are assigned the status "Back-up" + 2. The subclass ´PrefVendor´, for the preferred vendors, that has 2 class attributes: ´Preferred´ by default set to True, and ´Status´ by default set to "Preferred". + It is possible to change those values using the change_status function. """ import argparse @@ -25,9 +26,9 @@ class VendorData: ProjectName = "Toyota MM24" #Class attribute no.1, the project the vendors will be working on SourceLang = "English" #Class attribute no.2, the source language CatTools = ["XTM", "Trados Studio", "MemoQ", "Memsource"] #Class attribute no.3, the list of possible Cat Tools - Status = "Potential" + Preference = [True, False, None] - def __init__(self, VendorName, TargLang, WordRate, VendorMail = "", CatTool = "XTM"): + def __init__(self, VendorName, TargLang, WordRate = None, Preferred = None, VendorMail = "", CatTool = "XTM"): """ Instantiate Args: "VendorName" (str): First and last name of the vendor @@ -35,16 +36,7 @@ def __init__(self, VendorName, TargLang, WordRate, VendorMail = "", CatTool = "X "TargLang" (str): Language the vendor will be translating to "WordRate" (float): Vendor's word rate for new words in Euro "CatTool" (str): Vendor's preferred CAT-tool - """ - self.VendorName = VendorName - self.TargLang = TargLang - self.WordRate = WordRate - self.VendorMail = VendorMail - self.CatTool = CatTool - - regex_mail = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" #regex used to validate email - - + """ """ Exceptions: VendorName should be a string, if not a TypeError is raised. @@ -56,75 +48,104 @@ def __init__(self, VendorName, TargLang, WordRate, VendorMail = "", CatTool = "X CatTool should be a string, if not a TypeError is raised. CatTool should be one of the options in the list "CatTools", if not a ValueError is raised. """ + regex_mail = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" #regex used to validate email if type(VendorName) !=str: raise TypeError("VendorName should be a string!") + else: + self.VendorName = VendorName + if type(TargLang) != str: raise TypeError("TargLang should be a string!") - if type(WordRate) != float: - raise TypeError("WordRate should be a float!") + else: + self.TargLang = TargLang + if WordRate: + if type(WordRate) != float: + raise TypeError("WordRate should be a float!") if WordRate > 0.15: raise ValueError("This vendor is too expensive, consider another one.") - elif WordRate == 0.00: - raise ValueError("Word rate cannot be 0.00.") + if WordRate == 0.00: + raise ValueError("Word rate cannot be 0.00.") else: self.WordRate = WordRate - if type(CatTool) != str: - raise TypeError("CatTool should be a string!") - if type(VendorMail) != str: - raise TypeError ("VendorMail should be a string!") - if VendorMail: + + if Preferred in VendorData.Preference: + self.Preferred = Preferred + else: + raise ValueError("Run 'VendorData.Preference' to check options!") + if Preferred == True: + self.Status = "Preferred" + elif Preferred == False: + self.Status = "Back-up" + else: + self.Status = "Potential" + + if VendorMail: + if type(VendorMail) != str: + raise TypeError ("VendorMail should be a string!") if(re.search(regex_mail,VendorMail)): self.VendorMail = VendorMail else: raise ValueError("Please insert a valid email address.") else: self.VendorMail = VendorMail + + if type(CatTool) != str: + raise TypeError("CatTool should be a string!") + else: + self.CatTool = CatTool if CatTool in VendorData.CatTools: self.CatTool = CatTool else: raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") + + def set_wordrate(self, NewRate): + if type(NewRate) != float: + raise TypeError("WordRate should be a float!") + elif NewRate > 0.15: + raise ValueError("This vendor is too expensive, consider another one.") + elif NewRate == 0.00: + raise ValueError("Word rate cannot be 0.00.") + else: + self.WordRate = NewRate + + def set_status(self, PrefVend): + if PrefVend in VendorData.Preference: + PrefVend = PrefVend + else: + raise ValueError("Run 'VendorData.Preference' to check options!") + if PrefVend == True: + self.Status = "Preferred" + elif PrefVend == False: + self.Status = "Back-up" + else: + self.Status = "Potential" def set_mail(self,mail): regex_mail = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" #regex used to validate email if (re.search(regex_mail,mail)): self.VendorMail = mail else: - raise ValueError("Please insert a valid email address.") - - def to_excel(self): - data = { - "Target Language": [self.TargLang], - "Vendor": [self.VendorName], - "E-mail": [self.VendorMail], - "Word rate": [self.WordRate], - "CAT-tool": [self.CatTool] - } - filename = "_".join([str(self.ProjectName), str(self.SourceLang)]) - df = pd.DataFrame(data) - if os.path.exists(f"{filename}.xlsx") != True: - df.to_excel(f"{filename}.xlsx", index=False, sheet_name="VendorData") - else: - with pd.ExcelWriter(f"{filename}.xlsx", 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) - -class PrefVendor(VendorData): - Preferred = True - Status = "Preferred" - """ Class Attribute: - Preffered (bool.) by default set to "True" indicating this is a Preferred Vendor, if "False" it is a back-up vendor.""" + raise ValueError("Please insert a valid email address.") - def __init__(self, VendorName, TargLang, WordRate, VendorMail="", CatTool = "XTM"): - super().__init__(VendorName, TargLang, WordRate, VendorMail, CatTool) + def change_tool (self, tool): + if type(tool) != str: + raise TypeError("CatTool should be a string!") + elif tool not in VendorData.CatTools: + raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") + else: + self.CatTool = tool + def to_excel(self): data = { "Target Language": [self.TargLang], "Vendor": [self.VendorName], + "Word Rate": [self.WordRate], + "Status": [self.Status], "E-mail": [self.VendorMail], - "Word rate": [self.WordRate], - "CAT-tool": [self.CatTool] + "CAT Tool": [self.CatTool] } filename = "_".join([str(self.ProjectName), str(self.SourceLang)]) df = pd.DataFrame(data) @@ -134,23 +155,33 @@ def to_excel(self): with pd.ExcelWriter(f"{filename}.xlsx", 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) - def change_status(self): - self.Preferred = False - if self.Preferred == True: - self.Status = "Preferred" - else: - self.Status = "Back-Up" - - - # don't forget to properly dcument them with docstrings!! if __name__ == "__main__": - parser = argparse.ArgumentParser("docstring") - parser.add_argument("VendorName", type=str, help="Vendor's name") - parser.add_argument("TargLang", type=str, help="Language the vendor will be translating into") - parser.add_argument("--WordRate", type=float, help="The vendor's word rate in Euro") - parser.add_argument("--VendorMail", type=str, help="The vendor's email address") - parser.add_argument("--CatTool", type=str, help="The CAT-tool the vendor wants to use") + parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser() + parser.add_argument("-a", "--add", action='store_true', help = "Add a vendor") + parser.add_argument ("-m", "--modify", action='store_true', help = "Modify an existing vendor") args = parser.parse_args() - Vndr = VendorData(args.VendorName, args.TargLang, args.WordRate, args.VendorMail, args.CatTool) + + if args.add == True: + done = "no" + VendorName = "" + TargLang = "" + WordRate = None + Preferred = None + VendorMail = "" + CatTool = "" + while done.lower() != "yes": + VendorName = pyip.inputStr(f"What's the vendor's name? (Previous value: {VendorName}) ") + TargLang = pyip.inputStr(f"Into which language will the vendor translate? (Previous value: {TargLang}) ") + WordRate = pyip.inputNum(f"What is the vendor's word rate in EUR? (Previous value: {WordRate}) ", blank = True) + Preferred = pyip.inputBool(f"True or False: Is this vendor a preferred vendor? If neither, leave blank. (Previous value: {Preferred}) ", blank = True) + VendorMail = pyip.inputStr(f"What is the vendor's email address? (Previous value: {VendorMail}) ", blank = True) + CatTool= pyip.inputStr(f"In which tool will the vendor be working? (Previous value: {CatTool}) ", blank = True) + done = pyip.inputStr("Are you done? ") + if done.lower() == "yes": + Vndr=VendorData(VendorName, TargLang, WordRate, Preferred, VendorMail, CatTool) + Excel = pyip.inputStr(f"Do you want add this vendor to the excel file?") + if Excel.lower() == "yes": + Vndr.to_excel() \ No newline at end of file From 4585991d12303afa89fae8bbabe8fb0455dd76ae Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Sat, 27 May 2023 16:55:22 +0200 Subject: [PATCH 12/24] Update vendor_data --- vendor_data.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/vendor_data.py b/vendor_data.py index bab5df2..34e2be6 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -142,10 +142,9 @@ def to_excel(self): data = { "Target Language": [self.TargLang], "Vendor": [self.VendorName], - "Word Rate": [self.WordRate], - "Status": [self.Status], "E-mail": [self.VendorMail], - "CAT Tool": [self.CatTool] + "CAT Tool": [self.CatTool], + "Status": [self.Status], } filename = "_".join([str(self.ProjectName), str(self.SourceLang)]) df = pd.DataFrame(data) @@ -166,19 +165,13 @@ def to_excel(self): if args.add == True: done = "no" - VendorName = "" - TargLang = "" - WordRate = None - Preferred = None - VendorMail = "" - CatTool = "" while done.lower() != "yes": - VendorName = pyip.inputStr(f"What's the vendor's name? (Previous value: {VendorName}) ") - TargLang = pyip.inputStr(f"Into which language will the vendor translate? (Previous value: {TargLang}) ") - WordRate = pyip.inputNum(f"What is the vendor's word rate in EUR? (Previous value: {WordRate}) ", blank = True) - Preferred = pyip.inputBool(f"True or False: Is this vendor a preferred vendor? If neither, leave blank. (Previous value: {Preferred}) ", blank = True) - VendorMail = pyip.inputStr(f"What is the vendor's email address? (Previous value: {VendorMail}) ", blank = True) - CatTool= pyip.inputStr(f"In which tool will the vendor be working? (Previous value: {CatTool}) ", blank = True) + VendorName = pyip.inputStr(f"What's the vendor's name?") + TargLang = pyip.inputStr(f"Into which language will the vendor translate?") + WordRate = pyip.inputNum(f"What is the vendor's word rate in EUR?", blank = True, default=None) + Preferred = pyip.inputBool(f"True or False: Is this vendor a preferred vendor? If neither, leave blank.", blank = True, default=None) + VendorMail = pyip.inputStr(f"What is the vendor's email address?", blank = True, default="") + CatTool= pyip.inputStr(f"In which tool will the vendor be working?", blank = True, default = "XTM") done = pyip.inputStr("Are you done? ") if done.lower() == "yes": Vndr=VendorData(VendorName, TargLang, WordRate, Preferred, VendorMail, CatTool) From e101c0f424f68310b9b75b22dafdec39e786d7ff Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Sat, 27 May 2023 17:31:33 +0200 Subject: [PATCH 13/24] Update vendor_data --- vendor_data.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/vendor_data.py b/vendor_data.py index 34e2be6..c1c30ea 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -26,7 +26,6 @@ class VendorData: ProjectName = "Toyota MM24" #Class attribute no.1, the project the vendors will be working on SourceLang = "English" #Class attribute no.2, the source language CatTools = ["XTM", "Trados Studio", "MemoQ", "Memsource"] #Class attribute no.3, the list of possible Cat Tools - Preference = [True, False, None] def __init__(self, VendorName, TargLang, WordRate = None, Preferred = None, VendorMail = "", CatTool = "XTM"): """ Instantiate @@ -70,14 +69,11 @@ def __init__(self, VendorName, TargLang, WordRate = None, Preferred = None, Vend else: self.WordRate = WordRate - if Preferred in VendorData.Preference: - self.Preferred = Preferred - else: - raise ValueError("Run 'VendorData.Preference' to check options!") - if Preferred == True: - self.Status = "Preferred" - elif Preferred == False: - self.Status = "Back-up" + if Preferred != None: + if Preferred == True: + self.Status = "Preferred" + elif Preferred == False: + self.Status = "Back-up" else: self.Status = "Potential" @@ -138,13 +134,14 @@ def change_tool (self, tool): self.CatTool = tool - def to_excel(self): + def to_excel (self): data = { "Target Language": [self.TargLang], "Vendor": [self.VendorName], "E-mail": [self.VendorMail], "CAT Tool": [self.CatTool], - "Status": [self.Status], + "Word Rate": [self.WordRate], + "Status": [self.Status] } filename = "_".join([str(self.ProjectName), str(self.SourceLang)]) df = pd.DataFrame(data) @@ -165,13 +162,21 @@ def to_excel(self): if args.add == True: done = "no" + WordRate = None + Preferred = None + VendorMail = "" + CatTool = "XTM" while done.lower() != "yes": VendorName = pyip.inputStr(f"What's the vendor's name?") TargLang = pyip.inputStr(f"Into which language will the vendor translate?") - WordRate = pyip.inputNum(f"What is the vendor's word rate in EUR?", blank = True, default=None) - Preferred = pyip.inputBool(f"True or False: Is this vendor a preferred vendor? If neither, leave blank.", blank = True, default=None) - VendorMail = pyip.inputStr(f"What is the vendor's email address?", blank = True, default="") - CatTool= pyip.inputStr(f"In which tool will the vendor be working?", blank = True, default = "XTM") + NewWordRate = pyip.inputNum(f"What is the vendor's word rate in EUR?", blank = True) + VendorWordRate = NewWordRate if NewWordRate else WordRate + NewPreferred = pyip.inputBool(f"True or False: Is this vendor a preferred vendor? If neither, leave blank.", blank = True, default=None) + Preferred = NewPreferred if NewPreferred else Preferred + NewVendorMail = pyip.inputStr(f"What is the vendor's email address?", blank = True, default="") + VendorMail = NewVendorMail if NewVendorMail else VendorMail + NewCatTool= pyip.inputStr(f"In which tool will the vendor be working?", blank = True, default = "XTM") + CatTool = NewCatTool if NewCatTool else CatTool done = pyip.inputStr("Are you done? ") if done.lower() == "yes": Vndr=VendorData(VendorName, TargLang, WordRate, Preferred, VendorMail, CatTool) From f6557b7ea1facf4ca73f1ef0f22249aba2e3e90f Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Sun, 28 May 2023 16:40:00 +0200 Subject: [PATCH 14/24] Update README & vendor_data --- README.md | 10 +++++----- vendor_data.py | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 3da6bf5..971697b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ You can import the script as a module by adding the repository to your path in a ```python import sys sys.path.append('/path/to/intro_machine_learning_using_python') -import script as s +import vendor_data as vd ``` Check out `tutorial.md` to see an example of the different functionalities of the script! @@ -25,19 +25,19 @@ Check out `tutorial.md` to see an example of the different functionalities of th You can also run the script directly with the following code in a console: ```sh -python script.py +python vendor_data.py ``` Or in Jupyter notebook with: ```python -%run script.py +%run vendor_data.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 +python vendor_data.py --help ``` -If you run this script, you become proud of yourself. +If you run this script, you can easily write an excel file that gives an overview of the vendors working on the project. The excel file will be named after the project name and the source language: projectname_sourcelanguage.xlsx diff --git a/vendor_data.py b/vendor_data.py index c1c30ea..cd4df03 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -23,11 +23,9 @@ import pyinputplus as pyip class VendorData: - ProjectName = "Toyota MM24" #Class attribute no.1, the project the vendors will be working on - SourceLang = "English" #Class attribute no.2, the source language - CatTools = ["XTM", "Trados Studio", "MemoQ", "Memsource"] #Class attribute no.3, the list of possible Cat Tools + CatTools = ["XTM", "Trados Studio", "MemoQ", "Memsource"] - def __init__(self, VendorName, TargLang, WordRate = None, Preferred = None, VendorMail = "", CatTool = "XTM"): + def __init__(self, ProjectName, SourceLang, VendorName, TargLang, WordRate = None, Preferred = None, VendorMail = "", CatTool = "XTM"): """ Instantiate Args: "VendorName" (str): First and last name of the vendor @@ -49,6 +47,15 @@ def __init__(self, VendorName, TargLang, WordRate = None, Preferred = None, Vend """ regex_mail = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" #regex used to validate email + + if type(ProjectName) != str: + raise TypeError("ProjectName should be a string!") + else: + self.ProjectName = ProjectName + if type(SourceLang) != str: + raise TypeError("SourceLang should be a string!") + else: + self.SourceLang = SourceLang if type(VendorName) !=str: raise TypeError("VendorName should be a string!") else: @@ -63,7 +70,7 @@ def __init__(self, VendorName, TargLang, WordRate = None, Preferred = None, Vend if type(WordRate) != float: raise TypeError("WordRate should be a float!") if WordRate > 0.15: - raise ValueError("This vendor is too expensive, consider another one.") + raise ValueError("This vendor is too expensive, pick another one.") if WordRate == 0.00: raise ValueError("Word rate cannot be 0.00.") else: @@ -143,18 +150,17 @@ def to_excel (self): "Word Rate": [self.WordRate], "Status": [self.Status] } - filename = "_".join([str(self.ProjectName), str(self.SourceLang)]) + filename = "_".join([str(self.ProjectName), str(self.SourceLang)]) + ".xlsx" df = pd.DataFrame(data) - if os.path.exists(f"{filename}.xlsx") != True: - df.to_excel(f"{filename}.xlsx", index=False, sheet_name="VendorData") + if os.path.exists(filename) != True: + df.to_excel(filename, index=False, sheet_name="VendorData") else: - with pd.ExcelWriter(f"{filename}.xlsx", mode="a", engine="openpyxl", if_sheet_exists="overlay") as writer: + 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) # don't forget to properly dcument them with docstrings!! if __name__ == "__main__": - parser = argparse.ArgumentParser() parser = argparse.ArgumentParser() parser.add_argument("-a", "--add", action='store_true', help = "Add a vendor") parser.add_argument ("-m", "--modify", action='store_true', help = "Modify an existing vendor") @@ -167,19 +173,21 @@ def to_excel (self): VendorMail = "" CatTool = "XTM" while done.lower() != "yes": - VendorName = pyip.inputStr(f"What's the vendor's name?") - TargLang = pyip.inputStr(f"Into which language will the vendor translate?") - NewWordRate = pyip.inputNum(f"What is the vendor's word rate in EUR?", blank = True) + 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? ") + NewWordRate = pyip.inputNum("What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor.", blank = True) VendorWordRate = NewWordRate if NewWordRate else WordRate - NewPreferred = pyip.inputBool(f"True or False: Is this vendor a preferred vendor? If neither, leave blank.", blank = True, default=None) + 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 - NewVendorMail = pyip.inputStr(f"What is the vendor's email address?", blank = True, default="") + NewVendorMail = pyip.inputStr("What is the vendor's email address? ", blank = True, default="") VendorMail = NewVendorMail if NewVendorMail else VendorMail - NewCatTool= pyip.inputStr(f"In which tool will the vendor be working?", blank = True, default = "XTM") + NewCatTool= pyip.inputMenu(["XTM", "Trados Studio", "MemoQ", "MemSource"], prompt = "In which tool will the vendor be working?", blank = True, default = "XTM") CatTool = NewCatTool if NewCatTool else CatTool done = pyip.inputStr("Are you done? ") if done.lower() == "yes": - Vndr=VendorData(VendorName, TargLang, WordRate, Preferred, VendorMail, CatTool) - Excel = pyip.inputStr(f"Do you want add this vendor to the excel file?") + Vndr=VendorData(ProjectName, SourceLang, VendorName, TargLang, WordRate, Preferred, VendorMail, CatTool) + Excel = pyip.inputStr("Do you want add this vendor to the excel file? ") if Excel.lower() == "yes": Vndr.to_excel() \ No newline at end of file From 4a2a485d4bc10a0d6f838084ab94f07e62ae42dc Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Mon, 29 May 2023 16:38:35 +0200 Subject: [PATCH 15/24] Update vendor_data --- vendor_data.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/vendor_data.py b/vendor_data.py index cd4df03..5bfd25e 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -22,6 +22,13 @@ import os import pyinputplus as pyip +def change_dictionary_value(dictionary, key, index, new_value): + if key in dictionary and index in dictionary[key]: + dictionary[key][index] = new_value + return True + else: + return False + class VendorData: CatTools = ["XTM", "Trados Studio", "MemoQ", "Memsource"] @@ -177,17 +184,62 @@ def to_excel (self): 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? ") - NewWordRate = pyip.inputNum("What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor.", blank = True) + NewWordRate = pyip.inputNum("What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor. ", blank = True) VendorWordRate = NewWordRate if NewWordRate else WordRate 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 NewVendorMail = pyip.inputStr("What is the vendor's email address? ", blank = True, default="") VendorMail = NewVendorMail if NewVendorMail else VendorMail - NewCatTool= pyip.inputMenu(["XTM", "Trados Studio", "MemoQ", "MemSource"], prompt = "In which tool will the vendor be working?", blank = True, default = "XTM") + NewCatTool= pyip.inputMenu(["XTM", "Trados Studio", "MemoQ", "Memsource"], prompt = "In which tool will the vendor be working?", blank = True, default = "XTM") CatTool = NewCatTool if NewCatTool else CatTool done = pyip.inputStr("Are you done? ") if done.lower() == "yes": Vndr=VendorData(ProjectName, SourceLang, VendorName, TargLang, WordRate, Preferred, VendorMail, CatTool) Excel = pyip.inputStr("Do you want add this vendor to the excel file? ") if Excel.lower() == "yes": - Vndr.to_excel() \ No newline at end of file + Vndr.to_excel() + if args.modify == True: + done = "no" + while done.lower() != "yes": + 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): + excel_records = pd.read_excel(filename) + excel_records_df = excel_records.loc[:, ~excel_records.columns.str.contains('^Unnamed')] + VendorDict=excel_records_df.to_dict() + + vendors = VendorDict["Vendor"] + print ("These are the vendor's already in the database: ") + for index, vendor_name in vendors.items(): + print(f"{index}: {vendor_name}") + + vendor_index = pyip.inputInt("Enter the index of the vendor you want to modify: ") + if vendor_index in vendors: + vendor_key = "Vendor" + email_key = "E-mail" + cat_tool_key = "CAT Tool" + word_rate_key = "Word Rate" + status_key = "Status" + + new_email = pyip.inputStr("What is the vendor's e-mail? ", blank = True) + new_cat_tool = pyip.inputMenu(["XTM", "Trados Studio", "MemoQ", "Memsource"], prompt = "In which tool will the vendor be working?", blank = True, default = "XTM") + new_word_rate = pyip.inputNum("What is the vendor's word rate? Should be between 0.01 and 0.15. If higher, choose another vendor. ", blank = True) + new_status = pyip.inputMenu(["Potential", "Preferred", "Back-up"], prompt = "What is the vendor's new status? ", blank = True) + done = pyip.inputStr("Are you done? ") + if done.lower() == "yes": + + if new_email: + change_dictionary_value(VendorDict, email_key, vendor_index, new_email) + if new_cat_tool: + change_dictionary_value(VendorDict, cat_tool_key, vendor_index, new_cat_tool) + if new_word_rate: + change_dictionary_value(VendorDict, word_rate_key, vendor_index, new_word_rate) + if new_status: + change_dictionary_value(VendorDict, status_key, vendor_index, new_status) + df = pd.DataFrame(VendorDict) + with pd.ExcelWriter(filename, engine="openpyxl", mode="a", if_sheet_exists="replace") as writer: + df.to_excel(writer, sheet_name = "VendorData", index=False) + print("This vendor is modified correctly.") + else: + print("A file for this project and this source language does not yet exist. Check the project name and source language.") \ No newline at end of file From 465b5f2bcae6bfca193561f25acbcf238658d815 Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Mon, 29 May 2023 16:40:34 +0200 Subject: [PATCH 16/24] Update vendor_data --- vendor_data.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vendor_data.py b/vendor_data.py index 5bfd25e..809a569 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -121,10 +121,6 @@ def set_wordrate(self, NewRate): self.WordRate = NewRate def set_status(self, PrefVend): - if PrefVend in VendorData.Preference: - PrefVend = PrefVend - else: - raise ValueError("Run 'VendorData.Preference' to check options!") if PrefVend == True: self.Status = "Preferred" elif PrefVend == False: From fe13379d757b61e8d2b9a0a6dc2dc7aa47dcbd66 Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Sat, 3 Jun 2023 13:05:15 +0200 Subject: [PATCH 17/24] Update vendor_data --- vendor_data.py | 282 ++++++++++++++++++++----------------------------- 1 file changed, 115 insertions(+), 167 deletions(-) diff --git a/vendor_data.py b/vendor_data.py index 809a569..696e166 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -1,150 +1,89 @@ #! /usr/bin/python -"""This script is meant to help Translation Project Managers with keeping a clear overview of the vendors participating in a project. - -The script contains three classes: - 1. The main parent class ´VendorData´. This class is meant for a general potential vendor profile, without assigning a status (preferred/back-up). - It has 4 class attributes ´ProjectName´, representing the project name and ´SourceLang´, the source language the translators will be translating from (by default set to English), - ´CatTools´, the possible Cat Tools the translator can use and ´Status´ which is by default set to "Potential". - It takes 5 arguments: - - ´VendorName´: The first and last name of the vendor. - - ´TargLang´: the language the translators will be translating into. - - ´WordRate´: the translator's word rate in Euro. - - ´VendorMail´: The vendor's email address. - - ´CatTool´: the vendor's preferred cat tool. - 2. The subclass ´PrefVendor´, for the preferred vendors, that has 2 class attributes: ´Preferred´ by default set to True, and ´Status´ by default set to "Preferred". - It is possible to change those values using the change_status function. -""" - import argparse import re import pandas as pd import os import pyinputplus as pyip -def change_dictionary_value(dictionary, key, index, new_value): - if key in dictionary and index in dictionary[key]: - dictionary[key][index] = new_value - return True - else: - return False +def ChangeDictionaryValue(Dictionary, Key, Index, NewValue): + if Key in Dictionary and Index in Dictionary[Key]: + Dictionary[Key][Index] = NewValue +def CheckVendorMail(VendorMail): + 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): + 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.") +def CheckCatTool(CatTool): + 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"] + CatTools = ["XTM", "Trados Studio", "MemoQ", "Memsource"] - def __init__(self, ProjectName, SourceLang, VendorName, TargLang, WordRate = None, Preferred = None, VendorMail = "", CatTool = "XTM"): - """ Instantiate - Args: - "VendorName" (str): First and last name of the vendor - "VendorMail" (str): the vendor's email address - "TargLang" (str): Language the vendor will be translating to - "WordRate" (float): Vendor's word rate for new words in Euro - "CatTool" (str): Vendor's preferred CAT-tool - """ - """ - Exceptions: - VendorName should be a string, if not a TypeError is raised. - TargLang should be a string, if not a TypeError is raised. - WordRate should be a float, if not a TypeError is raised. - WordRate should NOT be > 0.15, if not a ValueError is raised. - VendorMail should be a string, if not a TypeError is raised. - VendorMail should be an email, if not a ValueError is raised. - CatTool should be a string, if not a TypeError is raised. - CatTool should be one of the options in the list "CatTools", if not a ValueError is raised. - """ - regex_mail = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" #regex used to validate email - - + def __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail = "", WordRate = None, CatTool = "XTM", Preferred = None): if type(ProjectName) != str: raise TypeError("ProjectName should be a string!") - else: - self.ProjectName = ProjectName if type(SourceLang) != str: raise TypeError("SourceLang should be a string!") - else: - self.SourceLang = SourceLang - if type(VendorName) !=str: - raise TypeError("VendorName should be a string!") - else: - self.VendorName = VendorName - if type(TargLang) != str: raise TypeError("TargLang should be a string!") - else: - self.TargLang = TargLang - - if WordRate: - 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.") - else: - self.WordRate = WordRate - + if type(VendorName) !=str: + raise TypeError("VendorName should be a string!") + if VendorMail: + CheckVendorMail(VendorMail) + if WordRate != None: + CheckWordRate(WordRate) + if CatTool: + CheckCatTool(CatTool) if Preferred != None: - if Preferred == True: + if Preferred: self.Status = "Preferred" elif Preferred == False: self.Status = "Back-up" else: self.Status = "Potential" - if VendorMail: - if type(VendorMail) != str: - raise TypeError ("VendorMail should be a string!") - if(re.search(regex_mail,VendorMail)): - self.VendorMail = VendorMail - else: - raise ValueError("Please insert a valid email address.") - else: - self.VendorMail = VendorMail - - if type(CatTool) != str: - raise TypeError("CatTool should be a string!") - else: - self.CatTool = CatTool - if CatTool in VendorData.CatTools: - self.CatTool = CatTool - else: - raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") + self.ProjectName = ProjectName + self.SourceLang = SourceLang + self.VendorName = VendorName + self.TargLang = TargLang + self.WordRate = WordRate + self.VendorMail = VendorMail + self.CatTool = CatTool - def set_wordrate(self, NewRate): - if type(NewRate) != float: - raise TypeError("WordRate should be a float!") - elif NewRate > 0.15: - raise ValueError("This vendor is too expensive, consider another one.") - elif NewRate == 0.00: - raise ValueError("Word rate cannot be 0.00.") - else: - self.WordRate = NewRate - - def set_status(self, PrefVend): - if PrefVend == True: - self.Status = "Preferred" - elif PrefVend == False: - self.Status = "Back-up" - else: - self.Status = "Potential" - - def set_mail(self,mail): - regex_mail = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" #regex used to validate email - if (re.search(regex_mail,mail)): - self.VendorMail = mail - else: - raise ValueError("Please insert a valid email address.") + def SetVendorMail(self, NewMail): + CheckVendorMail(NewMail) + self.VendorMail = NewMail + + def SetWordRate(self, NewRate): + CheckWordRate(NewRate) + self.WordRate = NewRate - def change_tool (self, tool): - if type(tool) != str: - raise TypeError("CatTool should be a string!") - elif tool not in VendorData.CatTools: - raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") + def ChangeTool (self, NewTool): + CheckCatTool(NewTool) + self.CatTool = NewTool + + def SetStatus(self, PrefVend): + if PrefVend != None: + if PrefVend: + self.Status = "Preferred" + elif PrefVend == False: + self.Status = "Back-Up" else: - self.CatTool = tool - + self.Status = "Potential" - def to_excel (self): + def ToExcel(self): data = { "Target Language": [self.TargLang], "Vendor": [self.VendorName], @@ -155,21 +94,19 @@ def to_excel (self): } filename = "_".join([str(self.ProjectName), str(self.SourceLang)]) + ".xlsx" df = pd.DataFrame(data) - if os.path.exists(filename) != True: + if not os.path.exists(filename): df.to_excel(filename, index=False, sheet_name="VendorData") 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) -# don't forget to properly dcument them with docstrings!! - if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-a", "--add", action='store_true', help = "Add a vendor") parser.add_argument ("-m", "--modify", action='store_true', help = "Modify an existing vendor") args = parser.parse_args() - if args.add == True: + if args.add: done = "no" WordRate = None Preferred = None @@ -180,62 +117,73 @@ def to_excel (self): 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.inputNum("What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor. ", blank = True) - VendorWordRate = NewWordRate if NewWordRate else WordRate + if NewWordRate != None: + CheckWordRate(NewWordRate) + VendorWordRate = NewWordRate + else: + WordRate = WordRate 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 - NewVendorMail = pyip.inputStr("What is the vendor's email address? ", blank = True, default="") - VendorMail = NewVendorMail if NewVendorMail else VendorMail NewCatTool= pyip.inputMenu(["XTM", "Trados Studio", "MemoQ", "Memsource"], prompt = "In which tool will the vendor be working?", blank = True, default = "XTM") CatTool = NewCatTool if NewCatTool else CatTool + Preferred = NewPreferred if NewPreferred else Preferred done = pyip.inputStr("Are you done? ") - if done.lower() == "yes": - Vndr=VendorData(ProjectName, SourceLang, VendorName, TargLang, WordRate, Preferred, VendorMail, CatTool) - Excel = pyip.inputStr("Do you want add this vendor to the excel file? ") - if Excel.lower() == "yes": - Vndr.to_excel() - if args.modify == True: + + Vndr=VendorData(ProjectName, SourceLang, TargLang, VendorName, VendorMail, WordRate, CatTool, Preferred) + Excel = pyip.inputStr("Do you want to add this vendor to the excel file? ") + if Excel.lower() == "yes": + Vndr.ToExcel() + if args.modify: done = "no" while done.lower() != "yes": 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): - excel_records = pd.read_excel(filename) - excel_records_df = excel_records.loc[:, ~excel_records.columns.str.contains('^Unnamed')] - VendorDict=excel_records_df.to_dict() + 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"] + Vendors = VendorDict["Vendor"] print ("These are the vendor's already in the database: ") - for index, vendor_name in vendors.items(): - print(f"{index}: {vendor_name}") + for index, VendorName in Vendors.items(): + print(f"{index}: {VendorName}") - vendor_index = pyip.inputInt("Enter the index of the vendor you want to modify: ") - if vendor_index in vendors: - vendor_key = "Vendor" - email_key = "E-mail" - cat_tool_key = "CAT Tool" - word_rate_key = "Word Rate" - status_key = "Status" + 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" - new_email = pyip.inputStr("What is the vendor's e-mail? ", blank = True) - new_cat_tool = pyip.inputMenu(["XTM", "Trados Studio", "MemoQ", "Memsource"], prompt = "In which tool will the vendor be working?", blank = True, default = "XTM") - new_word_rate = pyip.inputNum("What is the vendor's word rate? Should be between 0.01 and 0.15. If higher, choose another vendor. ", blank = True) - new_status = pyip.inputMenu(["Potential", "Preferred", "Back-up"], prompt = "What is the vendor's new status? ", blank = True) + NewEmail = pyip.inputStr("What is the vendor's e-mail? ", blank = True) + if NewEmail: + CheckVendorMail(NewEmail) + NewWordRate = pyip.inputNum("What is the vendor's word rate? Should be between 0.01 and 0.15. If higher, choose another vendor. ", blank = True) + if NewWordRate != None: + CheckWordRate(NewWordRate) + NewCatTool = pyip.inputMenu(["XTM", "Trados Studio", "MemoQ", "Memsource"], prompt = "In which tool will the vendor be working?", blank = True, default = "XTM") + NewStatus = pyip.inputMenu(["Potential", "Preferred", "Back-up"], prompt = "What is the vendor's new status? ", blank = True) done = pyip.inputStr("Are you done? ") - if done.lower() == "yes": - - if new_email: - change_dictionary_value(VendorDict, email_key, vendor_index, new_email) - if new_cat_tool: - change_dictionary_value(VendorDict, cat_tool_key, vendor_index, new_cat_tool) - if new_word_rate: - change_dictionary_value(VendorDict, word_rate_key, vendor_index, new_word_rate) - if new_status: - change_dictionary_value(VendorDict, status_key, vendor_index, new_status) - df = pd.DataFrame(VendorDict) - with pd.ExcelWriter(filename, engine="openpyxl", mode="a", if_sheet_exists="replace") as writer: - df.to_excel(writer, sheet_name = "VendorData", index=False) - print("This vendor is modified correctly.") else: - print("A file for this project and this source language does not yet exist. Check the project name and source language.") \ No newline at end of file + 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) + with pd.ExcelWriter(FileName, engine="openpyxl", mode="w") as writer: + df.to_excel(writer, sheet_name = "VendorData", index=False) + print("This vendor is modified correctly.") \ No newline at end of file From 4ede2b1ddc8d290a72b5f6e46ad8fdaf80708c01 Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Sat, 3 Jun 2023 16:57:19 +0200 Subject: [PATCH 18/24] Update vendor_data --- vendor_data.py | 247 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 209 insertions(+), 38 deletions(-) diff --git a/vendor_data.py b/vendor_data.py index 696e166..7601458 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -1,21 +1,70 @@ #! /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: + 1. `ProjectName` (str): the name of the translation project + 2. `SourceLang` (str): the source language, i.e. the language the translator will translate from + 3. `TargLang` (str): the target language, i.e. the language the translator will translate into + 4. `VendorName` (str): the translator's/vendor's name + 5. `VendorMail` (str): the vendor's e-mail address, by default empty + 6. `WordRate` (float): the vendor's word rate in EUR/word, by default set to "None" + 7. `CatTool` (str): the CAT Tool the translator will use, by default set to "XTM" + 8. `Preferred` (bool): indicates if a vendor is a preferred vendor or not, by default set to "None" + - `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 -import pandas as pd -import os -import pyinputplus as pyip +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 methods to make validation easier def ChangeDictionaryValue(Dictionary, Key, Index, NewValue): + """ChangeDictionaryValue, change values of a 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): + """CheckVendorMail, validate 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): + """CheckWordRate, validate 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 + """ if type(WordRate) != float: raise TypeError("WordRate should be a float!") if WordRate > 0.15: @@ -23,15 +72,50 @@ def CheckWordRate(WordRate): if WordRate == 0.00: raise ValueError("Word rate cannot be 0.00.") def CheckCatTool(CatTool): + """CheckCatTool, validate CatTOol + + 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 ["XTM", "Trados Studio", "MemoQ", "Memsource"] + """ if type(CatTool) != str: raise TypeError("CatTool should be a string!") - if not CatTool in VendorData.CatTools: + if not CatTool in ["XTM", "Trados Studio", "MemoQ", "Memsource"]: raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") - + class VendorData: - CatTools = ["XTM", "Trados Studio", "MemoQ", "Memsource"] + + 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: @@ -40,13 +124,13 @@ def __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail = " raise TypeError("TargLang should be a string!") if type(VendorName) !=str: raise TypeError("VendorName should be a string!") - if VendorMail: + if VendorMail: #validate e-mail address if one is provided CheckVendorMail(VendorMail) - if WordRate != None: + if WordRate != None: #validate word rate if one is provided CheckWordRate(WordRate) - if CatTool: + if CatTool: #validate CAT Tool if one is provided CheckCatTool(CatTool) - if Preferred != 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: @@ -63,18 +147,38 @@ def __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail = " self.CatTool = CatTool def SetVendorMail(self, NewMail): - CheckVendorMail(NewMail) - self.VendorMail = NewMail + """Method + + Args: + NewMail (str): a new e-mail address for a certain vendor + """ + CheckVendorMail(NewMail) #validate e-mail address + self.VendorMail = NewMail #value of VendorMail is changed def SetWordRate(self, NewRate): - CheckWordRate(NewRate) - self.WordRate = NewRate + """Method + + Args: + NewRate (float): a new word rate for a certain vendor + """ + CheckWordRate(NewRate) #validate new word rate + self.WordRate = NewRate #value of WordRate is changed def ChangeTool (self, NewTool): - CheckCatTool(NewTool) - self.CatTool = NewTool + """Method + + Args: + NewTool (str): a new tool for a certain vendor + """ + CheckCatTool(NewTool) #validate new CAT Tool + self.CatTool = NewTool #value of CatTool is changed def SetStatus(self, PrefVend): + """Method + + Args: + PrefVend (bool): new value for Preferred, has an influence on status + """ if PrefVend != None: if PrefVend: self.Status = "Preferred" @@ -83,8 +187,8 @@ def SetStatus(self, PrefVend): else: self.Status = "Potential" - def ToExcel(self): - data = { + def ToExcel(self): #method to write data to an excel file + Data = { #dump arguments provided in a dictionary "Target Language": [self.TargLang], "Vendor": [self.VendorName], "E-mail": [self.VendorMail], @@ -92,27 +196,86 @@ def ToExcel(self): "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") - else: - with pd.ExcelWriter(filename, mode="a", engine="openpyxl", if_sheet_exists="overlay") as writer: + FileName = "_".join([str(self.ProjectName), str(self.SourceLang)]) + ".xlsx" #the name of the excel file, based on arguments `ProjectName` and `SourceLang` + df = pd.DataFrame(Data) #make a panda dataframe out of the dictionary + if not os.path.exists(FileName): #check if the file exists, if not a new file is written + df.to_excel(FileName, index=False, sheet_name="VendorData") + else: #if file exists, the data is appended to the existing file + 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) + def ReadExcel(self): #method to read the file with filename {ProjectName_SourceLang} into a dictionary + FileName = "_".join([str(self.ProjectName), str(self.SourceLang)]) + ".xlsx" + ExcelRecords = pd.read_excel(FileName) #read filename + ExcelRecordsDf = ExcelRecords.loc[:, ~ExcelRecords.columns.str.contains('^Unnamed')] #remove any unnamed columns + VendorDict = ExcelRecordsDf.to_dict() #turn dataframe into a dictionary + return VendorDict #print the Dictionary + + def ModExcel(self, Key, Index, NewValue): + """Method to modify excel name + + Args: + Key (str): one of the modifiable keys in VendorData.Keys + Index (int): the index of the value that needs to be modified + NewValue : the new value of the index, 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 Index is not valid for a certain key + """ + 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() + if not Key in self.Keys: + raise ValueError("Invalid key, run 'VendorData.Keys' to see options.") + if not Index in VendorDict[Key]: + raise ValueError("Invalid index, run 'self.ReadExcel()' to see options") + if Key == "E-mail": #validate e-mail address if a value for the key E-mail is modified + CheckVendorMail(NewValue) + if Key == "Word Rate": #validate word rate if a value for the key Word Rate is modified + CheckWordRate(NewValue) + if Key == "CAT Tool": #validate CAT Tool if a value for the key CAT Tool is modified + CheckCatTool(NewValue) + if Key == "Status": #validate Status if a value for the key Status is modified + if not NewValue in VendorData.Statuses: + raise ValueError("Invalid status, run 'VendorData.Statuses' to see options") + ChangeDictionaryValue(VendorDict, Key, Index, NewValue) #change the dictionary value in the dictionary `VendorDict` using the arguments provided for the method ModExcel + df = pd.DataFrame(VendorDict) #turn VendorDict dictionary back into a panda DataFrame + with pd.ExcelWriter(FileName, engine="openpyxl", mode="w") as writer: + df.to_excel(writer, sheet_name = "VendorData", index=False) #overwrite the existing excel file 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 = "Add a vendor") parser.add_argument ("-m", "--modify", action='store_true', help = "Modify an existing vendor") args = parser.parse_args() if args.add: + """Action: add a vendor + + Prompts the user to provide the following data, validates it and writes it to an excel file with {ProjectName_SourceLang} as name: + 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". + """ done = "no" WordRate = None Preferred = None VendorMail = "" CatTool = "XTM" - while done.lower() != "yes": + 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? ") @@ -129,23 +292,30 @@ def ToExcel(self): VendorWordRate = NewWordRate else: WordRate = WordRate - NewPreferred = pyip.inputBool("True or False: Is this vendor a preferred vendor? If neither, leave blank. ", blank = True, default=None) - NewCatTool= pyip.inputMenu(["XTM", "Trados Studio", "MemoQ", "Memsource"], prompt = "In which tool will the vendor be working?", blank = True, default = "XTM") + 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? ") - + 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? ") + 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() + Vndr.ToExcel() #data written to excel if args.modify: + """Action: modify an existing vendor + """ done = "no" - while done.lower() != "yes": + while done.lower() != "yes": #Code underneath is run as long as value for done = no + """Provide ProjectName and SourceLang to look for the excel file + """ 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): + """If the file exists, excel file is read and turned into a dictionary + Prompts the user to choose the vendor for which certain values will be changed. + """ ExcelRecords = pd.read_excel(FileName) ExcelRecordsDf = ExcelRecords.loc[:, ~ExcelRecords.columns.str.contains('^Unnamed')] VendorDict=ExcelRecordsDf.to_dict() @@ -169,12 +339,13 @@ def ToExcel(self): NewWordRate = pyip.inputNum("What is the vendor's word rate? Should be between 0.01 and 0.15. If higher, choose another vendor. ", blank = True) if NewWordRate != None: CheckWordRate(NewWordRate) - NewCatTool = pyip.inputMenu(["XTM", "Trados Studio", "MemoQ", "Memsource"], prompt = "In which tool will the vendor be working?", blank = True, default = "XTM") - NewStatus = pyip.inputMenu(["Potential", "Preferred", "Back-up"], prompt = "What is the vendor's new status? ", blank = True) + 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.") - + """Values for provided keys are changed + """ if NewEmail: ChangeDictionaryValue(VendorDict, EmailKey, VendorIndex, NewEmail) if NewWordRate: @@ -183,7 +354,7 @@ def ToExcel(self): ChangeDictionaryValue(VendorDict, CatToolKey, VendorIndex, NewCatTool) if NewStatus: ChangeDictionaryValue(VendorDict, StatusKey, VendorIndex, NewStatus) - df = pd.DataFrame(VendorDict) - with pd.ExcelWriter(FileName, engine="openpyxl", mode="w") as writer: + 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 From f5869e5687cf4a66f74fd0f0005613da0d1d8d88 Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Sun, 4 Jun 2023 13:12:55 +0200 Subject: [PATCH 19/24] General Update --- tutorial.ipynb | 601 +++++++++++++++++++++++++++++++++++++++++++++++++ tutorial.md | 5 - vendor_data.py | 31 ++- 3 files changed, 624 insertions(+), 13 deletions(-) create mode 100644 tutorial.ipynb delete mode 100644 tutorial.md diff --git a/tutorial.ipynb b/tutorial.ipynb new file mode 100644 index 0000000..445981e --- /dev/null +++ b/tutorial.ipynb @@ -0,0 +1,601 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "b251afbe", + "metadata": {}, + "source": [ + "# Tutorial: how to use `vendor_data.py`\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:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b3611132", + "metadata": {}, + "outputs": [], + "source": [ + "import sys\n", + "sys.path.append ('vendor_data.py') #this is the relative path to the script. If the script is not directly next to the notebook, it could be better to copy the full path of the notebook.\n", + "import vendor_data as vd # 'as vd' is not necessary but makes it shorter." + ] + }, + { + "cell_type": "markdown", + "id": "fa2cf4f7", + "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:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ade0148e", + "metadata": {}, + "outputs": [], + "source": [ + "help(vd)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6fb22b9", + "metadata": {}, + "outputs": [], + "source": [ + "?vd" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "803ee5b0", + "metadata": {}, + "outputs": [], + "source": [ + "vd.__doc__" + ] + }, + { + "cell_type": "markdown", + "id": "b9df49cf", + "metadata": {}, + "source": [ + "## Instantiating an instance of VendorData\n", + "Now that we know the different fucntionalities we can instantiate an instance of the class VendorData.\n", + "To illustrate the code to it's full extent, we'll instantiate a couple of them:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "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": null, + "id": "c6675ef0", + "metadata": {}, + "outputs": [], + "source": [ + "VendorNL.VendorName" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "23b52971", + "metadata": {}, + "outputs": [], + "source": [ + "VendorFR.VendorMail" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "69659b86", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.WordRate" + ] + }, + { + "cell_type": "markdown", + "id": "a831785f", + "metadata": {}, + "source": [ + "Some arguments had default arguments. When we check the e-mail for VendorNL, for which we didn't provide one, we'll see that it does not return anything:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cb2ca64c", + "metadata": {}, + "outputs": [], + "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": null, + "id": "c7180a19", + "metadata": {}, + "outputs": [], + "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": null, + "id": "e26d1539", + "metadata": {}, + "outputs": [], + "source": [ + "VendorFR.Preferred" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "935c0a38", + "metadata": {}, + "outputs": [], + "source": [ + "VendorFR.Status" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9ebc7f07", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.Preferred" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1158b1de", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.Status" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ab5e5f54", + "metadata": {}, + "outputs": [], + "source": [ + "VendorNL.Preferred #Will not return anything since value is None" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "50cd8967", + "metadata": {}, + "outputs": [], + "source": [ + "VendorNL.Status" + ] + }, + { + "cell_type": "markdown", + "id": "47936f2c", + "metadata": {}, + "source": [ + "## Functions\n", + "The class also contains a couple of functions:\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": null, + "id": "90cb5c10", + "metadata": {}, + "outputs": [], + "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": null, + "id": "730b35ca", + "metadata": {}, + "outputs": [], + "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": null, + "id": "391e7c5d", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.ChangeTool(\"Trados Studio\")\n", + "VendorES.CatTool" + ] + }, + { + "cell_type": "markdown", + "id": "574ef338", + "metadata": {}, + "source": [ + "Because we sat 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": null, + "id": "96819356", + "metadata": {}, + "outputs": [], + "source": [ + "VendorFR.SetStatus(False)\n", + "VendorFR.Preferred" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e8335217", + "metadata": {}, + "outputs": [], + "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 value for the argument `ProjectName` and `SourceLang`, they will be written to the same excel file. We should execute this function for every vendor. Be careful because if you run this function multiple times for the same vendor, it will not overwrite but append and you will have duplicates in the excel file." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aeafcb32", + "metadata": {}, + "outputs": [], + "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 function 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": null, + "id": "37124f32", + "metadata": {}, + "outputs": [], + "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 function without writing it to an excel file, 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": null, + "id": "10dc02d2", + "metadata": {}, + "outputs": [], + "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` function. Again, it does not matter for which vendor you call this function.\n", + "This function takes 3 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", + "2. The `Index`: if you have run the ReadExcel() function, you have noticed that before every value for a key in the dictionrary there's a number. By picking a number, you can change the value for that index.\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": null, + "id": "17292d31", + "metadata": {}, + "outputs": [], + "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": null, + "id": "abf2dc40", + "metadata": {}, + "outputs": [], + "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": null, + "id": "52e91ff2", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.ModExcel(\"CAT Tool\", 2, \"MemoQ\")" + ] + }, + { + "cell_type": "markdown", + "id": "cfec5fae", + "metadata": {}, + "source": [ + "If you check this by running `.CatTool`, the old value will still be there." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f4e539d4", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.CatTool" + ] + }, + { + "cell_type": "markdown", + "id": "85cc6b7f", + "metadata": {}, + "source": [ + "However, if we read the excel file again, we'll notice it has changed:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "072bbb59", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.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:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "854ef143", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(0.1, \"English\", \"German\", \"Thomas Zwiebel\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cd524417", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", 1, \"German\", \"Thomas Zwiebel\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6497db2", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", True, \"Thomas Zwiebel\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b01bfed", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", None)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "20b5cc03", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", 3)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7c32d39f", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = \"0.15\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "32715f64", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", Preferred = \"Test\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b74ce10", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", CatTool = True)" + ] + } + ], + "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.16" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/tutorial.md b/tutorial.md deleted file mode 100644 index 589872f..0000000 --- a/tutorial.md +++ /dev/null @@ -1,5 +0,0 @@ -# How to use my script - -In this notebook you will learn how to use the functions and classes defined in `script.py`. - -This will become a great tutorial. diff --git a/vendor_data.py b/vendor_data.py index 7601458..fd0f3d6 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -130,6 +130,9 @@ def __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail = " 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" @@ -145,6 +148,7 @@ def __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail = " self.WordRate = WordRate self.VendorMail = VendorMail self.CatTool = CatTool + self.Preferred = Preferred def SetVendorMail(self, NewMail): """Method @@ -180,12 +184,18 @@ def SetStatus(self, PrefVend): PrefVend (bool): new value for Preferred, has an influence on status """ if PrefVend != None: - if PrefVend: + 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.Status = "Back-Up" + self.Preferred = False + self.Status = "Back-up" else: - self.Status = "Potential" + self.Preferred = None + self.Status = "Potential" def ToExcel(self): #method to write data to an excel file Data = { #dump arguments provided in a dictionary @@ -205,13 +215,16 @@ def ToExcel(self): #method to write data to an excel file df.to_excel(writer, sheet_name = "VendorData", startrow=writer.sheets["VendorData"].max_row, header = None, index=False) def ReadExcel(self): #method to read the file with filename {ProjectName_SourceLang} into a dictionary FileName = "_".join([str(self.ProjectName), str(self.SourceLang)]) + ".xlsx" - ExcelRecords = pd.read_excel(FileName) #read filename - ExcelRecordsDf = ExcelRecords.loc[:, ~ExcelRecords.columns.str.contains('^Unnamed')] #remove any unnamed columns - VendorDict = ExcelRecordsDf.to_dict() #turn dataframe into a dictionary - return VendorDict #print the Dictionary + if os.path.exists(FileName): + ExcelRecords = pd.read_excel(FileName) #read filename + ExcelRecordsDf = ExcelRecords.loc[:, ~ExcelRecords.columns.str.contains('^Unnamed')] #remove any unnamed columns + VendorDict = ExcelRecordsDf.to_dict() #turn dataframe into a dictionary + return VendorDict #print the Dictionary + else: + raise ValueError(f"There is no file for {self.ProjectName} in {self.SourceLang}") def ModExcel(self, Key, Index, NewValue): - """Method to modify excel name + """Method to modify existing vendor in excel file Args: Key (str): one of the modifiable keys in VendorData.Keys @@ -244,6 +257,8 @@ def ModExcel(self, Key, Index, NewValue): df = pd.DataFrame(VendorDict) #turn VendorDict dictionary back into a panda DataFrame with pd.ExcelWriter(FileName, engine="openpyxl", mode="w") as writer: df.to_excel(writer, sheet_name = "VendorData", index=False) #overwrite the existing excel file + 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 From ee3cd4a57bf49be08134865c01f4a4392cc8efdf Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Sun, 4 Jun 2023 13:14:08 +0200 Subject: [PATCH 20/24] General Update --- README.md | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 971697b..4bf3481 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,17 @@ # Script: Translation Vendor Database -This repository contains a Python program that could help a translation agency to keep track of a vendor database. The idea is to make it easier for project managers to keep track of who the preferred and back-up vendors are for a project, in which languages they work, what their contact details and rates are and other information that might be useful for the PMs. +## The repository +This repository has been created by Elmo Geeraerts for the final assignment of an introductory class on python. -The code has been developed by Elmo Geeraerts. +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.json` file which allows the user to test out the code; +- 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 @@ -22,6 +28,7 @@ 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 @@ -40,4 +47,17 @@ In both cases `example.json` stands for the `filename` argument that the script python vendor_data.py --help ``` -If you run this script, you can easily write an excel file that gives an overview of the vendors working on the project. The excel file will be named after the project name and the source language: projectname_sourcelanguage.xlsx +## 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 specific vendors; +- Joining multiple excel files in the excel file created by this code. From 8d3baa4e66a9e67686916ae045580b4d5d40e3e8 Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Sun, 4 Jun 2023 17:26:53 +0200 Subject: [PATCH 21/24] General Update --- README.md | 10 +- TestProject_English.xlsx | Bin 0 -> 5083 bytes Tutorial_English.xlsx | Bin 0 -> 5214 bytes example.json | 0 tutorial.ipynb | 1484 ++++++++++++++++++++++++++++++++++-- tutorial.md | 1555 ++++++++++++++++++++++++++++++++++++++ vendor_data.py | 8 +- 7 files changed, 2974 insertions(+), 83 deletions(-) create mode 100644 TestProject_English.xlsx create mode 100644 Tutorial_English.xlsx delete mode 100644 example.json create mode 100644 tutorial.md diff --git a/README.md b/README.md index 4bf3481..c844a0b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This repository has been created by Elmo Geeraerts for the final assignment of a 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.json` file which allows the user to test out the code; +- Two `xlsx` files which were generated while creating the `tutorial.ipynb` file. Be aware that if you run the code in the tutorial notebook, some data will be duplicated in the excel if you do not change anything. To avoid this you can delete the two excel files from the directory or you can change the data in the tutorial code to fit your needs.; - The `vendor_data.py` file, i.e. the actual python script that can be run or imported as a module. ## Installation and usage @@ -32,16 +32,18 @@ Check out `tutorial.md` to see an example of the different functionalities of th You can also run the script directly with the following code in a console: ```sh -python vendor_data.py +python vendor_data.py <"-a/--add or -m/--modify"> ``` Or in Jupyter notebook with: ```python -%run vendor_data.py +%run vendor_data.py <"-a/--add or -m/--modify"> ``` -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: +Running vendor_data.py without either the argument -a (to add a new vendor) or -m (to modify an existing vendor) will not do anything. The argument -a prompts the user to add a new vendor. The data is provided by answering some questions regarding the vendor and the project. The argument -m prompts the user to modify an existing vendor. Again the data is provided by answering some questions regarding the vendor and the project. + +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 diff --git a/TestProject_English.xlsx b/TestProject_English.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..948563cae3a91444a840355ebfc9f0e8ece8266c GIT binary patch literal 5083 zcmZ`-2Q*yU`yD-cC(20F2&0$iQJ$I@B%)39nJ8f}ghA8@LUhrBsL{KK7R+ct7@g?R zMf509|C40BmG}JL@7{IqU3aa!zkAMJ``hO`pY9zzd^!LCa0P$}Ycn8H(zXh~zExl^ zD(nSyverd7IlBs3Iy(y@9UZhIcKPsL38ieM*nh9QlG2++C>p9#sqEV% zjf#S^IbBtoC9&a~FQ5^Oai(BcVvA=#;o9i7teu(ezlJ-|Xb9fI z4wD}j0HFToaIKvXu%F}YjYWZ5g~@`=36^GL9Nz=81QXf8*V#pg+XS>41+p}=+w!L; z;}S|}1BvFYo?uomu@GR;CZ|HDf(2Lj8r&^SM>#}5mYM)3`a5x&77TneCHH;cW;X^I zl<_@8hGRI@sfGP!wgw6xgjR-DN|>yMh8-hOEFb1tZN5E98t@0oe2>rIks+F@ zTwfe}4$vy)(?v_uIu#gxH)d_3jUc_S1UUeW3v-{|$LA(UBo5xS$nLh&?rj;IU8*NIzpg!+t#~-yDWJ(ZML!?C$PylYV z4cygzTBcMJHiwQKd>B27x%p0)`AW*ifPM8q_V%f=v;D+|t{gG1G#{D1$MJr4ML2mI z4X-hAr>?7uZ}Q^Cw3Yju8$rZ7C!7$=kQ;DWT7(R%jq+2>!9h$ewifqQhoDLpnj2B>YXOJDDCYlX~9YMx~#Z4 z#3Biq!AI2{#nf}OKJS~Ze4LF4JuGrckvGgV(wqo7qEcg?Pjy{(9dI}y%2gXUc+fbN zooGallX!JjyifwvK8k$RvQv^O2c)IxjVC2k3QpwWp(&8|)z+Xr=g*xuPaRU+ju+xO z){2R;tK!UargpsZwJPvTN98E8~hxDM3^7 zD=SzrNirkeF$C1O6a-nA&~ywS!GqP*r^dw+aS9e6zxBpE=^KrqppG@Wh5fcKJes&eItW^`W8rbvbtkySpM9cvcd8j_jsI^GRlXrVfRGcU~#hCa*kb(W1 z!VqzVd^S-Mf}J`xg(WW}$*qKrM%~gtZ=8#PiCgHRqretvKS3W%?pED*`OLxhw>W)l zP($I688tYh?W9y>VoY3+*V+)#`>|8MEbivG^qZD%XSNFII~&KJxq`}4j0HFuqVEJ$ zDRI@FhIeoCwGppEA>710`a`f=VKnK=Ebz7a`&zHYmdfgQYvmw|Yh{^k3Lwl6IrEk3 zUQ#iY_lP@RYvP;U@knWXulVE)X6qr7wULVj)_7z9B~A`Z-4{7?h3_Y-)G{kK;W^f) zP02{5C&ko}4Bd-%YW=a+j%1#f{)}JelVs?)GCnYHvVzhp&)$+t0CtA%X0dN(1}9-! zRYE+y&68|ib?A!IIXV<`fz;kx)Q;_d=;ojn0vSZl%Jgt|?>(>(fpp;UM`t~~`%-n) zc_s0o`NBZ#!sJ`nJ9ybm4<<*Bd(vpTBwCxI?ipAG>H!e*0J2-&WG`P$55}AumwbFf zMh#{lrO~jCXMC%bwa0Y7X@y_2?SWLYs#pz8;?>55 z2Ad6X)6j*LlM%2pA{Mr`;_N+Mjva#n9E0>lp(BjlDlbs-VhELSeeS)|2_Dktlk@t$ z4a`kE7I#{`;AsLkE+)-}<*OOx)%LQJ=h&)3Twi|kxzdjwE%sH5zBYQerWReTzr@noM=;^gsLhF~1 z@8afBbXFyAD@r;hM94h-jrPbgA4$!IsHQNBjf59VN02xvjVLbNo*X8(Js=lnjUg}- zNv@I1UIdfKO`UI%m!sPvzifmzIN9R9mn9H^XKB zi;LQ8M}xEzHikGBg2~29KM=egfsY@6ZRUimM2$d@TV3vOC>rpl{U>E^qP7*Prvi_X*vl zF3mRHZAl1;;-|`x@{$arn03pwNPLM+Kj2}G>{J}ZVNR#jXI-=Q?E_*1EzT1%3j!mA zNQ+PRF2`|>Wqfv|(&o@+32%P|P~v&p)rI$H!%&~MEEnHVCcK1Kz_NiuY>Dp(Xw}E_ zjtJ4^b@`h0t0h7+B<95X$>&qI+iJ;-N=}L;H7qnp=oipszF+&x*-qc^MOc$W&N#>& zJHHk_8N@fkMc4bFh`5xeDfnk^p@PYM&q5WZrLV~6ueW`^{cowvZR)BQV5=|&QUHMb zw^Ur+JRM-JKdX#sgUPT-VX8CwFO>OlNh!5$0g_a_)iBG$%rY%dC$2F9Ce3xSpBBTq zQkjywVNEN^);o|amcsPKbbqtB&6P9AI?rIO=`Qn1y^h_)7R$iy`Lnek!W_w(C5nWD z=z}!+#;-BMg>E9Rm+X3S!K3{0)sv(94o-v{-Oz-b^#_jMN2)Xe@oIJr$~g^Tm0z?r zi@$q&@{dT@GOmuZz(B6iVZ3qDUdLkqOe;wh>q7NCmhe7t-k{m(+B3rKC^kur+)XjO zPOlM{m7o!b5i-)FDPY{TIaO9;!{Uc$(^1kx;&U7hS!;gFEok855BIX%70Y+~=Z2C6 zRr{rf0`)X~g;P#g1z$pV_Dc9^#}wCuEZNei_6F$j**?Uz*(xr3XAX;P9vkbdVc5^^ z_bR_>HW;@G9%)Q+ULGK`MB^^Zs*zSWp#{%xg4P!YYK8Dp)lc@zP*OWkRRJAepTZkH ze8;Jw6uvW0zMdL)J%g)Com?X=H9SRIM^x<64?B|_&QVEPs#~T_WfL(k_P7>yGHWmG zwAb^WF2azW-HSvsnol0U8kG2M?AO{u9}u6tJ*S%40X{r#I4WG`o!lZ?H!-Wq z9a59zE^o=*VQP57(l;mf1}DSJ+xM4%~9M=8GH3$BvS!kdL&f&q+3$vw%`q~1e{l<@eoHouu<7U#+o|A? zd1T&qtXnAA0gqY9grnA+Re;E3@iwq}z|)T^of+D;I9XLc9Q8iA<_#2$AOdlcxDion~o27OC*!&KDrCgQ*cCES6I7*$Kd`xl1-lY+C z%Gc4~>K4f@cywFh-jD_P<3evDg-ChPacF-CLqmpW88F_Saz?i@^FFU9%(}y0FV%FU zoirZD>C>u<=%WlJ%4O~9!0mhYJ}iNN&-yl|&%P;jua@}GZB94GO5X2Vi!!)mk6di8 zvr4ec9${H#{>|`jHT{$4U&?wHBTw;6nCy8O%@RODw?Kv9uBj2fAQizLCk;(|Dam`G z=QzhUp0P~W31aYm?>8YT zPH;CE+|69y(;4P!`cq0JaoRtngq!Yv3g%6Q9SL2BxZW39tnbRK78GB_y)p3usm zp?|JjjGSr2q$d{7L{XQortOc%1NENL;XWV&TLC$crPb`xnx`o>99r+VV@4C(U zfSZUmPrC3+OvC3>)FYCQ-P$D7(iQlAooSq1(+{AW8ql|8NcPJ8ZzoD%$g`%H-i0$V zyIYF^Rz}O1BkvBz3zoheYV>CF?TW@xFtgus_?O#eepn`PaOnX5yAgxc%&)^A%kTeh z%UniZ?u-1!0s#IvW&cF~-6gpUzuY+Z1MkKD{y*9Xmjhfb9RChb6F_n0SAhR4BQHm} zTvPlV#UDqS5xuIWl2ftU15=25EcXp5d=gjDOnl>X zcC*)mxw(4^*}A(6!d;woUdWT;icsD9(c|&HMj54Ir!-(tUP<|gMJNWWTB-85NgDOi zmEG;K`YegVjW2~10%1lk=ego20rZTK)ga3^uB=IpdG@{l+2z>&=V(nWo1zi+0^+=s zC7pAM7wQ=>3ic8>Xz6Q(JLGCx9w!0$517kL;fTa0-(KRCu`OAsmEK?O4mO&AHnDE< z;{pKG|902j4F>t?Z(ke=)Fw<8W=*g-BjZxTmMxgX3F6=sA#NAYZWPGY%4sjaOvNXb z(1sArT|PlCqvI^tLN~Y-x)f}9qE=nK5V|Vi0p7Yzd|;~zxKhG=BM`DJg54sYcqPbGrNuo3H}z0c!}Gn3uC@VOixNxL-6S$Z)0N*A z#_#(y2ijCFJv7|XL7AL52^^Xiryg|gh0p3t>~*rQDM~hx^e{ZeJUzwzo1K(0jtvcL){vy?O(b8B)2V+ghYwsm=~vTOUXk+M-4L`}344~X1Go7kG&R;x zBQ!H-BFaOpEX?$#Y^#MN?~YZKITX+)70^vf(>5Ivb?G*ou6OL-oCUKG_t;nD6vj9d z>YR0118fsu1$0yzFw!@7v*ti9UJ*N_?=^~slTL8XVFL3h53=AgI^c&l#q_BuXwTgD~y)_TO(` z&v@Q5=_T&MJU71$m#Xd^igIVgpVMzhZ$*4}Zq8LEM&>{Vz!UqErLp;MqYZV34+3Vt zy>?6^iMG%ke&B-{ei6}GG5{xU+SUzkD~;$Z8u0oC<-2-T`XG0e!BIth{+k~Sebu7U zFbBZY-Fxig5MH9y_2Y*L%%9jAFv|C~OgE$>sLwk)@W-G-Oo`&^FhmRi1>k1;;2k~x zGUe*Xxz@O$dog3^>s5Npmr_3j?`ec^c1)L@?IksI=Zg6u0%ZChBm_c>aNevpyhg{L zdaf*Fyon#zQR#PY1QKtba9h}hUv-tGg~_lwsQ9Dz_ha*TMbVo_B;P=C4p)p5%PrC9 zh4kkz?gq@hX~4d&hAa1YVaq$N@dR}qwTuq}^$XNeRa)etw2GGyVaZNN(ngnx;!1W}}}S6uG6!n`D`4O@& zJMK4Le0?io%qaCTmWSbvLvnuS1V?ESB&@M4Y`6|A@6Nu;L*l+uzVyK(h!=$uR z*RwrL@z2t&+O$wBA-(s{Y9EJYV4HpHe6hx zfL)Y?V7rc8VbKpxax<~BQLi-Q5zddn$(yZ3haoM}fr0_(yv@4r@>xSQH@O2GP{UCc zGwQAu?I)!oljGuo*X&JTeIL4v%Hpq2NN2RHojEF`Z?7MJ;t4HFH51@wh`Am7PMN3n zG^%IoMmzBe*n*e1*Jv1WGm<7Kj zJvp|HWY{3at?g*F1J3+K`V)R#K(dL;^2Ffa$udg6JZDobk*(|5PB!O8R#-B+O*P#2 zk#(}et4=*}Iv3|+9-w-SP3`zLkZulaBalh-q)Z=o$KbAwh(#wJe@wRjo#$#R?#oH{ ztmg;g=BM%@Rjy^%eVAOh45VA3$+QkdJu{FB)Ll08U5lOaCMS6$JqUenR`MZ(j2gs1 zN~39?z?iR{y~||Sw9K#7epjklO{|(G>2l-zQkMtFu$IQVni5yEu0guc4UAD8!Wk`Kye=ghrZgK|-J+4{SsYU$&B%>1!yysYM(G~W(t z94|Fo?pLgY42+@+dK+;ugtRz)3Ej80a6`cPtU<}gr0;jg>aNrGmncXFssW#bfvkpj zY3L%$$p|>bp59bL{WJJzx9PwyG8XFdbt*5}lQHpOTruvs$7Bs^&gM z1w=*$Q5V@Y)tBiW@utZlA8iM7ygnV9%H7Azk@=4lndgD|sTFS%`Co}6w0~~#UEKO5 zon1+OMM>wR2$^q?=`LB;eW}@SwNz%Y(WqkSXc9N&QKd!2sS$F=eR6TuSOP1NlxoSG z1rUkc^!X-vd29QN&+AdmIDZ!q@Ajk^IJUGd5CH&}e-{uRH`oJDM+n5rQ|Q;@R~32s zY6>aQz8{FakP(CD?PvrXuHQtig1^gNIZXHan=2DN$Su--D z7y}Ofs?P`rJ7u`{)z;{;p;dcDKM9qQPdPr+VXOdOqPj@3LXdu-k%5@~paJ7kk$FcQ zYVfk}ZmJDLDqh&+mWhhqo&!FsPg?<_JmqwSj_tHk8XqsF1@~hOtkhY^^&X5*$tf)E znki*Y(M-qM$C5I}X|ajbCz2kq#Z*@;mpv7p*Ka7baEkQ@Pofz*Tk6CryAG=ko~H^R zw#v`e6pHL?DvArjM0SW0U)xVXjVe?ZR4!CB${;HlD#e^0k(j_huw6 zHKb~3Ky4Ec5O3Ld!NSRjhT1Hcq1g>B=e3AwqqKE$^>xAn4o@R?Os(Zj`3j#8^7UE` zuKra#w{K;@CQJR5Ud78g`78HN=8>xEIYz@E3lMD-9U{=!C zQ$JC9nlPJGqadT(i+T4c9|Jm&i>L|5S8??e=OE8%uNaG>@|Nqp9p2pJQQzE3~?X(233A@vD&>U$Gm)oSik z`E(-)Y0og>B6P(8SO}i%73E1G>12u{o(Ko28!e3xiRFfY`b|Jyt3$^oVd{C}se9RF>*Nf{C%%$i}W<1xcI3M^*$XTT{xNFi* zg4C?4Y2+|dz4qAW0j*+u>V%J7Up?Yr?5_N1!kZVUO3*WYaY8i=(3y#FkzwLUVsd?- z&15LGHT|66Z?(>C=xG#U)yhB$0FeJytEZQ*GsN>}qk}P?ikuRrI-~zgSrDI`TH78h zNp%egu|3Et(*}0on!zB_JSTgISk~pr)Vy_jT1oc4!4$Dnrq7mp8^!IO+@bbwj8~iP zFfZ5ZLMJy_26xV%tcDWiN>(pYB<{!TBj_8y#*V!85_!D{?ac#?@yjEp#`c`u2-kbS ziMikIx_lpfrx}7*y<=R?Z33zMti4hE{gE&KsB|sk$^;7p=ou4vEneF1cpQLkBYDR< zk2GM3>KDHjI*X}2Biwq)E~%NfA%@rGH|nt*I%;7Gf8o;q!n(hg6G$P z-xdaIh49iePWH-BQrloP0o}&|Z?6X2I8J*;@p$Ip*Hg3ZC$4HzCs#;IO-@_wqbqjk zN8Cvc=BOlXHEa>nIYi70y`FEom~|GnJL>sQ7a(xoo&};At%r9Z4azsJ?$tVh?-HNo zpHt0jv)wyxI4p0bk+_oZD5XWTZgN(QH@rI8Ti%wp)6(RGrGHK?!&T5x%Q7OqKyrSF z-FpUX6ZG|Pd-o*B`RwWoy|kbX>h^1FH}E29O%wWmc%}3DrU&WQ3FLf;TL5Z-Y&v41 ze;CMkfN(MnwW7FschcUj+^6lcQ5_XPZws+U_mDFsP~14PELn9OrrkMb)sqi!Qz?ia ziq}LWluB@I*K_7v`+~{$icx+ToXR%x^4r{<4r#M6%RE?)t8g?O!P7Zlr-L{;;_Jd; z^g(z%ubDBO2Yv;d&`g~Z&H@eX0eEJ{0CzW0;RpJDzPfqiKSIYZX5ggA2G$m=mT9rN z#>yIC4TCs)3JLzaBjV~@v0EFZz>a}*VWI)fXJU|T2K*x&<7~o<|HR zldrrS%``hyX5WZ z)1#cKVHIn%jQ%ZN!L+p$%V>wrUa{>8E}8q*{l|K5B|BYXm$O_^tM007@D%ZOkVdfo z2i2}j9Y>t(cSkPzA3fg;7LCG&CSi}suc@%bHpWCuaHq9x%AwXmarlv!n{P`@3lx0J z(gEAs6QdU*0JjD}X zvZrMS1*XGm$i|vJH*rSr<6+Kb$&_-yE=#k zuOQGgGoQtV)Y2WtUYEJ(Jl?^4Xi5w;shvqf|5T?KKGTR!Pb!{yNnO5z*qcaT)Ay&t zy-NhLW8;FCA~~hCPE)J7w5#GRs1AA;pXi}z;cu@!O87P^hJ?8l!dHD+bhdO-TI|f^ zqFX;YX*1!Xy!K-00_b<`#1WZLCr<@#o5Il zcpvun|7DVK(ZI#t^&bP(!4#K%8ThZA>_saVdy0Ro1mQH2{Ic?=!?*~&n7aQ!W3b)H zzY_UH;Kfw<2k1-jf1dx77%ze^M)@D`6gI75dHWwRf6>mxK>A~+1v?k~FJYy3n*cj% R0sx4yrvf&KlhFKp`wx1GC29Zw literal 0 HcmV?d00001 diff --git a/example.json b/example.json deleted file mode 100644 index e69de29..0000000 diff --git a/tutorial.ipynb b/tutorial.ipynb index 445981e..29f03e7 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -7,15 +7,17 @@ "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:" + "We'll begin with importing the code as module:" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "b3611132", "metadata": {}, "outputs": [], @@ -30,24 +32,192 @@ "id": "fa2cf4f7", "metadata": {}, "source": [ - "## Docstrings\n", + "### 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:" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "ade0148e", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on module vendor_data:\n", + "\n", + "NAME\n", + " vendor_data - 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.\n", + "\n", + "DESCRIPTION\n", + " It contains:\n", + " - 4 functions: \n", + " `ChangeDictionaryValue` to easily change values in a certain dictionary.\n", + " `CheckVendorMail` to easily check if an e-mail address is valid.\n", + " `CheckWordRate` to check if a word rate falls between EUR 0.01 and EUR 0.15 per word.\n", + " `CheckCatTool` to validate the CAT tool provided.\n", + " - 1 class, `VendorData` that has 3 class attributes: `CatTools`, the CAT Tools that can be used for the project,\n", + " `Keys`, the keys of the dictionary that can be modified, and `Statuses`, the possible statuses a vendor can have.\n", + " The class takes 4 positional arguments and 4 optional arguments:\n", + " 1. `ProjectName` (str): the name of the translation project\n", + " 2. `SourceLang` (str): the source language, i.e. the language the translator will translate from\n", + " 3. `TargLang` (str): the target language, i.e. the language the translator will translate into\n", + " 4. `VendorName` (str): the translator's/vendor's name\n", + " 5. `VendorMail` (str): the vendor's e-mail address, by default empty\n", + " 6. `WordRate` (float): the vendor's word rate in EUR/word, by default set to \"None\"\n", + " 7. `CatTool` (str): the CAT Tool the translator will use, by default set to \"XTM\"\n", + " 8. `Preferred` (bool): indicates if a vendor is a preferred vendor or not, by default set to \"None\"\n", + " - `Argparse` inside `if __name__ == \"__main__\":` statement to receive arguments when the script is run\n", + "\n", + "CLASSES\n", + " builtins.object\n", + " VendorData\n", + " \n", + " class VendorData(builtins.object)\n", + " | VendorData(ProjectName, SourceLang, TargLang, VendorName, VendorMail='', WordRate=None, CatTool='XTM', Preferred=None)\n", + " | \n", + " | Methods defined here:\n", + " | \n", + " | ChangeTool(self, NewTool)\n", + " | Method\n", + " | \n", + " | Args:\n", + " | NewTool (str): a new tool for a certain vendor\n", + " | \n", + " | ModExcel(self, Key, Index, NewValue)\n", + " | Method to modify existing vendor in excel file\n", + " | \n", + " | Args:\n", + " | Key (str): one of the modifiable keys in VendorData.Keys\n", + " | Index (int): the index of the value that needs to be modified\n", + " | NewValue : the new value of the index, type depends on the key, either str or float\n", + " | \n", + " | Raises:\n", + " | ValueError: raised if the key is not one of the keys in VendorData.Keys\n", + " | ValueError: raised if the Index is not valid for a certain key\n", + " | \n", + " | ReadExcel(self)\n", + " | \n", + " | SetStatus(self, PrefVend)\n", + " | Method\n", + " | \n", + " | Args:\n", + " | PrefVend (bool): new value for Preferred, has an influence on status\n", + " | \n", + " | SetVendorMail(self, NewMail)\n", + " | Method\n", + " | \n", + " | Args:\n", + " | NewMail (str): a new e-mail address for a certain vendor\n", + " | \n", + " | SetWordRate(self, NewRate)\n", + " | Method\n", + " | \n", + " | Args:\n", + " | NewRate (float): a new word rate for a certain vendor\n", + " | \n", + " | ToExcel(self)\n", + " | \n", + " | __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail='', WordRate=None, CatTool='XTM', Preferred=None)\n", + " | Instantiate\n", + " | \n", + " | Class Attributes:\n", + " | CatTools (list) :\n", + " | Keys (list) :\n", + " | Statuses (list) :\n", + " | \n", + " | Args:\n", + " | ProjectName (str): the name of the translation project\n", + " | SourceLang (str): the source language, i.e. the language the translator will translate from\n", + " | TargLang (str): the target language, i.e. the language the translator will translate into\n", + " | VendorName (str): the translator's/vendor's name\n", + " | VendorMail (str, optional): the vendor's e-mail address, by default empty\n", + " | WordRate (float, optional): the vendor's word rate in EUR/word, by default set to \"None\"\n", + " | CatTool (str, optional): the CAT Tool the translator will use, by default set to \"XTM\"\n", + " | Preferred (bool, optional): indicates if a vendor is a preferred vendor or not, by default set to \"None\".\n", + " | \n", + " | Raises:\n", + " | TypeError: ProjectName should be a string\n", + " | TypeError: SourceLang should be a string\n", + " | TypeError: TargLang should be a string\n", + " | TypeError: VendorName should be a string\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors defined here:\n", + " | \n", + " | __dict__\n", + " | dictionary for instance variables (if defined)\n", + " | \n", + " | __weakref__\n", + " | list of weak references to the object (if defined)\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data and other attributes defined here:\n", + " | \n", + " | CatTools = ['XTM', 'Trados Studio', 'MemoQ', 'Memsource']\n", + " | \n", + " | Keys = ['E-mail', 'CAT Tool', 'Word Rate', 'Status']\n", + " | \n", + " | Statuses = ['Preferred', 'Back-up', 'Potential']\n", + "\n", + "FUNCTIONS\n", + " ChangeDictionaryValue(Dictionary, Key, Index, NewValue)\n", + " ChangeDictionaryValue, change values of a dictionary\n", + " \n", + " Args:\n", + " Dictionary (dict): name of the dictionary that will be read\n", + " Key (str): the key for which the value will be changed\n", + " Index (int): the index of the value that will be changed\n", + " NewValue: new value for the chosen index, type depends on the key\n", + " \n", + " CheckCatTool(CatTool)\n", + " CheckCatTool, validate CatTOol\n", + " \n", + " Args:\n", + " CatTool (str): a CAT Tool\n", + " \n", + " Raises:\n", + " TypeError: if the argument provided is not string, a TypeError is raised\n", + " ValueError: the argument provided should be one of the four CAT Tools in the list [\"XTM\", \"Trados Studio\", \"MemoQ\", \"Memsource\"]\n", + " \n", + " CheckVendorMail(VendorMail)\n", + " CheckVendorMail, validate e-mail address\n", + " \n", + " Args:\n", + " VendorMail (str): an e-mail address\n", + " \n", + " Raises:\n", + " TypeError: if the argument provided is not a string, a TypeError is raised\n", + " ValueError: if the address provided does not conform with the regex string `regex_mail`, a ValueError is raised\n", + " \n", + " CheckWordRate(WordRate)\n", + " CheckWordRate, validate word rate\n", + " \n", + " Args:\n", + " WordRate (float): a word rate in EUR/word\n", + " \n", + " Raises:\n", + " TypeError: if the argument provided is not a float, a TypeError is raised\n", + " ValueError: the argument provided should not be higher than 0.15\n", + " ValueError: the argument provided should not be 0.00\n", + "\n", + "FILE\n", + " c:\\users\\geera\\onedrive\\documenten\\school\\postgraduaattranslationtechnology\\introductiontopython\\final_assignment1\\vendor_data.py\n", + "\n", + "\n" + ] + } + ], "source": [ "help(vd)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "d6fb22b9", "metadata": {}, "outputs": [], @@ -57,10 +227,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "803ee5b0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'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.\\n\\n It contains:\\n - 4 functions: \\n `ChangeDictionaryValue` to easily change values in a certain dictionary.\\n `CheckVendorMail` to easily check if an e-mail address is valid.\\n `CheckWordRate` to check if a word rate falls between EUR 0.01 and EUR 0.15 per word.\\n `CheckCatTool` to validate the CAT tool provided.\\n - 1 class, `VendorData` that has 3 class attributes: `CatTools`, the CAT Tools that can be used for the project,\\n `Keys`, the keys of the dictionary that can be modified, and `Statuses`, the possible statuses a vendor can have.\\n The class takes 4 positional arguments and 4 optional arguments:\\n 1. `ProjectName` (str): the name of the translation project\\n 2. `SourceLang` (str): the source language, i.e. the language the translator will translate from\\n 3. `TargLang` (str): the target language, i.e. the language the translator will translate into\\n 4. `VendorName` (str): the translator\\'s/vendor\\'s name\\n 5. `VendorMail` (str): the vendor\\'s e-mail address, by default empty\\n 6. `WordRate` (float): the vendor\\'s word rate in EUR/word, by default set to \"None\"\\n 7. `CatTool` (str): the CAT Tool the translator will use, by default set to \"XTM\"\\n 8. `Preferred` (bool): indicates if a vendor is a preferred vendor or not, by default set to \"None\"\\n - `Argparse` inside `if __name__ == \"__main__\":` statement to receive arguments when the script is run\\n '" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "vd.__doc__" ] @@ -70,14 +251,14 @@ "id": "b9df49cf", "metadata": {}, "source": [ - "## Instantiating an instance of VendorData\n", + "### Instantiating an instance of VendorData\n", "Now that we know the different fucntionalities we can instantiate an instance of the class VendorData.\n", "To illustrate the code to it's full extent, we'll instantiate a couple of them:" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "4ab17746", "metadata": {}, "outputs": [], @@ -97,30 +278,63 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "c6675ef0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Elmo Geeraerts'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorNL.VendorName" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "23b52971", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'j.lefevre@hotmail.com'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorFR.VendorMail" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "69659b86", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.09" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.WordRate" ] @@ -135,10 +349,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "cb2ca64c", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "''" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorNL.VendorMail" ] @@ -153,10 +378,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "c7180a19", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'XTM'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.CatTool" ] @@ -172,47 +408,91 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "e26d1539", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorFR.Preferred" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "935c0a38", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Preferred'" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorFR.Status" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "9ebc7f07", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.Preferred" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "1158b1de", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Back-up'" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.Status" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "id": "ab5e5f54", "metadata": {}, "outputs": [], @@ -222,10 +502,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "id": "50cd8967", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Potential'" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorNL.Status" ] @@ -235,7 +526,7 @@ "id": "47936f2c", "metadata": {}, "source": [ - "## Functions\n", + "### Functions\n", "The class also contains a couple of functions:\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", @@ -250,10 +541,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "id": "90cb5c10", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'e.dlbanda@outlook.com'" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.SetVendorMail(\"e.dlbanda@outlook.com\")\n", "VendorES.VendorMail" @@ -269,10 +571,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "730b35ca", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.08" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorNL.SetWordRate(0.08)\n", "VendorNL.WordRate" @@ -288,10 +601,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "391e7c5d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Trados Studio'" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.ChangeTool(\"Trados Studio\")\n", "VendorES.CatTool" @@ -307,10 +631,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "id": "96819356", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorFR.SetStatus(False)\n", "VendorFR.Preferred" @@ -318,10 +653,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "e8335217", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Back-up'" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorFR.Status" ] @@ -336,7 +682,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "aeafcb32", "metadata": {}, "outputs": [], @@ -357,10 +703,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "37124f32", "metadata": {}, - "outputs": [], + "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": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorNL.ReadExcel()" ] @@ -375,10 +737,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "id": "10dc02d2", "metadata": {}, - "outputs": [], + "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_12116\\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 222\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mVendorDict\u001b[0m \u001b[1;31m#print the Dictionary\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 223\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--> 224\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 225\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 226\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[0mIndex\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()" @@ -400,10 +775,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "id": "17292d31", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['E-mail', 'CAT Tool', 'Word Rate', 'Status']" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "vd.VendorData.Keys" ] @@ -418,10 +804,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "id": "abf2dc40", "metadata": {}, - "outputs": [], + "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": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorNL.ReadExcel()" ] @@ -436,7 +838,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "id": "52e91ff2", "metadata": {}, "outputs": [], @@ -454,10 +856,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "id": "f4e539d4", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Trados Studio'" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.CatTool" ] @@ -472,10 +885,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "id": "072bbb59", "metadata": {}, - "outputs": [], + "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: 'Potential', 1: 'Back-up', 2: 'Back-up'}}" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.ReadExcel()" ] @@ -485,7 +914,7 @@ "id": "c6e675e6", "metadata": {}, "source": [ - "## Validation\n", + "### Validation\n", "\n", "This script also uses some functions to validate the user input anytime when user interaction is necessary.\n", "That is:\n", @@ -493,88 +922,993 @@ "- 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:" + "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": null, + "execution_count": 31, "id": "854ef143", "metadata": {}, - "outputs": [], + "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_12116\\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 118\u001b[0m \"\"\"\n\u001b[0;32m 119\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--> 120\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 121\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 122\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": null, + "execution_count": 32, "id": "cd524417", "metadata": {}, - "outputs": [], + "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_12116\\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 120\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 121\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--> 122\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 123\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 124\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": null, + "execution_count": 33, "id": "d6497db2", "metadata": {}, - "outputs": [], + "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_12116\\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 122\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 123\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--> 124\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 125\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 126\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": null, + "execution_count": 34, "id": "8b01bfed", "metadata": {}, - "outputs": [], + "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_12116\\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 124\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 125\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--> 126\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 127\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 128\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": null, + "execution_count": 35, "id": "20b5cc03", "metadata": {}, - "outputs": [], + "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_12116\\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 126\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 127\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--> 128\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 129\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 130\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 52\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 53\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---> 54\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 55\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 56\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": null, + "execution_count": 36, "id": "7c32d39f", "metadata": {}, - "outputs": [], + "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_12116\\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 128\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 129\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--> 130\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 131\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 132\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 67\u001b[0m \"\"\"\n\u001b[0;32m 68\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---> 69\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 70\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 71\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": null, + "execution_count": 37, "id": "32715f64", "metadata": {}, - "outputs": [], + "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_12116\\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 133\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 134\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--> 135\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 136\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 137\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": null, + "execution_count": 38, "id": "8b74ce10", "metadata": {}, - "outputs": [], + "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_12116\\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 130\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 131\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--> 132\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 133\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 134\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 83\u001b[0m \"\"\"\n\u001b[0;32m 84\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---> 85\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 86\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mCatTool\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m\"XTM\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Trados Studio\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"MemoQ\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Memsource\"\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 87\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\n", + "- `CatTool` is one of the following: XTM, Trados Studio, MemoQ or Memsource" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "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_12116\\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 126\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 127\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--> 128\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 129\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 130\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 54\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 55\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---> 56\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 57\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 58\u001b[0m \"\"\"CheckWordRate, validate 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": 40, + "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_12116\\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 128\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 129\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--> 130\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 131\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 132\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 69\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 70\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---> 71\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 72\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 73\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": 41, + "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_12116\\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 128\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 129\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--> 130\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 131\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 132\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 71\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 72\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---> 73\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 74\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 75\u001b[0m \"\"\"CheckCatTool, validate CatTOol\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": 42, + "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_12116\\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 130\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 131\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--> 132\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 133\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 134\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 85\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 86\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mCatTool\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m\"XTM\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Trados Studio\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"MemoQ\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Memsource\"\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---> 87\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 88\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 89\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": 43, + "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": 44, + "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_12116\\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[0mNewMail\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0ma\u001b[0m \u001b[0mnew\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mmail\u001b[0m \u001b[0maddress\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0ma\u001b[0m \u001b[0mcertain\u001b[0m \u001b[0mvendor\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 54\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 55\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---> 56\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 57\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 58\u001b[0m \"\"\"CheckWordRate, validate word rate\n", + "\u001b[1;31mValueError\u001b[0m: Please insert a valid email address." + ] + } + ], + "source": [ + "VendorDE.SetVendorMail(\"thomas.zw@\")" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "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_12116\\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 166\u001b[0m \u001b[0mNewRate\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mfloat\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0ma\u001b[0m \u001b[0mnew\u001b[0m \u001b[0mword\u001b[0m \u001b[0mrate\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0ma\u001b[0m \u001b[0mcertain\u001b[0m \u001b[0mvendor\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 167\u001b[0m \"\"\"\n\u001b[1;32m--> 168\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 169\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 170\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 69\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 70\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---> 71\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 72\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 73\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": 46, + "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_12116\\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 166\u001b[0m \u001b[0mNewRate\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mfloat\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0ma\u001b[0m \u001b[0mnew\u001b[0m \u001b[0mword\u001b[0m \u001b[0mrate\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0ma\u001b[0m \u001b[0mcertain\u001b[0m \u001b[0mvendor\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 167\u001b[0m \"\"\"\n\u001b[1;32m--> 168\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 169\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 170\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 71\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 72\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---> 73\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 74\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 75\u001b[0m \"\"\"CheckCatTool, validate CatTOol\n", + "\u001b[1;31mValueError\u001b[0m: Word rate cannot be 0.00." + ] + } + ], + "source": [ + "VendorDE.SetWordRate (0.00)" + ] + }, + { + "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_12116\\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 175\u001b[0m \u001b[0mNewTool\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0ma\u001b[0m \u001b[0mnew\u001b[0m \u001b[0mtool\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0ma\u001b[0m \u001b[0mcertain\u001b[0m \u001b[0mvendor\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 176\u001b[0m \"\"\"\n\u001b[1;32m--> 177\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 178\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 179\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 85\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 86\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mCatTool\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m\"XTM\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Trados Studio\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"MemoQ\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Memsource\"\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---> 87\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 88\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 89\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_12116\\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 186\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 187\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--> 188\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 189\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 190\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:" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "b9e3cd49", + "metadata": {}, + "outputs": [], + "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": "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_12116\\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;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mModExcel\u001b[1;34m(self, Key, Index, NewValue)\u001b[0m\n\u001b[0;32m 246\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid index, run 'self.ReadExcel()' to see options\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 247\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"E-mail\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate e-mail address if a value for the key E-mail is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 248\u001b[1;33m \u001b[0mCheckVendorMail\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[0m\n\u001b[0m\u001b[0;32m 249\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"Word Rate\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate word rate if a value for the key Word Rate is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 250\u001b[0m \u001b[0mCheckWordRate\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[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 54\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 55\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---> 56\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 57\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 58\u001b[0m \"\"\"CheckWordRate, validate word rate\n", + "\u001b[1;31mValueError\u001b[0m: Please insert a valid email address." + ] + } + ], + "source": [ + "VendorDE.ModExcel(\"E-mail\", 3, \"thomaszw@\")" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "3db36ec1", + "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_12116\\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;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mModExcel\u001b[1;34m(self, Key, Index, NewValue)\u001b[0m\n\u001b[0;32m 250\u001b[0m \u001b[0mCheckWordRate\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[0m\n\u001b[0;32m 251\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"CAT Tool\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate CAT Tool if a value for the key CAT Tool is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 252\u001b[1;33m \u001b[0mCheckCatTool\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[0m\n\u001b[0m\u001b[0;32m 253\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"Status\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate Status if a value for the key Status is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 254\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mNewValue\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mVendorData\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mStatuses\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 85\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 86\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mCatTool\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m\"XTM\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Trados Studio\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"MemoQ\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Memsource\"\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---> 87\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 88\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 89\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.ModExcel(\"CAT Tool\", 3, \"Trados Studio 2019\")" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "43492fbd", + "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_12116\\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;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mModExcel\u001b[1;34m(self, Key, Index, NewValue)\u001b[0m\n\u001b[0;32m 248\u001b[0m \u001b[0mCheckVendorMail\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[0m\n\u001b[0;32m 249\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"Word Rate\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate word rate if a value for the key Word Rate is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 250\u001b[1;33m \u001b[0mCheckWordRate\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[0m\n\u001b[0m\u001b[0;32m 251\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"CAT Tool\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate CAT Tool if a value for the key CAT Tool is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 252\u001b[0m \u001b[0mCheckCatTool\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[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 69\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 70\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---> 71\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 72\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 73\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.ModExcel(\"Word Rate\", 3, 0.18)" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "fcc7bf99", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Invalid status, run 'VendorData.Statuses' 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_12116\\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;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mModExcel\u001b[1;34m(self, Key, Index, NewValue)\u001b[0m\n\u001b[0;32m 253\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"Status\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate Status if a value for the key Status is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 254\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mNewValue\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mVendorData\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mStatuses\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 255\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid status, run 'VendorData.Statuses' 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 256\u001b[0m \u001b[0mChangeDictionaryValue\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorDict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mKey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mIndex\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mNewValue\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#change the dictionary value in the dictionary `VendorDict` using the arguments provided for the method ModExcel\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 257\u001b[0m \u001b[0mdf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorDict\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#turn VendorDict dictionary back into a panda DataFrame\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: Invalid status, run 'VendorData.Statuses' to see options" + ] + } + ], + "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", + "Additionally it also is checked if the index is in the dictionary, otherwise the vendor is non-existent and cannot be modified." + ] + }, + { + "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_12116\\2634951232.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;36m2\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, Index, NewValue)\u001b[0m\n\u001b[0;32m 242\u001b[0m \u001b[0mVendorDict\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mExcelRecordsDf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_dict\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 243\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--> 244\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 245\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mIndex\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mVendorDict\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mKey\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 246\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid index, run 'self.ReadExcel()' to see options\"\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\", 2, \"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_12116\\614258264.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;36m3\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, Index, NewValue)\u001b[0m\n\u001b[0;32m 242\u001b[0m \u001b[0mVendorDict\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mExcelRecordsDf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_dict\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 243\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--> 244\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 245\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mIndex\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mVendorDict\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mKey\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 246\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid index, run 'self.ReadExcel()' to see options\"\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\", 3, \"Croatian\")" + ] + }, + { + "cell_type": "markdown", + "id": "2eb97cae", + "metadata": {}, + "source": [ + "Since there are only 4 vendors in the excel file and the index start at 0 and go up, an error message should appear when you try to modify a higher index:" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "66ca7b9e", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Invalid index, run 'self.ReadExcel()' 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_12116\\235551850.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;36m6\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"XTM\"\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, Index, NewValue)\u001b[0m\n\u001b[0;32m 244\u001b[0m \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[0;32m 245\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mIndex\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mVendorDict\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mKey\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--> 246\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid index, run 'self.ReadExcel()' 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 247\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"E-mail\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate e-mail address if a value for the key E-mail is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 248\u001b[0m \u001b[0mCheckVendorMail\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[0m\n", + "\u001b[1;31mValueError\u001b[0m: Invalid index, run 'self.ReadExcel()' to see options" + ] + } + ], + "source": [ + "VendorDE.ModExcel(\"CAT Tool\", 6, \"XTM\")" + ] + }, + { + "cell_type": "markdown", + "id": "092a40df", + "metadata": {}, + "source": [ + "You can check for the right index by running the `ReadExcel` method for any vendor you already defined:" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "38b01366", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Target Language': {0: 'Dutch', 1: 'French', 2: 'Spanish', 3: 'German'},\n", + " 'Vendor': {0: 'Elmo Geeraerts',\n", + " 1: 'Jean Lefèvre',\n", + " 2: 'Emilio De La Banda',\n", + " 3: 'Thomas Zwiebel'},\n", + " 'E-mail': {0: nan,\n", + " 1: 'j.lefevre@hotmail.com',\n", + " 2: 'e.dlbanda@outlook.com',\n", + " 3: nan},\n", + " 'CAT Tool': {0: 'XTM', 1: 'Trados Studio', 2: 'MemoQ', 3: 'XTM'},\n", + " 'Word Rate': {0: 0.08, 1: 0.1, 2: 0.09, 3: nan},\n", + " 'Status': {0: 'Potential', 1: 'Back-up', 2: 'Back-up', 3: 'Potential'}}" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "VendorNL.ReadExcel()" + ] + }, + { + "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. We'll first look at the help for this script." + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "1ac6c1de", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "usage: vendor_data.py [-h] [-a] [-m]\n", + "\n", + "optional arguments:\n", + " -h, --help show this help message and exit\n", + " -a, --add Add a vendor\n", + " -m, --modify Modify an existing vendor\n" + ] + } + ], + "source": [ + "%run vendor_data.py --help" + ] + }, + { + "cell_type": "markdown", + "id": "cc95becc", + "metadata": {}, + "source": [ + "As you can see, apart from the help argument, there are two other 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", + "\n", + "We'll start by writing a totally new excel file and adding a vendor to it:" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "a32de96d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What is the project name? TestProject\n", + "What is the source language? English\n", + "What's the vendor's name? Elmo Geeraerts\n", + "Into which language will the vendor translate? Dutch\n", + "What is the vendor's email address? geeraerts@me.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.12\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. True\n", + "Are you done? yes\n", + "Do you want to add this vendor to the excel file? yes\n" + ] + } + ], + "source": [ + "%run vendor_data.py --a" + ] + }, + { + "cell_type": "markdown", + "id": "61141753", + "metadata": {}, + "source": [ + "A new excel file will appear next to where you stored this notebook with the name `TestProject_English`, i.e. the project name and source language we provided.\n", + "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" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "id": "8f91cd3a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What is the project name? TestProject\n", + "What is the source language? English\n", + "What's the vendor's name? Jean Baptiste\n", + "Into which language will the vendor translate? French\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? \n", + "Blank values are not allowed.\n", + "Are you done? yes\n", + "Do you want to add this vendor to the excel file? yes\n" + ] + } + ], + "source": [ + "%run vendor_data.py --a" + ] + }, + { + "cell_type": "markdown", + "id": "d652047e", + "metadata": {}, + "source": [ + "If the project name and the source language are the same as for the previous vendor you've entered, this vendor will be added to the same excel file, if not a new excel file is created using the project name and the source language as the file name. You'll notice that for the prompts you leave blank the default value is enterred OR it is left blank.\n", + "\n", + "Just like when you use this script as a module, the data you provide is validate at every step of the user interaction. TypeErrors do not cause the prompts to stop but instead you get asked the same question again, ValueErrors do break off the code:" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "id": "7c4e5ac4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What is the project name? TestProject\n", + "What is the source language? English\n", + "What's the vendor's name? Emanuel Dos Santos\n", + "Into which language will the vendor translate? Portuguese\n", + "What is the vendor's email address? e_dossantos@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.19\n" + ] + }, + { + "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~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 304\u001b[0m \u001b[0mNewWordRate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpyip\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minputFloat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor. \"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mblank\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[0;32m 305\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mNewWordRate\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 306\u001b[1;33m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNewWordRate\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 307\u001b[0m \u001b[0mVendorWordRate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mNewWordRate\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 308\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~\\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 69\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 70\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---> 71\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 72\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 73\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": [ + "%run vendor_data.py -a" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "id": "ec294039", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What is the project name? TestProject\n", + "What is the source language? English\n", + "What's the vendor's name? Emanuel Dos Santos\n", + "Into which language will the vendor translate? Portuguese\n", + "What is the vendor's email address? e_dossantos@\n" + ] + }, + { + "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~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 298\u001b[0m \u001b[0mNewVendorMail\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpyip\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minputStr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"What is the vendor's email address? \"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mblank\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdefault\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 299\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mNewVendorMail\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 300\u001b[1;33m \u001b[0mCheckVendorMail\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNewVendorMail\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 301\u001b[0m \u001b[0mVendorMail\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mNewVendorMail\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 302\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~\\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 54\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 55\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---> 56\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 57\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 58\u001b[0m \"\"\"CheckWordRate, validate word rate\n", + "\u001b[1;31mValueError\u001b[0m: Please insert a valid email address." + ] + } + ], + "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", + "\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? TestProject\n", + "What is the source language? English\n", + "These are the vendor's already in the database: \n", + "0: Elmo Geeraerts\n", + "1: Jean Baptiste\n", + "Enter the index of the vendor you want to modify: 0\n", + "What is the vendor's e-mail? \n", + "What is the vendor's word rate? 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", + "Trados Studio\n", + "What is the vendor's new status? * Preferred\n", + "* Back-up\n", + "* Potential\n", + "\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!" + ] } ], "metadata": { @@ -593,7 +1927,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.9.13" } }, "nbformat": 4, diff --git a/tutorial.md b/tutorial.md new file mode 100644 index 0000000..1ac186f --- /dev/null +++ b/tutorial.md @@ -0,0 +1,1555 @@ +# Tutorial: how to use `vendor_data.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 ('vendor_data.py') #this is the relative path to the script. If the script is not directly next to the notebook, it could be better to copy the full path of the notebook. +import vendor_data as vd # 'as vd' is not necessary but makes it shorter. +``` + +### 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: + + +```python +help(vd) +``` + + Help on module vendor_data: + + NAME + vendor_data - 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. + + DESCRIPTION + 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: + 1. `ProjectName` (str): the name of the translation project + 2. `SourceLang` (str): the source language, i.e. the language the translator will translate from + 3. `TargLang` (str): the target language, i.e. the language the translator will translate into + 4. `VendorName` (str): the translator's/vendor's name + 5. `VendorMail` (str): the vendor's e-mail address, by default empty + 6. `WordRate` (float): the vendor's word rate in EUR/word, by default set to "None" + 7. `CatTool` (str): the CAT Tool the translator will use, by default set to "XTM" + 8. `Preferred` (bool): indicates if a vendor is a preferred vendor or not, by default set to "None" + - `Argparse` inside `if __name__ == "__main__":` statement to receive arguments when the script is run + + CLASSES + builtins.object + VendorData + + class VendorData(builtins.object) + | VendorData(ProjectName, SourceLang, TargLang, VendorName, VendorMail='', WordRate=None, CatTool='XTM', Preferred=None) + | + | Methods defined here: + | + | ChangeTool(self, NewTool) + | Method + | + | Args: + | NewTool (str): a new tool for a certain vendor + | + | ModExcel(self, Key, Index, NewValue) + | Method to modify existing vendor in excel file + | + | Args: + | Key (str): one of the modifiable keys in VendorData.Keys + | Index (int): the index of the value that needs to be modified + | NewValue : the new value of the index, 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 Index is not valid for a certain key + | + | ReadExcel(self) + | + | SetStatus(self, PrefVend) + | Method + | + | Args: + | PrefVend (bool): new value for Preferred, has an influence on status + | + | SetVendorMail(self, NewMail) + | Method + | + | Args: + | NewMail (str): a new e-mail address for a certain vendor + | + | SetWordRate(self, NewRate) + | Method + | + | Args: + | NewRate (float): a new word rate for a certain vendor + | + | ToExcel(self) + | + | __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 + | + | ---------------------------------------------------------------------- + | Data descriptors defined here: + | + | __dict__ + | dictionary for instance variables (if defined) + | + | __weakref__ + | list of weak references to the object (if defined) + | + | ---------------------------------------------------------------------- + | Data and other attributes defined here: + | + | CatTools = ['XTM', 'Trados Studio', 'MemoQ', 'Memsource'] + | + | Keys = ['E-mail', 'CAT Tool', 'Word Rate', 'Status'] + | + | Statuses = ['Preferred', 'Back-up', 'Potential'] + + FUNCTIONS + ChangeDictionaryValue(Dictionary, Key, Index, NewValue) + ChangeDictionaryValue, change values of a 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 + + CheckCatTool(CatTool) + CheckCatTool, validate CatTOol + + 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 ["XTM", "Trados Studio", "MemoQ", "Memsource"] + + CheckVendorMail(VendorMail) + CheckVendorMail, validate 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 + + CheckWordRate(WordRate) + CheckWordRate, validate 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 + + FILE + c:\users\geera\onedrive\documenten\school\postgraduaattranslationtechnology\introductiontopython\final_assignment1\vendor_data.py + + + + + +```python +?vd +``` + + +```python +vd.__doc__ +``` + + + + + '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.\n\n It contains:\n - 4 functions: \n `ChangeDictionaryValue` to easily change values in a certain dictionary.\n `CheckVendorMail` to easily check if an e-mail address is valid.\n `CheckWordRate` to check if a word rate falls between EUR 0.01 and EUR 0.15 per word.\n `CheckCatTool` to validate the CAT tool provided.\n - 1 class, `VendorData` that has 3 class attributes: `CatTools`, the CAT Tools that can be used for the project,\n `Keys`, the keys of the dictionary that can be modified, and `Statuses`, the possible statuses a vendor can have.\n The class takes 4 positional arguments and 4 optional arguments:\n 1. `ProjectName` (str): the name of the translation project\n 2. `SourceLang` (str): the source language, i.e. the language the translator will translate from\n 3. `TargLang` (str): the target language, i.e. the language the translator will translate into\n 4. `VendorName` (str): the translator\'s/vendor\'s name\n 5. `VendorMail` (str): the vendor\'s e-mail address, by default empty\n 6. `WordRate` (float): the vendor\'s word rate in EUR/word, by default set to "None"\n 7. `CatTool` (str): the CAT Tool the translator will use, by default set to "XTM"\n 8. `Preferred` (bool): indicates if a vendor is a preferred vendor or not, by default set to "None"\n - `Argparse` inside `if __name__ == "__main__":` statement to receive arguments when the script is run\n ' + + + +### Instantiating an instance of VendorData +Now that we know the different fucntionalities we can instantiate an instance of the class VendorData. +To illustrate the code to it's full extent, we'll instantiate a couple of them: + + +```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 had default arguments. When we check the e-mail for VendorNL, for which we didn't provide one, we'll see that it does not return anything: + + +```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' + + + +### Functions +The class also contains a couple of functions: +- `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 sat 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 value for the argument `ProjectName` and `SourceLang`, they will be written to the same excel file. We should execute this function for every vendor. Be careful because if you run this function multiple times for the same vendor, it will not overwrite but append and you will have duplicates in the excel file. + + +```python +VendorNL.ToExcel() +VendorFR.ToExcel() +VendorES.ToExcel() +``` + +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 function 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 function without writing it to an excel file, 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_12116\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) + 222 return VendorDict #print the Dictionary + 223 else: + --> 224 raise ValueError(f"There is no file for {self.ProjectName} in {self.SourceLang}") + 225 + 226 def ModExcel(self, Key, Index, NewValue): + + + ValueError: There is no file for Tutorial in German + + +We can also modify the excel file by running the `ModExcel` function. Again, it does not matter for which vendor you call this function. +This function takes 3 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 +2. The `Index`: if you have run the ReadExcel() function, you have noticed that before every value for a key in the dictionrary there's a number. By picking a number, you can change the value for that index. +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", 2, "MemoQ") +``` + +If you check this by running `.CatTool`, the old value will still be there. + + +```python +VendorES.CatTool +``` + + + + + 'Trados Studio' + + + +However, if we read the excel file again, we'll notice it has changed: + + +```python +VendorES.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: 'Potential', 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_12116\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) + 118 """ + 119 if type(ProjectName) != str: + --> 120 raise TypeError("ProjectName should be a string!") + 121 if type(SourceLang) != str: + 122 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_12116\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) + 120 raise TypeError("ProjectName should be a string!") + 121 if type(SourceLang) != str: + --> 122 raise TypeError("SourceLang should be a string!") + 123 if type(TargLang) != str: + 124 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_12116\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) + 122 raise TypeError("SourceLang should be a string!") + 123 if type(TargLang) != str: + --> 124 raise TypeError("TargLang should be a string!") + 125 if type(VendorName) !=str: + 126 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_12116\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) + 124 raise TypeError("TargLang should be a string!") + 125 if type(VendorName) !=str: + --> 126 raise TypeError("VendorName should be a string!") + 127 if VendorMail: #validate e-mail address if one is provided + 128 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_12116\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) + 126 raise TypeError("VendorName should be a string!") + 127 if VendorMail: #validate e-mail address if one is provided + --> 128 CheckVendorMail(VendorMail) + 129 if WordRate != None: #validate word rate if one is provided + 130 CheckWordRate(WordRate) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckVendorMail(VendorMail) + 52 regex_mail = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" #regex used to validate email + 53 if type(VendorMail) != str: + ---> 54 raise TypeError ("VendorMail should be a string!") + 55 if not(re.search(regex_mail,VendorMail)): + 56 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_12116\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) + 128 CheckVendorMail(VendorMail) + 129 if WordRate != None: #validate word rate if one is provided + --> 130 CheckWordRate(WordRate) + 131 if CatTool: #validate CAT Tool if one is provided + 132 CheckCatTool(CatTool) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 67 """ + 68 if type(WordRate) != float: + ---> 69 raise TypeError("WordRate should be a float!") + 70 if WordRate > 0.15: + 71 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_12116\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) + 133 if Preferred != None: + 134 if type(Preferred) != bool: + --> 135 raise TypeError("Preferred should either be True, False or None.") + 136 if Preferred != None: #if Preferred is set to True, status will be preferred, if set to False, back-up and if neither "Potential" + 137 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_12116\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) + 130 CheckWordRate(WordRate) + 131 if CatTool: #validate CAT Tool if one is provided + --> 132 CheckCatTool(CatTool) + 133 if Preferred != None: + 134 if type(Preferred) != bool: + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckCatTool(CatTool) + 83 """ + 84 if type(CatTool) != str: + ---> 85 raise TypeError("CatTool should be a string!") + 86 if not CatTool in ["XTM", "Trados Studio", "MemoQ", "Memsource"]: + 87 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 +- `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_12116\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) + 126 raise TypeError("VendorName should be a string!") + 127 if VendorMail: #validate e-mail address if one is provided + --> 128 CheckVendorMail(VendorMail) + 129 if WordRate != None: #validate word rate if one is provided + 130 CheckWordRate(WordRate) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckVendorMail(VendorMail) + 54 raise TypeError ("VendorMail should be a string!") + 55 if not(re.search(regex_mail,VendorMail)): + ---> 56 raise ValueError("Please insert a valid email address.") + 57 def CheckWordRate(WordRate): + 58 """CheckWordRate, validate 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_12116\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) + 128 CheckVendorMail(VendorMail) + 129 if WordRate != None: #validate word rate if one is provided + --> 130 CheckWordRate(WordRate) + 131 if CatTool: #validate CAT Tool if one is provided + 132 CheckCatTool(CatTool) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 69 raise TypeError("WordRate should be a float!") + 70 if WordRate > 0.15: + ---> 71 raise ValueError("This vendor is too expensive, pick another one.") + 72 if WordRate == 0.00: + 73 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_12116\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) + 128 CheckVendorMail(VendorMail) + 129 if WordRate != None: #validate word rate if one is provided + --> 130 CheckWordRate(WordRate) + 131 if CatTool: #validate CAT Tool if one is provided + 132 CheckCatTool(CatTool) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 71 raise ValueError("This vendor is too expensive, pick another one.") + 72 if WordRate == 0.00: + ---> 73 raise ValueError("Word rate cannot be 0.00.") + 74 def CheckCatTool(CatTool): + 75 """CheckCatTool, validate CatTOol + + + ValueError: Word rate cannot be 0.00. + + + +```python +VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", CatTool = "SDL Trados Studio") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_12116\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) + 130 CheckWordRate(WordRate) + 131 if CatTool: #validate CAT Tool if one is provided + --> 132 CheckCatTool(CatTool) + 133 if Preferred != None: + 134 if type(Preferred) != bool: + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckCatTool(CatTool) + 85 raise TypeError("CatTool should be a string!") + 86 if not CatTool in ["XTM", "Trados Studio", "MemoQ", "Memsource"]: + ---> 87 raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") + 88 + 89 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_12116\4282007076.py in + ----> 1 VendorDE.SetVendorMail("thomas.zw@") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in SetVendorMail(self, NewMail) + 157 NewMail (str): a new e-mail address for a certain vendor + 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) + 54 raise TypeError ("VendorMail should be a string!") + 55 if not(re.search(regex_mail,VendorMail)): + ---> 56 raise ValueError("Please insert a valid email address.") + 57 def CheckWordRate(WordRate): + 58 """CheckWordRate, validate word rate + + + ValueError: Please insert a valid email address. + + + +```python +VendorDE.SetWordRate(0.18) +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_12116\1677043638.py in + ----> 1 VendorDE.SetWordRate(0.18) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in SetWordRate(self, NewRate) + 166 NewRate (float): a new word rate for a certain vendor + 167 """ + --> 168 CheckWordRate(NewRate) #validate new word rate + 169 self.WordRate = NewRate #value of WordRate is changed + 170 + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 69 raise TypeError("WordRate should be a float!") + 70 if WordRate > 0.15: + ---> 71 raise ValueError("This vendor is too expensive, pick another one.") + 72 if WordRate == 0.00: + 73 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_12116\2070555766.py in + ----> 1 VendorDE.SetWordRate (0.00) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in SetWordRate(self, NewRate) + 166 NewRate (float): a new word rate for a certain vendor + 167 """ + --> 168 CheckWordRate(NewRate) #validate new word rate + 169 self.WordRate = NewRate #value of WordRate is changed + 170 + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 71 raise ValueError("This vendor is too expensive, pick another one.") + 72 if WordRate == 0.00: + ---> 73 raise ValueError("Word rate cannot be 0.00.") + 74 def CheckCatTool(CatTool): + 75 """CheckCatTool, validate CatTOol + + + ValueError: Word rate cannot be 0.00. + + + +```python +VendorDE.ChangeTool("SDL Trados Studio") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_12116\3483989379.py in + ----> 1 VendorDE.ChangeTool("SDL Trados Studio") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ChangeTool(self, NewTool) + 175 NewTool (str): a new tool for a certain vendor + 176 """ + --> 177 CheckCatTool(NewTool) #validate new CAT Tool + 178 self.CatTool = NewTool #value of CatTool is changed + 179 + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckCatTool(CatTool) + 85 raise TypeError("CatTool should be a string!") + 86 if not CatTool in ["XTM", "Trados Studio", "MemoQ", "Memsource"]: + ---> 87 raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") + 88 + 89 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_12116\3389852500.py in + ----> 1 VendorDE.SetStatus("None") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in SetStatus(self, PrefVend) + 186 if PrefVend != None: + 187 if type(PrefVend) != bool: + --> 188 raise TypeError("Preferred should either be True, False or None.") + 189 if PrefVend != None: + 190 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: + + +```python +VendorDE.ToExcel() +``` + +Now we can modify the German vendor and the input will be validated: + + +```python +VendorDE.ModExcel("E-mail", 3, "thomaszw@") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_12116\1589300048.py in + ----> 1 VendorDE.ModExcel("E-mail", 3, "thomaszw@") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) + 246 raise ValueError("Invalid index, run 'self.ReadExcel()' to see options") + 247 if Key == "E-mail": #validate e-mail address if a value for the key E-mail is modified + --> 248 CheckVendorMail(NewValue) + 249 if Key == "Word Rate": #validate word rate if a value for the key Word Rate is modified + 250 CheckWordRate(NewValue) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckVendorMail(VendorMail) + 54 raise TypeError ("VendorMail should be a string!") + 55 if not(re.search(regex_mail,VendorMail)): + ---> 56 raise ValueError("Please insert a valid email address.") + 57 def CheckWordRate(WordRate): + 58 """CheckWordRate, validate word rate + + + ValueError: Please insert a valid email address. + + + +```python +VendorDE.ModExcel("CAT Tool", 3, "Trados Studio 2019") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_12116\3469975144.py in + ----> 1 VendorDE.ModExcel("CAT Tool", 3, "Trados Studio 2019") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) + 250 CheckWordRate(NewValue) + 251 if Key == "CAT Tool": #validate CAT Tool if a value for the key CAT Tool is modified + --> 252 CheckCatTool(NewValue) + 253 if Key == "Status": #validate Status if a value for the key Status is modified + 254 if not NewValue in VendorData.Statuses: + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckCatTool(CatTool) + 85 raise TypeError("CatTool should be a string!") + 86 if not CatTool in ["XTM", "Trados Studio", "MemoQ", "Memsource"]: + ---> 87 raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") + 88 + 89 class VendorData: + + + ValueError: This CAT tool is not valid. Run 'VendorData.CatTools' to check options. + + + +```python +VendorDE.ModExcel("Word Rate", 3, 0.18) +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_12116\2651721014.py in + ----> 1 VendorDE.ModExcel("Word Rate", 3, 0.18) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) + 248 CheckVendorMail(NewValue) + 249 if Key == "Word Rate": #validate word rate if a value for the key Word Rate is modified + --> 250 CheckWordRate(NewValue) + 251 if Key == "CAT Tool": #validate CAT Tool if a value for the key CAT Tool is modified + 252 CheckCatTool(NewValue) + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 69 raise TypeError("WordRate should be a float!") + 70 if WordRate > 0.15: + ---> 71 raise ValueError("This vendor is too expensive, pick another one.") + 72 if WordRate == 0.00: + 73 raise ValueError("Word rate cannot be 0.00.") + + + ValueError: This vendor is too expensive, pick another one. + + + +```python +VendorDE.ModExcel("Status", 3, "Busy") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_12116\3428613633.py in + ----> 1 VendorDE.ModExcel("Status", 3, "Busy") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) + 253 if Key == "Status": #validate Status if a value for the key Status is modified + 254 if not NewValue in VendorData.Statuses: + --> 255 raise ValueError("Invalid status, run 'VendorData.Statuses' to see options") + 256 ChangeDictionaryValue(VendorDict, Key, Index, NewValue) #change the dictionary value in the dictionary `VendorDict` using the arguments provided for the method ModExcel + 257 df = pd.DataFrame(VendorDict) #turn VendorDict dictionary back into a panda DataFrame + + + ValueError: Invalid status, run 'VendorData.Statuses' to see options + + +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` +Additionally it also is checked if the index is in the dictionary, otherwise the vendor is non-existent and cannot be modified. + + +```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", 2, "John Doe") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_12116\2634951232.py in + ----> 1 VendorDE.ModExcel("Vendor", 2, "John Doe") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) + 242 VendorDict = ExcelRecordsDf.to_dict() + 243 if not Key in self.Keys: + --> 244 raise ValueError("Invalid key, run 'VendorData.Keys' to see options.") + 245 if not Index in VendorDict[Key]: + 246 raise ValueError("Invalid index, run 'self.ReadExcel()' to see options") + + + ValueError: Invalid key, run 'VendorData.Keys' to see options. + + + +```python +VendorDE.ModExcel("Target Language", 3, "Croatian") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_12116\614258264.py in + ----> 1 VendorDE.ModExcel("Target Language", 3, "Croatian") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) + 242 VendorDict = ExcelRecordsDf.to_dict() + 243 if not Key in self.Keys: + --> 244 raise ValueError("Invalid key, run 'VendorData.Keys' to see options.") + 245 if not Index in VendorDict[Key]: + 246 raise ValueError("Invalid index, run 'self.ReadExcel()' to see options") + + + ValueError: Invalid key, run 'VendorData.Keys' to see options. + + +Since there are only 4 vendors in the excel file and the index start at 0 and go up, an error message should appear when you try to modify a higher index: + + +```python +VendorDE.ModExcel("CAT Tool", 6, "XTM") +``` + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\AppData\Local\Temp\ipykernel_12116\235551850.py in + ----> 1 VendorDE.ModExcel("CAT Tool", 6, "XTM") + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) + 244 raise ValueError("Invalid key, run 'VendorData.Keys' to see options.") + 245 if not Index in VendorDict[Key]: + --> 246 raise ValueError("Invalid index, run 'self.ReadExcel()' to see options") + 247 if Key == "E-mail": #validate e-mail address if a value for the key E-mail is modified + 248 CheckVendorMail(NewValue) + + + ValueError: Invalid index, run 'self.ReadExcel()' to see options + + +You can check for the right index by running the `ReadExcel` method for any vendor you already defined: + + +```python +VendorNL.ReadExcel() +``` + + + + + {'Target Language': {0: 'Dutch', 1: 'French', 2: 'Spanish', 3: 'German'}, + 'Vendor': {0: 'Elmo Geeraerts', + 1: 'Jean Lefèvre', + 2: 'Emilio De La Banda', + 3: 'Thomas Zwiebel'}, + 'E-mail': {0: nan, + 1: 'j.lefevre@hotmail.com', + 2: 'e.dlbanda@outlook.com', + 3: nan}, + 'CAT Tool': {0: 'XTM', 1: 'Trados Studio', 2: 'MemoQ', 3: 'XTM'}, + 'Word Rate': {0: 0.08, 1: 0.1, 2: 0.09, 3: nan}, + 'Status': {0: 'Potential', 1: 'Back-up', 2: 'Back-up', 3: 'Potential'}} + + + +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. We'll first look at the help for this script. + + +```python +%run vendor_data.py --help +``` + + usage: vendor_data.py [-h] [-a] [-m] + + optional arguments: + -h, --help show this help message and exit + -a, --add Add a vendor + -m, --modify Modify an existing vendor + + +As you can see, apart from the help argument, there are two other 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; + +We'll start by writing a totally new excel file and adding a vendor to it: + + +```python +%run vendor_data.py --a +``` + + What is the project name? TestProject + What is the source language? English + What's the vendor's name? Elmo Geeraerts + Into which language will the vendor translate? Dutch + What is the vendor's email address? geeraerts@me.com + What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor. 0.12 + 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. True + Are you done? yes + Do you want to add this vendor to the excel file? yes + + +A new excel file will appear next to where you stored this notebook with the name `TestProject_English`, i.e. the project name and source language we provided. +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 + + +```python +%run vendor_data.py --a +``` + + What is the project name? TestProject + What is the source language? English + What's the vendor's name? Jean Baptiste + Into which language will the vendor translate? French + 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? + Blank values are not allowed. + Are you done? yes + Do you want to add this vendor to the excel file? yes + + +If the project name and the source language are the same as for the previous vendor you've entered, this vendor will be added to the same excel file, if not a new excel file is created using the project name and the source language as the file name. You'll notice that for the prompts you leave blank the default value is enterred OR it is left blank. + +Just like when you use this script as a module, the data you provide is validate at every step of the user interaction. TypeErrors do not cause the prompts to stop but instead you get asked the same question again, ValueErrors do break off the code: + + +```python +%run vendor_data.py -a +``` + + What is the project name? TestProject + What is the source language? English + What's the vendor's name? Emanuel Dos Santos + Into which language will the vendor translate? Portuguese + What is the vendor's email address? e_dossantos@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.19 + + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in + 304 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) + 305 if NewWordRate: + --> 306 CheckWordRate(NewWordRate) + 307 VendorWordRate = NewWordRate + 308 else: + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) + 69 raise TypeError("WordRate should be a float!") + 70 if WordRate > 0.15: + ---> 71 raise ValueError("This vendor is too expensive, pick another one.") + 72 if WordRate == 0.00: + 73 raise ValueError("Word rate cannot be 0.00.") + + + ValueError: This vendor is too expensive, pick another one. + + + +```python +%run vendor_data.py -a +``` + + What is the project name? TestProject + What is the source language? English + What's the vendor's name? Emanuel Dos Santos + Into which language will the vendor translate? Portuguese + What is the vendor's email address? e_dossantos@ + + + + --------------------------------------------------------------------------- + + ValueError Traceback (most recent call last) + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in + 298 NewVendorMail = pyip.inputStr("What is the vendor's email address? ", blank = True, default="") + 299 if NewVendorMail: + --> 300 CheckVendorMail(NewVendorMail) + 301 VendorMail = NewVendorMail + 302 else: + + + ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckVendorMail(VendorMail) + 54 raise TypeError ("VendorMail should be a string!") + 55 if not(re.search(regex_mail,VendorMail)): + ---> 56 raise ValueError("Please insert a valid email address.") + 57 def CheckWordRate(WordRate): + 58 """CheckWordRate, validate word rate + + + ValueError: Please insert a valid email address. + + +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 + +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? TestProject + What is the source language? English + These are the vendor's already in the database: + 0: Elmo Geeraerts + 1: Jean Baptiste + Enter the index of the vendor you want to modify: 0 + What is the vendor's e-mail? + What is the vendor's word rate? 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 + Trados Studio + What is the vendor's new status? * Preferred + * Back-up + * Potential + + 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! diff --git a/vendor_data.py b/vendor_data.py index fd0f3d6..1865416 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -301,8 +301,8 @@ def ModExcel(self, Key, Index, NewValue): VendorMail = NewVendorMail else: VendorMail = VendorMail - NewWordRate = pyip.inputNum("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 != None: + 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: @@ -351,8 +351,8 @@ def ModExcel(self, Key, Index, NewValue): NewEmail = pyip.inputStr("What is the vendor's e-mail? ", blank = True) if NewEmail: CheckVendorMail(NewEmail) - NewWordRate = pyip.inputNum("What is the vendor's word rate? Should be between 0.01 and 0.15. If higher, choose another vendor. ", blank = True) - if NewWordRate != None: + 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) From 11ddd3af7cedb5791a932c062a1e94d482a51b80 Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Sun, 11 Jun 2023 12:55:28 +0200 Subject: [PATCH 22/24] General Update --- README.md | 23 +- tutorial.ipynb | 1416 ++++++-------------------- tutorial.md | 2646 ++++++++++++++++++++---------------------------- vendor_data.py | 149 +-- 4 files changed, 1481 insertions(+), 2753 deletions(-) diff --git a/README.md b/README.md index c844a0b..b369f5b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This repository has been created by Elmo Geeraerts for the final assignment of a 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; -- Two `xlsx` files which were generated while creating the `tutorial.ipynb` file. Be aware that if you run the code in the tutorial notebook, some data will be duplicated in the excel if you do not change anything. To avoid this you can delete the two excel files from the directory or you can change the data in the tutorial code to fit your needs.; +- Two `xlsx` files which were generated while creating the `tutorial.ipynb` file. Be aware that if you run the code in the tutorial notebook, some data will be duplicated in the excel if you do not change anything. To avoid this you can delete the two excel files from the directory or you can change the data in the tutorial code to fit your needs. Or you could import the os package and run os.remove('path/to/the/file.xlsx); - The `vendor_data.py` file, i.e. the actual python script that can be run or imported as a module. ## Installation and usage @@ -32,16 +32,24 @@ Check out `tutorial.md` to see an example of the different functionalities of th You can also run the script directly with the following code in a console: ```sh -python vendor_data.py <"-a/--add or -m/--modify"> +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 -m/--modify"> +%run vendor_data.py <-a/--add> +``` +OR +```python +%run vendor_data.py <-m/--modify> ``` - -Running vendor_data.py without either the argument -a (to add a new vendor) or -m (to modify an existing vendor) will not do anything. The argument -a prompts the user to add a new vendor. The data is provided by answering some questions regarding the vendor and the project. The argument -m prompts the user to modify an existing vendor. Again the data is provided by answering some questions regarding the vendor and the project. For more information you can run the command below, or check in the notebook tuturial.ipynb in this repository under "Running `vendor_data.py`". @@ -62,4 +70,7 @@ The main advantage of this script is that it limits the posibilities of CAT tool 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 specific vendors; -- Joining multiple excel files in the excel file created by this code. +- Join multiple excel files in the excel file created by this code. +- not create multiple entries for the same vendor if the excel file already exists and the ToExcel() method is called multiple times for the same vendor. +- delete vendors from the file; +- modify multiple keys in a dictionary if the script is imported as a module. diff --git a/tutorial.ipynb b/tutorial.ipynb index 29f03e7..84eabba 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -17,248 +17,30 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "b3611132", "metadata": {}, "outputs": [], "source": [ "import sys\n", - "sys.path.append ('vendor_data.py') #this is the relative path to the script. If the script is not directly next to the notebook, it could be better to copy the full path of the notebook.\n", + "sys.path.append (r'C:\\Users\\geera\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1')\n", "import vendor_data as vd # 'as vd' is not necessary but makes it shorter." ] }, - { - "cell_type": "markdown", - "id": "fa2cf4f7", - "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:" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "ade0148e", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Help on module vendor_data:\n", - "\n", - "NAME\n", - " vendor_data - 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.\n", - "\n", - "DESCRIPTION\n", - " It contains:\n", - " - 4 functions: \n", - " `ChangeDictionaryValue` to easily change values in a certain dictionary.\n", - " `CheckVendorMail` to easily check if an e-mail address is valid.\n", - " `CheckWordRate` to check if a word rate falls between EUR 0.01 and EUR 0.15 per word.\n", - " `CheckCatTool` to validate the CAT tool provided.\n", - " - 1 class, `VendorData` that has 3 class attributes: `CatTools`, the CAT Tools that can be used for the project,\n", - " `Keys`, the keys of the dictionary that can be modified, and `Statuses`, the possible statuses a vendor can have.\n", - " The class takes 4 positional arguments and 4 optional arguments:\n", - " 1. `ProjectName` (str): the name of the translation project\n", - " 2. `SourceLang` (str): the source language, i.e. the language the translator will translate from\n", - " 3. `TargLang` (str): the target language, i.e. the language the translator will translate into\n", - " 4. `VendorName` (str): the translator's/vendor's name\n", - " 5. `VendorMail` (str): the vendor's e-mail address, by default empty\n", - " 6. `WordRate` (float): the vendor's word rate in EUR/word, by default set to \"None\"\n", - " 7. `CatTool` (str): the CAT Tool the translator will use, by default set to \"XTM\"\n", - " 8. `Preferred` (bool): indicates if a vendor is a preferred vendor or not, by default set to \"None\"\n", - " - `Argparse` inside `if __name__ == \"__main__\":` statement to receive arguments when the script is run\n", - "\n", - "CLASSES\n", - " builtins.object\n", - " VendorData\n", - " \n", - " class VendorData(builtins.object)\n", - " | VendorData(ProjectName, SourceLang, TargLang, VendorName, VendorMail='', WordRate=None, CatTool='XTM', Preferred=None)\n", - " | \n", - " | Methods defined here:\n", - " | \n", - " | ChangeTool(self, NewTool)\n", - " | Method\n", - " | \n", - " | Args:\n", - " | NewTool (str): a new tool for a certain vendor\n", - " | \n", - " | ModExcel(self, Key, Index, NewValue)\n", - " | Method to modify existing vendor in excel file\n", - " | \n", - " | Args:\n", - " | Key (str): one of the modifiable keys in VendorData.Keys\n", - " | Index (int): the index of the value that needs to be modified\n", - " | NewValue : the new value of the index, type depends on the key, either str or float\n", - " | \n", - " | Raises:\n", - " | ValueError: raised if the key is not one of the keys in VendorData.Keys\n", - " | ValueError: raised if the Index is not valid for a certain key\n", - " | \n", - " | ReadExcel(self)\n", - " | \n", - " | SetStatus(self, PrefVend)\n", - " | Method\n", - " | \n", - " | Args:\n", - " | PrefVend (bool): new value for Preferred, has an influence on status\n", - " | \n", - " | SetVendorMail(self, NewMail)\n", - " | Method\n", - " | \n", - " | Args:\n", - " | NewMail (str): a new e-mail address for a certain vendor\n", - " | \n", - " | SetWordRate(self, NewRate)\n", - " | Method\n", - " | \n", - " | Args:\n", - " | NewRate (float): a new word rate for a certain vendor\n", - " | \n", - " | ToExcel(self)\n", - " | \n", - " | __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail='', WordRate=None, CatTool='XTM', Preferred=None)\n", - " | Instantiate\n", - " | \n", - " | Class Attributes:\n", - " | CatTools (list) :\n", - " | Keys (list) :\n", - " | Statuses (list) :\n", - " | \n", - " | Args:\n", - " | ProjectName (str): the name of the translation project\n", - " | SourceLang (str): the source language, i.e. the language the translator will translate from\n", - " | TargLang (str): the target language, i.e. the language the translator will translate into\n", - " | VendorName (str): the translator's/vendor's name\n", - " | VendorMail (str, optional): the vendor's e-mail address, by default empty\n", - " | WordRate (float, optional): the vendor's word rate in EUR/word, by default set to \"None\"\n", - " | CatTool (str, optional): the CAT Tool the translator will use, by default set to \"XTM\"\n", - " | Preferred (bool, optional): indicates if a vendor is a preferred vendor or not, by default set to \"None\".\n", - " | \n", - " | Raises:\n", - " | TypeError: ProjectName should be a string\n", - " | TypeError: SourceLang should be a string\n", - " | TypeError: TargLang should be a string\n", - " | TypeError: VendorName should be a string\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Data descriptors defined here:\n", - " | \n", - " | __dict__\n", - " | dictionary for instance variables (if defined)\n", - " | \n", - " | __weakref__\n", - " | list of weak references to the object (if defined)\n", - " | \n", - " | ----------------------------------------------------------------------\n", - " | Data and other attributes defined here:\n", - " | \n", - " | CatTools = ['XTM', 'Trados Studio', 'MemoQ', 'Memsource']\n", - " | \n", - " | Keys = ['E-mail', 'CAT Tool', 'Word Rate', 'Status']\n", - " | \n", - " | Statuses = ['Preferred', 'Back-up', 'Potential']\n", - "\n", - "FUNCTIONS\n", - " ChangeDictionaryValue(Dictionary, Key, Index, NewValue)\n", - " ChangeDictionaryValue, change values of a dictionary\n", - " \n", - " Args:\n", - " Dictionary (dict): name of the dictionary that will be read\n", - " Key (str): the key for which the value will be changed\n", - " Index (int): the index of the value that will be changed\n", - " NewValue: new value for the chosen index, type depends on the key\n", - " \n", - " CheckCatTool(CatTool)\n", - " CheckCatTool, validate CatTOol\n", - " \n", - " Args:\n", - " CatTool (str): a CAT Tool\n", - " \n", - " Raises:\n", - " TypeError: if the argument provided is not string, a TypeError is raised\n", - " ValueError: the argument provided should be one of the four CAT Tools in the list [\"XTM\", \"Trados Studio\", \"MemoQ\", \"Memsource\"]\n", - " \n", - " CheckVendorMail(VendorMail)\n", - " CheckVendorMail, validate e-mail address\n", - " \n", - " Args:\n", - " VendorMail (str): an e-mail address\n", - " \n", - " Raises:\n", - " TypeError: if the argument provided is not a string, a TypeError is raised\n", - " ValueError: if the address provided does not conform with the regex string `regex_mail`, a ValueError is raised\n", - " \n", - " CheckWordRate(WordRate)\n", - " CheckWordRate, validate word rate\n", - " \n", - " Args:\n", - " WordRate (float): a word rate in EUR/word\n", - " \n", - " Raises:\n", - " TypeError: if the argument provided is not a float, a TypeError is raised\n", - " ValueError: the argument provided should not be higher than 0.15\n", - " ValueError: the argument provided should not be 0.00\n", - "\n", - "FILE\n", - " c:\\users\\geera\\onedrive\\documenten\\school\\postgraduaattranslationtechnology\\introductiontopython\\final_assignment1\\vendor_data.py\n", - "\n", - "\n" - ] - } - ], - "source": [ - "help(vd)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "d6fb22b9", - "metadata": {}, - "outputs": [], - "source": [ - "?vd" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "803ee5b0", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'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.\\n\\n It contains:\\n - 4 functions: \\n `ChangeDictionaryValue` to easily change values in a certain dictionary.\\n `CheckVendorMail` to easily check if an e-mail address is valid.\\n `CheckWordRate` to check if a word rate falls between EUR 0.01 and EUR 0.15 per word.\\n `CheckCatTool` to validate the CAT tool provided.\\n - 1 class, `VendorData` that has 3 class attributes: `CatTools`, the CAT Tools that can be used for the project,\\n `Keys`, the keys of the dictionary that can be modified, and `Statuses`, the possible statuses a vendor can have.\\n The class takes 4 positional arguments and 4 optional arguments:\\n 1. `ProjectName` (str): the name of the translation project\\n 2. `SourceLang` (str): the source language, i.e. the language the translator will translate from\\n 3. `TargLang` (str): the target language, i.e. the language the translator will translate into\\n 4. `VendorName` (str): the translator\\'s/vendor\\'s name\\n 5. `VendorMail` (str): the vendor\\'s e-mail address, by default empty\\n 6. `WordRate` (float): the vendor\\'s word rate in EUR/word, by default set to \"None\"\\n 7. `CatTool` (str): the CAT Tool the translator will use, by default set to \"XTM\"\\n 8. `Preferred` (bool): indicates if a vendor is a preferred vendor or not, by default set to \"None\"\\n - `Argparse` inside `if __name__ == \"__main__\":` statement to receive arguments when the script is run\\n '" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "vd.__doc__" - ] - }, { "cell_type": "markdown", "id": "b9df49cf", "metadata": {}, "source": [ - "### Instantiating an instance of VendorData\n", - "Now that we know the different fucntionalities we can instantiate an instance of the class VendorData.\n", - "To illustrate the code to it's full extent, we'll instantiate a couple of them:" + "### 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": 6, + "execution_count": null, "id": "4ab17746", "metadata": {}, "outputs": [], @@ -278,63 +60,30 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "id": "c6675ef0", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Elmo Geeraerts'" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorNL.VendorName" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "23b52971", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'j.lefevre@hotmail.com'" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorFR.VendorMail" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "69659b86", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.09" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorES.WordRate" ] @@ -344,26 +93,15 @@ "id": "a831785f", "metadata": {}, "source": [ - "Some arguments had default arguments. When we check the e-mail for VendorNL, for which we didn't provide one, we'll see that it does not return anything:" + "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 does not return anything:" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "cb2ca64c", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "''" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorNL.VendorMail" ] @@ -378,21 +116,10 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "c7180a19", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'XTM'" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorES.CatTool" ] @@ -408,91 +135,47 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "e26d1539", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorFR.Preferred" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "id": "935c0a38", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Preferred'" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorFR.Status" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "9ebc7f07", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorES.Preferred" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "id": "1158b1de", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Back-up'" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorES.Status" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "id": "ab5e5f54", "metadata": {}, "outputs": [], @@ -502,21 +185,10 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "id": "50cd8967", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Potential'" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorNL.Status" ] @@ -526,8 +198,8 @@ "id": "47936f2c", "metadata": {}, "source": [ - "### Functions\n", - "The class also contains a couple of functions:\n", + "### 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", @@ -541,21 +213,10 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "id": "90cb5c10", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'e.dlbanda@outlook.com'" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorES.SetVendorMail(\"e.dlbanda@outlook.com\")\n", "VendorES.VendorMail" @@ -571,21 +232,10 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "id": "730b35ca", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.08" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorNL.SetWordRate(0.08)\n", "VendorNL.WordRate" @@ -601,21 +251,10 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "id": "391e7c5d", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Trados Studio'" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorES.ChangeTool(\"Trados Studio\")\n", "VendorES.CatTool" @@ -631,21 +270,10 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "id": "96819356", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorFR.SetStatus(False)\n", "VendorFR.Preferred" @@ -653,21 +281,10 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "id": "e8335217", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Back-up'" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorFR.Status" ] @@ -677,12 +294,34 @@ "id": "0bf8e1d0", "metadata": {}, "source": [ - "We can now write the data for the vendors to an excel file. Since every vendor has the value for the argument `ProjectName` and `SourceLang`, they will be written to the same excel file. We should execute this function for every vendor. Be careful because if you run this function multiple times for the same vendor, it will not overwrite but append and you will have duplicates in the excel file." + "We can now write the data for the vendors to an excel file. To be sure the file does not already exist, we'll first delete the excel file for the project called `Tutorial` in the source language `English`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ca4a9c99", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "os.remove('Tutorial_English.xlsx') #If the file is stored elsewhere, copy the full path to the excel file." + ] + }, + { + "cell_type": "markdown", + "id": "813e7f50", + "metadata": {}, + "source": [ + "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": 23, + "execution_count": null, "id": "aeafcb32", "metadata": {}, "outputs": [], @@ -698,31 +337,15 @@ "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 function 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:" + "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": 24, + "execution_count": null, "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": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorNL.ReadExcel()" ] @@ -732,28 +355,15 @@ "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 function without writing it to an excel file, we'll get an error message saying that a file for the project in the given source language does not exist." + "If we create another vendor that works on a different project or translates from another source language and call the same method without writing it to an excel file, 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": 25, + "execution_count": null, "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_12116\\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 222\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mVendorDict\u001b[0m \u001b[1;31m#print the Dictionary\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 223\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--> 224\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 225\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 226\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[0mIndex\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" - ] - } - ], + "outputs": [], "source": [ "VendorBG = vd.VendorData(\"Tutorial\", \"German\", \"Bulgarian\", \"Bulgarian Jacob\")\n", "VendorBG.ReadExcel()" @@ -764,8 +374,13 @@ "id": "e0592b3d", "metadata": {}, "source": [ - "We can also modify the excel file by running the `ModExcel` function. Again, it does not matter for which vendor you call this function.\n", - "This function takes 3 arguments:\n", + "We can also modify the excel file by running the `ModExcel` method. You could call this method for any instance you created and modify any vendor in the excel file. However this is not advisable since it will modify the correct vendor, but if you check the values by calling the argument (self.argument), the script thinks it is the vendor that you called the method for that is modified.\n", + "\n", + "
\n", + "Run the `ModExcel()` method for the vendor you actually want to modify. It is possible to modify another vendor, but the script will still think you modified the vendor you called the method.\n", + "
\n", + "\n", + "This method takes 3 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", "2. The `Index`: if you have run the ReadExcel() function, you have noticed that before every value for a key in the dictionrary there's a number. By picking a number, you can change the value for that index.\n", "3. The `NewValue`, the new value for the index in a key.\n", @@ -775,21 +390,10 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "id": "17292d31", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['E-mail', 'CAT Tool', 'Word Rate', 'Status']" - ] - }, - "execution_count": 26, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "vd.VendorData.Keys" ] @@ -804,26 +408,10 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "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": 27, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorNL.ReadExcel()" ] @@ -838,7 +426,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "id": "52e91ff2", "metadata": {}, "outputs": [], @@ -851,62 +439,89 @@ "id": "cfec5fae", "metadata": {}, "source": [ - "If you check this by running `.CatTool`, the old value will still be there." + "If you check this by running `.CatTool`, the value will be changed." ] }, { "cell_type": "code", - "execution_count": 29, + "execution_count": null, "id": "f4e539d4", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Trados Studio'" - ] - }, - "execution_count": 29, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorES.CatTool" ] }, { "cell_type": "markdown", - "id": "85cc6b7f", + "id": "6539e2b4", + "metadata": {}, + "source": [ + "As already mentioned, you could call the `ModExcel()` method for any vendor and modify another one, but the script will still think you modified the vendor you called the method for. This is bad practice and you should not do this! We'll illustrate what would happen if you did:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "055d1046", + "metadata": {}, + "outputs": [], + "source": [ + "VendorNL.ModExcel(\"Status\", 2, \"Preferred\")" + ] + }, + { + "cell_type": "markdown", + "id": "0eae995b", + "metadata": {}, + "source": [ + "We'll see that the status for the Spanish vendor is not changed:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "95ddcda9", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.Status" + ] + }, + { + "cell_type": "markdown", + "id": "92fbdd31", + "metadata": {}, + "source": [ + "But the status for the Dutch one is:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7c7d3af1", + "metadata": {}, + "outputs": [], + "source": [ + "VendorNL.Status" + ] + }, + { + "cell_type": "markdown", + "id": "83fd2f6e", "metadata": {}, "source": [ - "However, if we read the excel file again, we'll notice it has changed:" + "However, if we read the excel (`ReadExcel()`), we'll see that it is in fact the Spanish vendor's status that is changed. Here it does not matter for which vendor we call the method:" ] }, { "cell_type": "code", - "execution_count": 30, - "id": "072bbb59", + "execution_count": null, + "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: 'Potential', 1: 'Back-up', 2: 'Back-up'}}" - ] - }, - "execution_count": 30, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "VendorES.ReadExcel()" + "VendorNL.ReadExcel()" ] }, { @@ -936,187 +551,80 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": null, "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_12116\\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 118\u001b[0m \"\"\"\n\u001b[0;32m 119\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--> 120\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 121\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 122\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!" - ] - } - ], + "outputs": [], "source": [ "VendorDE = vd.VendorData(0.1, \"English\", \"German\", \"Thomas Zwiebel\")" ] }, { "cell_type": "code", - "execution_count": 32, + "execution_count": null, "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_12116\\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 120\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 121\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--> 122\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 123\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 124\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!" - ] - } - ], + "outputs": [], "source": [ "VendorDE = vd.VendorData(\"Tutorial\", 1, \"German\", \"Thomas Zwiebel\")" ] }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "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_12116\\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 122\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 123\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--> 124\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 125\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 126\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!" - ] - } - ], + "outputs": [], "source": [ "VendorDE = vd.VendorData(\"Tutorial\", \"English\", True, \"Thomas Zwiebel\")" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": null, "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_12116\\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 124\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 125\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--> 126\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 127\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 128\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!" - ] - } - ], + "outputs": [], "source": [ "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", None)" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": null, "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_12116\\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 126\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 127\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--> 128\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 129\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 130\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 52\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 53\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---> 54\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 55\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 56\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!" - ] - } - ], + "outputs": [], "source": [ "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", 3)" ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": null, "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_12116\\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 128\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 129\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--> 130\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 131\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 132\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 67\u001b[0m \"\"\"\n\u001b[0;32m 68\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---> 69\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 70\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 71\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!" - ] - } - ], + "outputs": [], "source": [ "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = \"0.15\")" ] }, { "cell_type": "code", - "execution_count": 37, + "execution_count": null, "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_12116\\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 133\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 134\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--> 135\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 136\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 137\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." - ] - } - ], + "outputs": [], "source": [ "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", Preferred = \"Test\")" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": null, "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_12116\\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 130\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 131\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--> 132\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 133\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 134\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 83\u001b[0m \"\"\"\n\u001b[0;32m 84\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---> 85\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 86\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mCatTool\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m\"XTM\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Trados Studio\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"MemoQ\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Memsource\"\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 87\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!" - ] - } - ], + "outputs": [], "source": [ "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", CatTool = True)" ] @@ -1128,102 +636,56 @@ "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\n", - "- `CatTool` is one of the following: XTM, Trados Studio, MemoQ or Memsource" + "- `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": 39, + "execution_count": null, "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_12116\\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 126\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 127\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--> 128\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 129\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 130\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 54\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 55\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---> 56\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 57\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 58\u001b[0m \"\"\"CheckWordRate, validate word rate\n", - "\u001b[1;31mValueError\u001b[0m: Please insert a valid email address." - ] - } - ], + "outputs": [], "source": [ "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", VendorMail = \"thomas.zw\")" ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": null, "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_12116\\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 128\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 129\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--> 130\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 131\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 132\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 69\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 70\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---> 71\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 72\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 73\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." - ] - } - ], + "outputs": [], "source": [ "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = 0.19)" ] }, { "cell_type": "code", - "execution_count": 41, + "execution_count": null, "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_12116\\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 128\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 129\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--> 130\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 131\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 132\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 71\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 72\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---> 73\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 74\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 75\u001b[0m \"\"\"CheckCatTool, validate CatTOol\n", - "\u001b[1;31mValueError\u001b[0m: Word rate cannot be 0.00." - ] - } - ], + "outputs": [], "source": [ "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = 0.00)" ] }, { "cell_type": "code", - "execution_count": 42, + "execution_count": null, + "id": "87ad7fb4", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = -0.04)" + ] + }, + { + "cell_type": "code", + "execution_count": null, "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_12116\\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 130\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 131\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--> 132\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 133\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 134\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 85\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 86\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mCatTool\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m\"XTM\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Trados Studio\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"MemoQ\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Memsource\"\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---> 87\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 88\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 89\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." - ] - } - ], + "outputs": [], "source": [ "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", CatTool = \"SDL Trados Studio\")" ] @@ -1241,7 +703,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": null, "id": "adb90ded", "metadata": {}, "outputs": [], @@ -1251,119 +713,60 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": null, "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_12116\\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[0mNewMail\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0ma\u001b[0m \u001b[0mnew\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mmail\u001b[0m \u001b[0maddress\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0ma\u001b[0m \u001b[0mcertain\u001b[0m \u001b[0mvendor\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 54\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 55\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---> 56\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 57\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 58\u001b[0m \"\"\"CheckWordRate, validate word rate\n", - "\u001b[1;31mValueError\u001b[0m: Please insert a valid email address." - ] - } - ], + "outputs": [], "source": [ "VendorDE.SetVendorMail(\"thomas.zw@\")" ] }, { "cell_type": "code", - "execution_count": 45, + "execution_count": null, "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_12116\\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 166\u001b[0m \u001b[0mNewRate\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mfloat\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0ma\u001b[0m \u001b[0mnew\u001b[0m \u001b[0mword\u001b[0m \u001b[0mrate\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0ma\u001b[0m \u001b[0mcertain\u001b[0m \u001b[0mvendor\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 167\u001b[0m \"\"\"\n\u001b[1;32m--> 168\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 169\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 170\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 69\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 70\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---> 71\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 72\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 73\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." - ] - } - ], + "outputs": [], "source": [ "VendorDE.SetWordRate(0.18)" ] }, { "cell_type": "code", - "execution_count": 46, + "execution_count": null, "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_12116\\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 166\u001b[0m \u001b[0mNewRate\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mfloat\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0ma\u001b[0m \u001b[0mnew\u001b[0m \u001b[0mword\u001b[0m \u001b[0mrate\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0ma\u001b[0m \u001b[0mcertain\u001b[0m \u001b[0mvendor\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 167\u001b[0m \"\"\"\n\u001b[1;32m--> 168\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 169\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 170\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 71\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 72\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---> 73\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 74\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 75\u001b[0m \"\"\"CheckCatTool, validate CatTOol\n", - "\u001b[1;31mValueError\u001b[0m: Word rate cannot be 0.00." - ] - } - ], + "outputs": [], "source": [ "VendorDE.SetWordRate (0.00)" ] }, { "cell_type": "code", - "execution_count": 47, + "execution_count": null, + "id": "63dc4cab", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE.SetWordRate(-0.04)" + ] + }, + { + "cell_type": "code", + "execution_count": null, "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_12116\\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 175\u001b[0m \u001b[0mNewTool\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0ma\u001b[0m \u001b[0mnew\u001b[0m \u001b[0mtool\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0ma\u001b[0m \u001b[0mcertain\u001b[0m \u001b[0mvendor\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 176\u001b[0m \"\"\"\n\u001b[1;32m--> 177\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 178\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 179\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 85\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 86\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mCatTool\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m\"XTM\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Trados Studio\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"MemoQ\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Memsource\"\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---> 87\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 88\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 89\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." - ] - } - ], + "outputs": [], "source": [ "VendorDE.ChangeTool(\"SDL Trados Studio\")" ] }, { "cell_type": "code", - "execution_count": 48, + "execution_count": null, "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_12116\\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 186\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 187\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--> 188\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 189\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 190\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." - ] - } - ], + "outputs": [], "source": [ "VendorDE.SetStatus(\"None\")" ] @@ -1373,12 +776,15 @@ "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:" + "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, + "execution_count": null, "id": "b9e3cd49", "metadata": {}, "outputs": [], @@ -1396,95 +802,40 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": null, "id": "f9d200e7", "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_12116\\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;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mModExcel\u001b[1;34m(self, Key, Index, NewValue)\u001b[0m\n\u001b[0;32m 246\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid index, run 'self.ReadExcel()' to see options\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 247\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"E-mail\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate e-mail address if a value for the key E-mail is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 248\u001b[1;33m \u001b[0mCheckVendorMail\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[0m\n\u001b[0m\u001b[0;32m 249\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"Word Rate\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate word rate if a value for the key Word Rate is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 250\u001b[0m \u001b[0mCheckWordRate\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[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 54\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 55\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---> 56\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 57\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 58\u001b[0m \"\"\"CheckWordRate, validate word rate\n", - "\u001b[1;31mValueError\u001b[0m: Please insert a valid email address." - ] - } - ], + "outputs": [], "source": [ "VendorDE.ModExcel(\"E-mail\", 3, \"thomaszw@\")" ] }, { "cell_type": "code", - "execution_count": 51, + "execution_count": null, "id": "3db36ec1", "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_12116\\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;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mModExcel\u001b[1;34m(self, Key, Index, NewValue)\u001b[0m\n\u001b[0;32m 250\u001b[0m \u001b[0mCheckWordRate\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[0m\n\u001b[0;32m 251\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"CAT Tool\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate CAT Tool if a value for the key CAT Tool is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 252\u001b[1;33m \u001b[0mCheckCatTool\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[0m\n\u001b[0m\u001b[0;32m 253\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"Status\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate Status if a value for the key Status is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 254\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mNewValue\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mVendorData\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mStatuses\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 85\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 86\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mCatTool\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m\"XTM\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Trados Studio\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"MemoQ\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Memsource\"\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---> 87\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 88\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 89\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." - ] - } - ], + "outputs": [], "source": [ "VendorDE.ModExcel(\"CAT Tool\", 3, \"Trados Studio 2019\")" ] }, { "cell_type": "code", - "execution_count": 52, + "execution_count": null, "id": "43492fbd", "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_12116\\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;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mModExcel\u001b[1;34m(self, Key, Index, NewValue)\u001b[0m\n\u001b[0;32m 248\u001b[0m \u001b[0mCheckVendorMail\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[0m\n\u001b[0;32m 249\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"Word Rate\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate word rate if a value for the key Word Rate is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 250\u001b[1;33m \u001b[0mCheckWordRate\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[0m\n\u001b[0m\u001b[0;32m 251\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"CAT Tool\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate CAT Tool if a value for the key CAT Tool is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 252\u001b[0m \u001b[0mCheckCatTool\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[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 69\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 70\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---> 71\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 72\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 73\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." - ] - } - ], + "outputs": [], "source": [ "VendorDE.ModExcel(\"Word Rate\", 3, 0.18)" ] }, { "cell_type": "code", - "execution_count": 53, + "execution_count": null, "id": "fcc7bf99", "metadata": {}, - "outputs": [ - { - "ename": "ValueError", - "evalue": "Invalid status, run 'VendorData.Statuses' 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_12116\\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;32m~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36mModExcel\u001b[1;34m(self, Key, Index, NewValue)\u001b[0m\n\u001b[0;32m 253\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"Status\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate Status if a value for the key Status is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 254\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mNewValue\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mVendorData\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mStatuses\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 255\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid status, run 'VendorData.Statuses' 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 256\u001b[0m \u001b[0mChangeDictionaryValue\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorDict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mKey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mIndex\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mNewValue\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#change the dictionary value in the dictionary `VendorDict` using the arguments provided for the method ModExcel\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 257\u001b[0m \u001b[0mdf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mVendorDict\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#turn VendorDict dictionary back into a panda DataFrame\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mValueError\u001b[0m: Invalid status, run 'VendorData.Statuses' to see options" - ] - } - ], + "outputs": [], "source": [ "VendorDE.ModExcel(\"Status\", 3, \"Busy\")" ] @@ -1495,26 +846,18 @@ "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", - "Additionally it also is checked if the index is in the dictionary, otherwise the vendor is non-existent and cannot be modified." + "Additionally it also is checked if the index is in the dictionary, otherwise the vendor is non-existent and cannot be modified.\n", + "
\n", + "You can only modify one value for one key.\n", + "
" ] }, { "cell_type": "code", - "execution_count": 54, + "execution_count": null, "id": "405573dd", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['E-mail', 'CAT Tool', 'Word Rate', 'Status']" - ] - }, - "execution_count": 54, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "vd.VendorData.Keys" ] @@ -1529,46 +872,20 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": null, "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_12116\\2634951232.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;36m2\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, Index, NewValue)\u001b[0m\n\u001b[0;32m 242\u001b[0m \u001b[0mVendorDict\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mExcelRecordsDf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_dict\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 243\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--> 244\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 245\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mIndex\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mVendorDict\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mKey\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 246\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid index, run 'self.ReadExcel()' to see options\"\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." - ] - } - ], + "outputs": [], "source": [ "VendorDE.ModExcel(\"Vendor\", 2, \"John Doe\")" ] }, { "cell_type": "code", - "execution_count": 56, + "execution_count": null, "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_12116\\614258264.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;36m3\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, Index, NewValue)\u001b[0m\n\u001b[0;32m 242\u001b[0m \u001b[0mVendorDict\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mExcelRecordsDf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_dict\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 243\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--> 244\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 245\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mIndex\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mVendorDict\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mKey\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 246\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid index, run 'self.ReadExcel()' to see options\"\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." - ] - } - ], + "outputs": [], "source": [ "VendorDE.ModExcel(\"Target Language\", 3, \"Croatian\")" ] @@ -1583,23 +900,10 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": null, "id": "66ca7b9e", "metadata": {}, - "outputs": [ - { - "ename": "ValueError", - "evalue": "Invalid index, run 'self.ReadExcel()' 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_12116\\235551850.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;36m6\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"XTM\"\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, Index, NewValue)\u001b[0m\n\u001b[0;32m 244\u001b[0m \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[0;32m 245\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mIndex\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mVendorDict\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mKey\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--> 246\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid index, run 'self.ReadExcel()' 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 247\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mKey\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"E-mail\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m#validate e-mail address if a value for the key E-mail is modified\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 248\u001b[0m \u001b[0mCheckVendorMail\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[0m\n", - "\u001b[1;31mValueError\u001b[0m: Invalid index, run 'self.ReadExcel()' to see options" - ] - } - ], + "outputs": [], "source": [ "VendorDE.ModExcel(\"CAT Tool\", 6, \"XTM\")" ] @@ -1614,32 +918,10 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": null, "id": "38b01366", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'Target Language': {0: 'Dutch', 1: 'French', 2: 'Spanish', 3: 'German'},\n", - " 'Vendor': {0: 'Elmo Geeraerts',\n", - " 1: 'Jean Lefèvre',\n", - " 2: 'Emilio De La Banda',\n", - " 3: 'Thomas Zwiebel'},\n", - " 'E-mail': {0: nan,\n", - " 1: 'j.lefevre@hotmail.com',\n", - " 2: 'e.dlbanda@outlook.com',\n", - " 3: nan},\n", - " 'CAT Tool': {0: 'XTM', 1: 'Trados Studio', 2: 'MemoQ', 3: 'XTM'},\n", - " 'Word Rate': {0: 0.08, 1: 0.1, 2: 0.09, 3: nan},\n", - " 'Status': {0: 'Potential', 1: 'Back-up', 2: 'Back-up', 3: 'Potential'}}" - ] - }, - "execution_count": 58, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "VendorNL.ReadExcel()" ] @@ -1658,71 +940,19 @@ "metadata": {}, "source": [ "## Running `vendor_data.py`\n", - "The script can also be run on its own. We'll first look at the help for this script." - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "id": "1ac6c1de", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "usage: vendor_data.py [-h] [-a] [-m]\n", - "\n", - "optional arguments:\n", - " -h, --help show this help message and exit\n", - " -a, --add Add a vendor\n", - " -m, --modify Modify an existing vendor\n" - ] - } - ], - "source": [ - "%run vendor_data.py --help" - ] - }, - { - "cell_type": "markdown", - "id": "cc95becc", - "metadata": {}, - "source": [ - "As you can see, apart from the help argument, there are two other optional arguments:\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", - "\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", "We'll start by writing a totally new excel file and adding a vendor to it:" ] }, { "cell_type": "code", - "execution_count": 60, + "execution_count": null, "id": "a32de96d", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "What is the project name? TestProject\n", - "What is the source language? English\n", - "What's the vendor's name? Elmo Geeraerts\n", - "Into which language will the vendor translate? Dutch\n", - "What is the vendor's email address? geeraerts@me.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.12\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. True\n", - "Are you done? yes\n", - "Do you want to add this vendor to the excel file? yes\n" - ] - } - ], + "outputs": [], "source": [ "%run vendor_data.py --a" ] @@ -1740,114 +970,20 @@ "- Whether or not the vendor is a preferred vendor" ] }, - { - "cell_type": "code", - "execution_count": 61, - "id": "8f91cd3a", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "What is the project name? TestProject\n", - "What is the source language? English\n", - "What's the vendor's name? Jean Baptiste\n", - "Into which language will the vendor translate? French\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? \n", - "Blank values are not allowed.\n", - "Are you done? yes\n", - "Do you want to add this vendor to the excel file? yes\n" - ] - } - ], - "source": [ - "%run vendor_data.py --a" - ] - }, { "cell_type": "markdown", "id": "d652047e", "metadata": {}, "source": [ - "If the project name and the source language are the same as for the previous vendor you've entered, this vendor will be added to the same excel file, if not a new excel file is created using the project name and the source language as the file name. You'll notice that for the prompts you leave blank the default value is enterred OR it is left blank.\n", - "\n", - "Just like when you use this script as a module, the data you provide is validate at every step of the user interaction. TypeErrors do not cause the prompts to stop but instead you get asked the same question again, ValueErrors do break off the code:" + "If the project name and the source language are the same as for the previous vendor you've entered, this vendor will be added to the same excel file, if not a new excel file is created using the project name and the source language as the file name. You'll notice that for the prompts you leave blank the default value is enterred OR it is left blank." ] }, { "cell_type": "code", - "execution_count": 62, + "execution_count": null, "id": "7c4e5ac4", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "What is the project name? TestProject\n", - "What is the source language? English\n", - "What's the vendor's name? Emanuel Dos Santos\n", - "Into which language will the vendor translate? Portuguese\n", - "What is the vendor's email address? e_dossantos@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.19\n" - ] - }, - { - "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~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 304\u001b[0m \u001b[0mNewWordRate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpyip\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minputFloat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor. \"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mblank\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[0;32m 305\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mNewWordRate\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 306\u001b[1;33m \u001b[0mCheckWordRate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNewWordRate\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 307\u001b[0m \u001b[0mVendorWordRate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mNewWordRate\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 308\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~\\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 69\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 70\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---> 71\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 72\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 73\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": [ - "%run vendor_data.py -a" - ] - }, - { - "cell_type": "code", - "execution_count": 63, - "id": "ec294039", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "What is the project name? TestProject\n", - "What is the source language? English\n", - "What's the vendor's name? Emanuel Dos Santos\n", - "Into which language will the vendor translate? Portuguese\n", - "What is the vendor's email address? e_dossantos@\n" - ] - }, - { - "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~\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1\\vendor_data.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 298\u001b[0m \u001b[0mNewVendorMail\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpyip\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minputStr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"What is the vendor's email address? \"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mblank\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdefault\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 299\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mNewVendorMail\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 300\u001b[1;33m \u001b[0mCheckVendorMail\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNewVendorMail\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 301\u001b[0m \u001b[0mVendorMail\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mNewVendorMail\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 302\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~\\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 54\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 55\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---> 56\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 57\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 58\u001b[0m \"\"\"CheckWordRate, validate word rate\n", - "\u001b[1;31mValueError\u001b[0m: Please insert a valid email address." - ] - } - ], + "outputs": [], "source": [ "%run vendor_data.py -a" ] @@ -1866,36 +1002,10 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": null, "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? TestProject\n", - "What is the source language? English\n", - "These are the vendor's already in the database: \n", - "0: Elmo Geeraerts\n", - "1: Jean Baptiste\n", - "Enter the index of the vendor you want to modify: 0\n", - "What is the vendor's e-mail? \n", - "What is the vendor's word rate? 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", - "Trados Studio\n", - "What is the vendor's new status? * Preferred\n", - "* Back-up\n", - "* Potential\n", - "\n", - "Are you done? yes\n", - "This vendor is modified correctly.\n" - ] - } - ], + "outputs": [], "source": [ "%run vendor_data.py -m" ] @@ -1909,6 +1019,52 @@ "\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", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "927da363", + "metadata": {}, + "outputs": [], + "source": [ + "%run vendor_data.py -h" + ] } ], "metadata": { @@ -1927,7 +1083,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.9.16" } }, "nbformat": 4, diff --git a/tutorial.md b/tutorial.md index 1ac186f..0b5affe 100644 --- a/tutorial.md +++ b/tutorial.md @@ -1,1555 +1,1091 @@ -# Tutorial: how to use `vendor_data.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 ('vendor_data.py') #this is the relative path to the script. If the script is not directly next to the notebook, it could be better to copy the full path of the notebook. -import vendor_data as vd # 'as vd' is not necessary but makes it shorter. -``` - -### 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: - - -```python -help(vd) -``` - - Help on module vendor_data: - - NAME - vendor_data - 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. - - DESCRIPTION - 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: - 1. `ProjectName` (str): the name of the translation project - 2. `SourceLang` (str): the source language, i.e. the language the translator will translate from - 3. `TargLang` (str): the target language, i.e. the language the translator will translate into - 4. `VendorName` (str): the translator's/vendor's name - 5. `VendorMail` (str): the vendor's e-mail address, by default empty - 6. `WordRate` (float): the vendor's word rate in EUR/word, by default set to "None" - 7. `CatTool` (str): the CAT Tool the translator will use, by default set to "XTM" - 8. `Preferred` (bool): indicates if a vendor is a preferred vendor or not, by default set to "None" - - `Argparse` inside `if __name__ == "__main__":` statement to receive arguments when the script is run - - CLASSES - builtins.object - VendorData - - class VendorData(builtins.object) - | VendorData(ProjectName, SourceLang, TargLang, VendorName, VendorMail='', WordRate=None, CatTool='XTM', Preferred=None) - | - | Methods defined here: - | - | ChangeTool(self, NewTool) - | Method - | - | Args: - | NewTool (str): a new tool for a certain vendor - | - | ModExcel(self, Key, Index, NewValue) - | Method to modify existing vendor in excel file - | - | Args: - | Key (str): one of the modifiable keys in VendorData.Keys - | Index (int): the index of the value that needs to be modified - | NewValue : the new value of the index, 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 Index is not valid for a certain key - | - | ReadExcel(self) - | - | SetStatus(self, PrefVend) - | Method - | - | Args: - | PrefVend (bool): new value for Preferred, has an influence on status - | - | SetVendorMail(self, NewMail) - | Method - | - | Args: - | NewMail (str): a new e-mail address for a certain vendor - | - | SetWordRate(self, NewRate) - | Method - | - | Args: - | NewRate (float): a new word rate for a certain vendor - | - | ToExcel(self) - | - | __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 - | - | ---------------------------------------------------------------------- - | Data descriptors defined here: - | - | __dict__ - | dictionary for instance variables (if defined) - | - | __weakref__ - | list of weak references to the object (if defined) - | - | ---------------------------------------------------------------------- - | Data and other attributes defined here: - | - | CatTools = ['XTM', 'Trados Studio', 'MemoQ', 'Memsource'] - | - | Keys = ['E-mail', 'CAT Tool', 'Word Rate', 'Status'] - | - | Statuses = ['Preferred', 'Back-up', 'Potential'] - - FUNCTIONS - ChangeDictionaryValue(Dictionary, Key, Index, NewValue) - ChangeDictionaryValue, change values of a 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 - - CheckCatTool(CatTool) - CheckCatTool, validate CatTOol - - 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 ["XTM", "Trados Studio", "MemoQ", "Memsource"] - - CheckVendorMail(VendorMail) - CheckVendorMail, validate 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 - - CheckWordRate(WordRate) - CheckWordRate, validate 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 - - FILE - c:\users\geera\onedrive\documenten\school\postgraduaattranslationtechnology\introductiontopython\final_assignment1\vendor_data.py - - - - - -```python -?vd -``` - - -```python -vd.__doc__ -``` - - - - - '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.\n\n It contains:\n - 4 functions: \n `ChangeDictionaryValue` to easily change values in a certain dictionary.\n `CheckVendorMail` to easily check if an e-mail address is valid.\n `CheckWordRate` to check if a word rate falls between EUR 0.01 and EUR 0.15 per word.\n `CheckCatTool` to validate the CAT tool provided.\n - 1 class, `VendorData` that has 3 class attributes: `CatTools`, the CAT Tools that can be used for the project,\n `Keys`, the keys of the dictionary that can be modified, and `Statuses`, the possible statuses a vendor can have.\n The class takes 4 positional arguments and 4 optional arguments:\n 1. `ProjectName` (str): the name of the translation project\n 2. `SourceLang` (str): the source language, i.e. the language the translator will translate from\n 3. `TargLang` (str): the target language, i.e. the language the translator will translate into\n 4. `VendorName` (str): the translator\'s/vendor\'s name\n 5. `VendorMail` (str): the vendor\'s e-mail address, by default empty\n 6. `WordRate` (float): the vendor\'s word rate in EUR/word, by default set to "None"\n 7. `CatTool` (str): the CAT Tool the translator will use, by default set to "XTM"\n 8. `Preferred` (bool): indicates if a vendor is a preferred vendor or not, by default set to "None"\n - `Argparse` inside `if __name__ == "__main__":` statement to receive arguments when the script is run\n ' - - - -### Instantiating an instance of VendorData -Now that we know the different fucntionalities we can instantiate an instance of the class VendorData. -To illustrate the code to it's full extent, we'll instantiate a couple of them: - - -```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 had default arguments. When we check the e-mail for VendorNL, for which we didn't provide one, we'll see that it does not return anything: - - -```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' - - - -### Functions -The class also contains a couple of functions: -- `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 sat 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 value for the argument `ProjectName` and `SourceLang`, they will be written to the same excel file. We should execute this function for every vendor. Be careful because if you run this function multiple times for the same vendor, it will not overwrite but append and you will have duplicates in the excel file. - - -```python -VendorNL.ToExcel() -VendorFR.ToExcel() -VendorES.ToExcel() -``` - -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 function 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 function without writing it to an excel file, 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_12116\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) - 222 return VendorDict #print the Dictionary - 223 else: - --> 224 raise ValueError(f"There is no file for {self.ProjectName} in {self.SourceLang}") - 225 - 226 def ModExcel(self, Key, Index, NewValue): - - - ValueError: There is no file for Tutorial in German - - -We can also modify the excel file by running the `ModExcel` function. Again, it does not matter for which vendor you call this function. -This function takes 3 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 -2. The `Index`: if you have run the ReadExcel() function, you have noticed that before every value for a key in the dictionrary there's a number. By picking a number, you can change the value for that index. -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", 2, "MemoQ") -``` - -If you check this by running `.CatTool`, the old value will still be there. - - -```python -VendorES.CatTool -``` - - - - - 'Trados Studio' - - - -However, if we read the excel file again, we'll notice it has changed: - - -```python -VendorES.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: 'Potential', 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_12116\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) - 118 """ - 119 if type(ProjectName) != str: - --> 120 raise TypeError("ProjectName should be a string!") - 121 if type(SourceLang) != str: - 122 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_12116\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) - 120 raise TypeError("ProjectName should be a string!") - 121 if type(SourceLang) != str: - --> 122 raise TypeError("SourceLang should be a string!") - 123 if type(TargLang) != str: - 124 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_12116\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) - 122 raise TypeError("SourceLang should be a string!") - 123 if type(TargLang) != str: - --> 124 raise TypeError("TargLang should be a string!") - 125 if type(VendorName) !=str: - 126 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_12116\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) - 124 raise TypeError("TargLang should be a string!") - 125 if type(VendorName) !=str: - --> 126 raise TypeError("VendorName should be a string!") - 127 if VendorMail: #validate e-mail address if one is provided - 128 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_12116\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) - 126 raise TypeError("VendorName should be a string!") - 127 if VendorMail: #validate e-mail address if one is provided - --> 128 CheckVendorMail(VendorMail) - 129 if WordRate != None: #validate word rate if one is provided - 130 CheckWordRate(WordRate) - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckVendorMail(VendorMail) - 52 regex_mail = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" #regex used to validate email - 53 if type(VendorMail) != str: - ---> 54 raise TypeError ("VendorMail should be a string!") - 55 if not(re.search(regex_mail,VendorMail)): - 56 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_12116\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) - 128 CheckVendorMail(VendorMail) - 129 if WordRate != None: #validate word rate if one is provided - --> 130 CheckWordRate(WordRate) - 131 if CatTool: #validate CAT Tool if one is provided - 132 CheckCatTool(CatTool) - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) - 67 """ - 68 if type(WordRate) != float: - ---> 69 raise TypeError("WordRate should be a float!") - 70 if WordRate > 0.15: - 71 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_12116\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) - 133 if Preferred != None: - 134 if type(Preferred) != bool: - --> 135 raise TypeError("Preferred should either be True, False or None.") - 136 if Preferred != None: #if Preferred is set to True, status will be preferred, if set to False, back-up and if neither "Potential" - 137 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_12116\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) - 130 CheckWordRate(WordRate) - 131 if CatTool: #validate CAT Tool if one is provided - --> 132 CheckCatTool(CatTool) - 133 if Preferred != None: - 134 if type(Preferred) != bool: - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckCatTool(CatTool) - 83 """ - 84 if type(CatTool) != str: - ---> 85 raise TypeError("CatTool should be a string!") - 86 if not CatTool in ["XTM", "Trados Studio", "MemoQ", "Memsource"]: - 87 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 -- `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_12116\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) - 126 raise TypeError("VendorName should be a string!") - 127 if VendorMail: #validate e-mail address if one is provided - --> 128 CheckVendorMail(VendorMail) - 129 if WordRate != None: #validate word rate if one is provided - 130 CheckWordRate(WordRate) - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckVendorMail(VendorMail) - 54 raise TypeError ("VendorMail should be a string!") - 55 if not(re.search(regex_mail,VendorMail)): - ---> 56 raise ValueError("Please insert a valid email address.") - 57 def CheckWordRate(WordRate): - 58 """CheckWordRate, validate 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_12116\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) - 128 CheckVendorMail(VendorMail) - 129 if WordRate != None: #validate word rate if one is provided - --> 130 CheckWordRate(WordRate) - 131 if CatTool: #validate CAT Tool if one is provided - 132 CheckCatTool(CatTool) - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) - 69 raise TypeError("WordRate should be a float!") - 70 if WordRate > 0.15: - ---> 71 raise ValueError("This vendor is too expensive, pick another one.") - 72 if WordRate == 0.00: - 73 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_12116\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) - 128 CheckVendorMail(VendorMail) - 129 if WordRate != None: #validate word rate if one is provided - --> 130 CheckWordRate(WordRate) - 131 if CatTool: #validate CAT Tool if one is provided - 132 CheckCatTool(CatTool) - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) - 71 raise ValueError("This vendor is too expensive, pick another one.") - 72 if WordRate == 0.00: - ---> 73 raise ValueError("Word rate cannot be 0.00.") - 74 def CheckCatTool(CatTool): - 75 """CheckCatTool, validate CatTOol - - - ValueError: Word rate cannot be 0.00. - - - -```python -VendorDE = vd.VendorData("Tutorial", "English", "German", "Thomas Zwiebel", CatTool = "SDL Trados Studio") -``` - - - --------------------------------------------------------------------------- - - ValueError Traceback (most recent call last) - - ~\AppData\Local\Temp\ipykernel_12116\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) - 130 CheckWordRate(WordRate) - 131 if CatTool: #validate CAT Tool if one is provided - --> 132 CheckCatTool(CatTool) - 133 if Preferred != None: - 134 if type(Preferred) != bool: - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckCatTool(CatTool) - 85 raise TypeError("CatTool should be a string!") - 86 if not CatTool in ["XTM", "Trados Studio", "MemoQ", "Memsource"]: - ---> 87 raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") - 88 - 89 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_12116\4282007076.py in - ----> 1 VendorDE.SetVendorMail("thomas.zw@") - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in SetVendorMail(self, NewMail) - 157 NewMail (str): a new e-mail address for a certain vendor - 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) - 54 raise TypeError ("VendorMail should be a string!") - 55 if not(re.search(regex_mail,VendorMail)): - ---> 56 raise ValueError("Please insert a valid email address.") - 57 def CheckWordRate(WordRate): - 58 """CheckWordRate, validate word rate - - - ValueError: Please insert a valid email address. - - - -```python -VendorDE.SetWordRate(0.18) -``` - - - --------------------------------------------------------------------------- - - ValueError Traceback (most recent call last) - - ~\AppData\Local\Temp\ipykernel_12116\1677043638.py in - ----> 1 VendorDE.SetWordRate(0.18) - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in SetWordRate(self, NewRate) - 166 NewRate (float): a new word rate for a certain vendor - 167 """ - --> 168 CheckWordRate(NewRate) #validate new word rate - 169 self.WordRate = NewRate #value of WordRate is changed - 170 - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) - 69 raise TypeError("WordRate should be a float!") - 70 if WordRate > 0.15: - ---> 71 raise ValueError("This vendor is too expensive, pick another one.") - 72 if WordRate == 0.00: - 73 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_12116\2070555766.py in - ----> 1 VendorDE.SetWordRate (0.00) - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in SetWordRate(self, NewRate) - 166 NewRate (float): a new word rate for a certain vendor - 167 """ - --> 168 CheckWordRate(NewRate) #validate new word rate - 169 self.WordRate = NewRate #value of WordRate is changed - 170 - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) - 71 raise ValueError("This vendor is too expensive, pick another one.") - 72 if WordRate == 0.00: - ---> 73 raise ValueError("Word rate cannot be 0.00.") - 74 def CheckCatTool(CatTool): - 75 """CheckCatTool, validate CatTOol - - - ValueError: Word rate cannot be 0.00. - - - -```python -VendorDE.ChangeTool("SDL Trados Studio") -``` - - - --------------------------------------------------------------------------- - - ValueError Traceback (most recent call last) - - ~\AppData\Local\Temp\ipykernel_12116\3483989379.py in - ----> 1 VendorDE.ChangeTool("SDL Trados Studio") - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ChangeTool(self, NewTool) - 175 NewTool (str): a new tool for a certain vendor - 176 """ - --> 177 CheckCatTool(NewTool) #validate new CAT Tool - 178 self.CatTool = NewTool #value of CatTool is changed - 179 - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckCatTool(CatTool) - 85 raise TypeError("CatTool should be a string!") - 86 if not CatTool in ["XTM", "Trados Studio", "MemoQ", "Memsource"]: - ---> 87 raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") - 88 - 89 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_12116\3389852500.py in - ----> 1 VendorDE.SetStatus("None") - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in SetStatus(self, PrefVend) - 186 if PrefVend != None: - 187 if type(PrefVend) != bool: - --> 188 raise TypeError("Preferred should either be True, False or None.") - 189 if PrefVend != None: - 190 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: - - -```python -VendorDE.ToExcel() -``` - -Now we can modify the German vendor and the input will be validated: - - -```python -VendorDE.ModExcel("E-mail", 3, "thomaszw@") -``` - - - --------------------------------------------------------------------------- - - ValueError Traceback (most recent call last) - - ~\AppData\Local\Temp\ipykernel_12116\1589300048.py in - ----> 1 VendorDE.ModExcel("E-mail", 3, "thomaszw@") - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) - 246 raise ValueError("Invalid index, run 'self.ReadExcel()' to see options") - 247 if Key == "E-mail": #validate e-mail address if a value for the key E-mail is modified - --> 248 CheckVendorMail(NewValue) - 249 if Key == "Word Rate": #validate word rate if a value for the key Word Rate is modified - 250 CheckWordRate(NewValue) - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckVendorMail(VendorMail) - 54 raise TypeError ("VendorMail should be a string!") - 55 if not(re.search(regex_mail,VendorMail)): - ---> 56 raise ValueError("Please insert a valid email address.") - 57 def CheckWordRate(WordRate): - 58 """CheckWordRate, validate word rate - - - ValueError: Please insert a valid email address. - - - -```python -VendorDE.ModExcel("CAT Tool", 3, "Trados Studio 2019") -``` - - - --------------------------------------------------------------------------- - - ValueError Traceback (most recent call last) - - ~\AppData\Local\Temp\ipykernel_12116\3469975144.py in - ----> 1 VendorDE.ModExcel("CAT Tool", 3, "Trados Studio 2019") - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) - 250 CheckWordRate(NewValue) - 251 if Key == "CAT Tool": #validate CAT Tool if a value for the key CAT Tool is modified - --> 252 CheckCatTool(NewValue) - 253 if Key == "Status": #validate Status if a value for the key Status is modified - 254 if not NewValue in VendorData.Statuses: - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckCatTool(CatTool) - 85 raise TypeError("CatTool should be a string!") - 86 if not CatTool in ["XTM", "Trados Studio", "MemoQ", "Memsource"]: - ---> 87 raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") - 88 - 89 class VendorData: - - - ValueError: This CAT tool is not valid. Run 'VendorData.CatTools' to check options. - - - -```python -VendorDE.ModExcel("Word Rate", 3, 0.18) -``` - - - --------------------------------------------------------------------------- - - ValueError Traceback (most recent call last) - - ~\AppData\Local\Temp\ipykernel_12116\2651721014.py in - ----> 1 VendorDE.ModExcel("Word Rate", 3, 0.18) - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) - 248 CheckVendorMail(NewValue) - 249 if Key == "Word Rate": #validate word rate if a value for the key Word Rate is modified - --> 250 CheckWordRate(NewValue) - 251 if Key == "CAT Tool": #validate CAT Tool if a value for the key CAT Tool is modified - 252 CheckCatTool(NewValue) - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) - 69 raise TypeError("WordRate should be a float!") - 70 if WordRate > 0.15: - ---> 71 raise ValueError("This vendor is too expensive, pick another one.") - 72 if WordRate == 0.00: - 73 raise ValueError("Word rate cannot be 0.00.") - - - ValueError: This vendor is too expensive, pick another one. - - - -```python -VendorDE.ModExcel("Status", 3, "Busy") -``` - - - --------------------------------------------------------------------------- - - ValueError Traceback (most recent call last) - - ~\AppData\Local\Temp\ipykernel_12116\3428613633.py in - ----> 1 VendorDE.ModExcel("Status", 3, "Busy") - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) - 253 if Key == "Status": #validate Status if a value for the key Status is modified - 254 if not NewValue in VendorData.Statuses: - --> 255 raise ValueError("Invalid status, run 'VendorData.Statuses' to see options") - 256 ChangeDictionaryValue(VendorDict, Key, Index, NewValue) #change the dictionary value in the dictionary `VendorDict` using the arguments provided for the method ModExcel - 257 df = pd.DataFrame(VendorDict) #turn VendorDict dictionary back into a panda DataFrame - - - ValueError: Invalid status, run 'VendorData.Statuses' to see options - - -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` -Additionally it also is checked if the index is in the dictionary, otherwise the vendor is non-existent and cannot be modified. - - -```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", 2, "John Doe") -``` - - - --------------------------------------------------------------------------- - - ValueError Traceback (most recent call last) - - ~\AppData\Local\Temp\ipykernel_12116\2634951232.py in - ----> 1 VendorDE.ModExcel("Vendor", 2, "John Doe") - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) - 242 VendorDict = ExcelRecordsDf.to_dict() - 243 if not Key in self.Keys: - --> 244 raise ValueError("Invalid key, run 'VendorData.Keys' to see options.") - 245 if not Index in VendorDict[Key]: - 246 raise ValueError("Invalid index, run 'self.ReadExcel()' to see options") - - - ValueError: Invalid key, run 'VendorData.Keys' to see options. - - - -```python -VendorDE.ModExcel("Target Language", 3, "Croatian") -``` - - - --------------------------------------------------------------------------- - - ValueError Traceback (most recent call last) - - ~\AppData\Local\Temp\ipykernel_12116\614258264.py in - ----> 1 VendorDE.ModExcel("Target Language", 3, "Croatian") - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) - 242 VendorDict = ExcelRecordsDf.to_dict() - 243 if not Key in self.Keys: - --> 244 raise ValueError("Invalid key, run 'VendorData.Keys' to see options.") - 245 if not Index in VendorDict[Key]: - 246 raise ValueError("Invalid index, run 'self.ReadExcel()' to see options") - - - ValueError: Invalid key, run 'VendorData.Keys' to see options. - - -Since there are only 4 vendors in the excel file and the index start at 0 and go up, an error message should appear when you try to modify a higher index: - - -```python -VendorDE.ModExcel("CAT Tool", 6, "XTM") -``` - - - --------------------------------------------------------------------------- - - ValueError Traceback (most recent call last) - - ~\AppData\Local\Temp\ipykernel_12116\235551850.py in - ----> 1 VendorDE.ModExcel("CAT Tool", 6, "XTM") - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in ModExcel(self, Key, Index, NewValue) - 244 raise ValueError("Invalid key, run 'VendorData.Keys' to see options.") - 245 if not Index in VendorDict[Key]: - --> 246 raise ValueError("Invalid index, run 'self.ReadExcel()' to see options") - 247 if Key == "E-mail": #validate e-mail address if a value for the key E-mail is modified - 248 CheckVendorMail(NewValue) - - - ValueError: Invalid index, run 'self.ReadExcel()' to see options - - -You can check for the right index by running the `ReadExcel` method for any vendor you already defined: - - -```python -VendorNL.ReadExcel() -``` - - - - - {'Target Language': {0: 'Dutch', 1: 'French', 2: 'Spanish', 3: 'German'}, - 'Vendor': {0: 'Elmo Geeraerts', - 1: 'Jean Lefèvre', - 2: 'Emilio De La Banda', - 3: 'Thomas Zwiebel'}, - 'E-mail': {0: nan, - 1: 'j.lefevre@hotmail.com', - 2: 'e.dlbanda@outlook.com', - 3: nan}, - 'CAT Tool': {0: 'XTM', 1: 'Trados Studio', 2: 'MemoQ', 3: 'XTM'}, - 'Word Rate': {0: 0.08, 1: 0.1, 2: 0.09, 3: nan}, - 'Status': {0: 'Potential', 1: 'Back-up', 2: 'Back-up', 3: 'Potential'}} - - - -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. We'll first look at the help for this script. - - -```python -%run vendor_data.py --help -``` - - usage: vendor_data.py [-h] [-a] [-m] - - optional arguments: - -h, --help show this help message and exit - -a, --add Add a vendor - -m, --modify Modify an existing vendor - - -As you can see, apart from the help argument, there are two other 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; - -We'll start by writing a totally new excel file and adding a vendor to it: - - -```python -%run vendor_data.py --a -``` - - What is the project name? TestProject - What is the source language? English - What's the vendor's name? Elmo Geeraerts - Into which language will the vendor translate? Dutch - What is the vendor's email address? geeraerts@me.com - What is the vendor's word rate in EUR? Should be between 0.01 and 0.15. If higher, choose another vendor. 0.12 - 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. True - Are you done? yes - Do you want to add this vendor to the excel file? yes - - -A new excel file will appear next to where you stored this notebook with the name `TestProject_English`, i.e. the project name and source language we provided. -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 - - -```python -%run vendor_data.py --a -``` - - What is the project name? TestProject - What is the source language? English - What's the vendor's name? Jean Baptiste - Into which language will the vendor translate? French - 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? - Blank values are not allowed. - Are you done? yes - Do you want to add this vendor to the excel file? yes - - -If the project name and the source language are the same as for the previous vendor you've entered, this vendor will be added to the same excel file, if not a new excel file is created using the project name and the source language as the file name. You'll notice that for the prompts you leave blank the default value is enterred OR it is left blank. - -Just like when you use this script as a module, the data you provide is validate at every step of the user interaction. TypeErrors do not cause the prompts to stop but instead you get asked the same question again, ValueErrors do break off the code: - - -```python -%run vendor_data.py -a -``` - - What is the project name? TestProject - What is the source language? English - What's the vendor's name? Emanuel Dos Santos - Into which language will the vendor translate? Portuguese - What is the vendor's email address? e_dossantos@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.19 - - - - --------------------------------------------------------------------------- - - ValueError Traceback (most recent call last) - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in - 304 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) - 305 if NewWordRate: - --> 306 CheckWordRate(NewWordRate) - 307 VendorWordRate = NewWordRate - 308 else: - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckWordRate(WordRate) - 69 raise TypeError("WordRate should be a float!") - 70 if WordRate > 0.15: - ---> 71 raise ValueError("This vendor is too expensive, pick another one.") - 72 if WordRate == 0.00: - 73 raise ValueError("Word rate cannot be 0.00.") - - - ValueError: This vendor is too expensive, pick another one. - - - -```python -%run vendor_data.py -a -``` - - What is the project name? TestProject - What is the source language? English - What's the vendor's name? Emanuel Dos Santos - Into which language will the vendor translate? Portuguese - What is the vendor's email address? e_dossantos@ - - - - --------------------------------------------------------------------------- - - ValueError Traceback (most recent call last) - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in - 298 NewVendorMail = pyip.inputStr("What is the vendor's email address? ", blank = True, default="") - 299 if NewVendorMail: - --> 300 CheckVendorMail(NewVendorMail) - 301 VendorMail = NewVendorMail - 302 else: - - - ~\OneDrive\Documenten\School\PostgraduaatTranslationTechnology\IntroductionToPython\Final_Assignment1\vendor_data.py in CheckVendorMail(VendorMail) - 54 raise TypeError ("VendorMail should be a string!") - 55 if not(re.search(regex_mail,VendorMail)): - ---> 56 raise ValueError("Please insert a valid email address.") - 57 def CheckWordRate(WordRate): - 58 """CheckWordRate, validate word rate - - - ValueError: Please insert a valid email address. - - -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 - -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? TestProject - What is the source language? English - These are the vendor's already in the database: - 0: Elmo Geeraerts - 1: Jean Baptiste - Enter the index of the vendor you want to modify: 0 - What is the vendor's e-mail? - What is the vendor's word rate? 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 - Trados Studio - What is the vendor's new status? * Preferred - * Back-up - * Potential - - 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! +{ + "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": null, + "id": "b3611132", + "metadata": {}, + "outputs": [], + "source": [ + "import sys\n", + "sys.path.append (r'C:\\Users\\geera\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1')\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": null, + "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": null, + "id": "c6675ef0", + "metadata": {}, + "outputs": [], + "source": [ + "VendorNL.VendorName" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "23b52971", + "metadata": {}, + "outputs": [], + "source": [ + "VendorFR.VendorMail" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "69659b86", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.WordRate" + ] + }, + { + "cell_type": "markdown", + "id": "a831785f", + "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 does not return anything:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cb2ca64c", + "metadata": {}, + "outputs": [], + "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": null, + "id": "c7180a19", + "metadata": {}, + "outputs": [], + "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": null, + "id": "e26d1539", + "metadata": {}, + "outputs": [], + "source": [ + "VendorFR.Preferred" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "935c0a38", + "metadata": {}, + "outputs": [], + "source": [ + "VendorFR.Status" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9ebc7f07", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.Preferred" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1158b1de", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.Status" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ab5e5f54", + "metadata": {}, + "outputs": [], + "source": [ + "VendorNL.Preferred #Will not return anything since value is None" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "50cd8967", + "metadata": {}, + "outputs": [], + "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": null, + "id": "90cb5c10", + "metadata": {}, + "outputs": [], + "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": null, + "id": "730b35ca", + "metadata": {}, + "outputs": [], + "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": null, + "id": "391e7c5d", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.ChangeTool(\"Trados Studio\")\n", + "VendorES.CatTool" + ] + }, + { + "cell_type": "markdown", + "id": "574ef338", + "metadata": {}, + "source": [ + "Because we sat 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": null, + "id": "96819356", + "metadata": {}, + "outputs": [], + "source": [ + "VendorFR.SetStatus(False)\n", + "VendorFR.Preferred" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e8335217", + "metadata": {}, + "outputs": [], + "source": [ + "VendorFR.Status" + ] + }, + { + "cell_type": "markdown", + "id": "0bf8e1d0", + "metadata": {}, + "source": [ + "We can now write the data for the vendors to an excel file. To be sure the file does not already exist, we'll first delete the excel file for the project called `Tutorial` in the source language `English`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fdd13cb8", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "os.remove('Tutorial_English.xlsx') #If the file is stored elsewhere, copy the full path to the excel file." + ] + }, + { + "cell_type": "markdown", + "id": "6c24b72f", + "metadata": {}, + "source": [ + "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": null, + "id": "aeafcb32", + "metadata": {}, + "outputs": [], + "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": null, + "id": "37124f32", + "metadata": {}, + "outputs": [], + "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 it to an excel file, 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": null, + "id": "10dc02d2", + "metadata": {}, + "outputs": [], + "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. You could call this method for any instance you created and modify any vendor in the excel file. However this is not advisable since it will modify the correct vendor, but if you check the values by calling the argument (self.argument), the script thinks it is the vendor that you called the method for that is modified.\n", + "\n", + "
\n", + "Run the `ModExcel()` method for the vendor you actually want to modify. It is possible to modify another vendor, but the script will still think you modified the vendor you called the method.\n", + "
\n", + "\n", + "This method takes 3 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", + "2. The `Index`: if you have run the ReadExcel() function, you have noticed that before every value for a key in the dictionrary there's a number. By picking a number, you can change the value for that index.\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": null, + "id": "17292d31", + "metadata": {}, + "outputs": [], + "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": null, + "id": "abf2dc40", + "metadata": {}, + "outputs": [], + "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": null, + "id": "52e91ff2", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.ModExcel(\"CAT Tool\", 2, \"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": null, + "id": "f4e539d4", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.CatTool" + ] + }, + { + "cell_type": "markdown", + "id": "079b36e6", + "metadata": {}, + "source": [ + "As already mentioned, you could call the `ModExcel()` method for any vendor and modify another one, but the script will still think you modified the vendor you called the method for. This is bad practice and you should not do this! We'll illustrate what would happen if you did:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8500c4c1", + "metadata": {}, + "outputs": [], + "source": [ + "VendorNL.ModExcel(\"Status\", 2, \"Preferred\")" + ] + }, + { + "cell_type": "markdown", + "id": "a5775c45", + "metadata": {}, + "source": [ + "We'll see that the status for the Spanish vendor is not changed:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8815e256", + "metadata": {}, + "outputs": [], + "source": [ + "VendorES.Status" + ] + }, + { + "cell_type": "markdown", + "id": "2111c773", + "metadata": {}, + "source": [ + "But the status for the Dutch one is:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e740b32b", + "metadata": {}, + "outputs": [], + "source": [ + "VendorNL.Status" + ] + }, + { + "cell_type": "markdown", + "id": "6bd49720", + "metadata": {}, + "source": [ + "However, if we read the excel (`ReadExcel()`), we'll see that it is in fact the Spanish vendor's status that is changed. Here it does not matter for which vendor we call the method:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eb036959", + "metadata": {}, + "outputs": [], + "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": null, + "id": "854ef143", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(0.1, \"English\", \"German\", \"Thomas Zwiebel\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cd524417", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", 1, \"German\", \"Thomas Zwiebel\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6497db2", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", True, \"Thomas Zwiebel\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b01bfed", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", None)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "20b5cc03", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", 3)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7c32d39f", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = \"0.15\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "32715f64", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", Preferred = \"Test\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b74ce10", + "metadata": {}, + "outputs": [], + "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": null, + "id": "14d9561a", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", VendorMail = \"thomas.zw\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "689a0133", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = 0.19)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a5a88daf", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = 0.00)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e682f9b1", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = -0.04)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a6506797", + "metadata": {}, + "outputs": [], + "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": null, + "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": null, + "id": "0e5da23b", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE.SetVendorMail(\"thomas.zw@\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2f58285", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE.SetWordRate(0.18)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e03407b2", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE.SetWordRate (0.00)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3c95b758", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE.SetWordRate(-0.04)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4f984703", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE.ChangeTool(\"SDL Trados Studio\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2c570d8f", + "metadata": {}, + "outputs": [], + "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": null, + "id": "b9e3cd49", + "metadata": {}, + "outputs": [], + "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": null, + "id": "f9d200e7", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE.ModExcel(\"E-mail\", 3, \"thomaszw@\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3db36ec1", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE.ModExcel(\"CAT Tool\", 3, \"Trados Studio 2019\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "43492fbd", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE.ModExcel(\"Word Rate\", 3, 0.18)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fcc7bf99", + "metadata": {}, + "outputs": [], + "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", + "Additionally it also is checked if the index is in the dictionary, otherwise the vendor is non-existent and cannot be modified.\n", + "
\n", + "You can only modify one value for one key.\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "405573dd", + "metadata": {}, + "outputs": [], + "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": null, + "id": "e37f7571", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE.ModExcel(\"Vendor\", 2, \"John Doe\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4a988964", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE.ModExcel(\"Target Language\", 3, \"Croatian\")" + ] + }, + { + "cell_type": "markdown", + "id": "2eb97cae", + "metadata": {}, + "source": [ + "Since there are only 4 vendors in the excel file and the index start at 0 and go up, an error message should appear when you try to modify a higher index:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "66ca7b9e", + "metadata": {}, + "outputs": [], + "source": [ + "VendorDE.ModExcel(\"CAT Tool\", 6, \"XTM\")" + ] + }, + { + "cell_type": "markdown", + "id": "092a40df", + "metadata": {}, + "source": [ + "You can check for the right index by running the `ReadExcel` method for any vendor you already defined:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "38b01366", + "metadata": {}, + "outputs": [], + "source": [ + "VendorNL.ReadExcel()" + ] + }, + { + "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", + "We'll start by writing a totally new excel file and adding a vendor to it:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a32de96d", + "metadata": {}, + "outputs": [], + "source": [ + "%run vendor_data.py --a" + ] + }, + { + "cell_type": "markdown", + "id": "61141753", + "metadata": {}, + "source": [ + "A new excel file will appear next to where you stored this notebook with the name `TestProject_English`, i.e. the project name and source language we provided.\n", + "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" + ] + }, + { + "cell_type": "markdown", + "id": "d652047e", + "metadata": {}, + "source": [ + "If the project name and the source language are the same as for the previous vendor you've entered, this vendor will be added to the same excel file, if not a new excel file is created using the project name and the source language as the file name. You'll notice that for the prompts you leave blank the default value is enterred OR it is left blank." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7c4e5ac4", + "metadata": {}, + "outputs": [], + "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", + "\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": null, + "id": "54012864", + "metadata": {}, + "outputs": [], + "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": "de6ddf9f", + "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": "0142a21d", + "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", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d5b846fc", + "metadata": {}, + "outputs": [], + "source": [ + "%run vendor_data.py -h" + ] + } + ], + "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.16" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/vendor_data.py b/vendor_data.py index 1865416..4627100 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -9,15 +9,7 @@ `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: - 1. `ProjectName` (str): the name of the translation project - 2. `SourceLang` (str): the source language, i.e. the language the translator will translate from - 3. `TargLang` (str): the target language, i.e. the language the translator will translate into - 4. `VendorName` (str): the translator's/vendor's name - 5. `VendorMail` (str): the vendor's e-mail address, by default empty - 6. `WordRate` (float): the vendor's word rate in EUR/word, by default set to "None" - 7. `CatTool` (str): the CAT Tool the translator will use, by default set to "XTM" - 8. `Preferred` (bool): indicates if a vendor is a preferred vendor or not, by default set to "None" + 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: @@ -27,9 +19,9 @@ import os #os package to check if files exists import pyinputplus as pyip #pyinputplus package to facilitate providing arguments -#4 methods to make validation easier +#4 functions to make validation easier def ChangeDictionaryValue(Dictionary, Key, Index, NewValue): - """ChangeDictionaryValue, change values of a dictionary + """Function to change the value of a certain key in a certain dictionary. Args: Dictionary (dict): name of the dictionary that will be read @@ -40,7 +32,7 @@ def ChangeDictionaryValue(Dictionary, Key, Index, NewValue): if Key in Dictionary and Index in Dictionary[Key]: Dictionary[Key][Index] = NewValue def CheckVendorMail(VendorMail): - """CheckVendorMail, validate e-mail address + """Function to validate the e-mail address. Args: VendorMail (str): an e-mail address @@ -55,7 +47,7 @@ def CheckVendorMail(VendorMail): if not(re.search(regex_mail,VendorMail)): raise ValueError("Please insert a valid email address.") def CheckWordRate(WordRate): - """CheckWordRate, validate word rate + """Function to validate the word rate Args: WordRate (float): a word rate in EUR/word @@ -64,6 +56,7 @@ def CheckWordRate(WordRate): 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!") @@ -71,20 +64,22 @@ def CheckWordRate(WordRate): 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): - """CheckCatTool, validate 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 ["XTM", "Trados Studio", "MemoQ", "Memsource"] + 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 ["XTM", "Trados Studio", "MemoQ", "Memsource"]: - raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") + if not CatTool in VendorData.CatTools: + raise ValueError("This CAT tool is not valid. Run 'VendorData.CatTools' to check options.") class VendorData: @@ -151,37 +146,54 @@ def __init__(self, ProjectName, SourceLang, TargLang, VendorName, VendorMail = " self.Preferred = Preferred def SetVendorMail(self, NewMail): - """Method + """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 + """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 + """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 + """Method to set a new value for self.Preferred and self.Status Args: - PrefVend (bool): new value for Preferred, has an influence on status + PrefVend (bool or None): new value for Preferred, has an influence on status """ if PrefVend != None: if type(PrefVend) != bool: @@ -197,8 +209,18 @@ def SetStatus(self, PrefVend): self.Preferred = None self.Status = "Potential" - def ToExcel(self): #method to write data to an excel file - Data = { #dump arguments provided in a dictionary + 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 a panda data frame. + 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], @@ -206,20 +228,31 @@ def ToExcel(self): #method to write data to an excel file "Word Rate": [self.WordRate], "Status": [self.Status] } - FileName = "_".join([str(self.ProjectName), str(self.SourceLang)]) + ".xlsx" #the name of the excel file, based on arguments `ProjectName` and `SourceLang` - df = pd.DataFrame(Data) #make a panda dataframe out of the dictionary - if not os.path.exists(FileName): #check if the file exists, if not a new file is written + 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") - else: #if file exists, the data is appended to the existing file + return(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) - def ReadExcel(self): #method to read the file with filename {ProjectName_SourceLang} into a dictionary + return(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) #read filename - ExcelRecordsDf = ExcelRecords.loc[:, ~ExcelRecords.columns.str.contains('^Unnamed')] #remove any unnamed columns - VendorDict = ExcelRecordsDf.to_dict() #turn dataframe into a dictionary - return VendorDict #print the Dictionary + 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}") @@ -234,6 +267,8 @@ def ModExcel(self, Key, Index, NewValue): Raises: ValueError: raised if the key is not one of the keys in VendorData.Keys ValueError: raised if the Index is not valid for a certain key + ValueError: 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): @@ -244,19 +279,25 @@ def ModExcel(self, Key, Index, NewValue): raise ValueError("Invalid key, run 'VendorData.Keys' to see options.") if not Index in VendorDict[Key]: raise ValueError("Invalid index, run 'self.ReadExcel()' to see options") - if Key == "E-mail": #validate e-mail address if a value for the key E-mail is modified + if Key == "E-mail": CheckVendorMail(NewValue) - if Key == "Word Rate": #validate word rate if a value for the key Word Rate is modified + self.VendorMail = NewValue + elif Key == "Word Rate": CheckWordRate(NewValue) - if Key == "CAT Tool": #validate CAT Tool if a value for the key CAT Tool is modified + self.WordRate = NewValue + elif Key == "CAT Tool": CheckCatTool(NewValue) - if Key == "Status": #validate Status if a value for the key Status is modified + self.CatTool = NewValue + elif Key == "Status": if not NewValue in VendorData.Statuses: raise ValueError("Invalid status, run 'VendorData.Statuses' to see options") - ChangeDictionaryValue(VendorDict, Key, Index, NewValue) #change the dictionary value in the dictionary `VendorDict` using the arguments provided for the method ModExcel - df = pd.DataFrame(VendorDict) #turn VendorDict dictionary back into a panda DataFrame + else: + self.Status = NewValue + ChangeDictionaryValue(VendorDict, Key, Index, NewValue) + df = pd.DataFrame(VendorDict) with pd.ExcelWriter(FileName, engine="openpyxl", mode="w") as writer: - df.to_excel(writer, sheet_name = "VendorData", index=False) #overwrite the existing excel file + df.to_excel(writer, sheet_name = "VendorData", index=False) + return("The vendor was correctly modified.") else: raise ValueError(f"There is no file for {self.ProjectName} in {self.SourceLang}") @@ -268,23 +309,11 @@ def ModExcel(self, Key, Index, NewValue): --modify, -m (flag) : indicating the user wants to modify an existing vendor """ parser = argparse.ArgumentParser() - parser.add_argument("-a", "--add", action='store_true', help = "Add a vendor") - parser.add_argument ("-m", "--modify", action='store_true', help = "Modify an existing vendor") + 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: - """Action: add a vendor - - Prompts the user to provide the following data, validates it and writes it to an excel file with {ProjectName_SourceLang} as name: - 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". - """ done = "no" WordRate = None Preferred = None @@ -317,20 +346,18 @@ def ModExcel(self, Key, Index, NewValue): 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 + print("Vendor was added!") + else: + print ("Action was cancelled.") if args.modify: - """Action: modify an existing vendor - """ done = "no" while done.lower() != "yes": #Code underneath is run as long as value for done = no - """Provide ProjectName and SourceLang to look for the excel file + """ """ 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): - """If the file exists, excel file is read and turned into a dictionary - Prompts the user to choose the vendor for which certain values will be changed. - """ ExcelRecords = pd.read_excel(FileName) ExcelRecordsDf = ExcelRecords.loc[:, ~ExcelRecords.columns.str.contains('^Unnamed')] VendorDict=ExcelRecordsDf.to_dict() @@ -359,8 +386,6 @@ def ModExcel(self, Key, Index, NewValue): 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.") - """Values for provided keys are changed - """ if NewEmail: ChangeDictionaryValue(VendorDict, EmailKey, VendorIndex, NewEmail) if NewWordRate: From fff69c0a042d2241715059e98439d7075fe0cc70 Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Wed, 14 Jun 2023 22:56:39 +0200 Subject: [PATCH 23/24] Final update --- Example_Dutch.xlsx | Bin 0 -> 5525 bytes ...oject_English.xlsx => Example_English.xlsx | Bin 5083 -> 5248 bytes README.md | 20 +- Tutorial_English.xlsx | Bin 5214 -> 0 bytes tutorial.ipynb | 1129 ++++++-- tutorial.md | 2432 +++++++++-------- vendor_data.py | 64 +- 7 files changed, 2286 insertions(+), 1359 deletions(-) create mode 100644 Example_Dutch.xlsx rename TestProject_English.xlsx => Example_English.xlsx (55%) delete mode 100644 Tutorial_English.xlsx diff --git a/Example_Dutch.xlsx b/Example_Dutch.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..2fe5ea20619424f986bba4026768507b4c5a93a9 GIT binary patch literal 5525 zcmZ`-byQS+yB(!Ny1ToE?gnA#R2)KtA*4eAC8SFb5l}j$yE|p1QxGJTmH`}^q3@{g z_j%>M_slxyx8|(1_aFO-^Xx}g0|k`?003YjZ#e)0RKTcr3jl~i1ptVVZ@@|}&Ylow zPYXjISBQrhpSP1^S;C-pw*Z04iQ0wIDlcfhS{_qmC#aW*OHa1*%bT8JD{zLr{dI== z83BV`^sH8?^^bXv-dJf0Uh22J4B2E7$n3VJvImo3G9-(ol zb`M5(S(Dxp`f+?eDurWFJ+e7W)sm3OyWEgbBnly-1u=YfNpf=I|P@pC8LK^Pd@4uw*{$67M(&~y?l)|HG0*5F|rQWWzL;>j#=Y@KUc2u zzEm#gYoy-O!A*kz{OSWa&(%86LvzkO8Q0@C*RZx>#+Gwy1eWe!5zzJ3?t&qe*Srk? z;2=*6cZj10Ki|)1S^O{v1xWA$9t0;?UmUIviV&XDAbdt#gfGBWBe%^)9Iw~l;zB^e zU3d5m_$JwXdo^PM|XZx`vbZ0 z5dA23IcO<1t2IiSTI;mrT!!>|6m#hQg!?|nTCybVczbDAlAI zQ0wHBn?r`3r0&mF`yG+2Do0yThQ2If1`6n$rB5I}NE@SJpVbb++~0O=OlF|cVm}^? zBm*YGSd?bA8e*-^?|(QIT1gul4&V#7$^O=te(wWC$IHXUxaKO=WoKRq&VRyi&Y*34Ki=isepcw-g_M+3Hzp z=W?&kqeAlWLdJr19;t2*1uv|@o`3&HNBpFVyD*9f^%=3_1{f`Kt|6S906Gg^z<7nN z%5wkniPxalw#WvfyBW)C18Gjzp*T&hS{ooc z?uN+)ip0PhpEpZx+UUzwqtr4=X@_NJ1tweR+IDi{YaXfknmZO0K5lMD_vI)Fb#iZS?AyRFQ7_(||ddyqy^ykRI&*Db8Q=9Yf8 zsuXYLIj1FfmBE9xuE4n;BSSw*>AUtzxccc5$T*ZF>3kAiXbO-D;&1jo_Z2Bnrsgv+ z&k2e156&O_zRx6{H4D4lNie4XizDlq#Od+Wm;ZQ#=@3WOuWK~_#c)k?8ryp|qB#CE zL(GblJf2R9XENZ~!=y;msdw94aqC}{75Zb2Dsc21sL+Zk-+?1I`V^a~_#b6fbJ(#3 zV2gh@*2MkVs(=+4I7tU!b*{RzJQb)@zbe5=ZMV`h8O_9L?Rzifp0spOAC6V3=IF%K z{4R&CH$$;~xx5YuPAvHp6n%>=MZa3Xs!|dX>Q|d(Dw@rrBwPS(i#`yG@CW=IFNR$ee;s7JxRDu+ z|0iDm$>o^W!#`VW2wbf-xXvquo|UjH#V{zSFyw`j{V3a_uraMvHLd<)hE_32qg%CY z>$$ycn`t`LN7->ndr!P^9@MaAVMUk{9(=Ah75s3-gSSzT$^)T@QL=pYc!v7rs^lydd z?TS#EhG~(DZ7|#JyPadgd7SOH{?@*av4nmRsrf6U{y#r_$Zq0cXXy^H zHt=+}ceeHTStpRVE)Y~6Hw@Wn1%~{*iZKY2N0>_Jloe{5&6TJNP@MGHi@wiEF-6q& z`pTVN5pU>pRR5E(e>)F+Cl@p?r*a>`6i9c~iIk*CGgyg$cJ(t^`_*IZd^hPBA4 zLefl}-RTu`UlMz6e5)Is!r;62Z#bDfKQY6^8z+h-J(yXl^VgDV50hq-Kb^lkmm_G+ z{U#zD$6VZm5+$U3s2%JjH|}x~H0fskX-jJlU!%FhQM0>s8Dk{f2i2@Ulf*MAF>N_6 z*J2s`qu+E7v_Ct~KaRp3&xY`d01gC`ijLky^;20RVUY(Zkcn5%NojHp8#c zX#xcP{D%RUKJX@Nnb{n=w%|}jFm^*|yJ`$oAHI5z3cLc&;`TXIitKERTuA72JvEsh zc-o!IBH^(WGLEJN$4hWEOI7_|p4Fk#i=WBi*6G=uJKmZluAr$GCC(L;;t7e78AR|h|l)_0zsG}J*fKBh1OynNBG=!me7e^b*sT7~BO7X(D z|GJQrEL>f2V9OGyyN-hL&6s|iG1@N$gQr68RE^kGY%Cq(k>WSc8iKZE+#~A!>3jfa zxE|l|0?XL5&7uo8@++zUc8qG}h#i~E8mm>N`UeOH$KjH|`=^emHEM6Y$3FNIQ|o4j zrs_gXn_DAeDyMBta1#pG^<|&u%k2~!MEM$M92Ul6w~L^C41i{?epGfN7y6{!djOwd zI*AoMXMZ4A$9)Z+*`%J?Ow#%y(06LL>^uG(w{!TKOQnFcL#>mKZ!?CJ{~ZkO9dpaM zC_qtuQZ^`@C@gbUCGZJ?;bUT{Ljt0sBunnniqXr-_FtdlG?dtc8 z;@&UuQnRK_4F@?N<1a?&`I+l=KxaCGX1C#2+W9Bh!8=Rb*SG)9lg)hA#%g4a7*PKn z4Uu)@X$NtF{C@uWyzH20y_!>|XlLG|S8Z>IC6*d4Pbm|f$qjuv_u2Wu(twWK}>*XzDye)!x$I$u^H zI3cf2#CFkYmy|o%8KFsoNLEf~>W*d8K4Z469z>OdmO2Hd5z0};oewDDYM_bD8uOmt zKc0d-SAZI#m8njT%A%Pm2&7C3NfP3chiHFYXsoUIW-)qNvHYyfykUa}0Re2EKP;*V zdUDQNAhb~wxIbvLxR7$sW6(P$zzVHneABZvhN!&?+QN-6F57gT*6{X%EyE1%d zfWDw;(wNsNtky66I-j@+laLhL-ev2WP4^vq%MC8#VewNS{#-AsEno;G+TWjf#h)po zfV^e>cMlO={Jr?}baIFpdG9;Df!c`WbN;KVV}rx#H*j<5vw@dyC9h60WzTn}`G@86 zP%;B95w8kfWd&fw ze|s^_(&obxwHY5TRAB(|F6_`;eL7fIlT-vy5w3^TI4H5@YAL+&j7vkzmI}jW=~3~@ zF;G^x|3?O8Kh+f^2kaW?k;n&4V&+Yj(2QOds zE$(;SR&&VwKoh zAiALt3-?Atg3T8KvCo*9@*>xh-X%`9#by&zcDE1O=uvW#q`!+36WEY+57%jCj3s(M zB8>NB`>y+K&Zu#^d#bG7O^TmHptpJxm)eygCBY_N^A+s0;|@m*Nz7U%1DL5Yr(RNq zI$yL?jxNpZ+6g8?`^ij0&*?=MX{BRMFjvpc+t1tK?a_V>#YxjU^@HdRTOMvb{KYi! zy$Mw)B37$mLl0_D^X~e686u+`f5fJv*vJD-bPepB5g{`5Q#A4>SVo14Cx^(Bm7+uv z@h!1DG}<4DeM9nc^tknul3?uq&c0sz!q{jSj_3?mTyvJ{z(X_37!4P;q5ePzkcV`Q zFx=3-eqE~&J!Ild$3*Ey4x^O-^ZQA-M6l2O5gBDcD6>Aa4@k8vJmm@A`fNUt>m0=Y=a;ry#z7s3x__0KFW2@rbti*dKJgY0YPBE78L4zE(`~{ul-=Vq9?HgGR za7Ul!cCFWXK2Ah`tIVQUOv}@q#?>Mc@Pvr}sN%UZEc^i2ITkZDku&aorNq1aCYyBy zxM%cn#NA|m#XtqBATFt>BuaWtarpFLn@SIB^yQf^W0v9q)80U$g<)6!JzAzN&X*7} z3CE$J5j4pn52{u(QsnVlN`ry$-uiKGycTO>FgzEQ4^k{J$Y!wCA${5&lx#4aS>d6o zl4(-N{pP|;4G)Vt_w$_QPJ^yEoGp}DaK1llCLczHe%au?@5arRInf)O$8f?^6Hy}K zx1(3NXTz1Yrw0}To1RShPqMip2qF@5wiv^_+B1Zvh7b{(N7grB{D;Iaj&$%c) ze(Sb>_DjeChZ<{=kX!aVJr!?d{ zu8#5VlFT*=t!7anq`}_8Z7>suEP9d?jrm=r^@W@RM8g)!s%968SXI7AAwcL5#J+L9TijP z=kNd{0<{bZKH)Vi-L@4N+zZ2D3Qew{C46+}2Rh5Ei&8+!mU4~eN0nh0l#8Y2U&D>8 zvd_Rk`6vC9mSly~^?Z8}LcD4HjeAQy;9D1)1c%fvy(&Gj-}Er$dm7o-YP|hT`1R5Y zdoc zeeY0O2zE8ul+&v$iU9GD=W&ds>VgAGp%YhI3+#FX!4+L-uM)+XBcEShrO)OQ0IO8E zszVDvwL@;atjT0jSt`!w^Y)6c7aqy6g2FK(2!bJv@Qk%$9yyRS@QiA!MVvA!dZl^e zTBIzPa(~=1Aa+KlWE3dr@Z!J%2A|56&t6&{?9VcAUo@Pt3twk7k=@eo_bGacPUBo% z<=jcgbqXrH8)9h(u8gdO`7FF&io>q%IQU|mgFp*WN&_9n@pzMw&*V{5MMKrEaW|76 zD6_G$yN7t}(9GdKlfV{iBpu*X>uDf7NuvGq$_6L$`n9)&jyG_*&a`l@B94p>>VY(! zOYUpWnjR#aQlI#*CHS`4USjBK+`3Kj%Ln}X0t^|iUsrwL&*NX#VK)hG?r(m>0f73z zAY=~wuWimv;LR<^A7CP~9RL5F$4#D_yMRAD4afvU^8D*&;3msWhx&)b7C8g{!}1@$ zdJ}xpV*LTHp#Qt!y2)_Ul>A{h!1&GZUyE`RdUH4`VtH_QDG+z{DQ{|o=8_;oeVkdgoZ*vQ`tWSp;we*XI()w6f< literal 0 HcmV?d00001 diff --git a/TestProject_English.xlsx b/Example_English.xlsx similarity index 55% rename from TestProject_English.xlsx rename to Example_English.xlsx index 948563cae3a91444a840355ebfc9f0e8ece8266c..b58f6f07d7028c6a0042a2b5603b46f1ab5264ec 100644 GIT binary patch delta 1291 zcmcbu-k`}F;LXe;!oa}5!Qip=+(h0rfYHdmS+l zXpeU-%2)SIV7_xp5f=d()rMH z5hb-vGxF8Uf9RCn*`ypeg&|V@;>wumE&69`J^TVImod96wZFpXSg?<=eMyfJtMP^| z?TKIKUJOzX5xFFp|D~&cer8018*@G1iwnVR%kmn&em+t$tBr46gQVMxn16Z;B0Igm z`oFovSmx(@Tlx3h?AN&U zZgu6adRC^sBd6ubpW3p&56eZ%4&K=N_xLgKgZrA}%P-b5qJ&D=%$Uu08LiobKtW@t zerMQneMG)YJ1KqC+xh*@#`9I2In}|=~WU_kA;L6uGuWaa@BT?!>wti zT8_PIS1Dba$~4P-!h?^I`|UeeQ;obPKf4*Tl=E7fF=w%Bi7rcMzVd?|l5WfEFaB<3 z51Vq#w&U`WMXWjpYF0lxb?uRvYC6-BG>y)tuLip;_s-&t`M>P2a&xbphVb@DqK`JO zt~u8pc;A=9BITHB!0*pY$q(+Z-pu@SE7k4o1U?&`{makK+IoBIniXw^pVX(#E|RG2 z@!-pjD*oIs+kZp!`BdwJoTeteB6%G}uYKw#pAnt4QCe`D`Q&q#4r$yz^`<~AHYoH) z`N!5%i?)SLx^Y8t=Q4}itUbG!ZbLpDjP7Y0u$@m9Ib8OfU*o z_$%amL^i-v%^~mY{bS$n9asF2uCFgs9J{Dc+VqLxk^h$;8}8UH!Sz?ZTYT-&?h9$_ zR;1ioZP?<&I@PoweNwQ|BBSMYGmrm>3(@!`$5Qu|^A*SJ)(_s|$tieR=cdQtZD)*lP@Bq!+Wi5zD__53 zJG<88Sp^ZdH`KjvzPff>y6)F)NgJ~GW{FBQFVdX$t%~_n>4vx2TMoa~dbjFA+>A^1 zD2aKq8`ni9W?)L5EXDf_L~my1i)RE2r1C!k3wQ~5LIkD>T64mSgUPo9&E!G6nK5&e z1=tuE=BP6;2m=cV7-(QTGg)6q39JS+m%vmoFl=k&om?QK4z_NVkhIM`E(V5*9R1>w z%AC|ceqmsi<3^an(7?E9@<$;lut9vn(oD1YCTk1J pg1O$p(u{v6rweO>U6MMXa*`w?1H*Y{bk{zbyk1z1O-Bf1DgczXF9rYr delta 1157 zcmZqBysgd~;LXe;!oa}5!BEt7WFqgHdLR{caZkA4d!V2;69a=FkWR@@4k*emDArHT zFG|&`$jv!B>7d_X1D>{c)~ENZa<|Ja(wna6r=V!ac|_N1kM1JR#Ya}$y*+u_THz-4 z2NJ)}KR-VyTDIk#vfXjJ1eNZWc_nlGo!WJ+1z8y}4refr&M61aV3(Hc|#>I+(~p4Z;#Zqzr^Dv+Bq{q1f3J4eojya|8S@c;h~`5%{r zZ>5Jb3jAI?wQ%zirB&}O$}3r;b_iZe_;X5dtyujN=jfvFXaQI4OI`lQ9)FMF&YYx^ z``paTd!wQ%Z;noJ@3lk!<~AR?th3WoPdGX+OPWA)n*g^ zX0vkcL+_`l1>BnWb@ip?i*xjIUcP^{+aUGv$|ZCDbRH5qf1d4gVzave>#dGF!!^-+ zKbNmi+VylpUg7@q>LW9XOxM&nMQ>QUAY$U{#Fu?6rtj)yzb~n`zB8Hc`;y~HHv{61 ze)z^2=B50bCxJDh$nZezsZUD3mLyJD+~@f2^1HPf7dFb8wjPmqy!}vkN9{7{|6dM9 zX|QqlSvOslo4%D**!{-xA8dy<>|Eiw>&06AdtC9HUuXWiV}E1^PsG~aYs@?nJh((3 zA6j4c>cR%OKl8PElezlt<=7bgDwu8X`w~kW)1h6p2iaAe?(%8hH$T|MTlcra?ye<= z?TXh&ZrY=!o7Y?ynV5kYZ1R5IXCQj>3ch$oumG39Be1}G0Z)j4wU9L@JS$GF7c!Fv z@n*)%Q5IlhV3?!Mz#t4vZ!plncy{s?AtkUH^fU=mv#pVDvZ$~+*gAV*X-3P*(ZVud zUX`%4H7_p%Lwr$cPO-iohz#&%WD;S37Yt#~X0WN40u#DAutea8nFypC7{BpOz91|M nHs=G-)QHJEBAQ@#q)w=uBni}Vo*CV(wv$6d)Y#fVB?|)p07d0+ diff --git a/README.md b/README.md index b369f5b..42d0fbd 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This repository has been created by Elmo Geeraerts for the final assignment of a 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; -- Two `xlsx` files which were generated while creating the `tutorial.ipynb` file. Be aware that if you run the code in the tutorial notebook, some data will be duplicated in the excel if you do not change anything. To avoid this you can delete the two excel files from the directory or you can change the data in the tutorial code to fit your needs. Or you could import the os package and run os.remove('path/to/the/file.xlsx); +- 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 @@ -32,23 +32,23 @@ Check out `tutorial.md` to see an example of the different functionalities of th You can also run the script directly with the following code in a console: ```sh -python vendor_data.py <-a/--add> +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> +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> +%run vendor_data.py -a/--add ``` OR ```python -%run vendor_data.py <-m/--modify> +%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`". @@ -69,8 +69,8 @@ The main advantage of this script is that it limits the posibilities of CAT tool ## 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 specific vendors; -- Join multiple excel files in the excel file created by this code. -- not create multiple entries for the same vendor if the excel file already exists and the ToExcel() method is called multiple times for the same vendor. -- delete vendors from the file; -- modify multiple keys in a dictionary if the script is imported as a module. +- 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/Tutorial_English.xlsx b/Tutorial_English.xlsx deleted file mode 100644 index b3d0221e54913bfe54729dcba2d58d65a2a7e7a8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5214 zcmZ`-1ymGm+g@6_K~maa>5xuIWl2ftU15=25EcXp5d=gjDOnl>X zcC*)mxw(4^*}A(6!d;woUdWT;icsD9(c|&HMj54Ir!-(tUP<|gMJNWWTB-85NgDOi zmEG;K`YegVjW2~10%1lk=ego20rZTK)ga3^uB=IpdG@{l+2z>&=V(nWo1zi+0^+=s zC7pAM7wQ=>3ic8>Xz6Q(JLGCx9w!0$517kL;fTa0-(KRCu`OAsmEK?O4mO&AHnDE< z;{pKG|902j4F>t?Z(ke=)Fw<8W=*g-BjZxTmMxgX3F6=sA#NAYZWPGY%4sjaOvNXb z(1sArT|PlCqvI^tLN~Y-x)f}9qE=nK5V|Vi0p7Yzd|;~zxKhG=BM`DJg54sYcqPbGrNuo3H}z0c!}Gn3uC@VOixNxL-6S$Z)0N*A z#_#(y2ijCFJv7|XL7AL52^^Xiryg|gh0p3t>~*rQDM~hx^e{ZeJUzwzo1K(0jtvcL){vy?O(b8B)2V+ghYwsm=~vTOUXk+M-4L`}344~X1Go7kG&R;x zBQ!H-BFaOpEX?$#Y^#MN?~YZKITX+)70^vf(>5Ivb?G*ou6OL-oCUKG_t;nD6vj9d z>YR0118fsu1$0yzFw!@7v*ti9UJ*N_?=^~slTL8XVFL3h53=AgI^c&l#q_BuXwTgD~y)_TO(` z&v@Q5=_T&MJU71$m#Xd^igIVgpVMzhZ$*4}Zq8LEM&>{Vz!UqErLp;MqYZV34+3Vt zy>?6^iMG%ke&B-{ei6}GG5{xU+SUzkD~;$Z8u0oC<-2-T`XG0e!BIth{+k~Sebu7U zFbBZY-Fxig5MH9y_2Y*L%%9jAFv|C~OgE$>sLwk)@W-G-Oo`&^FhmRi1>k1;;2k~x zGUe*Xxz@O$dog3^>s5Npmr_3j?`ec^c1)L@?IksI=Zg6u0%ZChBm_c>aNevpyhg{L zdaf*Fyon#zQR#PY1QKtba9h}hUv-tGg~_lwsQ9Dz_ha*TMbVo_B;P=C4p)p5%PrC9 zh4kkz?gq@hX~4d&hAa1YVaq$N@dR}qwTuq}^$XNeRa)etw2GGyVaZNN(ngnx;!1W}}}S6uG6!n`D`4O@& zJMK4Le0?io%qaCTmWSbvLvnuS1V?ESB&@M4Y`6|A@6Nu;L*l+uzVyK(h!=$uR z*RwrL@z2t&+O$wBA-(s{Y9EJYV4HpHe6hx zfL)Y?V7rc8VbKpxax<~BQLi-Q5zddn$(yZ3haoM}fr0_(yv@4r@>xSQH@O2GP{UCc zGwQAu?I)!oljGuo*X&JTeIL4v%Hpq2NN2RHojEF`Z?7MJ;t4HFH51@wh`Am7PMN3n zG^%IoMmzBe*n*e1*Jv1WGm<7Kj zJvp|HWY{3at?g*F1J3+K`V)R#K(dL;^2Ffa$udg6JZDobk*(|5PB!O8R#-B+O*P#2 zk#(}et4=*}Iv3|+9-w-SP3`zLkZulaBalh-q)Z=o$KbAwh(#wJe@wRjo#$#R?#oH{ ztmg;g=BM%@Rjy^%eVAOh45VA3$+QkdJu{FB)Ll08U5lOaCMS6$JqUenR`MZ(j2gs1 zN~39?z?iR{y~||Sw9K#7epjklO{|(G>2l-zQkMtFu$IQVni5yEu0guc4UAD8!Wk`Kye=ghrZgK|-J+4{SsYU$&B%>1!yysYM(G~W(t z94|Fo?pLgY42+@+dK+;ugtRz)3Ej80a6`cPtU<}gr0;jg>aNrGmncXFssW#bfvkpj zY3L%$$p|>bp59bL{WJJzx9PwyG8XFdbt*5}lQHpOTruvs$7Bs^&gM z1w=*$Q5V@Y)tBiW@utZlA8iM7ygnV9%H7Azk@=4lndgD|sTFS%`Co}6w0~~#UEKO5 zon1+OMM>wR2$^q?=`LB;eW}@SwNz%Y(WqkSXc9N&QKd!2sS$F=eR6TuSOP1NlxoSG z1rUkc^!X-vd29QN&+AdmIDZ!q@Ajk^IJUGd5CH&}e-{uRH`oJDM+n5rQ|Q;@R~32s zY6>aQz8{FakP(CD?PvrXuHQtig1^gNIZXHan=2DN$Su--D z7y}Ofs?P`rJ7u`{)z;{;p;dcDKM9qQPdPr+VXOdOqPj@3LXdu-k%5@~paJ7kk$FcQ zYVfk}ZmJDLDqh&+mWhhqo&!FsPg?<_JmqwSj_tHk8XqsF1@~hOtkhY^^&X5*$tf)E znki*Y(M-qM$C5I}X|ajbCz2kq#Z*@;mpv7p*Ka7baEkQ@Pofz*Tk6CryAG=ko~H^R zw#v`e6pHL?DvArjM0SW0U)xVXjVe?ZR4!CB${;HlD#e^0k(j_huw6 zHKb~3Ky4Ec5O3Ld!NSRjhT1Hcq1g>B=e3AwqqKE$^>xAn4o@R?Os(Zj`3j#8^7UE` zuKra#w{K;@CQJR5Ud78g`78HN=8>xEIYz@E3lMD-9U{=!C zQ$JC9nlPJGqadT(i+T4c9|Jm&i>L|5S8??e=OE8%uNaG>@|Nqp9p2pJQQzE3~?X(233A@vD&>U$Gm)oSik z`E(-)Y0og>B6P(8SO}i%73E1G>12u{o(Ko28!e3xiRFfY`b|Jyt3$^oVd{C}se9RF>*Nf{C%%$i}W<1xcI3M^*$XTT{xNFi* zg4C?4Y2+|dz4qAW0j*+u>V%J7Up?Yr?5_N1!kZVUO3*WYaY8i=(3y#FkzwLUVsd?- z&15LGHT|66Z?(>C=xG#U)yhB$0FeJytEZQ*GsN>}qk}P?ikuRrI-~zgSrDI`TH78h zNp%egu|3Et(*}0on!zB_JSTgISk~pr)Vy_jT1oc4!4$Dnrq7mp8^!IO+@bbwj8~iP zFfZ5ZLMJy_26xV%tcDWiN>(pYB<{!TBj_8y#*V!85_!D{?ac#?@yjEp#`c`u2-kbS ziMikIx_lpfrx}7*y<=R?Z33zMti4hE{gE&KsB|sk$^;7p=ou4vEneF1cpQLkBYDR< zk2GM3>KDHjI*X}2Biwq)E~%NfA%@rGH|nt*I%;7Gf8o;q!n(hg6G$P z-xdaIh49iePWH-BQrloP0o}&|Z?6X2I8J*;@p$Ip*Hg3ZC$4HzCs#;IO-@_wqbqjk zN8Cvc=BOlXHEa>nIYi70y`FEom~|GnJL>sQ7a(xoo&};At%r9Z4azsJ?$tVh?-HNo zpHt0jv)wyxI4p0bk+_oZD5XWTZgN(QH@rI8Ti%wp)6(RGrGHK?!&T5x%Q7OqKyrSF z-FpUX6ZG|Pd-o*B`RwWoy|kbX>h^1FH}E29O%wWmc%}3DrU&WQ3FLf;TL5Z-Y&v41 ze;CMkfN(MnwW7FschcUj+^6lcQ5_XPZws+U_mDFsP~14PELn9OrrkMb)sqi!Qz?ia ziq}LWluB@I*K_7v`+~{$icx+ToXR%x^4r{<4r#M6%RE?)t8g?O!P7Zlr-L{;;_Jd; z^g(z%ubDBO2Yv;d&`g~Z&H@eX0eEJ{0CzW0;RpJDzPfqiKSIYZX5ggA2G$m=mT9rN z#>yIC4TCs)3JLzaBjV~@v0EFZz>a}*VWI)fXJU|T2K*x&<7~o<|HR zldrrS%``hyX5WZ z)1#cKVHIn%jQ%ZN!L+p$%V>wrUa{>8E}8q*{l|K5B|BYXm$O_^tM007@D%ZOkVdfo z2i2}j9Y>t(cSkPzA3fg;7LCG&CSi}suc@%bHpWCuaHq9x%AwXmarlv!n{P`@3lx0J z(gEAs6QdU*0JjD}X zvZrMS1*XGm$i|vJH*rSr<6+Kb$&_-yE=#k zuOQGgGoQtV)Y2WtUYEJ(Jl?^4Xi5w;shvqf|5T?KKGTR!Pb!{yNnO5z*qcaT)Ay&t zy-NhLW8;FCA~~hCPE)J7w5#GRs1AA;pXi}z;cu@!O87P^hJ?8l!dHD+bhdO-TI|f^ zqFX;YX*1!Xy!K-00_b<`#1WZLCr<@#o5Il zcpvun|7DVK(ZI#t^&bP(!4#K%8ThZA>_saVdy0Ro1mQH2{Ic?=!?*~&n7aQ!W3b)H zzY_UH;Kfw<2k1-jf1dx77%ze^M)@D`6gI75dHWwRf6>mxK>A~+1v?k~FJYy3n*cj% R0sx4yrvf&KlhFKp`wx1GC29Zw diff --git a/tutorial.ipynb b/tutorial.ipynb index 84eabba..4258a98 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -17,13 +17,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "b3611132", "metadata": {}, "outputs": [], "source": [ "import sys\n", - "sys.path.append (r'C:\\Users\\geera\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1')\n", + "sys.path.append ('..\\Final_Assignment1')\n", "import vendor_data as vd # 'as vd' is not necessary but makes it shorter." ] }, @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "4ab17746", "metadata": {}, "outputs": [], @@ -60,48 +60,92 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "c6675ef0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Elmo Geeraerts'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorNL.VendorName" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "23b52971", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'j.lefevre@hotmail.com'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorFR.VendorMail" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "69659b86", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.09" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.WordRate" ] }, { - "cell_type": "markdown", - "id": "a831785f", + "cell_type": "raw", + "id": "91ddcb10", "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 does not return anything:" + "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": null, + "execution_count": 6, "id": "cb2ca64c", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "''" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorNL.VendorMail" ] @@ -116,10 +160,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "c7180a19", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'XTM'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.CatTool" ] @@ -135,47 +190,91 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "e26d1539", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorFR.Preferred" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "935c0a38", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Preferred'" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorFR.Status" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "9ebc7f07", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.Preferred" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "1158b1de", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Back-up'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.Status" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "ab5e5f54", "metadata": {}, "outputs": [], @@ -185,10 +284,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "50cd8967", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Potential'" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorNL.Status" ] @@ -213,10 +323,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "90cb5c10", "metadata": {}, - "outputs": [], + "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" @@ -232,10 +353,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "730b35ca", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.08" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorNL.SetWordRate(0.08)\n", "VendorNL.WordRate" @@ -251,10 +383,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "id": "391e7c5d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Trados Studio'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.ChangeTool(\"Trados Studio\")\n", "VendorES.CatTool" @@ -265,15 +408,26 @@ "id": "574ef338", "metadata": {}, "source": [ - "Because we sat 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:" + "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": null, + "execution_count": 17, "id": "96819356", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorFR.SetStatus(False)\n", "VendorFR.Preferred" @@ -281,10 +435,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "id": "e8335217", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Back-up'" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorFR.Status" ] @@ -294,26 +459,7 @@ "id": "0bf8e1d0", "metadata": {}, "source": [ - "We can now write the data for the vendors to an excel file. To be sure the file does not already exist, we'll first delete the excel file for the project called `Tutorial` in the source language `English`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ca4a9c99", - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "os.remove('Tutorial_English.xlsx') #If the file is stored elsewhere, copy the full path to the excel file." - ] - }, - { - "cell_type": "markdown", - "id": "813e7f50", - "metadata": {}, - "source": [ - "Since every vendor has the same value for the argument `ProjectName` and `SourceLang`, they will be written to the same excel file.\n", + "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", "
" @@ -321,10 +467,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "aeafcb32", "metadata": {}, - "outputs": [], + "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", @@ -342,10 +498,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "37124f32", "metadata": {}, - "outputs": [], + "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()" ] @@ -355,15 +527,28 @@ "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 it to an excel file, we'll get an error message saying that a file for the project in the given source language does not exist." + "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": null, + "execution_count": 21, "id": "10dc02d2", "metadata": {}, - "outputs": [], + "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()" @@ -374,15 +559,13 @@ "id": "e0592b3d", "metadata": {}, "source": [ - "We can also modify the excel file by running the `ModExcel` method. You could call this method for any instance you created and modify any vendor in the excel file. However this is not advisable since it will modify the correct vendor, but if you check the values by calling the argument (self.argument), the script thinks it is the vendor that you called the method for that is modified.\n", - "\n", + "We can also modify the excel file by running the `ModExcel` method.\n", "
\n", - "Run the `ModExcel()` method for the vendor you actually want to modify. It is possible to modify another vendor, but the script will still think you modified the vendor you called the method.\n", + "You can only modify one value for one key at a time.\n", "
\n", "\n", - "This method takes 3 arguments:\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", - "2. The `Index`: if you have run the ReadExcel() function, you have noticed that before every value for a key in the dictionrary there's a number. By picking a number, you can change the value for that index.\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:" @@ -390,10 +573,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "17292d31", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['E-mail', 'CAT Tool', 'Word Rate', 'Status']" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "vd.VendorData.Keys" ] @@ -408,10 +602,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "abf2dc40", "metadata": {}, - "outputs": [], + "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()" ] @@ -426,12 +636,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "52e91ff2", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The vendor was correctly modified.\n" + ] + } + ], "source": [ - "VendorES.ModExcel(\"CAT Tool\", 2, \"MemoQ\")" + "VendorES.ModExcel(\"CAT Tool\", \"MemoQ\")" ] }, { @@ -444,10 +662,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "id": "f4e539d4", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'MemoQ'" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorES.CatTool" ] @@ -457,51 +686,44 @@ "id": "6539e2b4", "metadata": {}, "source": [ - "As already mentioned, you could call the `ModExcel()` method for any vendor and modify another one, but the script will still think you modified the vendor you called the method for. This is bad practice and you should not do this! We'll illustrate what would happen if you did:" + "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": null, + "execution_count": 26, "id": "055d1046", "metadata": {}, - "outputs": [], - "source": [ - "VendorNL.ModExcel(\"Status\", 2, \"Preferred\")" - ] - }, - { - "cell_type": "markdown", - "id": "0eae995b", - "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The vendor was correctly modified.\n" + ] + } + ], "source": [ - "We'll see that the status for the Spanish vendor is not changed:" + "VendorNL.ModExcel(\"Status\", \"Preferred\")" ] }, { "cell_type": "code", - "execution_count": null, - "id": "95ddcda9", - "metadata": {}, - "outputs": [], - "source": [ - "VendorES.Status" - ] - }, - { - "cell_type": "markdown", - "id": "92fbdd31", - "metadata": {}, - "source": [ - "But the status for the Dutch one is:" - ] - }, - { - "cell_type": "code", - "execution_count": null, + "execution_count": 27, "id": "7c7d3af1", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Preferred'" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "VendorNL.Status" ] @@ -511,15 +733,31 @@ "id": "83fd2f6e", "metadata": {}, "source": [ - "However, if we read the excel (`ReadExcel()`), we'll see that it is in fact the Spanish vendor's status that is changed. Here it does not matter for which vendor we call the method:" + "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": null, + "execution_count": 28, "id": "256e78dd", "metadata": {}, - "outputs": [], + "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()" ] @@ -551,80 +789,187 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "id": "854ef143", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 30, "id": "cd524417", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 31, "id": "d6497db2", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 32, "id": "8b01bfed", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 33, "id": "20b5cc03", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 34, "id": "7c32d39f", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 35, "id": "32715f64", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 36, "id": "8b74ce10", "metadata": {}, - "outputs": [], + "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)" ] @@ -642,50 +987,120 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "id": "14d9561a", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 38, "id": "689a0133", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 39, "id": "a5a88daf", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 40, "id": "87ad7fb4", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 41, "id": "a6506797", "metadata": {}, - "outputs": [], + "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\")" ] @@ -703,7 +1118,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "id": "adb90ded", "metadata": {}, "outputs": [], @@ -713,60 +1128,143 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "id": "0e5da23b", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 44, "id": "e2f58285", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 45, "id": "e03407b2", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 46, "id": "63dc4cab", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 47, "id": "4f984703", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 48, "id": "2c570d8f", "metadata": {}, - "outputs": [], + "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\")" ] @@ -784,10 +1282,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "id": "b9e3cd49", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The vendor Thomas Zwiebel was added to Tutorial_English.xlsx.\n" + ] + } + ], "source": [ "VendorDE.ToExcel()" ] @@ -802,40 +1308,88 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "id": "f9d200e7", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 51, "id": "3db36ec1", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 52, "id": "43492fbd", "metadata": {}, - "outputs": [], + "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": null, + "execution_count": 53, "id": "fcc7bf99", "metadata": {}, - "outputs": [], + "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\")" ] @@ -846,7 +1400,6 @@ "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", - "Additionally it also is checked if the index is in the dictionary, otherwise the vendor is non-existent and cannot be modified.\n", "
\n", "You can only modify one value for one key.\n", "
" @@ -854,10 +1407,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "id": "405573dd", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['E-mail', 'CAT Tool', 'Word Rate', 'Status']" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "vd.VendorData.Keys" ] @@ -872,58 +1436,67 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "id": "e37f7571", "metadata": {}, - "outputs": [], + "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\", 2, \"John Doe\")" + "VendorDE.ModExcel(\"Vendor\", \"John Doe\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "id": "4a988964", "metadata": {}, - "outputs": [], + "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\", 3, \"Croatian\")" + "VendorDE.ModExcel(\"Target Language\", \"Croatian\")" ] }, { "cell_type": "markdown", - "id": "2eb97cae", + "id": "c19c49ce", "metadata": {}, "source": [ - "Since there are only 4 vendors in the excel file and the index start at 0 and go up, an error message should appear when you try to modify a higher index:" + "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": null, - "id": "66ca7b9e", + "execution_count": 60, + "id": "35c5843b", "metadata": {}, "outputs": [], "source": [ - "VendorDE.ModExcel(\"CAT Tool\", 6, \"XTM\")" - ] - }, - { - "cell_type": "markdown", - "id": "092a40df", - "metadata": {}, - "source": [ - "You can check for the right index by running the `ReadExcel` method for any vendor you already defined:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "38b01366", - "metadata": {}, - "outputs": [], - "source": [ - "VendorNL.ReadExcel()" + "import os\n", + "os.remove(\".\\Tutorial_English.xlsx\")" ] }, { @@ -944,46 +1517,128 @@ "- `-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", - "We'll start by writing a totally new excel file and adding a vendor to it:" + "\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": null, - "id": "a32de96d", + "execution_count": 63, + "id": "7c4e5ac4", "metadata": {}, - "outputs": [], + "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" + "%run vendor_data.py -a" ] }, { "cell_type": "markdown", - "id": "61141753", + "id": "4825cb73", "metadata": {}, "source": [ - "A new excel file will appear next to where you stored this notebook with the name `TestProject_English`, i.e. the project name and source language we provided.\n", - "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" + "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": "markdown", - "id": "d652047e", + "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": [ - "If the project name and the source language are the same as for the previous vendor you've entered, this vendor will be added to the same excel file, if not a new excel file is created using the project name and the source language as the file name. You'll notice that for the prompts you leave blank the default value is enterred OR it is left blank." + "%run vendor_data.py -a" ] }, { - "cell_type": "code", - "execution_count": null, - "id": "7c4e5ac4", + "cell_type": "markdown", + "id": "61141753", "metadata": {}, - "outputs": [], + "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": "7c4e1906", + "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" ] @@ -996,16 +1651,46 @@ "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": null, + "execution_count": 64, "id": "54012864", "metadata": {}, - "outputs": [], + "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" ] @@ -1055,16 +1740,6 @@ "%run vendor_data.py --h\n", "```" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "927da363", - "metadata": {}, - "outputs": [], - "source": [ - "%run vendor_data.py -h" - ] } ], "metadata": { @@ -1083,7 +1758,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.9.13" } }, "nbformat": 4, diff --git a/tutorial.md b/tutorial.md index 0b5affe..2071bb4 100644 --- a/tutorial.md +++ b/tutorial.md @@ -1,1091 +1,1341 @@ -{ - "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": null, - "id": "b3611132", - "metadata": {}, - "outputs": [], - "source": [ - "import sys\n", - "sys.path.append (r'C:\\Users\\geera\\OneDrive\\Documenten\\School\\PostgraduaatTranslationTechnology\\IntroductionToPython\\Final_Assignment1')\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": null, - "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": null, - "id": "c6675ef0", - "metadata": {}, - "outputs": [], - "source": [ - "VendorNL.VendorName" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "23b52971", - "metadata": {}, - "outputs": [], - "source": [ - "VendorFR.VendorMail" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "69659b86", - "metadata": {}, - "outputs": [], - "source": [ - "VendorES.WordRate" - ] - }, - { - "cell_type": "markdown", - "id": "a831785f", - "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 does not return anything:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "cb2ca64c", - "metadata": {}, - "outputs": [], - "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": null, - "id": "c7180a19", - "metadata": {}, - "outputs": [], - "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": null, - "id": "e26d1539", - "metadata": {}, - "outputs": [], - "source": [ - "VendorFR.Preferred" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "935c0a38", - "metadata": {}, - "outputs": [], - "source": [ - "VendorFR.Status" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9ebc7f07", - "metadata": {}, - "outputs": [], - "source": [ - "VendorES.Preferred" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1158b1de", - "metadata": {}, - "outputs": [], - "source": [ - "VendorES.Status" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ab5e5f54", - "metadata": {}, - "outputs": [], - "source": [ - "VendorNL.Preferred #Will not return anything since value is None" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "50cd8967", - "metadata": {}, - "outputs": [], - "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": null, - "id": "90cb5c10", - "metadata": {}, - "outputs": [], - "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": null, - "id": "730b35ca", - "metadata": {}, - "outputs": [], - "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": null, - "id": "391e7c5d", - "metadata": {}, - "outputs": [], - "source": [ - "VendorES.ChangeTool(\"Trados Studio\")\n", - "VendorES.CatTool" - ] - }, - { - "cell_type": "markdown", - "id": "574ef338", - "metadata": {}, - "source": [ - "Because we sat 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": null, - "id": "96819356", - "metadata": {}, - "outputs": [], - "source": [ - "VendorFR.SetStatus(False)\n", - "VendorFR.Preferred" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e8335217", - "metadata": {}, - "outputs": [], - "source": [ - "VendorFR.Status" - ] - }, - { - "cell_type": "markdown", - "id": "0bf8e1d0", - "metadata": {}, - "source": [ - "We can now write the data for the vendors to an excel file. To be sure the file does not already exist, we'll first delete the excel file for the project called `Tutorial` in the source language `English`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "fdd13cb8", - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "os.remove('Tutorial_English.xlsx') #If the file is stored elsewhere, copy the full path to the excel file." - ] - }, - { - "cell_type": "markdown", - "id": "6c24b72f", - "metadata": {}, - "source": [ - "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": null, - "id": "aeafcb32", - "metadata": {}, - "outputs": [], - "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": null, - "id": "37124f32", - "metadata": {}, - "outputs": [], - "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 it to an excel file, 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": null, - "id": "10dc02d2", - "metadata": {}, - "outputs": [], - "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. You could call this method for any instance you created and modify any vendor in the excel file. However this is not advisable since it will modify the correct vendor, but if you check the values by calling the argument (self.argument), the script thinks it is the vendor that you called the method for that is modified.\n", - "\n", - "
\n", - "Run the `ModExcel()` method for the vendor you actually want to modify. It is possible to modify another vendor, but the script will still think you modified the vendor you called the method.\n", - "
\n", - "\n", - "This method takes 3 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", - "2. The `Index`: if you have run the ReadExcel() function, you have noticed that before every value for a key in the dictionrary there's a number. By picking a number, you can change the value for that index.\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": null, - "id": "17292d31", - "metadata": {}, - "outputs": [], - "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": null, - "id": "abf2dc40", - "metadata": {}, - "outputs": [], - "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": null, - "id": "52e91ff2", - "metadata": {}, - "outputs": [], - "source": [ - "VendorES.ModExcel(\"CAT Tool\", 2, \"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": null, - "id": "f4e539d4", - "metadata": {}, - "outputs": [], - "source": [ - "VendorES.CatTool" - ] - }, - { - "cell_type": "markdown", - "id": "079b36e6", - "metadata": {}, - "source": [ - "As already mentioned, you could call the `ModExcel()` method for any vendor and modify another one, but the script will still think you modified the vendor you called the method for. This is bad practice and you should not do this! We'll illustrate what would happen if you did:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8500c4c1", - "metadata": {}, - "outputs": [], - "source": [ - "VendorNL.ModExcel(\"Status\", 2, \"Preferred\")" - ] - }, - { - "cell_type": "markdown", - "id": "a5775c45", - "metadata": {}, - "source": [ - "We'll see that the status for the Spanish vendor is not changed:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8815e256", - "metadata": {}, - "outputs": [], - "source": [ - "VendorES.Status" - ] - }, - { - "cell_type": "markdown", - "id": "2111c773", - "metadata": {}, - "source": [ - "But the status for the Dutch one is:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e740b32b", - "metadata": {}, - "outputs": [], - "source": [ - "VendorNL.Status" - ] - }, - { - "cell_type": "markdown", - "id": "6bd49720", - "metadata": {}, - "source": [ - "However, if we read the excel (`ReadExcel()`), we'll see that it is in fact the Spanish vendor's status that is changed. Here it does not matter for which vendor we call the method:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "eb036959", - "metadata": {}, - "outputs": [], - "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": null, - "id": "854ef143", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE = vd.VendorData(0.1, \"English\", \"German\", \"Thomas Zwiebel\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "cd524417", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE = vd.VendorData(\"Tutorial\", 1, \"German\", \"Thomas Zwiebel\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d6497db2", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE = vd.VendorData(\"Tutorial\", \"English\", True, \"Thomas Zwiebel\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8b01bfed", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", None)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "20b5cc03", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", 3)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7c32d39f", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = \"0.15\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "32715f64", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", Preferred = \"Test\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8b74ce10", - "metadata": {}, - "outputs": [], - "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": null, - "id": "14d9561a", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", VendorMail = \"thomas.zw\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "689a0133", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = 0.19)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a5a88daf", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = 0.00)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e682f9b1", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE = vd.VendorData(\"Tutorial\", \"English\", \"German\", \"Thomas Zwiebel\", WordRate = -0.04)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a6506797", - "metadata": {}, - "outputs": [], - "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": null, - "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": null, - "id": "0e5da23b", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE.SetVendorMail(\"thomas.zw@\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e2f58285", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE.SetWordRate(0.18)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e03407b2", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE.SetWordRate (0.00)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3c95b758", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE.SetWordRate(-0.04)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4f984703", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE.ChangeTool(\"SDL Trados Studio\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2c570d8f", - "metadata": {}, - "outputs": [], - "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": null, - "id": "b9e3cd49", - "metadata": {}, - "outputs": [], - "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": null, - "id": "f9d200e7", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE.ModExcel(\"E-mail\", 3, \"thomaszw@\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3db36ec1", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE.ModExcel(\"CAT Tool\", 3, \"Trados Studio 2019\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "43492fbd", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE.ModExcel(\"Word Rate\", 3, 0.18)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "fcc7bf99", - "metadata": {}, - "outputs": [], - "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", - "Additionally it also is checked if the index is in the dictionary, otherwise the vendor is non-existent and cannot be modified.\n", - "
\n", - "You can only modify one value for one key.\n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "405573dd", - "metadata": {}, - "outputs": [], - "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": null, - "id": "e37f7571", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE.ModExcel(\"Vendor\", 2, \"John Doe\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4a988964", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE.ModExcel(\"Target Language\", 3, \"Croatian\")" - ] - }, - { - "cell_type": "markdown", - "id": "2eb97cae", - "metadata": {}, - "source": [ - "Since there are only 4 vendors in the excel file and the index start at 0 and go up, an error message should appear when you try to modify a higher index:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "66ca7b9e", - "metadata": {}, - "outputs": [], - "source": [ - "VendorDE.ModExcel(\"CAT Tool\", 6, \"XTM\")" - ] - }, - { - "cell_type": "markdown", - "id": "092a40df", - "metadata": {}, - "source": [ - "You can check for the right index by running the `ReadExcel` method for any vendor you already defined:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "38b01366", - "metadata": {}, - "outputs": [], - "source": [ - "VendorNL.ReadExcel()" - ] - }, - { - "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", - "We'll start by writing a totally new excel file and adding a vendor to it:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a32de96d", - "metadata": {}, - "outputs": [], - "source": [ - "%run vendor_data.py --a" - ] - }, - { - "cell_type": "markdown", - "id": "61141753", - "metadata": {}, - "source": [ - "A new excel file will appear next to where you stored this notebook with the name `TestProject_English`, i.e. the project name and source language we provided.\n", - "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" - ] - }, - { - "cell_type": "markdown", - "id": "d652047e", - "metadata": {}, - "source": [ - "If the project name and the source language are the same as for the previous vendor you've entered, this vendor will be added to the same excel file, if not a new excel file is created using the project name and the source language as the file name. You'll notice that for the prompts you leave blank the default value is enterred OR it is left blank." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7c4e5ac4", - "metadata": {}, - "outputs": [], - "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", - "\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": null, - "id": "54012864", - "metadata": {}, - "outputs": [], - "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": "de6ddf9f", - "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": "0142a21d", - "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", - "```" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d5b846fc", - "metadata": {}, - "outputs": [], - "source": [ - "%run vendor_data.py -h" - ] - } - ], - "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.16" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} +# Tutorial: how to use `vendor_data.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') +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 index 4627100..206b513 100644 --- a/vendor_data.py +++ b/vendor_data.py @@ -152,9 +152,9 @@ def SetVendorMail(self, NewMail): 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 + 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 @@ -166,11 +166,11 @@ def SetWordRate(self, NewRate): 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. + 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 @@ -182,9 +182,9 @@ def ChangeTool (self, NewTool): 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 + 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 @@ -215,7 +215,7 @@ def ToExcel(self): 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 a panda data frame. + 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`. @@ -232,11 +232,11 @@ def ToExcel(self): df = pd.DataFrame(Data) if not os.path.exists(FileName): df.to_excel(FileName, index=False, sheet_name="VendorData") - return(f"The file {FileName} is correctly created and the vendor {self.VendorName} was added.") + 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) - return(f"The vendor {self.VendorName} was added to {FileName}.") + print(f"The vendor {self.VendorName} was added to {FileName}.") def ReadExcel(self): """Method to read an existing excel file @@ -256,29 +256,27 @@ def ReadExcel(self): else: raise ValueError(f"There is no file for {self.ProjectName} in {self.SourceLang}") - def ModExcel(self, Key, Index, NewValue): + def ModExcel(self, Key, NewValue): """Method to modify existing vendor in excel file Args: Key (str): one of the modifiable keys in VendorData.Keys - Index (int): the index of the value that needs to be modified - NewValue : the new value of the index, type depends on the key, either str or float + 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 Index is not valid for a certain key - ValueError: if the provided Status is not in the list VendorData.Statuses + 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): - ExcelRecords = pd.read_excel(FileName) - ExcelRecordsDf = ExcelRecords.loc[:, ~ExcelRecords.columns.str.contains('^Unnamed')] - VendorDict = ExcelRecordsDf.to_dict() + ExcelRecordsDf = pd.read_excel(FileName) if not Key in self.Keys: raise ValueError("Invalid key, run 'VendorData.Keys' to see options.") - if not Index in VendorDict[Key]: - raise ValueError("Invalid index, run 'self.ReadExcel()' to see options") + + VendorRow = ExcelRecordsDf[ExcelRecordsDf.Vendor == self.VendorName] + Index = VendorRow.index[0] + if Key == "E-mail": CheckVendorMail(NewValue) self.VendorMail = NewValue @@ -293,11 +291,13 @@ def ModExcel(self, Key, Index, NewValue): raise ValueError("Invalid status, run 'VendorData.Statuses' to see options") else: self.Status = NewValue - ChangeDictionaryValue(VendorDict, Key, Index, NewValue) - df = pd.DataFrame(VendorDict) + + ExcelRecordsDf.at[Index, Key] = NewValue + with pd.ExcelWriter(FileName, engine="openpyxl", mode="w") as writer: - df.to_excel(writer, sheet_name = "VendorData", index=False) - return("The vendor was correctly modified.") + 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}") @@ -313,7 +313,10 @@ def ModExcel(self, Key, Index, NewValue): 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: + + 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 @@ -346,10 +349,9 @@ def ModExcel(self, Key, Index, NewValue): 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 - print("Vendor was added!") else: print ("Action was cancelled.") - if args.modify: + elif args.modify: done = "no" while done.lower() != "yes": #Code underneath is run as long as value for done = no """ From a671048af19207f97e1acdeb771266d47ba672db Mon Sep 17 00:00:00 2001 From: Elmo Geeraerts Date: Wed, 14 Jun 2023 23:03:26 +0200 Subject: [PATCH 24/24] Final update --- tutorial.ipynb | 12 ++++++------ tutorial.md | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tutorial.ipynb b/tutorial.ipynb index 4258a98..a04913c 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -23,7 +23,7 @@ "outputs": [], "source": [ "import sys\n", - "sys.path.append ('..\\Final_Assignment1')\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." ] }, @@ -123,7 +123,7 @@ }, { "cell_type": "raw", - "id": "91ddcb10", + "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:" @@ -1482,7 +1482,7 @@ }, { "cell_type": "markdown", - "id": "c19c49ce", + "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." @@ -1491,7 +1491,7 @@ { "cell_type": "code", "execution_count": 60, - "id": "35c5843b", + "id": "d046edf6", "metadata": {}, "outputs": [], "source": [ @@ -1555,7 +1555,7 @@ }, { "cell_type": "markdown", - "id": "4825cb73", + "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", @@ -1614,7 +1614,7 @@ { "cell_type": "code", "execution_count": 62, - "id": "7c4e1906", + "id": "5fba8692", "metadata": {}, "outputs": [ { diff --git a/tutorial.md b/tutorial.md index 2071bb4..a94fe94 100644 --- a/tutorial.md +++ b/tutorial.md @@ -10,7 +10,7 @@ We'll begin with importing the code as module: ```python import sys -sys.path.append ('..\Final_Assignment1') +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. ```