def search(self, **kwargs): words = [] nums = [] if "quicksearch" in kwargs: for word in kwargs["search"].split(): if abcre.match(word).end() != len(word): words.append(word) else: notes = process.parse(word)[0] nums += notes # for now, we discard words and search for nums elif "search" in kwargs: nums = process.parse(kwargs["abc"])[0] else: return lookup.get_template('search.mako').render(title="Search Moogle") if len(nums) < 5: return lookup.get_template('error.mako').render(title="Error", text= """You must search for a melody at least 5 notes long, and preferably a fair bit longer.""") results = [] for x in process.search(nums).split()[:10]: i, score = x.split(":")[:2] tune = process.single_tune(i) results.append((tune, score)) return lookup.get_template('results.mako').render(title="Results from Moogle", results = results)
def test_parse(self): country_level = 2 state_level = 4 admin_levels = [country_level, state_level] country_id = 192830 process.parse(self.fixture_dir, self.parse_output_dir, admin_levels, self.tolerance, country_id) output_files = os.listdir(self.parse_output_dir) assert len(output_files) == (len(admin_levels) * 2) assert "admin_level_0_simplified.json" in output_files assert "admin_level_1_simplified.json" in output_files assert "admin_level_1.json" in output_files assert "admin_level_0.json" in output_files
def test_parse(self): country_level = 2 state_level = 4 admin_levels = [country_level, state_level] country_id = 192830 process.parse(self.fixture_dir, self.parse_output_dir, admin_levels, self.tolerance, country_id) output_files = os.listdir(self.parse_output_dir) assert len(output_files) == (len(admin_levels) * 2) assert 'admin_level_0_simplified.json' in output_files assert 'admin_level_1_simplified.json' in output_files assert 'admin_level_1.json' in output_files assert 'admin_level_0.json' in output_files
def dataset_process(index, ask=0): data = parse(__paths[0]) rs1 = {} qs = {} la = {} j = 0 for i in data: rs1[j] = i['answer'] qs[j] = i['question'] la[j] = 'en' j += 1 if j >= 500: break Answers = process_set(rs1, la) Questions = process_set(qs, la) #store data for backup with open('Answers', 'w') as r: for l in Answers['documents']: r.write(str(l) + '\n') with open('Questions', 'w') as w: for l in Questions['documents']: w.write(str(l) + '\n')
def parse_question(question): query = "" if question == "": return "" query, question_type = process.parse(question) if query is None: return None print("Query is: ", query) print("Question is: ", question_type) return list(db.engine.execute(query)), question_type
import process from sseclient import SSEClient if __name__=="__main__": messages=SSEClient('https://api.particle.io/v1/devices/events?access_token=6a61e063f79781dddcc39729e77ed76696f23bfc') a=process.parse(messages.__iter__()) for item in a: print item
import process, sys, socket def search(nums): sock = socket.create_connection(('localhost', 16180)) sock.recv(16) #cmd> sock.sendall('search\n') sock.recv(16) #notes> sock.sendall(' '.join([str(num) for num in nums]) + '\n') resp = [] tmp = None while True: tmp = sock.recv(4096) if tmp.endswith('\ncmd>'): tmp = tmp[:-6] resp.append(tmp) break else: resp.append(tmp) sock.sendall('bye\n') sock.close() return ''.join(resp) if __name__ == "__main__": abc = sys.argv[1] (notes, chords, meta, _, __) = process.parse(abc) print search(notes)
import tokenize import process if __name__ == '__main__': while True: input_str = input() if input_str in ["exit", "exit()", "quit", "quit()"]: break tokens = tokenize.tokenize(input_str) rpn = process.parse(tokens) print(">>", process.calculate(rpn))