def main(): db = MongoClient().poky inverse_table = InverseTable() parser = Parser("Stopword.txt") for document in db.documents.find({"text": {"$exists": True}}): for textlist in document[u'text'].values(): for text in textlist: DRL = DocumentReverseList(parser.getIndexToken(text), document[u'_id']) inverse_table.merge(DRL) inverse_table.CalNormalizingPara() # inverse_table.printRT() for key in inverse_table.table: term = {} term['word'] = key term['df'] = inverse_table.table[key]['df'] term['idf'] = inverse_table.table[key]['idf'] term['posting'] = [{'doc_id': id, 'tf': inverse_table.table[key]['posting'][id] } for id in inverse_table.table[key]['posting']] db.terms.save(term) for key in inverse_table.Normalization: document = db.documents.find_one({"_id": key}) document["normalization"] = inverse_table.Normalization[key] db.documents.save(document)
def main(): db = MongoClient().poky inverse_table = InverseTable() parser = Parser("Stopword.txt") for document in db.documents.find({"text": {"$exists": True}}): for textlist in document[u'text'].values(): for text in textlist: DRL = DocumentReverseList(parser.getIndexToken(text), document[u'_id']) inverse_table.merge(DRL) inverse_table.CalNormalizingPara() # inverse_table.printRT() for key in inverse_table.table: term = {} term['word'] = key term['df'] = inverse_table.table[key]['df'] term['idf'] = inverse_table.table[key]['idf'] term['posting'] = [{ 'doc_id': id, 'tf': inverse_table.table[key]['posting'][id] } for id in inverse_table.table[key]['posting']] db.terms.save(term) for key in inverse_table.Normalization: document = db.documents.find_one({"_id": key}) document["normalization"] = inverse_table.Normalization[key] db.documents.save(document)
class QueryAnalysis(object): def __init__(self): self.parser = Parser( os.path.join(os.path.dirname(__file__), "Stopword.txt")) def analysis(self, Query): return self.parser.getIndexToken(Query)
class QueryAnalysis(object): def __init__(self): self.parser = Parser(os.path.join(os.path.dirname(__file__), "Stopword.txt")) def analysis(self, Query): return self.parser.getIndexToken(Query)
def __init__(self): self.parser = Parser(os.path.join(os.path.dirname(__file__), "Stopword.txt"))
def solve(): method = app.getOptionBox("Method") if (method == None): app.errorBox("Invalid Method", "You must specify the method") else: global data params = app.getAllEntries() print(params) # debugging if checkParameters(method, params): parser = Parser() if (parser.set_func(params["f(x)="])): func = parser.f() first_guess = params["First Initial Guess"] second_guess = params["Second Initial Guess"] max_iterations = params["Max Iterations"] epsilon = params["Epsilon"] print(func) #debugging if (method == "All Roots"): ga = General_Algorithm() data = [] data.append(ga.findAllRoots(func)) showAllRoots() else: try: is_root_exist = True if (method == "Bisection"): call_func = Bisection_method.BracketingMethod( func, second_guess, first_guess, max_iterations, epsilon) is_root_exist = call_func.verify_there_is_a_root() print(is_root_exist) # debugging if not is_root_exist: app.errorBox( "Root Does not exist", "Ther is no root in this interval") elif (method == "False Position"): call_func = False_position_method.FalsePosition( func, second_guess, first_guess, max_iterations, epsilon) is_root_exist = call_func.verify_there_is_a_root() print(is_root_exist) # debugging if not is_root_exist: app.errorBox( "Root Does not exist", "Ther is no root in these interval") elif (method == "Fixed Point"): call_func = Fixed_point_iteration_method.FixedPointIteration( func, first_guess, max_iterations, epsilon) elif (method == "Newton-Raphson"): call_func = Newton_raphson_method.NewtonRaphson( func, first_guess, max_iterations, epsilon) elif (method == "Secant"): call_func = Secant_method.Secant( func, second_guess, first_guess, max_iterations, epsilon) elif (method == "Bierge Vieta"): call_func = Brige_vieta_method.BrigeVeta( func, first_guess, parser.poly_coeffs(), max_iterations, epsilon) if is_root_exist: data, root, done = call_func.compute_root() if not done: app.errorBox( "Error arise", "Unfortunately, an error arises while computing the root" ) else: print(root) #debugging app.setLabel( "root", "root of f(x) = " + str(func) + " is " + str(root)) if call_func.is_root(): app.setLabel("convergence", "converged") app.setLabelBg("convergence", "green") app.setLabelFg("convergence", "white") else: app.setLabel("convergence", "diverged") app.setLabelBg("convergence", "red") app.setLabelFg("convergence", "white") current_mode = app.getTabbedFrameSelectedTab( "TabbedFrame") showPlot(current_mode, call_func.get_x_y()) if (current_mode == "Fast Mode"): show_fast_mode_table() elif (current_mode == "Single Step Mode"): show_single_step_mode_table() except PolynomialError: app.errorBox( "Polynomial Error", "multivariate polynomials are not supported") else: app.errorBox("Invalid Function", "f(x)=" + parser.func + " is an invalid function")
def eval_act(me, tree): '''Returns an action suitable for performing (PerformableAction)''' act_typ = tree[0] if act_typ in (ACT['attack'], ACT['defend'], ACT['signal']): return PerformableAction(act_typ, tree[1]) elif act_typ in (ACT['use'], ACT['take'], ACT['wait'], ACT['flee'], ACT['mate']): return PerformableAction(act_typ, None) elif act_typ == ACT['subcondition']: return evaluate(me, tree[1]) else: raise InvalidInstructionError("Didn't understand action: {0}"\ .format(act_typ)) if __name__ == '__main__': from Parsing import Parser, TooMuchThinkingError from Creatures import Creature last_action = PerformableAction(ACT['wait'], None) for _ in xrange(1000): a = Creature() b = Creature() a.target = b a.last_action = last_action try: p = Parser(a.dna) last_action = evaluate(a, next(p).tree) str(last_action) except TooMuchThinkingError: continue
def __init__(self): self.parser = Parser( os.path.join(os.path.dirname(__file__), "Stopword.txt"))