Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Trivial Text Translator (TTT) for supervised bilingual translation. WHAT I BASIC

ID: 642887 • Letter: T

Question

Trivial Text Translator (TTT) for supervised bilingual translation.

WHAT I BASICLLY NEED FROM YOUI IS THE ( GUI ), PLEASE DESIGN ONE .. ASAP    USING PYTHON

Your translator shall provide a graphical interface with three buttons (Translate, Clear, and Quit), an editable text Entry, and a multiline non-editable Text. The GUI (the main window, the Text, and the Entry) shall be resizable, and the buttons shall not be resizable. The Quit button shall exit the program. The Clear button shall clear the Entry. The Translate button shall translate the text in the Entry and display it in the Text. Initially, the Entry is empty, and the Text displays the message 'Welcome to TTT!', less the quotes.

Your program shall have at least the following classes:

(1) TextWords - shall store the text in either the native or foreign language. The class shall have an initializer that shall take one additional argument that is either a list of words (e.g., ["Mary", "had", "a", "little", "lamb"]) or one string ("Mary had a little lamb"). Use the function isinstance() to determine the argument type. If the argument is a list, the initializer shall check if each item is a string, and if not, then raise Exception("Bad text"). The class shall have the following methods:

- __str__(self) shall return the stored text as one string, with the words separated by single white spaces;

- list(self) shall return the stored text as a list of words.

Both methods shall work correctly, regardless of how the text was initialized. The text as string shall be converted to a text as list by first enclosing each non-isalnum() character with a white space in front and a white space behind and then using the .split() method. This way, any non-alphanumeric symbol shall become a separate word.

(2) DictionaryItem - shall store one word in two languages (native and foregin). The class shall have an initializer that shall take two additional arguments: the word in the native language and the word in the foreign language. The class shall have the following method:

(3) translate(self,native) shall return the foreign word in the item if 'native' matches the native word in the item, and False otherwise. Two words shall match if they are equal, when both converted to the lower case.

(4) Dictionary - shall store the bilingual, one-way dictionary as a list of DictionaryItem's. The class shall have an initalizer that takes no additional arguments and creates a dictionary with basic punctuation (such as '.,;:@#$%^&*~`"'). The class shall have the following methods:

- lookup(self,native) shall return the matching foreign word if 'native' is in the dictionary, and False otherwise;

- insert(self,native,foreign) shall insert a new Dictionary item translating 'native' into 'foreign' if the item 'native' word does not exist in the dictionary yet, and return None; otherwise, the method shall raise Exception("Duplicate dictionary item").

The program shall translate the foreign text by creating a TextWords object, looking up each foreign word from the text in the dictionary, replacing known words with their translations, creating another TextWords object for the translated text, and displaying the translated text. If a word is not in the dictionary, the program shall ask the user to translate the word using the askstring() dislog box and insert the new dictionary item in the dictionary.

Explanation / Answer

from google.appengine.ext import db import Models.BaseModels as bm from datetime import datetime as dt class Language(db.Model): DateCreated = db.DateTimeProperty(required=True); Creator = db.ReferenceProperty(bm.Person, required=True, collection_name='creator_languages') LanguageName = db.StringProperty(required=True) LanguageCode = db.StringProperty(required=True) ## Static Methods @classmethod def Get(cls, code): return cls.gql("WHERE LanguageCode =:c", c=code).get() @classmethod def GetAll(cls): return cls.all().fetch(100) @classmethod def CreateNew(cls, creator, lang_name, lang_code, _autoInsert=False): result = cls( DateCreated=dt.now(), Creator=creator, LanguageName=lang_name, LanguageCode=lang_code ) if _autoInsert: result.put() return result class PrimaryLanguage(db.Model): ''' Primary Language used for translation This language must be most complete of all Possibly to use some web service in order to retrieve it's items instead of storing them in datastore ''' DateModified = db.DateTimeProperty(required=True) Language = db.ReferenceProperty(Language, required=True, collection_name='language_primary_language') @classmethod def Change(cls, new_language): if new_language: current = cls.all().get() if current: current.Language = new_language current.DateModified = dt.now() else: current = cls(DateModified=dt.now(), Language=new_language) current.put() return current else: raise('None returned as a parameter for the new language') @classmethod def GetCurrent(cls): return cls.all().get() class VirtualLanguageItem(db.Model): DateCreated = db.DateTimeProperty(required=True); Creator = db.ReferenceProperty(bm.Person, required=True, collection_name='creator_virtual_language_items') Code = db.StringProperty(required=True) @classmethod def CreateNew(cls, creator, code, _autoInsert=True): result = cls( DateCreated=dt.now(), Creator=creator, Code = code ) if _autoInsert: result.put() return result @classmethod def Get(cls, code): return cls.gql("WHERE Code =:c", c=code).get() class DictionaryItem(db.Model): DateCreated = db.DateTimeProperty(required=True); Creator = db.ReferenceProperty(bm.Person, collection_name='creator_dictionary_items') Language = db.ReferenceProperty(Language, required=True, collection_name='language_dictionary_items') VItem = db.ReferenceProperty(VirtualLanguageItem, required=True, collection_name='vitem_dictionary_items') Value = db.StringProperty(required=True) Description = db.StringProperty(required=True) ## Static methods @classmethod def GetList(cls, language, word, limit=100, offset=0): '''List of all words with same value but different meaning''' return cls.gql("WHERE Language =:l AND Value =:v", l=language, v=word).fetch(limit, offset) @classmethod def GetAllByVItemLang(cls, vItem, language, limit=5, offset=0): '''Get the list of synonyms that has the meaning of the virtual item given''' return vItem.vitem_dictionary_items.all().filter('Language =', language).fetch(limit=limit, offset=offset) @classmethod def GetFirstByVItemLang(cls, vItem, language): '''Get the first word that has the meaning of the virtual item given''' return vItem.vitem_dictionary_items.all().filter('Language =', language).get() @classmethod def GetByVItemByLangByValue(cls, vItem, language, value): '''Get the first word that has the meaning of the virtual item given''' return vItem.vitem_dictionary_items.all().filter('Language=', language).filter('Value=', value).get() @classmethod def CreateNew(cls, creator, language, vItem, value, description, _autoInsert=False): if not cls.DictionaryItem.GetByVItemByLangByValue(vItem, language, value): result = cls( DateCreated=dt.now(), Creator=creator, Language=language, VItem=vItem, Value=value, Description=description ) if _autoInsert: result.put() return result else: return None #Methods def TranslateList(self, language, limit=10, offset=0): ''' Translate the word to another language if possible Return the list of all synonyms. ''' return DictionaryItem.gql("WHERE VItem =:v AND Language =:l", v=self.VItem, l=language).fetch(limit=limit, offset=offset)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote