Beispiel #1
0
	def __init__(self, maze):
		self.maze = maze
		self.inventory = {}
		inv_items = ReadFile.get_inventory_types()
		for i in range(len(inv_items)):
			inv_type = inv_items[i]
			self.inventory[inv_type] = ReadFile.get_init_inv_vals()[i]
Beispiel #2
0
def AddCorpus(sentences, name):
    old_sentences = ReadFile.readTXTFile(config.RegularsFilePath + name +
                                         '.query.txt')
    old_R_sentences = ReadFile.readTXTFile(config.RegularsFilePath + name +
                                           ".response.txt")
    count = len(old_sentences) + 1
    for sentence in sentences:
        contain = False
        Id = name
        for o_sen in old_sentences:
            lines = o_sen.split('\t')
            if lines[1][:-1] == sentence[0]:
                contain = True
                Id = lines[0]
                break
        if not contain:
            Id += '%05d' % count
            count += 1
            old_sentences.append(Id + '\t' + sentence[0] + '\n')
        for response in sentence[1:4]:
            if response != '' or response != '\n' or response != '\t' or len(
                    response) > 2:
                old_R_sentences.append(Id + '\t' + response + '\n')
    # write to file
    with open(config.ResultFilePath + name + ".query.txt", 'w') as fp:
        for line in old_sentences:
            fp.write(line)

    with open(config.ResultFilePath + name + ".response.txt", 'w') as fp:
        for line in old_R_sentences:
            fp.write(line)
Beispiel #3
0
def AddCorpus(sentences,name):
    old_sentences = ReadFile.readTXTFile(config.RegularsFilePath+name+'.query.txt')
    old_R_sentences = ReadFile.readTXTFile(config.RegularsFilePath+name+".response.txt")
    count = len(old_sentences)+1
    for sentence in sentences:
        contain = False
        Id = name
        for o_sen in old_sentences:
            lines = o_sen.split('\t')
            if lines[1][:-1] == sentence[0]:
                contain = True
                Id = lines[0]
                break
        if not contain:
            Id += '%05d'%count
            count += 1
            old_sentences.append(Id+'\t'+sentence[0]+'\n')
        for response in sentence[1:4]:
            if response != '' or response != '\n' or response != '\t' or len(response) > 2:
                old_R_sentences.append(Id+'\t'+response+'\n')
    # write to file
    with open(config.ResultFilePath+name+".query.txt",'w') as fp:
        for line in old_sentences:
            fp.write(line)

    with open(config.ResultFilePath+name+".response.txt",'w') as fp:
        for line in old_R_sentences:
            fp.write(line)
Beispiel #4
0
    def onStartTimeStep(self, interactions_filename, events_filename,
                        current_time_step):
        self.current_time_step = current_time_step

        for agent in self.agents_obj.agents.values():
            agent.new_time_step()

        for location in self.locations_obj.locations.values():
            location.new_time_step()

        #Add Interactions to agents
        if interactions_filename != None:
            ReadFile.ReadInteractions(interactions_filename, self.config_obj,
                                      self.agents_obj)

        #Add events to locations
        if events_filename != None:
            ReadFile.ReadEvents(events_filename, self.config_obj,
                                self.locations_obj)

        #Enact policies by updating agent and location states.
        for policy in self.policy_list:
            policy.enact_policy(self.current_time_step,
                                self.agents_obj.agents.values(),
                                self.locations_obj.locations.values(),
                                self.model)

        if events_filename != None:
            #Update event info to agents from location
            for location in self.locations_obj.locations.values():
                if not location.lock_down_state:
                    for event_info in location.events:
                        self.model.update_event_infection(
                            event_info, location, self.agents_obj,
                            self.current_time_step, self.event_restriction_fn)
Beispiel #5
0
def get_file_names_list(example_path, interactions_FilesList_filename,
                        events_FilesList_filename, config_obj):
    # Reading through a file (for interactions/events) that contain file names which contain interactions and event details for a time step

    interactions_files_list = None
    events_files_list = None

    if config_obj.interactions_files_list == '':
        print('No Interaction files uploaded!')
    else:
        interactionFiles_obj = ReadFile.ReadFilesList(
            interactions_FilesList_filename)
        interactions_files_list = list(
            map(lambda x: osp.join(example_path, x),
                interactionFiles_obj.file_list))
        if interactions_files_list == []:
            print('No Interactions inputted')

    if config_obj.events_files_list == '':
        print('No Event files uploaded!')
    else:
        eventFiles_obj = ReadFile.ReadFilesList(events_FilesList_filename)
        events_files_list = list(
            map(lambda x: osp.join(example_path, x), eventFiles_obj.file_list))
        if events_files_list == []:
            print('No Events inputted')

    return interactions_files_list, events_files_list
Beispiel #6
0
 def Remove(self, key):
     locate_file = ReadFile()
     record = locate_file.readFile("data.txt")
     for year in self.hashTable:
         for each in year:
             if each[-2:] == key:
                 year.remove(each)
                 year.append('-1')
Beispiel #7
0
 def Remove(self, key):
     locate_file = ReadFile()
     record = locate_file.readFile("data.txt")
     for year in self.hashTable:
         for each in year:
             if each[-2:] == key:
                 year.remove(each)
                 year.append('-1')
Beispiel #8
0
	def decrement(self):
		decrement_vals = ReadFile.read_decrement()	#Read in how much to decrement by
		inv_types = ReadFile.get_inventory_types()
		
		decrement_amounts = [0]*len(inv_types)
		
		for x in range(len(decrement_vals)):
			if (self.maze.total_step_count ) % decrement_vals[x][0] == 0:	#Should dec?
				self.inventory[inv_types[x]] -= decrement_vals[x][1]
				decrement_amounts[x] = decrement_vals[x][1]
		return decrement_amounts
Beispiel #9
0
def main():
    import os
    import sys

    A, b, c = ReadFile.read("../data/A.txt", "../data/b.txt", "../data/c.txt")
    x = np.zeros(len(c))
    x[0] = 0.1
    x[1] = 0.2
    H = Hessian(A, b, x)
    ReadFile.printMatrix(H)
    return 0
Beispiel #10
0
def create_data(data_in, data_flag, number):
    path = "C:/Users/Nao KeTeng/OneDrive/桌面/input.log"
    data = []
    ReadFile.readfile(path, data)
    for _ in data:                      # 舍弃第一个数据
        _.pop(0)

    time = 3
    flag = 0
    polynomial = [0, 0, 0, 0]
    # aa:训练拟合权重
    aa = 0.8

    for temp in data:
        z1 = np.polyfit(list(range(len(temp), 0, -1)), temp, time)
        p1 = np.poly1d(z1)

        if (polynomial[0] + polynomial[1] + polynomial[2] + polynomial[3]) == 0:
            flag = 1
        else:
            flag = 0
        if flag != 1:
            for i in range(time + 1):
                polynomial[i] = (1 - aa) * p1[i] + aa * polynomial[i]
        else:
            for i in range(time + 1):
                polynomial[i] = p1[i] + polynomial[i]

    result = []
    for i in range(15, 0, -1):
        result_temp = polynomial[0]+(polynomial[1]*i)+(polynomial[2]*(i**2))+(polynomial[3]*(i**3))
        result.append(result_temp)

    if data_flag == 2:
        for i in range(number):
            start = random.randint(1, 10)
            translation = np.random.normal(0, 4)
            jj = 0
            data_temp = []
            for _ in result:
                _ += (math.cos(math.pi * (start+jj)) * abs(np.random.normal(0, 4))) + translation
                jj += 1
                data_temp.append(_)
            data_in.append(copy.deepcopy(data_temp))
            data_temp.clear()

    elif data_flag == 3:
        for i in range(int(number/len(data))):
            for one in data:
                data_temp = []
                for _ in one:
                    data_temp.append(_ + +np.random.normal(-5, 5))
                data_in.append(copy.deepcopy(data_temp))
                data_temp.clear()
Beispiel #11
0
def Main(cp, ip, to_stem):
    global __corpus_path
    global __index_path
    global doc
    global __stem_suffix
    create_city_db()
    Parser.stem = to_stem
    if to_stem is True:
        __stem_suffix = '_stem'
    else:
        __stem_suffix = ''

    start = time.time()
    data_set_Path(cp, ip)
    Indexer.create_posting_files(__stem_suffix)
    counter = 0
    for root, dirs, files in os.walk(__corpus_path):
        for file in files:
            if (stop==True):
                reset() #will clear the memory of the program %% will remove the posting files and dictionary
                return
            #print("file!!!")
            end2 = time.time()
            # if ((end2-start)/60)>10 and ((end2-start)/60) <10.10:
            #     print(str(file))
            if str(file) != 'stop_words.txt':
                ReadFile.takeDocsInfoFromOneFile(str(pathlib.PurePath(root, file)))
                dic_of_one_file = Parser.parse(dic_to_parse)
                sorted_dictionary = collections.OrderedDict(sorted(dic_of_one_file.items()))
                index_start = time.time()
                Indexer.merge_dictionaries(sorted_dictionary)
                dic_to_parse.clear()
                counter += 1
            if counter == 100:
                Indexer.SaveAndMergePostings()
                counter = 0
    Indexer.SaveAndMergePostings()
    saveCityDictionaryToDisk(ip)
    saveMainDictionaryToDisk(ip)
    cleanDocsYeshuyot()
    saveDocumentDictionaryToDisk(ip)
    x= ReadFile.docs_dictionary
    saveLangListToDisk(ip)
    saveStopWordsDictToDisk(ip)

    #ranker things
    createAndSaveAvdlToDisk(ip)

    x=ReadFile.lang_list
    end2 = time.time()
    time_final = str((end2 - start) / 60)
    print("time of program: " + time_final)
    sendInfoToGUI(time_final)
Beispiel #12
0
	def give_prize(self, inv_type, amount):	
		num = -1
		for x in range(len(ReadFile.get_inventory_types())):	#Get the inv num
			if ReadFile.get_inventory_types()[x] == inv_type:
				num = x
				break	
				
		cap = ReadFile.read_caps()[num]
		if cap == None:	#Unbounded cap
			self.inventory[inv_type] += amount
		else:	#Bounded cap
			difference = cap - self.inventory[inv_type]	#How much left can be added
			self.inventory[inv_type] += min(difference, amount)
Beispiel #13
0
	def is_dead(self):
		inv_types = ReadFile.get_inventory_types()
		mins = ReadFile.get_mins()	#Smallest possible amount
		
		
		
		dead_at = [False, False, False]	#At each inventory item, are you ok?
		
		for x in range(len(self.inventory)):
			if self.inventory[inv_types[x]] < mins[x]:
				dead_at[x] = True
				self.inventory[inv_types[x]] = mins[x]
		return dead_at
Beispiel #14
0
def reset(param=None):
    global __corpus_path,__index_path, __stem_suffix
    if param == "Queries":
        Parser.reset()
        __corpus_path = ""
    else:
        ReadFile.reset()
        Parser.reset()
        Indexer.reset()
        remove_index_files()
        __stem_suffix = ''
        __corpus_path = ""
        __index_path = ""
Beispiel #15
0
    def log_in(self, u_log, u_pass):
        global login
        global user_path
        if u_log.get() in rf.check_login():

            if u_pass.get() == rf.check_pass(u_log.get()):
                print('Logged in')

                login = u_log.get()
                self.change_frame(MainMenu)

            else:
                print('wrong password')

        else:
            print('user not exist')
def mP(a, tab, Aligner, sc):
    manager = multiprocessing.Manager()
    alignments = manager.list()
    cores = int(input('Inserisci il numero di processori: '))
    if cores > multiprocessing.cpu_count():
        cores = multiprocessing.cpu_count()
        print("Superato il numero massimo di processori,", str(cores),
              "in uso")
    else:
        print(str(cores), "processori in uso")
    processes = []
    data = ReadFile.SPARKreadFile(sc)
    dict = [x["SEQ"] for x in data.rdd.collect()]
    #dict = ReadFile.HengLireadFile() #Heng Li
    chunk_size = len(dict) / cores
    slices = Chunks(dict, math.ceil(chunk_size))
    for i, s in enumerate(slices):
        procname = 'processor' + str(i)
        p = multiprocessing.Process(target=Alignment.mPalignment,
                                    args=(a, tab, Aligner, s, alignments,
                                          procname))
        p.start()
        processes.append(p)
    for p in processes:
        p.join()
    DF = spark.createDataFrame(alignments)
    DataFrame = DF.join(data, on=['seq'], how='inner')
    return DataFrame
Beispiel #17
0
	def draw_inv_text(self):	#Box around the text here
		PERCENT_UP = 0.95	#How far up is the text?
		FONT = GLUT_BITMAP_9_BY_15
		LOADING_WIDTH = 40
		LOADING_HEIGHT = 10
		TEXT_LOADINGBAR_GAP = 10
		
		text_top = PERCENT_UP * SCREEN_SIZE[1] #Text starts from here
		
		GLComponents.glEnable2D()
		max_length = 0
		for item_num in range(len(self.inventory.inventory)):	#Longest sentence
			key = self.inventory.inventory.keys()[item_num]
			
			cap = ReadFile.read_caps()[item_num]
			if cap:
				message = "{0}: {1:.2f}%".format(key, self.inventory.inventory[key]/cap * 100.0)
			else:
				message = "{0}: {1:.2f}".format(key, self.inventory.inventory[key])
			
			width = self.str_width(message, FONT)
			
			if width > max_length:
				max_length = width
			GLComponents.write_str(message, 0, text_top - item_num * 15, FONT)
			if cap:	#Only capped values get loading bars
				GLComponents.loading_bar(max_length + TEXT_LOADINGBAR_GAP, text_top - 15 * item_num, 
					self.inventory.inventory[key]/cap * 100, LOADING_WIDTH, LOADING_HEIGHT)
		
		GLComponents.draw_rect(0, max_length + LOADING_WIDTH + TEXT_LOADINGBAR_GAP + 2, 
			text_top + 15, text_top - len(self.inventory.inventory) * 15)
		
		GLComponents.glDisable2D()
 def generate_bulk_insert_data(self, file_folder, num):
     read_file = ReadFile.ReadFile(file_folder)
     # return list data -> generate bulk data
     # list data contains json like data
     # add action and meta data to every json data
     # 进行数据冗余
     # 从url指定位置,减少每次action动作的数据
     action = {"index": {}}
     bulk_data = ""
     for data_list in read_file.get_data(num):
         # data list -> data
         # 传过来的data为从源文件取出的json格式
         # 对content做数据冗余,先将json载入为map,再添加,然后再dumps为json格式
         for data in data_list:
             try:
                 data_map = json.loads(data, encoding='utf-8')
                 data_map['title1'] = data_map['title']
                 data_map['tag'] = {"input": data_map['title']}
                 data_map['text1'] = data_map['text']
                 data_map['time'] = data_map['time']
                 data_map['timestamp'] = time.mktime(
                     time.strptime(data_map['time'], '%Y-%m-%d %H:%M:%S'))
                 #print(data_map['timestamp'])
                 bulk_data += json.dumps(
                     action, ensure_ascii=False) + '\n' + json.dumps(
                         data_map, ensure_ascii=False) + '\n'
             except:
                 continue
         bulk_data += '\n'
         yield (bulk_data)
         bulk_data = ""
Beispiel #19
0
def inputfilecontaindict2list(filename):
    inputfilelines = ReadFile.ReadExpectFile(filename)
    inputlist = []
    for inputfileline in inputfilelines:
        inputfileline = inputfileline.replace('\n', '')
        inputfileline = inputfileline.replace('\"', '')
        inputfileline = inputfileline.replace(': ', '=')
        inputfileline = inputfileline.replace(' ', '')
        inputfileline = inputfileline.replace('={', '=@')
        inputfileline = inputfileline.replace('},', '**,')
        inputfileline = inputfileline.replace('{', '')
        inputfileline = inputfileline.replace('}', '')
        inputfileline = inputfileline.replace('[0,0,1,0,0,0,0,0]', '###')
        # print inputfileline

        inputtemplist = inputfileline.split(",")
        inputdict = {}
        for i in range(len(inputtemplist)):
            if inputtemplist[i].find('=@') != -1:
                inputtemplist[i] = inputtemplist[i].split("=@")[1]
            if inputtemplist[i].find('**') != -1:
                inputtemplist[i] = inputtemplist[i].split('**')[0]
            if inputtemplist[i].find('###') != -1:
                inputtemplist[i] = inputtemplist[i].replace(
                    "###", '[0,0,1,0,0,0,0,0]')
            inputtemplist2 = inputtemplist[i].split('=')
            inputdict[inputtemplist2[0]] = inputtemplist2[1]
        inputlist.append(inputdict)
    return inputlist
Beispiel #20
0
def HLalignment(a, alignments, tab, Aligner,sc):
    dict = ReadFile.readFile3()
    # counter = 0
    for name, seq, qual in dict.values():
        try:
            hit = next(a.map(seq, MD=True, cs=True))
            # dict = {}
            flag = 0 if hit.strand == 1 else 16
            seq = seq if hit.strand == 1 else seq.translate(tab)[::-1]
            clip = ['' if x == 0 else '{}S'.format(x) for x in (hit.q_st, len(seq) - hit.q_en)]
            if hit.strand == -1:
                clip = clip[::-1]
            cigar = "".join((clip[0], hit.cigar_str, clip[1]))
            alignment = Aligner(contig=hit.ctg, Rname=name, flag=flag, pos=hit.r_st, mapq=hit.mapq, cigar=cigar, seq=seq, is_primary=hit.is_primary, MDtag=hit.MD, cstag=hit.cs, basequal=qual)
            # dict['counter','Qname', 'flag', 'Rname', 'pos', 'mapq', 'cigar', 'seq', 'is_primary'] = name, flag, hit.ctg, hit.r_st, hit.mapq, hit.cigar_str, seq, hit.is_primary
            if hit.mapq >= 10:
                # alignments.append(dict['counter','Qname', 'flag', 'Rname', 'pos', 'mapq', 'cigar','seq', 'is_primary'])
                alignments.append(alignment)
                # counter += 1
        except StopIteration:
            alignment = Aligner(contig='chr0', Rname=name, flag=4, pos=None, mapq=None, cigar=None, seq=seq, is_primary=False, MDtag=None, cstag=None, basequal=qual)
            alignments.append(alignment)
    rdd = sc.parallelize(alignments)
    seqDF = rdd.map(lambda x: Row(contig=x[0], Rname=x[1], flag=x[2], pos=x[3], mapq=x[4], cigar=x[5], seq=x[6], is_primary=x[7], MDtag=x[8], cstag=x[9], basequal=x[10]))
    DF = sqlContext.createDataFrame(seqDF)
    return DF
Beispiel #21
0
	def __init__(self, room_type = None, colours = None, is_choice_room = False, 
		possible_prize = None, prize = None, depth = 0, options = None,
		last_pos = None):
		self.adjacent = {}
		self.room_type = room_type
		self.is_choice_room = is_choice_room
		if prize == None:
			self.prize = [None, 0, False]
		else:
			self.prize = prize
			
		
		self.depth = depth
		self.options = options
		
		if colours == None:
			self.colours = self.generate_colours(self.room_type)
		else:
			self.colours = colours
		
		self.last_pos = last_pos
		self.prize_infos = [ReadFile.get_option() for x in range(3)] 	#This contains three instances of ReadFile.get_option(). 
		self.prize_infos[1] = None #overwrite middle one so now cue in centre
		#This is just a detailed version of prize_order. In fact, prize order only exists
		#since it was made before prize_info was needed, and it is now hard to remove.

		self.prize_order = [None, None, None]
Beispiel #22
0
def main():
    root = utils.get_root_path(False)
    usage = "usage: %prog [options] arg"
    parser = OptionParser(usage)
    parser.add_option('--learning_rate_rbm',
                      action='store',
                      type='string',
                      dest='learning_rate_rbm')
    parser.add_option('--epochs_rbm',
                      action='store',
                      type='string',
                      dest='epochs_rbm')
    parser.add_option('--batch_size',
                      action='store',
                      type='string',
                      dest='batch_size')
    parser.add_option('--data_set',
                      action='store',
                      type='string',
                      dest='data_set')

    (opts, args) = parser.parse_args()

    file_data = ReadFile.ReadFile(root + '/NSL_KDD-master',
                                  opts=opts).get_data()
    data_pp = preprocess.Preprocess(file_data).do_predict_preprocess()
    dbn_model.DBN(data_pp).do_dbn('yadlt', opts=opts)
    dbn_model.DBN(data_pp).do_dbn_with_weight_matrix(root + '/save')
    model.do_svm()
Beispiel #23
0
def filterStopWords(Words):
    New_words = []
    stopWords = ReadFile.readStopWord(MyCode.config.StopWordPath + 'stop_2.txt')
    for word in Words:
        if word not in stopWords:
            New_words.append(word)
    return New_words
Beispiel #24
0
	def __init__(self, maze):
		self.time = pygame.time.get_ticks()
		self.maze = maze
		
		self.possible_times = ReadFile.read_times()
		self.next_straight_time = self.get_wait_time()
		
		self.num_chars = 0	#Number of times MRI outputs
Beispiel #25
0
    def print_path(self):
         self.filename = filedialog.askopenfilename(initialdir="/", title="Select file",
                                                           filetypes=(("text file", ".txt"), ("all files", ".*")))

         self.configure(background="white")
         global file
         file=1
         ReadFile.ReadFromFile(self.filename)
Beispiel #26
0
 def _get_majors(self, path):
     """ Read majors files and assign the course to the majors 
         Handle exceptions in the calling function.
     """
     for major, flag, course in rf.file_reading_gen(path, 3, sep='\t', header=True):
         if major not in self._majors:
             self._majors[major] = Major(major)
         self._majors[major].add_course(course, flag)
Beispiel #27
0
def partical_block(file_path, start_num_list_modify, end_num_list_modify):
    basic_text_only_if = list()
    for i in range(0, len(start_num_list_modify)):
        basic_text_only_if.append(
            ReadFile.read_need_partical_File(file_path,
                                             start_num_list_modify[i] - 1,
                                             end_num_list_modify[i]))
    return basic_text_only_if
Beispiel #28
0
def translatefile(filename):
    inputfile = filename
    iReadStart = getReadStart(filename)
    iFileIndex = getFileIndex(filename)
        
    readObj = ReadFile(inputfile)
    iFileSize = readObj.filesize()
    (iPos, data) = readObj.readvalue(iReadStart, 12)
    while(len(data) > 0):
        oldFile = getoldfile()
        if iReadStart == 0:
            newName = convert2filename(iFileSize, 0, filename)
        else:
            newName = convert2filename(iPos, iFileIndex, data)
        while (len(oldFile) == 0):
            sleep(1000)
            oldFile = getoldfile()
        convert2newfile(oldFile, newName)
Beispiel #29
0
def train():
    fileName = "trainData.model"
    test = ReadFile.QAData("training.data")
    test.readFile()

    ProD.wordSeg(test)
    ProD.delHighFre_useless(test)
    ProD.delHighFre_psg(test)
    trainModel(test, fileName)
Beispiel #30
0
def Allen(fileUsesMathSigns=True):
    if fileUsesMathSigns:
        file1 = "algebra/allen2.txt"
        file2 = "algebra/ia_ord_horn_C2.txt"
    else:
        file1 = "algebra/allen.txt"
        file2 = "algebra/ia_ord_horn_C.txt"

    algFile = ReadFile.AlgebraFile(file1)
    horn = ReadFile.ATractableSubsetsFile(file2)
    alg = Algebra(algFile, horn)
    alg.equality = ("=" if fileUsesMathSigns else "EQ")
    # print(alg)
    alg.checkIntegrity()
    print("Reading compositions file ...")
    print("\n")
    alg.readCompositionsFile("algebra/allen.compositions")
    return alg
Beispiel #31
0
 def _get_students(self, path):
     ''' Read students from path and add to the self.students
         Allow exceptions from reading the file to flow back to the caller.
     '''
     for cwid, name, major in rf.file_reading_gen(path, 3, sep=';', header=True):
         if major not in self._majors:
             print(f"Student {cwid} '{name}' has unknown major '{major}'")
         else:
             self._students[cwid] = Student(cwid, name, self._majors[major])
Beispiel #32
0
def getKeyWordsAndResponses(file):
    dataFilePath = config.InputDataFilePath
    resultFile  = config.InputDataFilePath
    bk,table_names = ReadFile.readCorpusExcel(dataFilePath+'badcase/'+file+'.xlsx')
    for name in table_names:
        table = bk.sheet_by_name(name)
        sentences = getTableContext(table)

        AddCorpus(sentences,name)
Beispiel #33
0
def ODPSoutputfile2list(filename):
    outputfilelines = ReadFile.ReadRealFlie(filename)
    outputlist = []

    for outputfileline in outputfilelines:
        outputfileline = outputfileline.replace('\n', '')
        outputfilelinelist = outputfileline.split(",")
        outputlist.append(outputfilelinelist)
    return outputlist
Beispiel #34
0
def getKeyWordsAndResponses(file):
    dataFilePath = config.InputDataFilePath
    resultFile = config.InputDataFilePath
    bk, table_names = ReadFile.readCorpusExcel(dataFilePath + 'badcase/' +
                                               file + '.xlsx')
    for name in table_names:
        table = bk.sheet_by_name(name)
        sentences = getTableContext(table)

        AddCorpus(sentences, name)
Beispiel #35
0
def filterStopWordFromSentences(sentences):
    stopWords = ReadFile.readStopWord(MyCode.config.StopWordPath + 'stop_2.txt')
    filter_sentences = []
    for sentence in sentences:
        filter_sentence = []
        for w in sentence:
            if w not in stopWords:
                filter_sentence.append(w)
        filter_sentences.append(filter_sentence)
    return filter_sentences
def run_simulation(test_cost, fp_cost, quarantine_cost, infection_cost, n, p,
                   beta, gamma, napt, ntpa, testing_gap, tests_per_period,
                   turnaround_time, restriction_time, fn, fp):

    testing_gap += 1

    config_filename = get_config_path('')

    # Read Config file using ReadFile.ReadConfiguration
    config_obj = ReadFile.ReadConfiguration(config_filename)

    agents_filename = 'agents.txt'
    interactions_files_list = ['interactions_list.txt']
    locations_filename = None
    events_files_list = []

    # User Model
    model = get_model(beta, gamma)

    ##########################################################################################

    policy_list = []

    # Group/Pool Testing
    def testing_fn(timestep):
        if timestep % testing_gap == 0:
            return tests_per_period * napt / ntpa
        return 0

    Pool_Testing = Testing_Policy.Test_Policy(testing_fn)
    Pool_Testing.add_machine('Simple_Machine', test_cost, fp, fn,
                             turnaround_time, 1000, 1)
    Pool_Testing.set_register_agent_testtube_func(
        Pool_Testing.random_agents(napt, ntpa))
    policy_list.append(Pool_Testing)

    ATP = Lockdown_Policy.agent_policy_based_lockdown("Testing", ["Positive"],
                                                      lambda x: True,
                                                      restriction_time)
    policy_list.append(ATP)

    def event_restriction_fn(agent, event_info, current_time_step):
        return False

    ###############################################################################################

    world_obj = World.World(config_obj, model, policy_list,
                            event_restriction_fn, agents_filename,
                            interactions_files_list, locations_filename,
                            events_files_list)
    # world_obj.simulate_worlds(plot=True)
    tdict, total_infection, total_quarantined_days, wrongly_quarantined_days, total_test_cost = world_obj.simulate_worlds(
        plot=False)
    cost = total_infection * infection_cost + total_quarantined_days * quarantine_cost + total_test_cost + world_obj.total_false_positives * fp_cost
    return cost
Beispiel #37
0
def main():
    import os
    import sys

    A, b, c = ReadFile.read("../data/A.txt", "../data/b.txt", "../data/c.txt")
    x = np.zeros(len(c))
    x[0] = 0.1
    x[1] = 0.2
    t = 1.0
    print "Gradient = ", gradient(t, A, b, c, x)
    return 0
def runScript(findsomething):
    command = 'show system info\n'
    inputValue = text_entry.get("1.0", "end-1c")
    arrayValue = ReadFile.openFile("file.txt")
    inputArray = inputValue.splitlines()
    for x in inputArray:
        print x
        sshOutput = SSH.connectToDevice(x, command)
        valueFound = Find.findString(findsomething, sshOutput)
        WriteOutput.appendOutput(valueFound, x, 'output.txt')
        print "Output written to output.txt"
def pruningAlgorithm(decisionTree, K, validation_filename):
    bestDecisionTree = copy.deepcopy(decisionTree)
    testFile = ReadFile.readfile(validation_filename)
    maxAccuracyWithID3 = accuracyFind(decisionTree, testFile.trainingValues)
    print("Accuracy with ID3 DT against Test set: ")
    print(str(maxAccuracyWithID3))

    pruneDecisionTree = copy.deepcopy(decisionTree)
    arrayOfNodes = []
    collectAllNodes(pruneDecisionTree, arrayOfNodes)
    j = 0
    while j < K:
        N = len(arrayOfNodes)
        P = random.randint(0, N - 1)
        pCnt = 0
        nCnt = 0
        arrayOfNodes[P].left = BinaryTreeFormat.BinTree()
        arrayOfNodes[P].right = BinaryTreeFormat.BinTree()
        arrayOfNodes[P].left.testAttrForCurrentNode = "class"
        arrayOfNodes[P].right.testAttrForCurrentNode = "class"

        for eachSet in arrayOfNodes[P].dataForPruning:
            if eachSet != "tested":
                if arrayOfNodes[P].dataForPruning[eachSet]["class"] == "1":
                    pCnt += 1
                else:
                    nCnt += 1

        if pCnt > nCnt:
            arrayOfNodes[P].left.label = "+"
            arrayOfNodes[P].right.label = "+"
        else:
            arrayOfNodes[P].left.label = "-"
            arrayOfNodes[P].right.label = "-"
        j += 1

    currentTreeAccuracy = accuracyFind(pruneDecisionTree,
                                       testFile.trainingValues)
    print("Accuracy after Pruning against Test set: ")
    print(currentTreeAccuracy)
    print("Number of nodes in a pruned tree:")
    print(DT_size(pruneDecisionTree, count=0))
    print("Number of Leaf nodes in a pruned tree:")
    print(DT_leaf_nodes(pruneDecisionTree))
    '''print("Average depth: ")
   average = float(totalDepth(pruneDecisionTree,level=0)) / float(DT_leaf_nodes(pruneDecisionTree))
   print(average)'''

    if maxAccuracyWithID3 < currentTreeAccuracy:
        maxAccuracyWithID3 = currentTreeAccuracy
        print("Overfitting deducted: Tree interchanged")
        bestDecisionTree = copy.deepcopy(pruneDecisionTree)

    return bestDecisionTree
Beispiel #40
0
	def generate_prize_order(self):
		possible_prizes = ReadFile.get_inventory_types()
		possible_prizes.append(None)
		ordered = []
		for x in range(3):
			random_number = randint(0, len(possible_prizes) - 1)
			ordered.append(possible_prizes[random_number])
			if possible_prizes[random_number] == None:
				possible_prizes.remove(None)	#Prevent more than 1 None
			
		return ordered
def main():
    start = time.time()
    input_filename = sys.argv[1]
    output_filename_id_zip = sys.argv[2]
    output_filename_id_date = sys.argv[3]

    io = rf.InputOutput(input_filename, output_filename_id_zip,
                        output_filename_id_date, '|')
    io.read_process_write()
    end = time.time()
    print('V1 (no pandas) processing time: ' + str(round(end - start, 3)) +
          ' (seconds)')
Beispiel #42
0
def filterStopWordsInSentences(par_sentences):
    # file = "../../Data/StopWords/stop.txt"
    stopWords = ReadFile.readStopWord(MyCode.config.StopWordPath + 'stop_2.txt')
    filter_Par_Sentences = []
    for par_sentence in par_sentences:
        filterSentences = []
        for sen in par_sentence:
            words = []
            for word in sen:
                if word not in stopWords:
                    words.append(word)
            filterSentences.append(words)
        filter_Par_Sentences.append(filterSentences)
    return filter_Par_Sentences
Beispiel #43
0
def filterStopWords(sentences,file=MyCode.config.StopWordPath+'stop_2.txt'):
    stopWords = ReadFile.readStopWord(file)
    filterSentences = []
    noFilterSentences = []
    for sentence in sentences:
        filter_words = []
        nofilterWords = []
        for sen in sentence:
            nofilterWords.append(sen)
            if sen not in stopWords:
                filter_words.append(sen)
        filterSentences.append(filter_words)
        noFilterSentences.append(nofilterWords)
    return filterSentences,noFilterSentences
Beispiel #44
0
 def Get(self, query):
     locate_file = ReadFile()
     record = locate_file.readFile("data.txt")
     if '|' in query:
         info = query.split('|')
         year_index = int(info[0]) % 10
         movie_type = self.type.index(info[1])
         index = str(info[0]) + '0' + str(movie_type)
         for each in self.hashTable[year_index]:
             if each[:6] == index:
                 location = int(each[6:])
                 print ", ".join(record[location])
             elif each == '-1':
                 return "The record is not in the database"
     else:
         year_index = int(query) % 10
         for each in self.hashTable[year_index]:
             if each == '-1':
                 # print "no more record in query"
                 break
             else:
                 if each[:4] == query:
                     location = int(each[6:])
                     print ", ".join(record[location])
Beispiel #45
0
	def add_output_buffer_postlim(self):
		position = self.maze.position.last_pos
		
		if position != None:		#Choice
			if position.is_choice_room:
				self.out_list.append(str(self.maze.position.prize[0]))
			else:
				self.out_list.append("-1")
				
		inv_types = ReadFile.get_inventory_types()
		
		self.out_list.extend([str(self.inventory.inventory[inv_types[x]]) for x in range(3)])
		
		if self.maze.position.prize[2]:	#If just got a prize
			self.out_list.extend([str(self.maze.position.prize[0]), str(self.maze.position.prize[1])])
		else:
			self.out_list.extend(['None', 'None'])
def makeBags():
        BagStrings = ReadFile.readFile()
        i = 0
        j = 0
        for a in BagStrings:
                for a2 in a:
                        BagStrings[i][j] = BagStrings[i][j] + " "
                        j+= 1
                i += 1
                j = 0
        BagDog = categoryDictionary(BagStrings[0])
        print("test")
        BagTweens = categoryDictionary(BagStrings[1])
        print("test")
        BagResearch = categoryDictionary(BagStrings[2])
        print("test")
        return [BagDog, BagTweens, BagResearch]
Beispiel #47
0
	def step(self, direction, hall_type = Hallways.TRIFURC):
		if direction not in self.position.adjacent:	#Not visited
			new_pos = MazeComponent(hall_type)
			new_pos.last_pos = self.position
			
			if self.position.is_choice_room:	#In a choice room
				new_pos.is_choice_room = False
				self.assign_possible_prize(new_pos, direction)
				new_pos.depth = 1
				new_pos.options = ReadFile.get_option(new_pos.prize[0])
				self.set_has_prize(new_pos)	#Winner?
			
			else:	#In a `straight' choiceless room
				if direction in [Directions.LEFT, Directions.RIGHT]:	#the user turns
					new_pos.is_choice_room = True
					
					#Determine order o' prizes
					new_pos.set_prize_order(self.generate_prize_order())
					
				elif direction == Directions.FORWARDS:	#User proceeds forward
					#default of is_choice_room is false
					new_pos.prize[0] = self.position.prize[0]
					new_pos.depth = self.position.depth + 1
					new_pos.options = self.position.options
										
					self.set_has_prize(new_pos)	#Winner?
			
			self.position.adjacent[direction] = new_pos	
			
			#Allow yourself to go backwards
			if direction == Directions.FORWARDS:
				new_pos.adjacent[Directions.BACKWARDS] = self.position
			elif direction == Directions.BACKWARDS:
				new_pos.adjacent[Directions.FORWARDS] = self.position
			elif direction == Directions.LEFT:
				new_pos.adjacent[Directions.BACKWARDS] = self.position
			elif direction == Directions.RIGHT:
				new_pos.adjacent[Directions.BACKWARDS] = self.position
				
			self.position = new_pos
		elif self.position.adjacent[direction] != None:
			self.position.adjacent[direction].last_pos = self.position
			self.position = self.position.adjacent[direction]
			self.position.prize = [self.position.prize[0], 0, False]
Beispiel #48
0
    def add_output_buffer_postlim(self, direction, current_inventory, decrement_amounts):

        position = self.maze.position.last_pos

        # 		if position != None:		#Choice
        # 			if position.is_choice_room:
        # 				self.out_list.append(str(self.maze.position.prize[0]))
        # 			else:
        # 				self.out_list.append("-1")

        global chosen_direction, chasing_infos, str_infos
        chosen_direction = direction  # for updating centre/chasing infos later

        self.out_list.append(direction)  # Direction chosen

        # to update chasing info for next turn (ie what you just selected) and output the infos of the current chosen direction to file
        if direction == "left":
            chasing_infos = self.prize_info_to_string(position.prize_infos[0])
            self.out_list.extend(str_infos[0:4])
        elif direction == "right":
            chasing_infos = self.prize_info_to_string(position.prize_infos[2])
            self.out_list.extend(str_infos[4:8])
        elif direction == "centre" and self.maze.position.prize.count(None) != len(
            self.maze.position.prize
        ):  # if centre, don't update, unless prize given, then update to nones
            chasing_infos = ["None", "None", "None", "None"]
            self.out_list.extend(str_infos[0:4])

        inv_types = ReadFile.get_inventory_types()
        # for prize and decrease
        for x in inv_types:
            if x == self.maze.position.prize[0]:
                self.out_list.append(str(self.maze.position.prize[1]))
            else:
                self.out_list.append("0")
        self.out_list.extend([str(x) for x in decrement_amounts])

        self.out_list.extend([str(current_inventory[inv_types[x]]) for x in range(len(inv_types))])  # Inventory
Beispiel #49
0
	def add_output_buffer_postlim(self, direction, current_inventory, decrement_amounts):
		position = self.maze.position.last_pos
		
		if position != None:		#Choice
			if position.is_choice_room:
				self.out_list.append(str(self.maze.position.prize[0]))
			else:
				self.out_list.append("-1")
		
		self.out_list.append(direction)	#Direction chosen
				
		inv_types = ReadFile.get_inventory_types()
		
		self.out_list.extend([str(current_inventory[inv_types[x]]) for x in range(3)])	#Inventory
		

		for x in inv_types:
			if x == self.maze.position.prize[0]:
				self.out_list.append(str(self.maze.position.prize[1]))
			else:
				self.out_list.append('0')
				
		self.out_list.extend([str(x) for x in decrement_amounts])
Beispiel #50
0
	def __init__(self):
		self.inventory = {}
		for inv_type in ReadFile.get_inventory_types():
			self.inventory[inv_type] = 0
__author__ = 'ajayvembu'

import ReadFile
import KMeanAlgorithmUpdatedV1
import ValidateKMean
import sys

numberOfClusters = int(sys.argv[1])
testFileName = str(sys.argv[2])
outPutFileName = str(sys.argv[3])

testData = ReadFile.readFileForKMean(testFileName)
KMeanResult = KMeanAlgorithmUpdatedV1.KMeanAlgorithm(testData,numberOfClusters)
sSE = ValidateKMean.squaredErrorFunction(KMeanResult.clusters,KMeanResult.centroids)
ReadFile.writeToKMeaFile(outPutFileName,KMeanResult)
print sSE
Beispiel #52
0
__author__ = 'jarfy'
from ReadFile import *
from hashmap import *

test = ReadFile()
data = test.readFile("data.txt")
formate = test.getType()
operator = MovieIndex(formate)
operator.MovieHash(data)
print "show movie index"
print operator.hashTable
print
print "put 46th record into index"
operator.Put(46, "The Abyss,1970,LaserDisc,Science Fiction,James Cameron,James Cameron,USA,20th Century Fox,$0.00")
print operator.hashTable
print
print "Find all movies made in 2000"
operator.Get("2000")
print
print "Find all movies made in 2005"
operator.Get("2005")
print
print "Find all movies made in 2010"
operator.Get("2010")
print
print "Find all DVD movies made in 1977"
operator.Get("1977|DVD")
print
print "Find all VHS movies made in 1990"
operator.Get("1990|VHS")
print
Beispiel #53
0
menuList = ["Read file", "Export XML File", "Update User"]

i = 1;

print "Available options:"
for menuEntry in menuList:
    print i, menuEntry
    i+=1

selectedEntry = 0;

while ((selectedEntry <= 0) or (selectedEntry > len(menuList))):
    try:
        selectedEntry = int(raw_input("Please select an option from the menu "))
        if((selectedEntry <= 0) or (selectedEntry > len(menuList))):
            print "Not a valid option"
    except(ValueError):
        print "That's not a valid entry"

print "You have selected", menuList[selectedEntry - 1]

if (selectedEntry == 1):
    readFile.doSomething()

elif (selectedEntry == 3):
    updateEntry.doSomething()

elif (selectedEntry == 2):
    generator.printXml()
Beispiel #54
0
import ReadFile
import os
import sys
if len(sys.argv)<2:
    print "Command Args error."
    print "Help: python ifc.py <filename> [-o <filetype>]"
    exit()
fname=sys.argv[1]
if(len(sys.argv)>2 and sys.argv[2]=='-o'):
    ty=sys.argv[3]
else:
    ty='png'
res=ReadFile.read(fname.strip(".ifc")+".ifc")

#for key,value in res.items():
    #print key,value
dot=file(fname+".dot","w")
dot.write("digraph classic0{\n")
for key,value in res.items():
    #print key,value
    i=value[1].find('#')
    while i>-1:
        strleft=value[1][i+1:]
        j1=strleft.find(',')
        j2=strleft.find(')')
        j=min(j1,j2) if (j1>-1 and j2>-1) else max(j1,j2)
        dot.write(key+"->"+strleft[:j]+"\n")
        #print (key+"->"+strleft[:j]+"\n")

        value[1]=strleft[j:]
        i=value[1].find('#')