def file_modified(event): """ react to file events """ if re.match(config.file_regex,event.name) or (event.name in config.sources.keys()): print "Change detected to: %s" % (event.name) config.stack = [] script = config.sources[event.name] if script.extension == config.source_ext: parse.parse_file(script) else: parse.parse_parents(script)
def main(): platform = sys.platform #print 'Running on a',platform if(len(sys.argv) != 2): sys.stderr.write(str(argv[0]) + " requires two arguments\n") return 1; inputFile = sys.argv[1] inputFilePath = str(sys.argv[1]) if(inputFilePath[-3:] != ".py"): sys.stderr.write(str(argv[0]) + " input file must be of type *.py\n") return 1 outputFilePath = inputFilePath.split('/') outputFileName = (outputFilePath[-1:])[0] outputFileName = outputFileName[:-3] + ".s" #print inputFile #ast = compiler.parseFile(inputFile); if(print_stmts): print 'compile'+inputFilePath ast = parse_file(inputFilePath); if(print_stmts): print ast, '\n\n\n' fast = flatten(ast) #print 'flatten(ast)\n',fast if(print_stmts): print fast assembly = instr_select(fast) if(print_stmts): print assembly write_to_file(map(str, assembly), outputFileName) return 0
def index(): global mainDictionary mainDictionary = parse.parse_file() if request.method == 'POST': return redirect(url_for('/results')) else: return render_template("index.html")
def test_parse_file_two(self): parsed_output = parse.parse_file(testdir+testfiletwo) self.assertTrue(isinstance(parsed_output, list)) self.assertTrue(len(parsed_output) == 2) self.assertTrue(isinstance(parsed_output[0], str)) self.assertTrue(isinstance(parsed_output[1], str)) self.assertTrue(regex.match(parsed_output[0])) self.assertTrue(regex.match(parsed_output[1]))
def organize_data(files): """ sort out data into patterns """ data = [{}, {}, {}, {}] files = sortbyname(files) for f in files: for i, d in enumerate(parse.parse_file(f)): pat = pattern(f) data[i].setdefault(pat, []).append(d) return data
def init_forest(filename: str): """ Init the repl. Args: filename: name of the file to parse Returns: the rules, the expression forest, the values queries """ symbols = reset_symbols() equations, init, queries = parse.parse_file(filename) expr_forest = parse.make_tree(equations, symbols) make_update(True, init, symbols) lst_queries = [ symbols[symbol] for symbol in queries ] return equations, expr_forest, lst_queries, symbols
def group_and_parse_files_by_scenario(dir_path): files = [f for f in listdir(dir_path) if (path.isfile('/'.join([dir_path, f])) and f.endswith('.json'))] scenarios = {} for f in files: # scenario name should be in format: <sceanrio-name>-<count>.json name = f.split('-')[0] count = f.split('-')[1].split('.')[0] content = parse_file('/'.join([dir_path, f])) s_data = add_key_if_need(scenarios, name) for action in content: s_action = add_key_if_need(s_data, action) s_count = add_key_if_need(s_action, count) s_count.update(content[action]) return scenarios
def tagReviews(directory="data/training", output=False): """Generates a list of tagged sentence/sentiment tuples for training our classifier. Only takes lines where there are either 0 features, or all positive or negative features.""" startingDir = os.getcwd() os.chdir(os.path.abspath(directory)) files = glob.glob("*.txt") if output: outputFile = open('../../output.txt', 'w') taggedReviews = [] for filename in files: lineNumber = 0 parsedReviews = parse.parse_file(os.path.abspath(os.path.join(os.curdir, filename))) reviewText = "" for review in parsedReviews: for taggedSentence in review: if len(taggedSentence.features) == 0: taggedReviews.append((taggedSentence.sentence, 0)) else: firstSentiment = taggedSentence.features[0].sign allSame = True for feature in taggedSentence.features: if feature.sign != firstSentiment: allSame = False if allSame: taggedReviews.append((taggedSentence.sentence, firstSentiment)) if output: outputFile.write("%s\t%d\t%d\n" % (filename, lineNumber, firstSentiment)) lineNumber += 1 if output: outputFile.close() print "Output stored for %s" % directory os.chdir(os.path.abspath(startingDir)) return taggedReviews
import datetime import ztmsync import parse import os now = datetime.datetime.now() x= int(now.strftime("%y%m%d")) print x+1 local_dir = '.' if not os.path.exists(local_dir + "/target"): os.makedirs(local_dir + "/target") if not os.path.exists(local_dir + "/sync"): os.makedirs(local_dir + "/sync") if not os.path.exists(local_dir + "/debug"): os.makedirs(local_dir + "/debug") processed_files = ztmsync.sync_files(local_dir) for f in processed_files: print f[:8] parse.parse_file(local_dir, f[:8])
def compile_programs_from_file(file_name): from parse import parse_file return compile_programs(parse_file(file_name))
def compile_sequences_from_file(file_name): """Compile sequences from a file name""" from parse import parse_file return compile_sequences(parse_file(file_name))
def compile(): for key,source in config.sources.iteritems(): if source.extension == config.source_ext: parse.parse_file(source)
def render(self, state): return parse.parse_file(self.value).render(state) # OPTIMIZE THIS
def doStuff(file_name): n_rows, n_cols, n_drones, deadline, max_load, p, products, warehouse_count, warehouses, o, orders = parse_file('data/' + file_name + '.in') drones = [] for _ in range(n_drones): drones.append(Drone(warehouses[0]["cords"][0], warehouses[0]["cords"][1])) turn = 0 while turn < deadline: for drone_i, drone in enumerate(drones): drone.tick(turn) if drone.isIdle(): order = getBestOrder(orders, products, max_load, drone.x, drone.y) if order: order["completed"] = True drone_free = turn for product, count in enumerate(order["products"]): for _, warehouse in enumerate(getOrderedWarehouses(warehouses, drone.x, drone.y)): if warehouse["products"][product] > 0 and count > 0: load_count = min(count, warehouse["products"][product], math.floor(max_load / products[product])) warehouse["products"][product] -= load_count count -= load_count # total_weight = 0 # load_count = 0 # # # while order not fullfilled and drone not maxed out # while count != 0 and total_weight + products[product] <= max_load and warehouse["products"][product] > 0: # warehouse["products"][product] -= 1 # count -= 1 # load_count += 1 # total_weight += products[product] drone_free = drone.to(warehouse["cords"][0], warehouse["cords"][1], drone_free) if (drone_free < deadline): printLoad(drone_i, warehouse["id"], product, load_count) drone_free = drone.to(order["cords"][0], order["cords"][1], drone_free) if (drone_free < deadline): printDeliver(drone_i, order["id"], product, load_count) turn += 1 printToFile(file_name + ".out")
def render_course(course_id): return render("render/CourseFrame.html", course_id=course_id, title="Course " + course_id, len=len(parse_file("courses/" + course_id + ".mgs").pages))
from sklearn.preprocessing import StandardScaler import eval import parse import sys TRAIN = "trainingSet.dat" TRAIN_LABELS = "trainingSetLabels.dat" train_articles = get_articles(TRAIN) train_labels = get_labels(TRAIN_LABELS) train = np.loadtxt("Features/train_perp_wit_uncinc_out") fname = 'perp_wit_uncinc_out' dev_features_perplexity1 = np.array( parse.parse_file(parse.parse_indices_1gram_inclusive, "1gram/dev_" + fname)) dev_features_perplexity2 = np.array( parse.parse_file(parse.parse_indices_2gram_inclusive, "2gram/dev_" + fname)) dev_features_perplexity3 = np.array( parse.parse_file(parse.parse_indices_3gram_inclusive, "3gram/dev_" + fname)) dev_features_perplexity4 = np.array( parse.parse_file(parse.parse_indices_4gram_inclusive, "4gram/dev_" + fname)) dev_features_perplexity5 = np.array( parse.parse_file(parse.parse_indices_5gram_inclusive, "5gram/dev_" + fname)) dev = np.c_[dev_features_perplexity1, dev_features_perplexity2, dev_features_perplexity3, dev_features_perplexity4, dev_features_perplexity5]
return map(lambda t: t[0], definedFns) def definedFnSyms(): return map(lambda t: t[1], definedFns) loadedSentimentDicts = [] taggedSentenceEvaluationFunctions = [('sum', 'util.sentenceSumSentiment'), ('ternary', 'util.sentenceTernarySentiment')] ###### Load tagged reviews #################################################### os.chdir('data/training') files = glob.glob("*.txt") taggedReviews = [] for filename in files: taggedReviews += parse.parse_file(filename) os.chdir(originalDir) ###### Compile/load sentiment dictionaries #################################### staticSentimentDicts = [('afinn96', 'dicts/afinn-96.dict'), ('afinn111', 'dicts/afinn-111.dict'), ('nielsen2009', 'dicts/Nielsen2009Responsible_emotion.dict'), ('nielsen2009', 'dicts/Nielsen2010Responsible_english.dict')] # load static dicts for name, path in staticSentimentDicts: dictSym = "{}SentimentsDict".format(name) exec("{} = util.loadWordSentimentDict(os.path.join(originalDir, '{}'))".format(dictSym, path)) loadedSentimentDicts.append((dictSym, eval(dictSym)))
import parse import sys from model import * from solvability import * from solve import * from generator import createPuzzle import os import argparse try: parser = argparse.ArgumentParser() parser.add_argument("-f", "--file", help="The file to resolve", type=str) args = parser.parse_args() if (args.file is not None): if (os.path.isfile(args.file)): tak = parse.parse_file(args.file) else: sys.stderr.write("File is not valid\n") sys.exit(1) else: tak = createPuzzle(3) model = Model(len(tak)) solvable = Solvability(tak, model.model).solvable if not solvable: print('N-Puzzle is not solvable') exit() except Exception as e: sys.stderr.write(str(e) + '\n') sys.exit() print('👋 Ok, we have a puzzle to solve. What algorithm shall we use ? 💁') print('1. A*')
from parse import get_train from parse import get_test import numpy import math from functions import get_mu from functions import get_sigma from functions import sigma from functions import get_id_matrix from analysis import lda from analysis import qda # extract data from text file iris_data = parse_file('training.txt') # prepare training dataset training = get_train(iris_data) setosa, versicolor, virginica = training[0], training[1], training[2] # prepare testing dataset testing = get_test(iris_data) test_setosa, test_versicolor, test_virginica = testing[0], testing[1], testing[ 2] # set numpy matrix setosa = numpy.array(setosa) versicolor = numpy.array(versicolor) virginica = numpy.array(virginica)
def test_parse_file_one(self): parsed_output = parse.parse_file(testdir+testfileone) self.assertTrue(isinstance(parsed_output, list)) self.assertTrue(len(parsed_output) == 1) self.assertTrue(isinstance(parsed_output[0], str)) self.assertTrue(regex.match(parsed_output[0]))