def fireRules(components, pBatch): """Fire the extra rules ...""" source = components[2] target = components[3] rl = Rules(source, target) if rl.ruleNumbers() == (True, "Number"): return True, "NumberRule", "1" elif rl.ruleNumbers() == (False, "Number"): return True, "NumberRule", "0" if rl.ruleSame(): return True, "SameRule", "1" if rl.ruleNameEntities(): return True, "NameEntitiesRule", "1" if rl.ruleIdenticalLC(components, pBatch): return True, "LanguageRule", "0" if rl.ruleCG(): return True, "ChurchGale", "0" return False, "", ""
def update_state(self, color, init_stone, init_move, aggro_stone,board_history=[]): self.board = [self.region0.stones, self.region1.stones, self.region2.stones, self.region3.stones] legality = Rules.Rules(self.board) updated_board= legality.update_board(color, init_stone, init_move, aggro_stone,board_history=[]) print(updated_board) for region in self.regions: region.set_stones(updated_board[region.region_number])
def fireRules(lineSegment, pDict): """Fire the extra rules ...""" components = lineSegment.split("@#@") source = components[2] target = components[3] booolean, rule, value = fireExtraRules(source, target, pDict) if rule: return booolean, rule, value rl = Rules(source, target) if rl.ruleNumbers() == (True, "Number"): return True, "NumberRule", "1" elif rl.ruleNumbers() == (False, "Number"): return True, "NumberRule", "0" if rl.ruleSame(): return True, "SameRule", "1" if rl.ruleNameEntities(): return True, "NameEntitiesRule", "1" if rl.ruleIdenticalLC(components, pDict): return True, "LanguageRule", "0" if rl.ruleCG(): return True, "ChurchGale", "0" return False, "", ""
def control_players(self): """Executes main control flow for player turns RAISES Exception if one occurs """ try: rules = Rules(self.deck, 0) same_player = True wincondition = False while wincondition == False: for hand in self.hands: same_player = True self._active = self.hands[hand][0] while same_player == True: print("you: %s" % hand) choice = self.choose_hand(hand) self.hands[hand][0].visi_override() if rules.play_game(self.hands[hand][0], self.hands[choice][0]) == False: same_player = False self.hands[hand][1] += rules.points else: self.hands[hand][1] += rules.points same_player = True if self.empty_hands == self.hand_count: wincondition = True except: Error.log_error(sys.exc_info()[1], "Game.control_players()")
def fireRules(lineSegment,pDict): """Fire the extra rules ...""" components=lineSegment.split("@#@") rl=Rules(components[2],components[3]) if rl.ruleNumbers() ==(True,"Number") : return True,"NumberRule","1" elif rl.ruleNumbers() ==(False,"Number") : return True,"NumberRule","0" if rl.ruleSame() : return True, "SameRule","1" if rl.ruleNameEntities() : return True, "NameEntitiesRule","1" if rl.ruleIdenticalLC(components,pDict) : return True,"LanguageRule","0" if rl.ruleCG() : return True,"ChurchGale","0" return False,"",""
def test_expansion(capsys): code = '''def trial357(param_0, param_1): op_lesser = param_0 < param_1 return op_lesser''' test_input = [ "a", "n", "y", "science", "lesser", "function determines the lesser of two objects", "y", "lesser", "name,op_lesser", "vars,2", "code,op_lesser = <var1> < <var2>", "return,return op_lesser", "end", "1,2", "test101", "trial357", "no" ] rules6 = Rules.Rules() exp = Expanding.Expands() def mock_input_6(s): #print(test_input) return test_input.pop(0) Rules.input = mock_input_6 Expanding.input = mock_input_6 out, err = capsys.readouterr() test = Rules.Rules.sentence_break( rules6, "I want a program to determine the lesser of two objects") mp = rules6.mp mp = mp.replace(" ", "") mp = mp.replace("\n", "") #print(mp) large = code.replace(" ", "") large = large.replace("\n", "") #print(large) assert mp == large
def test_function_player_answer_yes(self): rules = Rules() hand = Hand() card = Card(rank=Rank.ACEHIGH, suit=Suit.DIAMONDS) hand += card self.assertEqual(rules.player_answer(Rank.ACEHIGH, hand), "YES", "player answer Not returning YES when it should")
def test_function_book_check_fullbook(self): rules = Rules() hand = Hand() for s in Suit: hand.add_card(Card(rank=Rank.THREE, suit=s)) self.assertEqual(rules.book_check(Rank.THREE, hand), 4, "book check not finding book")
def __loadFireWallRules(self): root = self.__getFireWallRulesRoot() self.rules = [] for child in root.iter('entry'): self.rules.append( Rules( self.__getRuleName(child), self.__getRuleFrom(child), self.__getRuleTo(child), self.__getRuleSource(child), self.__getRuleDestination(child), self.__getRuleService(child), self.__getRuleApplication(child), self.__getRuleAction(child), self.__getRuleSourceUser(child), self.__getRuleDisableServerResponse(child), self.__getRuleNegateSource(child), self.__getRuleNegateDestination(child), self.__getRuleDisabled(child), self.__getRuleGroup(child), self.__getRuleHipProfile(child), self.__getRuleLogStart(child), self.__getRuleLogEnd(child), self.__getRuleDescription(child), ))
def fireRules(components,pBatch): """Fire the extra rules ...""" source=components[2].encode('utf-8') target=components[3].encode('utf-8') #booolean,rule,value=fireExtraRules(source,target,pBatch) #if rule : # return booolean,rule,value rl=Rules(source,target) if rl.ruleNumbers() ==(True,"Number") : return True,"NumberRule","1" elif rl.ruleNumbers() ==(False,"Number") : return True,"NumberRule","0" if rl.ruleSame() : return True, "SameRule","1" if rl.ruleNameEntities() : return True, "NameEntitiesRule","1" if rl.ruleIdenticalLC(components,pBatch) : return True,"LanguageRule","0" if rl.ruleCG() : return True,"ChurchGale","0" return False,"",""
def createFireWallRule(self, name, memFrom, memTo, src, dst, srv, app, act, srcUsr, disRsp, negSrc, negDst, disable, group, hipProf, logStart, logEnd, desc): newRule = Rules(name, memFrom, memTo, src, dst, srv, app, act, srcUsr, disRsp, negSrc, negDst, disable, group, hipProf, logStart, logEnd, desc) self.rules.append(newRule) return newRule
def test_function_check_deck_10pop(self): deck = Deck(ace_rank=Rank.ACELOW) rules = Rules(deck=deck) hand = Hand() for i in range(10): hand += deck.deal() self.assertEqual(rules.check_deck(), 42, "Deck not showing 42 cards after dealing 10")
def test_function_count_request_2(self): rules = Rules() hand = Hand() hand += [ Card(rank=Rank.THREE, suit=Suit.DIAMONDS), Card(rank=Rank.THREE, suit=Suit.SPADES) ] self.assertEqual( rules.count_request(hand, Rank.THREE), 2, "count request not returning 2 for hand with two rank matches")
def delete_data(self, list_fname): """ Delete files from hdfs and insert hdfs path items into postgre """ list_fname = ['test1.txt', 'test2.txt'] ruler = Rules() list_hdfs_paths = ruler.path_rules(list_fname) flag = self.delete_hdfs_index(list_hdfs_paths) if flag is True: print("Delete" + str(list_hdfs_paths) + "from HDFS and Index successful!")
def insert_index(self, dict_pg_info, list_insert=None): ruler = Rules() str_conn = ruler.pg_info_rules(dict_pg_info) try: conn = psycopg2.connect(str_conn) with conn: with conn.cursor() as cur: for i in list_insert: str_order = "INSERT INTO " + dict_pg_info['table'] + "(path) VALUES (%s)", i print(str_order) cur.execute(str_order) conn.commit() except: print("Fail to connect Index System!") return False return True
def test_generation_none(capsys): code = "" test_input_none = ["e"] rules5 = Rules.Rules() def mock_input_9(s): return test_input_none.pop(0) Rules.input = mock_input_9 out, err = capsys.readouterr() test = Rules.Rules.sentence_break(rules5, "") mp = rules5.mp mp = mp.replace(" ", "") mp = mp.replace("\n", "") #print(mp) large = code.replace(" ", "") large = large.replace("\n", "") assert mp == large
def test_call_pro(capsys): code = "3" test_call_input = ["test15,trial16", "1,2"] rules9 = Rules.Rules() def mock_input_8(s): return test_call_input.pop(0) Rules.input = mock_input_8 out, err = capsys.readouterr() test = Rules.Rules.call_pro(rules9) #sentence_break(rules5, "") res = rules9.res res = res.replace(" ", "") res = res.replace("\n", "") #print(mp) large = code.replace(" ", "") large = large.replace("\n", "") assert res == large
def search_index(self, dict_pg_info, list_raw_query=None): """ :return: """ list_hdfs_paths = [] ruler = Rules() list_final_query = ruler.query_rules(list_raw_query) str_conn = ruler.pg_info_rules(dict_pg_info) conn = psycopg2.connect(str_conn) with conn: with conn.cursor() as cur: for i in list_final_query: str_order = "SELECT * FROM " + dict_pg_info['table'] print(str_order) cur.execute(str_order) list_hdfs_paths.append(cur.fetchone()) return list_hdfs_paths
def create_new_index(self, dict_pg_info): """ Connect postgresql and create a table for index. :param tname: table name :return: true - creating is successful ,false - creating is unccessful. """ # ! Setting if fun can use default setting ruler = Rules() str_conn = ruler.pg_info_rules(dict_pg_info) conn = psycopg2.connect(str_conn) with conn: with conn.cursor() as cur: str_create_table = "CREATE TABLE " + dict_pg_info['table'] + " (path varchar PRIMARY KEY);" # ! Check if table already exit cur.execute(str_create_table) cur.close() conn.close()
def main(): urlDoc = URLsReader() rules = Rules() title = urlDoc.getTitle() while (title is not None): html = HTMLReader(title) htmlString = html.getHtml() # Devuelve en un string todas las palabras del documento words = rules.applyRules(htmlString) # Se crea el objeto DocWord que se envia el titulo del archivo y el string de palabras docWordCount = DocWordCounter(html, words) # Separa las palabras y las agrega en un diccionario por cada documento. docWordCount.generateStopWordsDict() docWordCount.separateWords() docWordCount.generateDict() # Obtiene el siguiente Documento de HTML title = urlDoc.getTitle()
def delete_index(self, dict_pg_info): """ Delete index table. :param table: table name :return: true - creating is successful ,false - creating is unccessful. """ ruler = Rules() str_conn = ruler.pg_info_rules(dict_pg_info) try: conn = psycopg2.connect(str_conn) except: print("Unable to connect to the database.") if conn is not None: cur = conn.cursor() str_order = "Delete TABLE " + dict_pg_info['table'] + ";" # ! Check if table already exit cur.execute(str_order) cur.close() else: print("Fail to open database, please complete correct information.") conn.close()
def test_generation_small(capsys): short = '''def trial6(param_0, param_1): op_add = param_0 + param_1 return op_add''' rules = Rules.Rules() input_values = ["1,2", "Test749", "trial6", "No"] def mock_input(s): return input_values.pop(0) Rules.input = mock_input out, err = capsys.readouterr() test = Rules.Rules.sentence_break(rules, "I want a program to add two numbers") print("MP ", rules.mp) mp = rules.mp mp = mp.replace(" ", "") mp = mp.replace("\n", "") short = short.replace(" ", "") short = short.replace("\n", "") print(mp == short) assert mp == short
def test_generation_large(capsys): large = '''def trial9(param_0, param_1, param_3): op_add = param_0 + param_1 hold1 = op_add op_mul = hold1 * param_3 return op_mul def trial89(param_0, param_1, param_3): op_sub = param_0 - param_1 hold1 = op_sub op_mul = hold1 * param_3 return op_mul''' rules2 = Rules.Rules() input_values_3 = [ "1,2,ans,3", "Test753852", "Trial9", "5,2,ans,9", "trial89", "No" ] def mock_input_3(s): #print(input_values_3) return input_values_3.pop(0) Rules.input = mock_input_3 out, err = capsys.readouterr() test = Rules.Rules.sentence_break( rules, "I want a program to add two numbers then multiply and subtract then multiply" ) mp = rules2.mp mp = mp.replace(" ", "") mp = mp.replace("\n", "") print(mp) large = large.replace(" ", "") large = large.replace("\n", "") print(large) assert mp == large
def test_generation_medium(capsys): medium = '''def trial7(param_0, param_1, param_3): op_add = param_0 + param_1 hold1 = op_add op_mul = hold1 * param_3 return op_mul''' rules = Rules.Rules() input_values_2 = ["1,2,ans,3", "Test741852", "trial7", "No"] def mock_input_2(s): #print(input_values_2) return input_values_2.pop(0) Rules.input = mock_input_2 out, err = capsys.readouterr() test = Rules.Rules.sentence_break( rules, "I want a program to add two numbers then multiply") mp = rules.mp mp = mp.replace(" ", "") mp = mp.replace("\n", "") medium = medium.replace(" ", "") medium = medium.replace("\n", "") assert mp == medium
def test_generation_multi_fail(capsys): short = '''def trial6(param_0, param_1): op_add = param_0 + param_1 return op_add''' rules7 = Rules.Rules() input_values_multi = ["1", "1,2", "Test1749", "trial6", "No"] def mock_input_multi(s): print(input_values_multi) return input_values_multi.pop(0) Rules.input = mock_input_multi out, err = capsys.readouterr() test = Rules.Rules.sentence_break( rules7, "I want a program to add subtract two numbers" ) #then multiply then subtract and subtract then multiply then multiply print("MP ", rules7.mp) mp = rules7.mp mp = mp.replace(" ", "") mp = mp.replace("\n", "") short = short.replace(" ", "") short = short.replace("\n", "") print(mp == short) assert mp == short
def test_constructor_none_books(self): rules = Rules() self.assertEqual(rules.books, 0, "books not defaulting to a count of 0") """Card Request not being tested as it is input function"""
def test_function_check_deck_none(self): rules = Rules(Deck(ace_rank=Rank.ACELOW)) self.assertEqual(rules.check_deck(), 52, "Deck not producing 52 cards")
def test_function_count_request_none(self): rules = Rules() hand = Hand() self.assertEqual(rules.count_request(hand, Rank.THREE), 0, "Count request not returning 0 for empty hand")
def test_function_book_check_emptybook(self): rules = Rules() hand = Hand() self.assertEqual(rules.book_check(Rank.THREE, hand), 0, "book check not returning 0 when 0 cards in hand")
def test_function_player_answer_gofish(self): rules = Rules() hand = Hand() self.assertEqual(rules.player_answer(Rank.ACEHIGH, hand), "GOFISH", "player answer not returning GO FIsh properly")