def search_line(line, search, searchtype): if searchtype == 're': return re.search(search, line) #, re.IGNORECASE) elif searchtype == 'pos': return Search.search_out(line, search) elif searchtype == 'hyper': return Search.hypernym_search(line, search)
def create_description(self): pat = 'VB|VBD|VBZ|VBG * NN IN * NN' #pat = 'PRP * VB|VBD|VBZ|VBG * NN' phrases = search.search_out(self.source_text, pat) conjugated_phrases = [] for phrase in phrases: words = [] for word, pos in tag(phrase): if pos in ["VBZ", "VBD", "VB", "VBG"]: words.append(conjugate(word, "3sg")) #elif pos == "NN" and random.random() < .1: #words.append(self.define_word(word)) else: words.append(word) conjugated_phrases.append(' '.join(words)) artifacts = list(self.artifacts) sentence_prefixes = ["The present invention", "The device", "The invention"] paragraph_prefixes = ["The present invention", "According to a beneficial embodiment, the invention", "According to another embodiment, the device", "According to a preferred embodiment, the invention", "In accordance with an alternative specific embodiment, the present invention"] i = 0 self.description = '' for phrase in conjugated_phrases: line = "" if i == 0: line = paragraph_prefixes[0] + " " + phrase else: if random.random() < .1: line = "\n\n" + random.choice(paragraph_prefixes) + " " + phrase else: line = random.choice(sentence_prefixes) + " " + phrase self.description += line + ". " i += 1
def create_illustrations(self): self.illustrations = [] templates = ["Figure {0} illustrates {1}.", "Figure {0} is a schematic drawing of {1}.", "Figure {0} is a perspective view of {1}.", "Figure {0} is an isometric view of {1}.", "Figure {0} schematically illustrates {1}.", "Figure {0} is a block diagram of {1}.", "Figure {0} is a cross section of {1}.", "Figure {0} is a diagrammatical view of {1}."] illustrations = list(set(search.search_out(self.source_text, 'DT JJ NP IN * NN'))) self.unformatted_illustrations = illustrations for i in range(len(illustrations)): self.illustrations.append(random.choice(templates).format(i+1, illustrations[i]))
def create_gerund_title(self, text): search_patterns = [ 'VBG DT NN RB', 'VBG NNP * NP', 'VBG NNP * .', 'RB VBG NNP', 'VBG JJ NP', 'VBG * JJ * NP', 'VBG * JJ *', 'VBG * NN', 'VBG * JJ *? NP NP?', 'VBG * JJ? NP'] gerund_phrases = search.search_out(text, search_patterns[-1]) self.possible_titles = [] for title in gerund_phrases: self.possible_titles.append(title) self.partial_title = random.choice(self.possible_titles) title = self.prefix() + self.partial_title self.set_keywords(self.partial_title) return title.capitalize()
def create_gerund_title(self, text): search_patterns = [ 'VBG DT NN RB', 'VBG NNP * NP', 'VBG NNP * .', 'RB VBG NNP', 'VBG JJ NP', 'VBG * JJ * NP', 'VBG * JJ *', 'VBG * NN', 'VBG * JJ *? NP NP?', 'VBG * JJ? NP' ] gerund_phrases = search.search_out(text, search_patterns[-1]) self.possible_titles = [] for title in gerund_phrases: self.possible_titles.append(title) self.partial_title = random.choice(self.possible_titles) title = self.prefix() + self.partial_title self.set_keywords(self.partial_title) return title.capitalize()
def create_illustrations(self): self.illustrations = [] templates = [ "Figure {0} illustrates {1}.", "Figure {0} is a schematic drawing of {1}.", "Figure {0} is a perspective view of {1}.", "Figure {0} is an isometric view of {1}.", "Figure {0} schematically illustrates {1}.", "Figure {0} is a block diagram of {1}.", "Figure {0} is a cross section of {1}.", "Figure {0} is a diagrammatical view of {1}." ] illustrations = list( set(search.search_out(self.source_text, 'DT JJ NP IN * NN'))) self.unformatted_illustrations = illustrations for i in range(len(illustrations)): self.illustrations.append( random.choice(templates).format(i + 1, illustrations[i]))
def create_description(self): pat = 'VB|VBD|VBZ|VBG * NN IN * NN' #pat = 'PRP * VB|VBD|VBZ|VBG * NN' phrases = search.search_out(self.source_text, pat) conjugated_phrases = [] for phrase in phrases: words = [] for word, pos in tag(phrase): if pos in ["VBZ", "VBD", "VB", "VBG"]: words.append(conjugate(word, "3sg")) #elif pos == "NN" and random.random() < .1: #words.append(self.define_word(word)) else: words.append(word) conjugated_phrases.append(' '.join(words)) artifacts = list(self.artifacts) sentence_prefixes = [ "The present invention", "The device", "The invention" ] paragraph_prefixes = [ "The present invention", "According to a beneficial embodiment, the invention", "According to another embodiment, the device", "According to a preferred embodiment, the invention", "In accordance with an alternative specific embodiment, the present invention" ] i = 0 self.description = '' for phrase in conjugated_phrases: line = "" if i == 0: line = paragraph_prefixes[0] + " " + phrase else: if random.random() < .1: line = "\n\n" + random.choice( paragraph_prefixes) + " " + phrase else: line = random.choice(sentence_prefixes) + " " + phrase self.description += line + ". " i += 1
def find_lines(self): lines = search.search_out(self.source_text, "|".join(self.nouns + self.verbs + self.adjectives)) print lines
def find_lines(self): lines = search.search_out( self.source_text, '|'.join(self.nouns + self.verbs + self.adjectives)) print lines