def unparsed(words): out = [] for actuaword in words: if any(letter in actuaword for letter in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'): werd = word.loanword(actuaword) else: werd = word.rootword(actuaword) out.append(phrase.phrase(werd)) return out
def attempt(sentence, i): part = sentence[i].part if (i < len(sentence) - 1) & (i >= 0): post = sentence[i + 1].part if (post == 'cj'): sentence[i - 1].part = ':cj' + part return True if (part == 'dn'): if post[:3] == ':dn': kind = post[3:] else: kind = post sentence[i].part = ':dn' + kind return True if (part not in ['dn', ':dnn']) & (post == 'ed'): sentence.insert(i + 1, phrase.phrase(dummy)) return True if part[:3] == ':dn': return False if (i < len(sentence) - 1) & (i >= 1): pre = sentence[i - 1].part post = sentence[i + 1].part if (pre == 'pr') & (part == 'n'): if (post[:3] == ':dn') and\ (describes(part,post[3:])): sentence[i - 1].desc.append(sentence.pop(i)) sentence.pop(i) return True if not describes('n', post): sentence[i - 1].desc.append(sentence.pop(i)) sentence[i - 1].part = 'av' return True if (describes(pre, part)): if (post[:3] == ':dn') and\ (describes(part,post[3:])): sentence[i - 1].desc.append(sentence.pop(i)) sentence.pop(i) return True if (not describes(part, post)): sentence[i - 1].desc.append(sentence.pop(i)) return True return False
def attempt(sentence,i): part = sentence[i].part if (i < len(sentence)-1) & (i >= 0): post = sentence[i+1].part if (post == 'cj'): sentence[i-1].part = ':cj'+part return True if (part == 'dn'): if post[:3] == ':dn': kind = post[3:] else: kind = post sentence[i].part = ':dn' + kind return True if (part not in ['dn',':dnn']) & (post == 'ed'): sentence.insert(i+1,phrase.phrase(dummy)) return True if part[:3] == ':dn': return False if (i < len(sentence)-1) & (i >= 1): pre = sentence[i-1].part post = sentence[i+1].part if (pre == 'pr') & (part == 'n'): if (post[:3] == ':dn') and\ (describes(part,post[3:])): sentence[i-1].desc.append(sentence.pop(i)) sentence.pop(i) return True if not describes('n',post): sentence[i-1].desc.append(sentence.pop(i)) sentence[i-1].part = 'av' return True if (describes(pre,part)): if (post[:3] == ':dn') and\ (describes(part,post[3:])): sentence[i-1].desc.append(sentence.pop(i)) sentence.pop(i) return True if (not describes(part,post)): sentence[i-1].desc.append(sentence.pop(i)) return True return False
"il campanello/doorbell", "la serratura/lock", "la maniglia/handle", "l'ascensore/lift", "il piano/floor level", "il pavimento/floor", "il soffitto/ceiling", "il caminetto/fireplace", "la tappezzeria/wallpaper" ] house_verbs = ["affitare/rent", "abitare/live"] q1 = 20*[ phrase.noun_phrase(rooms+house_parts,kind=['sd','sd','si','pd']) ]+\ [ phrase.phrase(["affitare/rent","possedere/own"],person=persons,tempus='present',dobj=houses), phrase.phrase("abitare/live",person=persons,tempus='present',iobj=phrase.prep_phrase(prep='in',noun=houses) )] systems = [ "il calorifero/radiator", "lo scaldaacqua/bolier", "l'acquaio/sink", "il rubinetto/tap", "la leva/lever", "lo scolo/drain", "il tappo/plug", "la vasca/bathtub", "la doccia/shower", "il lavandino/sink", "il water/water closet", "la lampadina/light bulb", "la presa/socket", "l'interruttore/switch", "l'elettricità/electricity", "la spina/plug", "il filo/wire", "il tubo/pipe" ] furniture = [ "il quadro/painting", "la lampada/lamp", "lo specchio/mirror", "il vaso/vase", "il divano/sofa", "la tenda/curtain", "la veneziana/venetian blind", "il tavolino/coffee table",
#adjective adjs = [ "cortese/polite", "scortese|rozzo/rude", "amichevole/friendly", "ostile/hostile", "popolare/popular", "famoso/famous", "infame/infamous", "importante/important", "timido/shy", "loquace|ciarliero/talkative", "solitario/lonely", "solo/alone", "simpatico|gentile/nice", "occupato/busy", "fidato/reliable", "imparentato/related" ] #verb.eng_verbs['raise'] = {'imperfect':'rose', 'perfect': 'risen' } persons = ['1s', '2s', '3sm', '3sf', '1p', '2p', '3pm', '3pf'] subjv_q = phrase.phrase(subj_verbs,person=persons,tempus=['present','perfect'],\ post=[phrase.phrase(['parlare','lavorare/work',"combattere/fight","rispondere/answer","ubbidire/obey","mentire|dire_bugie/lie(false)"],\ conj='che',subject=other_people,tempus='subjunctive present'), phrase.phrase(['parlare','lavorare/work',"combattere/fight","rispondere/answer","ubbidire/obey","mentire|dire_bugie/lie(false)"],\ conj='che',person=persons,tempus='subjunctive present')]) intransv_q= phrase.phrase(intrans_verbs,subject=relatives,\ tempus=['present','perfect','future','conditional','imperfect']) pluralv_q= phrase.phrase(plural_verbs,person=['1p','2p','3p'],\ tempus=['present','perfect','future','conditional','imperfect']) transv_q=phrase.phrase(trans_verbs,tempus=['present','perfect','future','conditional','imperfect'],\ person=persons,dobj=relatives) specialv_q =\ [phrase.phrase("raccontare/tell",tempus=['present','perfect','future','conditional','imperfect'],
def dictate(): # load loader = Loader.loader() res = loader.load_phrase() if res == -1: print('短语表为空!') exit() zh, en = res test, right = loader.load_record() # generate phrz_lst = [] for i in range(len(zh)): phrz = phrase.phrase(zh[i], en[i], test[i], right[i], i) phrz_lst.append(phrz) random.shuffle(phrz_lst) phrz_lst = sorted(phrz_lst, key=phrase.custom_key, reverse=True) print("输入要测试的词组数量:\033[34m") try: lines = int(input()) while not (lines > 0 and lines < len(zh) + 1): print("\033[37m输入范围内数字!") print("输入要测试的词组数量:\033[34m") lines = int(input()) phrz_lst = phrz_lst[:lines] random.shuffle(phrz_lst) print("\n\033[32m--start--\033[37m") cnt = 0 wrong = [] ans = [] for i in phrz_lst: print("\n\033[0m%s\033[34m" % (i.zh)) answer = input().rstrip() if not i.is_true(answer): cnt += 1 wrong.append(i) ans.append(answer) print("\n\033[32m--end--\033[37m") grade = 100 * (1 - cnt / lines) print("\n\033[37m最终成绩:\033[32m %.2f" % grade) if not len(wrong) == 0: print("\033[31m错误:") for i in range(len(wrong)): print("\033[37m%s\t\033[32m%s" % (wrong[i].zh, wrong[i].en)) print("\033[37mYour answer:\t\033[31m", ans[i]) print('\033[0m') for i in phrz_lst: test[i.id] = i.test right[i.id] = i.right loader.store_record(test, right) except ValueError: print("\033[37m输入数字!") except KeyboardInterrupt: print('\n\033[34mBye~')
if __name__ == "__main__": # initialize weight for running average aWeight = 0.5 # get the reference to the webcam camera = cv2.VideoCapture(camera) # region of interest (ROI) coordinates top, right, bottom, left = 100, 250, 300, 450 # initialize num of frames num_frames = 0 # keep looping, until interrupted sentence = phrase() while (True): # get the current frame (grabbed, frame) = camera.read() # resize the frame frame = cv2.resize(frame, (700, 700)) # flip the frame so that it is not the mirror view viewFrame = cv2.flip(frame, 1) # clone the frame clone = frame.copy() # get the height and width of the frame
f"Welcome {const.PLAYERS[0].name}, {const.PLAYERS[1].name}, {const.PLAYERS[2].name}!" ) return const.PLAYERS def start_game(player_list: list, phrase: str): wheel_img_folder_path = os.path.join(__location__, const.IMG_FOLDER, const.IMG_BASE_NAME) #Call game constructor and pass the phrase for game instance variable ready = game(phrase) #Load up wheel image w = wheel(wheel_img_folder_path) #Shows wheel image and pointer w.start() #Words constructor wor = words(phrase) #Print out blank words wor.start(w) #Call start_wof from game object ready.start_wof(player_list, w, wor) if __name__ == "__main__": #List of players players = start() p = phrase() #Get phrase from phile phrase = p.random(os.path.join(__location__, 'WofFPhrases.txt')) #Go to start game function start_game(players, phrase)
def keywords(self, NE, Gram, Col, Chunk, log): ''' This selects the most likly keyterms from potential candidates passed in. @param NE: list of pos tagged Named Entities @param Gram: list of pos tagged n-grams @param Col: list of pos tagged collocations @param Chunk: list of pos tagged chunks @param log: loglikly hood directory passed @return: selected keywords. ''' self.log = log master = [] fdist = FreqDist() for word in Gram + NE + Col + Chunk: if word: fdist.inc(tuple(word)) for key in fdist.keys(): if fdist[key] > 1: master.append(list(key)) input = filter(None, Gram + NE + Col + Chunk) tmplist = [] phrasearray = [] #Strips phrases which have stop words within them. for grams in input: boolean = False for word in grams: if word[0].lower() in self.stopwords: boolean = True if grams[0][0] == "The": boolean = False #If capital The at end of phrase then remove it form the word. if grams[-1][0] == "The": tmp = [] for tupple in grams[:-1]: tmp.append(tupple) grams = tuple(tmp) if (self.all_same(grams) == True) & (len(grams) > 1): boolean = True if boolean == False: tmplist.append(grams) #parses the list into phrase objects for w in tmplist: phrasearray.append(phrase(w, tmplist, self.log)) #Retrives there intercepts for each word. intercepts = [] for a in phrasearray: b = a.getSet() if b: intercepts.append(list(b)) oneword = [] for w in phrasearray: if w.getNumberCapitals() >= (w.getLength()): oneword.append(w.getPhrase()) ma = self.duplicates(oneword + intercepts) master = self.du(ma) master = self.lookforjoins(master) tmp1 = [] for grams in master: tmp = [] avrage = 0 i = 0 for words in grams: tmp.append(words[0]) try: avrage = avrage + log[words[0].lower()] except: avrage = avrage + 0 i = i + 1 try: avrage = avrage / i except: avrage = 0 tmp.append(avrage) tmp1.append(tmp) tmp3 = self.bubbleSort(tmp1) tmp1 = [] for grams in tmp3: tmp1.append(' '.join(grams[0:-1])) #The number of items which is the x% x = int( round(float(float(float(len(tmp1)) / float(100)) * self.percentil))) return tmp1[-x:]
def keywords(self, NE, Gram, Col, Chunk, log): ''' This selects the most likly keyterms from potential candidates passed in. @param NE: list of pos tagged Named Entities @param Gram: list of pos tagged n-grams @param Col: list of pos tagged collocations @param Chunk: list of pos tagged chunks @param log: loglikly hood directory passed @return: selected keywords. ''' self.log = log master = [] fdist = FreqDist() for word in Gram + NE + Col + Chunk: if word: fdist.inc(tuple(word)) for key in fdist.keys(): if fdist[key] > 1: master.append(list(key)) input = filter(None, Gram + NE + Col + Chunk) tmplist = [] phrasearray = [] #Strips phrases which have stop words within them. for grams in input: boolean = False for word in grams: if word[0].lower() in self.stopwords: boolean = True if grams[0][0] == "The": boolean = False #If capital The at end of phrase then remove it form the word. if grams[-1][0] == "The": tmp = [] for tupple in grams[:-1]: tmp.append(tupple) grams = tuple(tmp) if (self.all_same(grams) == True) & (len(grams) > 1): boolean = True if boolean == False: tmplist.append(grams) #parses the list into phrase objects for w in tmplist: phrasearray.append(phrase(w, tmplist, self.log)) #Retrives there intercepts for each word. intercepts = [] for a in phrasearray: b = a.getSet() if b: intercepts.append(list(b)) oneword = [] for w in phrasearray: if w.getNumberCapitals() >= (w.getLength()): oneword.append(w.getPhrase()) ma = self.duplicates(oneword + intercepts) master = self.du(ma) master = self.lookforjoins(master) tmp1 = [] for grams in master: tmp = [] avrage = 0 i = 0 for words in grams: tmp.append(words[0]) try: avrage = avrage + log[words[0].lower()] except: avrage = avrage + 0 i = i + 1 try: avrage = avrage / i except: avrage = 0 tmp.append(avrage) tmp1.append(tmp) tmp3 = self.bubbleSort(tmp1) tmp1 = [] for grams in tmp3: tmp1.append(' '.join(grams[0:-1])) #The number of items which is the x% x = int(round(float(float(float(len(tmp1))/float(100))*self.percentil))) return tmp1[-x:]