def fit(self, lines): # Split lines to sentences sentences = split_lines(lines) # Fit model w2vModel = Word2Vec(sentences, size=self.size, window=self.window, \ min_count=self.min_count, workers=self.workers) self.word_vectors = w2vModel.wv
def edit_bmml(bmml): print() print("Regarding \"%s\"" % bmml.path) print(utils.split_lines("What should its name be? This is the name" " used to reference back-links," " so it should be an identifier")) name = utils.prompt_user("Enter name", checks=[utils.checks.identifier]) print() print(utils.split_lines("Now, under what URL path should serve this" " page? This goes straight to Django's urls file so this" " should be a regex")) regex = utils.prompt_user("Enter URL regex", checks=[utils.checks.not_empty]) bmml.data['name'] = name bmml.data['regex'] = regex print(utils.split_lines("So file %s is going to serve on \"%s\" and have reference name %s" % (bmml.path, regex, name))) print("Got it, moving on...")
def fit(self, lines): # Tfidf self.tfidf_vectorizer = TfidfVectorizer() self.tfidf_vectorizer.fit(lines) # Split lines to sentences sentences = split_lines(lines) # Word2vec w2vModel = Word2Vec(sentences, size=self.size, window=self.window, \ min_count=self.min_count, workers=self.workers) self.word_vectors = w2vModel.wv
async def send_msg(self, source, target, message): messages = split_lines(message) tgt = target.lower() if target else '' is_chan = tgt in self.irc_channels.keys() # source None (False): it's self Telegram user, see [1] source_mask = source.get_irc_mask() if source else '' for msg in messages: if is_chan: irc_users = (u for u in self.users.values() if u.stream and u.irc_nick in self.irc_channels[tgt]) else: irc_users = (u for u in self.users.values() if u.stream) for irc_user in irc_users: await self.send_privmsg(irc_user, source_mask, target, msg)
def edit_bmml(bmml): import pdb;pdb.set_trace() print() print("Regarding \"%s\"'s method types..." % bmml.path) cur = bmml.data['method_types'] if 'method_types' in bmml.data else ["GET"] if 'method_types' in bmml.data: print(" (current method types: %s)" % cur) get = utils.prompt_yn("Should GET be a method type?", "GET" in cur) post = utils.prompt_yn("Should POST be a method type?", "POST" in cur) put = utils.prompt_yn("Should PUT be a method type?", "PUT" in cur) delete = utils.prompt_yn("Should DELETE be a method type?", "DELETE" in cur) mtypes = [] if get: mtypes.append("GET") if post: mtypes.append("POST") if put: mtypes.append("PUT") if delete: mtypes.append("DELETE") print() print("Regarding \"%s\"'s return types..." % bmml.path) cur = bmml.data['return_types'] if 'return_types' in bmml.data else ["HTML"] if 'return_types' in bmml.data: print(" (current return types: %s)" % cur) html = utils.prompt_yn("Should HTML be a return type?", "HTML" in cur) json = utils.prompt_yn("Should JSON be a return type?", "JSON" in cur) xml = utils.prompt_yn("Should XML be a return type?", "XML" in cur) rtypes = [] if html: rtypes.append("HTML") if json: rtypes.append("JSON") if xml: rtypes.append("XML") bmml.data['method_types'] = mtypes bmml.data['return_types'] = rtypes print(utils.split_lines("So file %s is going to serve these method types: %s and have these return types: %s" % (bmml.path, mtypes, rtypes))) print("Got it, moving on...")
def transform(self, lines): result = [] # Split lines to sentences sentences = split_lines(lines) for s in sentences: vec = np.zeros(self.size) count = 0 for token in s: try: vec += self.word_vectors[token] count += 1 except KeyError: continue if count != 0: vec = vec / count result.append(vec) return np.array(result)
def transform(self, lines): result = [] # Split lines to sentences sentences = split_lines(lines) tfidf_vocab = self.tfidf_vectorizer.vocabulary_ tfidf_matrix = self.tfidf_vectorizer.transform(lines) for i in range(len(sentences)): vec = np.zeros(self.size) count = 0 for token in sentences[i]: try: vec += self.word_vectors[token] * tfidf_matrix[i, tfidf_vocab[token]] count += 1 except KeyError: continue if count != 0: vec = vec / count result.append(vec) return np.array(result)
def exists_base(self, param, name, _type): FLAG = 'noprogram' param.cmd = "if [ ! -%s %s ]; then echo '%s'; fi" % (_type, name, FLAG) res = self.run(param) l = utils.split_lines(res) return len(l) != 1 or l[0] != FLAG
def list(self, param): res = self._list(param) return utils.split_lines(res)