def threeaction(topic,noun,w2v,lock=nones): useLock = True #if lock[4] is not None: # noun = lock[4] #else: # noun = nv.makeNoun(topic) # if noun is None: # print "ABORT! NO NOUN FOR:",topic # exit() # useLock = False if lock[5] is not None and useLock: verb = conjugate(lock[5],INFINITIVE) + '_VB' else: verbs = nv.makeVerb(topic,[noun],1,w2v,False) #how to decide jux? if not verbs: print "NO VERB FOR:",noun return None verb = verbs[0] useLock = False # print "VERB:",verb bgs = ['', '', ''] for i in range(3): if lock[i] is not None and useLock: bgs[i] = lock[i] else: b = p.get_bg(topic,[verb, noun+'_NN'],w2v) # add tag for w2v if b is None: print "NO BG WORDS FOR:",noun,verb return None bgs[i] = b art = h.firstCharUp(article(noun.lower(), function=random.choice([INDEFINITE,DEFINITE]))) return ". ".join([h.firstCharUp(x) for x in bgs])+". "+art+" "+noun+" "+h.toPresent(h.strip_tag(verb))+"."
def make_description(self, results): noun_to_use = '' adjective_to_use = '' nouns, adjectives = self.nouns_and_adjectives(results) if len(nouns) >= 1: noun_to_use = ''.join(sample(nouns, 1)) else: return "blank" if len(adjectives) >= 1: adjective_to_use = ''.join(sample(adjectives, 1)) return article( adjective_to_use) + ' ' + adjective_to_use + ' ' + noun_to_use else: return article(noun_to_use) + ' ' + noun_to_use
def handle_recognize_intent(self, message): self.speak_dialog("general.eye") object_name = message.data.get("ObjName") self.take_picture() results = self.general_model_results() nouns, adjectives = self.nouns_and_adjectives(results) if adjectives: adjective_to_use = ''.join(sample(adjectives, 1)) if object_name in nouns: yes_str = "Yes I see " + article(object_name) + " " + object_name self.speak(yes_str) else: speak_str = "no I don't see " + article( object_name) + " " + object_name noun_to_use = ''.join(sample(nouns, 1)) speak_str = speak_str + " but I do see " + article( noun_to_use) + " " + noun_to_use self.speak(speak_str)
def fixaan(l): for i in range(len(l)): if l[i] == 'a' or l[i] == 'an': newa = article(l[i + 1]) if newa == 'an': print l, i elif newa == 'a' and newa != l[i]: print l, i l[i] = newa
def test_indefinite_article(self): # Assert "a" or "an". for article, word in (("an", "hour"), ("an", "FBI"), ("a", "bear"), ("a", "one-liner"), ("a", "European"), ("a", "university"), ("a", "uterus"), ("an", "owl"), ("an", "yclept"), ("a", "year")): self.assertEqual(en.inflect.indefinite_article(word), article) self.assertEqual(en.article("heir", function=en.INDEFINITE), "an") self.assertEqual(en.referenced("ewe"), "a ewe") print "pattern.en.article()"
def article_corrector(self, structure: list) -> None: """ Goes through the poem and changed any indefinite articles that are incorrect. For example, if the phrase 'a elephant' is present, this function changes it to 'an elephant'. Args: structure (list): the structure of the poem in the form of a list. ex) ['ARTICLE', 'NOUN', 'VERB'] """ assert len(self.poem) == len(structure) for i in range(len(structure)): part_of_speech = structure[i] if part_of_speech == 'ARTICLE': if self.poem[i].lower() == 'a': if self.inflect.singular_noun(self.poem[i + 1]) != False: self.poem[i] = 'the' else: self.poem[i] = en.article(self.poem[i + 1])
def test_indefinite_article(self): # Assert "a" or "an". for article, word in ( ("an", "hour"), ("an", "FBI"), ("a", "bear"), ("a", "one-liner"), ("a", "European"), ("a", "university"), ("a", "uterus"), ("an", "owl"), ("an", "yclept"), ("a", "year")): self.assertEqual(en.article(word, function=en.INDEFINITE), article) self.assertEqual(en.inflect.article("heir", function=en.DEFINITE), "the") self.assertEqual(en.inflect.referenced("ewe"), "a ewe") print "pattern.en.inflect.article()"
def gen(fraw, w2v, lock, w2vmax=30, w2vmin=10, verbgen=False): #traverse tree; if parent locked, regen all children (set a force flag) root = fraw['root'] if lock[root['index']] is None: new_root = genRoot(root, w2v) if not new_root: return None lock[root['index']] = new_root genrec(root, None, None, False, w2v, lock, w2vmax, w2vmin, verbgen) #lock is out var if None in lock: return None for i in range(len(lock)): if i + 1 < len(lock) and (lock[i] == 'a' or lock[i] == 'an'): lock[i] = article(lock[i + 1]) for i in fraw['cap']: lock[i] = h.firstCharUp(lock[i]) return plugin(fraw['plug'], lock), fraw
def indefify(span): # find that article (will raise IndexError, watch out) det = [t for t in span.root.children \ if t.dep_ == 'det' and t.lower_ in ('the', 'this', 'these')][0] # flatten to string replacing article following = span.doc[det.i+1] if span.root.tag_ == 'NNS': det_s = 'some' else: det_s = article(following.lower_) output = list() for t in span.subtree: if t.dep_ == 'predet': continue if t.i == det.i: output.append(det_s) else: output.append(t.orth_) return " ".join(output)
def indefify(span): # find that article (will raise IndexError, watch out) det = [t for t in span.root.children \ if t.dep_ == 'det' and t.lower_ in ('the', 'this', 'these')][0] # flatten to string replacing article following = span.doc[det.i + 1] if span.root.tag_ == 'NNS': det_s = 'some' else: det_s = article(following.lower_) output = list() for t in span.subtree: if t.dep_ == 'predet': continue if t.i == det.i: output.append(det_s) else: output.append(t.orth_) return " ".join(output)
from pattern.en import article, referenced from pattern.en import pluralize, singularize from pattern.en import comparative, superlative from pattern.en import conjugate, lemma, lexeme, tenses from pattern.en import NOUN, VERB, ADJECTIVE # The en module has a range of tools for word inflection: # guessing the indefinite article of a word (a/an?), # pluralization and singularization, comparative and superlative # adjectives, verb conjugation. # INDEFINITE ARTICLE # ------------------ # The article() function returns the indefinite article (a/an) for a given noun. # The definitive article is always "the". The plural indefinite is "some". print(article("bear"), "bear") print() # The referenced() function returns a string with article() prepended to the given word. # The referenced() funtion is non-trivial, as demonstrated with the # exception words below: for word in ["hour", "one-liner", "European", "university", "owl", "yclept", "year"]: print(referenced(word)) print() print() # PLURALIZATION # ------------- # The pluralize() function returns the plural form of a singular noun (or adjective). # The algorithm is robust and handles about 98% of exceptions correctly: for word in ["part-of-speech", "child", "dog's", "wolf", "bear", "kitchen knife"]:
from pattern.en import article, referenced from pattern.en import pluralize, singularize from pattern.en import comparative, superlative from pattern.en import conjugate, lemma, lexeme, tenses from pattern.en import NOUN, VERB, ADJECTIVE # The en module has a range of tools for word inflection: # guessing the indefinite article of a word (a/an?), # pluralization and singularization, comparative and superlative adjectives, verb conjugation. # INDEFINITE ARTICLE # ------------------ # The article() function returns the indefinite article (a/an) for a given noun. # The definitive article is always "the". The plural indefinite is "some". print article("bear"), "bear" print # The referenced() function returns a string with article() prepended to the given word. # The referenced() funtion is non-trivial, as demonstrated with the exception words below: for word in [ "hour", "one-liner", "European", "university", "owl", "yclept", "year" ]: print referenced(word) print print # PLURALIZATION # ------------- # The pluralize() function returns the plural form of a singular noun (or adjective). # The algorithm is robust and handles about 98% of exceptions correctly:
from pattern.en import article, referenced from pattern.en import pluralize, singularize from pattern.en import comparative, superlative from pattern.en import conjugate, lemma, lexeme, tenses from pattern.en import NOUN, VERB, ADJECTIVE # The en module has a range of tools for word inflection: # guessing the indefinite article of a word (a/an?), # pluralization and singularization, comparative and superlative adjectives, verb conjugation. # INDEFINITE ARTICLE # ------------------ # The article() function returns the indefinite article (a/an) for a given noun. # The definitive article is always "the". The plural indefinite is "some". print(article("bear") + " bear") print("") # The referenced() function returns a string with article() prepended to the given word. # The referenced() funtion is non-trivial, as demonstrated with the exception words below: for word in ["hour", "one-liner", "European", "university", "owl", "yclept", "year"]: print(referenced(word)) print("") # PLURALIZATION # ------------- # The pluralize() function returns the plural form of a singular noun (or adjective). # The algorithm is robust and handles about 98% of exceptions correctly: for word in ["part-of-speech", "child", "dog's", "wolf", "bear", "kitchen knife"]: print(pluralize(word)) print(pluralize("octopus", classical=True))
from pattern.en import referenced, article from pattern.en import pluralize, singularize from pattern.en import conjugate, lemma, lexeme, tenses, PAST, PL from pattern.en import quantify from pattern.en import ngrams from pattern.en import parse, tag, pprint from pattern.en import sentiment, polarity, subjectivity, modality from pattern.en import Sentence #Indefinite article print article('university') print article('hour') print referenced('university') print referenced('hour') #singularity print pluralize('child') print singularize('wolves') # print print lexeme('run') print lemma('running') print conjugate('purred', '3sg') print PAST in tenses('purred') # 'p' in tenses() also works. print (PAST, 1, PL) in tenses('purred') print 'Quantification'
from pattern.en import article, referenced from pattern.en import pluralize, singularize from pattern.en import comparative, superlative from pattern.en import conjugate, lemma, lexeme, tenses from pattern.en import NOUN, VERB, ADJECTIVE # The en module has a range of tools for word inflection: # guessing the indefinite article of a word (a/an?), # pluralization and singularization, comparative and superlative adjectives, verb conjugation. # INDEFINITE ARTICLE # ------------------ # The article() command returns the indefinite article (a/an) for a given noun. # The definitive article is always "the". The plural indefinite is "some". print article("bear"), "bear" print # The referenced() command returns a string with article() prepended to the given word. # The referenced() command is non-trivial, as demonstrated with the exception words below: for word in ["hour", "one-liner", "European", "university", "owl", "yclept", "year"]: print referenced(word) print print # PLURALIZATION # ------------- # The pluralize() command returns the plural form of a singular noun (or adjective). # The algorithm is robust and handles about 98% of exceptions correctly: for word in ["part-of-speech", "child", "dog's", "wolf", "bear", "kitchen knife"]: print pluralize(word)
from pattern.en import article, referenced from pattern.en import pluralize, singularize from pattern.en import comparative, superlative from pattern.en import conjugate, lemma, lexeme, tenses from pattern.en import NOUN, VERB, ADJECTIVE # The en module has a range of tools for word inflection: # guessing the indefinite article of a word (a/an?), # pluralization and singularization, comparative and superlative adjectives, verb conjugation. # INDEFINITE ARTICLE # ------------------ # The article() function returns the indefinite article (a/an) for a given noun. # The definitive article is always "the". The plural indefinite is "some". print(article("bear"), "bear") print() # The referenced() function returns a string with article() prepended to the given word. # The referenced() funtion is non-trivial, as demonstrated with the exception words below: for word in ["hour", "one-liner", "European", "university", "owl", "yclept", "year"]: print(referenced(word)) print() print() # PLURALIZATION # ------------- # The pluralize() function returns the plural form of a singular noun (or adjective). # The algorithm is robust and handles about 98% of exceptions correctly: for word in ["part-of-speech", "child", "dog's", "wolf", "bear", "kitchen knife"]: print(pluralize(word))
from pattern.en import referenced, article from pattern.en import pluralize, singularize from pattern.en import conjugate, lemma, lexeme, tenses, PAST, PL from pattern.en import quantify from pattern.en import ngrams from pattern.en import parse, tag, pprint from pattern.en import sentiment, polarity, subjectivity, modality from pattern.en import Sentence #Indefinite article print article('university') print article('hour') print referenced('university') print referenced('hour') #singularity print pluralize('child') print singularize('wolves') # print print lexeme('run') print lemma('running') print conjugate('purred', '3sg') print PAST in tenses('purred') # 'p' in tenses() also works. print(PAST, 1, PL) in tenses('purred') print 'Quantification' print quantify(['goose', 'goose', 'duck', 'chicken', 'chicken', 'chicken'])