def main(): S_basic = Scorer(os.getcwd()) # MatrixMatrixの課題 testdata_matrix = [30, 30, 45, 75, 58, 80, 75, 62, 85] S_basic.test_stdout("MatrixMatrix", convert=convert_Matrix, testdata=testdata_matrix, max_score=10) # Power20の標準出力の課題 S_applied = Scorer(os.getcwd()) testdata_pow = [ 68586, 34420, 75432, 63894, 37660, 18901, 41423, 35087, 70324, 35307, 77377, 65538, 105001, 52701, 115496, 97829 ] S_applied.test_stdout("Power20", convert=convert_Power20, testdata=testdata_pow, max_score=5) # Power20の関数の課題 testdata_in = [[[0.1, 0.2, 0.3, 0.4], [0.5, 0.6, 0.7, 0.8], [0.9, 0.10, 0.11, 0.12], [0.13, 0.14, 0.15, 0.16]]] testdata_out = [[17.947, 11.41, 14.022, 16.633], [49.864, 31.703, 38.959, 46.214], [19.887, 12.644, 15.537, 18.431], [11.37, 7.229, 8.883, 10.538]] S_applied.test_function("Power20", "Power20", convert=convert_Power20_2, testdata_in=testdata_in, testdata_out=testdata_out, max_score=5) df_basic = pd.DataFrame({ "ID": list(S_basic.score_dict.keys()), "通常": list(S_basic.score_dict.values()) }) df_applied = pd.DataFrame({ "ID": list(S_applied.score_dict.keys()), "応用": list(S_applied.score_dict.values()) }) df_score = pd.merge(df_basic, df_applied, on="ID", how="outer").fillna(0) df_score.sort_values("ID") df_score.to_csv("score.csv", index=False)
def main(): S = Scorer(os.getcwd()) # MatrixMatrixの課題 S.test_stdout("MatrixMatrix") # Power20の標準出力の課題 testdata = [ 205485., 205485., 205485., 205484., 247793., 247789., 247792., 247788., 269950., 269950., 269949., 269952., 325348., 325352., 325350., 325351. ] S.test_stdout("Power20", convert=convert_Power20, testdata=testdata, max_score=0.5) # Power20の関数の課題 testdata_in = [[[0.1, 0.2, 0.3, 0.4], [0.5, 0.6, 0.7, 0.8], [0.9, 0.10, 0.11, 0.12], [0.13, 0.14, 0.15, 0.16]]] testdata_out = [[17.947, 11.41, 14.022, 16.633], [49.864, 31.703, 38.959, 46.214], [19.887, 12.644, 15.537, 18.431], [11.37, 7.229, 8.883, 10.538]] S.test_function("Power20", "Power20", convert=convert_Power20_2, testdata_in=testdata_in, testdata_out=testdata_out, max_score=0.5) print(S.score_dict)
def test000_900_init_invalidparam(self): correctError = "__init__: " try: score = Scorer("Invalid") self.fail("Error: no error!") except ValueError, e: self.assertEqual(correctError, str(e)[:len(correctError)])
def setUp(self): self.words = ['pizza', 'tacos', 'burgers', 'fries'] weights = [1, 3, 2, 2] sentiments = [1, 1, 1, 1] attribute = Attribute("Attribute1", 1, self.words, weights, sentiments) self.packet = SearchPacket([attribute]) self.scorer = Scorer(self.packet)
def __init__(self, words, weights, sentiments): self.db = dbFacade() self.db.connect() self.db.create_keyspace_and_schema() self.twitterCrawler = TwitterCrawler() self.twitterCrawler.login() self.scorer = Scorer(zip(words,weights,sentiments))
def run_spellchecker(self, question=None, answers=None, data_obj=None): self.clear_all_text() if question and answers: print(f"gui: SpellChecker: We have question and answers") # all good, we have question and answers else: self.adb_screencap(self.filename) question, answers = ScreenProcessor.process_file(self.filename) self.score_obj = Scorer( question, answers, False, None, self.mainlbl) # untested 22/03/19 to allow answer input if data_obj: self.score_obj.set_data_obj(data_obj) # question = " .. ." # answers = ["a: massachusetts", "b: massachusettss", "0: mssachusetts"] self.answer1lbl["text"] = answers[0] + ": " self.answer2lbl["text"] = answers[1] + ": " self.answer3lbl["text"] = answers[2] + ": " in_list = [] for answer in answers: index = answer.find(":") in_list.append([answer[index + 1:].strip(), "define", "", -1]) pool = ThreadPool(3) pool_results = pool.map(self.trait_search, in_list) pool.close() pool.join() scores = [0, 0, 0] for result in pool_results: for i, answer in enumerate(answers): for title in result[1]: # titles if title.lower().find(answer[answer.find(':') + 1:].strip( ).lower() + " ") != -1 or title.lower().find( " " + answer[answer.find(':') + 1:].strip().lower()) != -1: scores[i] += 1 # print(f"True {answer}, {title}") for desc in result[2]: # descriptions if desc.lower().find(answer[answer.find(':') + 1:].strip( ).lower() + " ") != -1 or desc.lower().find( " " + answer[answer.find(':') + 1:].strip().lower()) != -1: scores[i] += 1 # print("added") else: pass try: self.answer1whichlbl["text"] = scores[0] self.answer2whichlbl["text"] = scores[1] self.answer3whichlbl["text"] = scores[2] except IndexError: self.infolbl[ "text"] = "Spell checking module: list out of bound. This shouldn't happen" print( "Spell checking module: list out of bound. This shouldn't happen" ) return self.infolbl["text"] = "Ready."
def test100_003_score_multiattr(self): attr1 = Attribute("1", 1, ["burgers"], [1], [0]) attr2 = Attribute("2", 1, ["fries"], [2], [0]) attr3 = Attribute("3", 1, ["tacos"], [3], [0]) packet = SearchPacket([attr1, attr2, attr3]) score = Scorer(packet) text = "I hate tacos and love fries and burgers are okay." self.assertEquals(score.score(text), [1, 2, 3, 0, 0])
def setUpClass(self): words = ['pizza', 'tacos', 'burgers', 'fries'] weights = [1, 3, 2, 2] sentiments = [1, 1, 1, 1] self.args = {'location': None, 'since': None, 'until': None} attribute = Attribute("Attribute1", 1, words, weights, sentiments) attributes = [attribute] search_packet = SearchPacket(attributes) self.scorer = Scorer(search_packet)
def test100_002_score_mixed(self): weights = [1, 3, 2, 2] sentiments = [0, 0, 0, 0] attribute = Attribute("Attribute1", 1, self.words, weights, sentiments) packet = SearchPacket([attribute]) score = Scorer(packet) text = "I hate tacos and love fries." #tacos has weight 3, fries 2 self.assertEquals(score.score(text), [5, 0, 0, 0, 0])
def setUpClass(self): words = ['pizza', 'tacos', 'burgers', 'fries'] weights = [1, 3, 2, 2] sentiments = [1, 1, 1, 1] self.query = "pizza OR tacos OR burgers OR fries" attribute = Attribute("Attribute1", 1, words, weights, sentiments) attributes = [attribute] search_packet = SearchPacket(attributes) self.scorer = Scorer(search_packet) self.db = dbFacade()
def setUpClass(self): words = ['pizza', 'tacos', 'burgers', 'fries'] weights = [1,3,2,2] targetSentiment = [1,1,1,1] self.args = { 'location' : None } self.query = "pizza OR tacos OR burgers OR fries" self.db = dbFacade() self.db.connect() self.db.create_keyspace_and_schema() self.scorer = Scorer(zip(words, weights, targetSentiment))
def run_tests(image): scorer = Scorer(image, show_results=False) image = copy.deepcopy(image) scorer.add_dct_calc_class(CudaDctCalcualtor(image)) scorer.add_dct_calc_class(CudaBlockDctCalculator(image)) scorer.add_dct_calc_class(BlockThreadedDctCalculator(image)) scorer.add_dct_calc_class(BlockDctCalculator(image)) scorer.add_dct_calc_class(NaiveDctCalculator(image)) scorer.add_dct_calc_class(ScipyDctCalculator(image)) scorer.add_dct_calc_class(NaiveThreadedDctCalculator(image)) scorer.run_all_tests()
def setUpClass(self): self.words = ['pizza', 'tacos', 'burgers', 'fries'] weights = [1, 3, 2, 2] sentiments = [1, 1, 1, 1] self.query = "pizza OR tacos OR burgers OR fries" attribute = Attribute("Attribute1", 1, self.words, weights, sentiments) attributes = [attribute] search_packet = SearchPacket(attributes) self.scorer = Scorer(search_packet) self.directory = '/users/lukelindsey/Downloads/enron_mail_20110402/maildir' self.db = dbFacade() self.e = EnronSearch(self.words, self.db, self.scorer, self.directory)
def setUpClass(self): words = ['pizza', 'tacos', 'burgers', 'fries'] weights = [1, 3, 2, 2] sentiments = [1, 1, 1, 1] self.query = "pizza OR tacos OR burgers OR fries" attribute = Attribute("Attribute1", 1, words, weights, sentiments) attributes = [attribute] search_packet = SearchPacket(attributes) self.scorer = Scorer(search_packet) self.db = dbFacade() # self.db.connect() # self.db.create_keyspace_and_schema() self.api_key = GoogleAPIWrapper.get_api_key()
def setUpClass(self): words = ['pizza', 'tacos', 'burgers', 'fries'] weights = [1, 3, 2, 2] sentiments = [1, 1, 1, 1] self.query = "pizza OR tacos OR burgers OR fries" attribute = Attribute("Attribute1", 1, words, weights, sentiments) attributes = [attribute] search_packet = SearchPacket(attributes) self.scorer = Scorer(search_packet) self.args = { 'folder_location': '/users/lukelindsey/Downloads/enron_mail_20110402/maildir' } self.db = dbFacade()
def setUpClass(self): words = ['pizza', 'tacos', 'burgers', 'fries'] weights = [1, 3, 2, 2] sentiments = [1, 1, 1, 1] self.args = {'location': None, 'since': None, 'until': None} self.query = "pizza OR tacos OR burgers OR fries" attribute = Attribute("Attribute1", 1, words, weights, sentiments) attributes = [attribute] search_packet = SearchPacket(attributes) self.scorer = Scorer(search_packet) self.db = dbFacade() self.db.connect() self.db.create_keyspace_and_schema() self.api = TwitterAPIWrapper() self.api.login()
def createNewResume(self, name, hpNumber, email, contentName, content): con = None try: con = psycopg2.connect( database='d1s3idai1l2u3d', user='******', password='******', host='ec2-54-197-241-24.compute-1.amazonaws.com', port='5432', sslmode='require') cur = con.cursor() except psycopg2.DatabaseError as e: print('Error %s' % e) sys.exit(1) finally: if con: cur.execute("SELECT * FROM job") rows = cur.fetchall() numRows = (len(rows)) newResume = ResumeNode(name, hpNumber, email, contentName, content) if (numRows == 0): ResumeProcessor.construct(newResume) toPrint = encodeClassToJson(newResume) cur.execute( "INSERT INTO resume VALUES (%s,%s,%s,%s,%s,%s)", (toPrint, 'f', contentName, name, hpNumber, email)) con.commit() else: ResumeProcessor.construct(newResume) toPrint = encodeClassToJson(newResume) cur.execute( "INSERT INTO resume VALUES (%s,%s,%s,%s,%s,%s)", (toPrint, 'f', contentName, name, hpNumber, email)) con.commit() f = Facade() matcher = Matcher(f) scorer = Scorer(f) matcher.matchAll(1) scorer.calculateScore() con.close()
def search(self, question, answers, question_num, data_obj=None): """ Takes question as string and answers as list of strings. performs forward search. This is a good place to put checks on question string """ if " not " in question.lower(): not_question = True else: not_question = False self.score_obj = Scorer(question, answers, not_question, question_num, self.mainlbl) if data_obj: self.score_obj.set_data_obj(data_obj) # signal all players that the question has started, we need a data object to initiate this properly if self.player_manager: self.player_manager.question_start(self.score_obj) if " not " in question.lower(): not_question = True birth_keywords = [ " born", " birth", "young" ] # "old" but don't want to interfere with date of death" if any(x in question.lower() for x in birth_keywords): self.dox_search("date of birth", "") death_keywords = ["die", "died", "death"] if any(x in question.lower() for x in death_keywords): self.dox_search("date of death", "") release_keywords = [ "released", "written", "sung", "sang", "published", "written" ] if any(x in question.lower() for x in release_keywords): self.dox_search("", "release date") self.forward_search(self.score_obj)
print('End Times: ') if dateString in simMap.usersEnding: for user in simMap.usersEnding[dateString]: print(user) if user.endStation in simMap.stations: if simMap.stations[user.endStation].isDocAvail(): simMap.stations[user.endStation].increaseBikeAvail() nonErrors += 1 else: stationsDocUnavail.append(user.endStation) DocUnavailErrors += 1 else: missingStations.append(user.endStation) stationMissingErrors += 1 print('Station Missing: ', stationMissingErrors) print('Missing Stations: ', set(missingStations)) print('Doc Unavail Errors: ', DocUnavailErrors) print('Doc Unavail Stations: ', set(stationsDocUnavail)) print('Bike Unavail Errors: ', BikeUnavailErrors) print('Bike Unavail Stations: ', set(stationsBikeUnavail)) print('Nonerrors: ', nonErrors) with open('StationJson/StationDataOut.json', 'w') as outfile: simMap.generateStationJson(outfile) #print(list(simMap.stations.keys())) Scorer().scorer('StationJson/StationDataOut.json')
(0, np.pi / 2, 0), # right (np.pi / 2, 0, 0), # top # (0, np.pi, 0), # back # (0, -np.pi/2, 0), # left # (-np.pi/2, 0, 0) # bottom ] depthScreenshots = [] for generatedChair in progressbar(newChairs, "Making Screenshots"): perspectives = mps.captureDepth(generatedChair, rotations, imageWidth=224, imageHeight=224) depthScreenshots.append((generatedChair, perspectives)) s = Scorer() # Assign a score scoredChairs = [] for generatedChair, perspectives in progressbar(depthScreenshots, "Evaluating Chairs"): score = s.score(perspectives) generatedChair.cachedScore = score scoredChairs.append((generatedChair, score)) # sort models depending on the score, from bigger to smaller chairsToDisplay = [] sortedChairs = sorted(scoredChairs, reverse=True, key=lambda tup: tup[1]) for chair, value in sortedChairs: print(value) chairsToDisplay.append(chair)
numRows = (len(rows)) newJob = JobDescNode(contentID, contentFile, keyword) if (numRows == 0): ResumeProcessor.construct(newJob) toPrint = encodeClassToJson(newJob) cur.execute("INSERT INTO job VALUES (%s,%s,%s,%s)",(toPrint,'f', contentID ,contentName)) con.commit() print('just store job') else: ResumeProcessor.construct(newJob) toPrint = encodeClassToJson(newJob) cur.execute("INSERT INTO job VALUES (%s,%s,%s,%s)",(toPrint,'f', contentID ,contentName)) con.commit() f = Facade() matcher = Matcher(f) scorer = Scorer(f) cur.execute("SELECT isonce_resume FROM once") rows = cur.fetchall() for row in rows: if(row[0] is True): cur.execute("UPDATE once SET isonce_resume=%s",('f',)) con.commit() print('calling match 0 --1 ') matcher.matchAll(0) scorer.calculateScore() print('calling match 0 --2') else: matcher.matchAll(2) scorer.calculateScore() print('fdsfds') con.close()
def __init__(self, words, weights, sentiments): self.db = dbFacade() self.words = words self.db.connect() self.db.create_keyspace_and_schema() self.scorer = Scorer(zip(words, weights, sentiments))
def main(): S_basic = Scorer(os.getcwd()) print("##### Density #####") S_basic.test_stdout("Density", convert=convert_density, testdata=testdata_density, max_score=10) print("##### MonteCarlo #####") S_basic.test_stdout("MonteCarlo", convert=convert_montecarlo, testdata=True, max_score=10) S_applied = Scorer(os.getcwd()) print("##### PrimeFactorization 1 #####") S_applied.test_function("PrimeFactorization", "PrimeFactorization", testdata_in=[12], testdata_out=[[2, 2], [3, 1]], max_score=2) print("##### PrimeFactorization 2 #####") S_applied.test_function("PrimeFactorization", "PrimeFactorization", testdata_in=[30], testdata_out=[[2, 1], [3, 1], [5, 1]], max_score=2) print("##### PrimeFactorization 3 #####") S_applied.test_function("PrimeFactorization", "PrimeFactorization", testdata_in=[32], testdata_out=[[2, 5]], max_score=2) print("##### PrimeFactorization 4 #####") S_applied.test_function("PrimeFactorization", "PrimeFactorization", testdata_in=[111], testdata_out=[[3, 1], [37, 1]], max_score=2) print("##### PrimeFactorization 5 #####") S_applied.test_function("PrimeFactorization", "PrimeFactorization", testdata_in=[20200518], testdata_out=[[2, 1], [3, 2], [13, 1], [173, 1], [499, 1]], max_score=2) df_basic = pd.DataFrame({ "ID": list(S_basic.score_dict.keys()), "通常": list(S_basic.score_dict.values()) }) df_applied = pd.DataFrame({ "ID": list(S_applied.score_dict.keys()), "応用": list(S_applied.score_dict.values()) }) df_score = pd.merge(df_basic, df_applied, on="ID", how="outer").fillna(0) df_score.sort_values("ID") df_score.to_csv("score.csv", index=False)
def __init__(self, search_packet): self.db = dbFacade() self.db.connect() self.db.create_keyspace_and_schema() self.scorer = Scorer(search_packet)
def __init__(self): self.LOGGER = LoggerFactory.getLogger("ScoreManager") self.scorer =Scorer() self.round = 1
def __init__(self): self.models = [] self.inputModels = [] self.renderMode = 0 self.viewerModelIndex = 0 self.scorer = Scorer()
def test000_000_init(self): score = Scorer(self.packet) self.assertIsInstance(score, Scorer)
im_train = (im_train + 1.0) / 2.0 # renormalize to [0, 1] im_valid = (im_valid + 1.0) / 2.0 # renormalize to [0, 1] # define placeholders im_pl = tf.placeholder(dtype=tf.float32, shape=[BATCH_SIZE, C, H, W]) # placeholder for images scores_pl = tf.placeholder(dtype=tf.float32, shape=[BATCH_SIZE, 1]) # placeholder for scores training_pl = tf.placeholder(dtype=tf.bool, shape=[]) #model print("Building model ...") sys.stdout.flush() model = Scorer() scores_pred = model(inp=im_pl, training=training_pl, zero_centered=ZERO_CENTER) # print(scores_pred.shape) # sys.exit(0) # losses print("Losses ...") sys.stdout.flush() loss = model.compute_loss(scores_pl, scores_pred) # sys.exit(0) # define trainer print("Train_op ...")
def main(): S_basic = Scorer(os.getcwd()) print("##### Harmonic Mean #####") S_basic.test_stdout("HarmonicMean", convert=convert_harm, testdata=79.902, max_score=10) print("##### Triangle 1 #####") S_basic.test_stdout("Triangle", convert=convert_tri, testdata=6, max_score=3, stdin_file="triangle_stdin1.py") print("##### Triangle 2 #####") S_basic.test_stdout("Triangle", convert=convert_tri, testdata=30, max_score=4, stdin_file="triangle_stdin2.py") print("##### Triangle 3 #####") S_basic.test_stdout("Triangle", convert=convert_tri, testdata=60, max_score=4, stdin_file="triangle_stdin3.py") S_applied = Scorer(os.getcwd()) print("##### QuadEquation 1 #####") S_applied.test_function("QuadEquation", "QuadEquation", testdata_in=[0, 1, -2], testdata_out=2, max_score=2) print("##### QuadEquation 2 #####") S_applied.test_function("QuadEquation", "QuadEquation", convert=lambda x: (min(x), max(x)), testdata_in=[1, -7, 12], testdata_out=(3, 4), max_score=2) print("##### QuadEquation 3 #####") S_applied.test_function("QuadEquation", "QuadEquation", convert=lambda x: (min(x), max(x)), testdata_in=[1, 1, -2], testdata_out=(-2, 1), max_score=2) print("##### QuadEquation 4 #####") S_applied.test_function("QuadEquation", "QuadEquation", testdata_in=[3, 1, 8], testdata_out="no solutions", max_score=2) print("##### QuadEquation 5 #####") S_applied.test_function("QuadEquation", "QuadEquation", testdata_in=[2, 8, 8], testdata_out=-2, max_score=2) df_basic = pd.DataFrame({ "ID": list(S_basic.score_dict.keys()), "通常": list(S_basic.score_dict.values()) }) df_applied = pd.DataFrame({ "ID": list(S_applied.score_dict.keys()), "応用": list(S_applied.score_dict.values()) }) df_score = pd.merge(df_basic, df_applied, on="ID", how="outer").fillna(0) df_score.sort_values("ID") df_score.to_csv("score.csv", index=False)
def initialize_scorer(self, search_packet): self.scorer = Scorer(search_packet)