Example #1
0
    def __init__(self):

        #Se almacena el nombre del archivo .xml donde se
        #almacenan los nombres de todas las técnicas con
        #sus parámetros que se encuentran disponibles para el usuario.
        self.__features_filename = "Features.xml"

        #Se guarda el nombre del archivo .xml que contiene
        #los M.O.P.'s disponibles para el usuario.
        #Un M.O.P. (Multi-Objective Problem) es un conjunto de variables
        #de decisión y funciones objetivo cuyo resultado está bien
        #estudiado, se utiliza principalmente para comprobar que el
        #funcionamiento del proyecto es el óptimo y además proveer
        #al usuario de una alternativa rápida y concisa para utilizar
        #el proyecto.
        self.__mop_examples_filename = "MOPExamples.xml"

        #A continuación se toma el nombre del archivo que almacena las
        #expresiones especiales de Python.
        #Esto sucede porque en ocasiones hay algunas funciones o constantes
        #especiales que el intérprete de Python no comprende directamente,
        #por ello es que se necesita establecer una relación entre las
        #expresiones que ingresa el usuario y su equivalente en Python.
        #Por ello es que al crear o evaluar funciones objetivo se debe hacer
        #uso de estas expresiones.
        self.__python_expressions_filename = "PythonExpressions.xml"

        #Se obtiene una instancia de la clase que opera con archivos
        #.xml.
        self.__parser = XMLParser()

        #Se guarda una instancia de la clase que verifica y convierte
        #apropiadamente los datos que el usuario ingresa para ejecutar
        #algún algoritmo M.O.E.A. (Multi-Objective Evolutionary Algorithm).
        self.__verifier = Verifier()
Example #2
0
def learnPerceptrons():
    MULTI = False
    HEIGHT = 50
    WIDTH = 50
    ENTRANCES = HEIGHT * WIDTH
    xmlParser = XMLParser()
    examples = xmlParser.getAllExamples()
    print("Got examples")
    perceptrons = []
    for i in range(HEIGHT):
        row = []
        for j in range(WIDTH):
            perc = Perceptron(i, j, examples, ENTRANCES)
            row.append(perc)
        perceptrons.append(row)
    print("Created perceptrons")
    beforeTime = time.process_time()
    if MULTI:
        print("Created pool")
        percPool = PerceptronPool(perceptrons, examples)
        perceptrons = percPool.learnPerc()
    else:
        for row in perceptrons:
            print("processing row %s" % str(perceptrons.index(row)))
            for perc in row:
                perc.learn()
    learnTime = elapsed_time = time.process_time() - beforeTime
    print("LearnTime : " + str(learnTime))

    xmlParser.setWeights(perceptrons)
Example #3
0
 def get(self):
     xmlParser = XMLParser()
     opened = xmlParser.open(self.OPTIONS_FILE)
     
     if(opened == True):
         rootNode = None
         if(xmlParser.hasRoot("Logging") == False):
             rootNode = xmlParser.createRoot("Logging")
         else:
             rootNode = xmlParser.root("Logging")
         
         # logging level
         self.level = xmlParser.child(rootNode, "Level").attribute("val")
         
         # status strategy
         if(xmlParser.child(rootNode, "StatusStrategy").attribute("type") == "database"):
             self.exportStatusDB = True
         else:
             self.exportStatusDB = False
         
         # description strategy
         if(xmlParser.child(rootNode, "DescriptionStrategy").attribute("type") == "xml"):
             self.exportDescriptionXML = True
         else:
             self.exportDescriptionXML = False
     
         xmlParser.close()
def create_new_hero(hero_xml_element):
    parser = XMLParser()
    id = hero_xml_element.getAttribute('id')
    information = parser.create_info_object_with_attributes(
        hero_xml_element, Hero.keys)
    new_hero = Hero(id, information)
    return new_hero
Example #5
0
def manuallySegmentDisparities():

    # Define Source Directories
    src_dir_anno = '../data/img/terra/405late_20161011194413_3_116_lb'
    src_dir_left = '/media/paloma/Data1/Linux_Data/TERRA/texas_field_tests/20161011/CS_405late_2016-10-11-19-44-13_PIF3_116_lb/qc_l_tr/rectified'
    src_dir_right = '/media/paloma/Data1/Linux_Data/TERRA/texas_field_tests/20161011/CS_405late_2016-10-11-19-44-13_PIF3_116_lb/qc_r_tl/rectified'

    # Read Source File Paths into alist
    src_xmlfiles = collectFilePaths(src_dir_anno, '.xml')
    src_imgfiles = collectFilePaths(src_dir_anno, '.jpg')
    src_imgfiles_left = collectFilePaths(src_dir_left, '.jpg')
    src_imgfiles_right = collectFilePaths(src_dir_right, '.jpg')

    # Source Image Checks
    assert (len(src_xmlfiles) == len(src_imgfiles)
            ), "number of image and annotation files should be equal"
    assert (len(src_imgfiles_left) == len(src_imgfiles_right)
            ), "number of left and right images should be equal"

    # Objects and Classes being called
    stemXMLParser = XMLParser('stem')
    dispComputer = DisparityComputer()
    comImgOps = CommonImageOperations()

    # Define Destination Directories
    dest_img_left = '/home/paloma/code/OpenCVReprojectImageToPointCloud/CS_405late_2016-10-11-19-44-13_PIF3_116_lb/rgb-image-'
    dest_disp = '/home/paloma/code/OpenCVReprojectImageToPointCloud/CS_405late_2016-10-11-19-44-13_PIF3_116_lb/disparity-image-'

    file_idx = 0
    for (xmlfile, imgfile, imgfile_right) in zip(src_xmlfiles, src_imgfiles,
                                                 src_imgfiles_right):

        print 'File Idx : ' + str(file_idx)

        xmlroot = (ET.parse(xmlfile)).getroot()
        img = cv2.imread(imgfile)
        img_left = cv2.imread(imgfile, cv2.CV_LOAD_IMAGE_GRAYSCALE)
        img_right = cv2.imread(imgfile_right, cv2.CV_LOAD_IMAGE_GRAYSCALE)

        mask_stem = stemXMLParser.getLabelMask(img, xmlroot)
        (disp_left, disp_left_fgnd,
         img_fgnd) = dispComputer.getDisparity(img_left, img_right)

        img_left = comImgOps.cropImage(img_left,
                                       numrows_crop=45,
                                       numcols_crop=35)
        disp_left = comImgOps.cropImage(disp_left,
                                        numrows_crop=45,
                                        numcols_crop=35)
        mask_stem = comImgOps.cropImage(mask_stem,
                                        numrows_crop=45,
                                        numcols_crop=35)

        cv2.imwrite(dest_img_left + str(file_idx) + '.ppm',
                    img_left * mask_stem[:, :, 1])
        cv2.imwrite(dest_disp + str(file_idx) + '.pgm',
                    disp_left * mask_stem[:, :, 1])

        file_idx = file_idx + 1
Example #6
0
 def __init__(self, gen=None): # Override
     XMLParser.__init__(self)
     if gen is None:
         gen = TALGenerator()
     self.gen = gen
     self.nsStack = []
     self.nsDict = {XML_NS: 'xml'}
     self.nsNew = []
Example #7
0
 def __init__(self, gen=None):  # Override
     XMLParser.__init__(self)
     if gen is None:
         gen = TALGenerator()
     self.gen = gen
     self.nsStack = []
     self.nsDict = {XML_NS: 'xml'}
     self.nsNew = []
Example #8
0
    def __init__(self, parent=None):
        super(MainWidget, self).__init__(parent)

        self.xmlParser = XMLParser()
        self.examples = self.xmlParser.getAllExamples()
        self.currentExampleIndex = 0
        self.currentExample = self.examples[self.currentExampleIndex]
        self.hopfield = HopfieldNet(WIDTH, HEIGHT)
        self.hopfield.setWeights(self.xmlParser.getWeights())

        self.setupUI()
    def __init__(self) :
        XMLParser.__init__(self)
	self.dimensionsNode = None
	self.objectClassNode = None
	self.vacuumIDNode = None
	self.probSuccessNode = None
        self.xPosNode = None;
        self.yPosNode = None;
	self.vacuumID = -1
        self.xPos = None
        self.yPos = None
Example #10
0
 def learn(self, examples):
     for example in examples:
         convExample = []
         for row in example:
             convExample.extend(row)
         self.convExamples.append(np.array(convExample))
     for i in range(len(self.convExamples[0])):
         for j in range(len(self.convExamples[0])):
             wij = 0
             if i != j:
                 for example in self.convExamples:
                     wij += example[i] * example[j]
             self.weights[i][j] = wij
     xmlParser = XMLParser()
     xmlParser.setWeights(self.weights)
    def __init__(self) :
	XMLParser.__init__(self)
	self.setMyInformationType(self.MESSAGE_EXTERNAL_PARAMETER);
	self.dimensionsNode = None
	self.objectClassNode = None


        # Initialize the list of parameters that will be defined in
        # this XML tree. This is a list of things that will be
        # defined. Each entry in the list is a list of information
        # used to define a parameter.
        #
        #    An entry in the previous list has the following form:
        #        [parameter type (ex: DUST_RATE), parameter value (ex: 0.2)]
        #
        self.parameterList = []
Example #12
0
	def collectTasks(self):
		xmlParser = XMLParser()
		opened = xmlParser.open(self.TASKS_FILE)
		taskNames = []
		
		if(opened == True):
			taskNode = xmlParser.root("Task")
			
			while(taskNode.isNull() == False):
				name = taskNode.firstChildElement("Name").attribute("val")
				taskNames.append(name)
				taskNode = taskNode.nextSiblingElement("Task")

			xmlParser.close()
		
		return taskNames
    def getCollectionContentInfo(link, typ='all', start=0, maxnumber=500):
        sync = SugarSyncInstance.instance

        if typ in ['file', 'folder']:
            typ = '&type=%s' % typ
        else:
            typ = ''

        if link[:1] != '/':
            link = '/' + link

        response = sync.sendRequest(
            link + '?start=%i&max=%i%s' % (start, maxnumber, typ), {}, True,
            False)

        if response is not None:
            raw_data = response.read().decode('utf8')
            #print(raw_data)
            #data = XMLElement.parse(raw_data)
            data = XMLParser.parse(raw_data)

            return data

        else:
            return None
Example #14
0
def trim_comment():
    buf = ""
    fout = open("/home/b/xml_parse_time.txt", 'w')
    fmu = open("/home/b/xml_mutation_time.txt", 'w')
    for root, directories, files in os.walk("/home/b/libplist_xml/"):
        for f in files:
            print(f)
            types = []
            gl.error = 0
            gl.chunk = {}
            gl.code_fragments = {}
            try:
                start = time.time()
                with open(root + "/" + f, 'rb') as file:
                    bytes = file.read()
                    buf = codecs.decode(bytes, 'utf-8', 'strict')
                #print("@@@@@@@@@@@@@@@@@@@@@@@@\n"+str(buf))
                input = InputStream(buf)
                lexer = XMLLexer(input)
                stream = CommonTokenStream(lexer)
                parser = XMLParser(stream)
                tree = parser.document()
                gl.currentstream = stream
                visitor = XMLParserVisitor()
                visitor.visit(tree)
                end = time.time()
                #print(end-start)
                #print("$$$$$$$$$$$$$$$\n"+str(ret))
                fout.write(str(end - start) + "," + str(len(bytes)) + "\n")

                for type in gl.chunk.keys():
                    for interval in gl.chunk[type]:
                        if interval[0] < interval[1] and interval[0] > 0:
                            start = time.time()
                            rewriter = TokenStreamRewriter(stream)
                            rewriter.replaceRange(interval[0], interval[1],
                                                  "a")
                            ret = rewriter.getText("default")
                            end = time.time()
                            fmu.write(str(end - start) + "\n")
            except UnicodeDecodeError:
                continue
            except ValueError:
                continue
    fout.close()
    fmu.close()
Example #15
0
    def do_savefile(self, line):
        """savefile <xml-file>
        Saves XML data for people to specified <xml-file>
        e.g., savefile familytree.xml"""

        lstTokens = line.split()
        if len(lstTokens) == 1:
            dbgPrint(INF_DBG, ("CLI.do_savefile - %s" % lstTokens[0]))
            xmlParser = XMLParser()
            bSuccess, sSuccess, sFailure = xmlParser.saveFile(
                lstTokens[0],  # Output XML filename
                self.family)  # Family instance to populate from XML file
            print(sSuccess) if bSuccess else print(sFailure)
        else:
            print("savefile: invalid parameters (try 'help savefile')")

        return
Example #16
0
    def __init__(self):
        self.g_dss_url = 'https://dss.uc.rncb.ru:443'
        self.g_resourse = 'urn:cryptopro:dss:signserver:signserver'
        self.g_oauth_clientid = 'Test01'
        self.g_oauth_redirect_uri = 'urn:ietf:wg:oauth:2.0:oob:auto'
        self.g_debug = False
        self.g_username = ''
        self.g_password = ''
        self.g_auth_token = ''
        self.g_refresh_token = ''
        self.g_auth_refid = ''
        self.g_auth_refid_expires_at = ''
        self.g_auth_token_expires_at = ''

        self.logger = Logger()
        self.json_generator = JsonGenerator()
        self.xml_parser = XMLParser()
Example #17
0
 def __init__(self, parent=None):
     super(MainWidget, self).__init__(parent)
     
     self.xmlParser = XMLParser()
     self.examples = self.xmlParser.getAllExamples()
     self.currentExampleIndex = 0
     self.currentExample = self.examples[self.currentExampleIndex]
     self.percInfo = self.xmlParser.getAllPerceptrons()
     self.perceptrons = []
     for i in range(HEIGHT):
         row = []
         for j in range(WIDTH):
             perc = Perceptron(i,j, self.examples, ENTRANCES)
             perc.setWeights(newWeights = self.percInfo[i][j][1], newTheta = self.percInfo[i][j][0])
             row.append(perc)
         self.perceptrons.append(row)
     
     self.setupUI()
Example #18
0
    def __init__(self, parent=None):
        super(MainWidget, self).__init__(parent)

        self.isCurrExProper = False
        self.pixelMap = np.array([-1.0 for i in range(ENTRANCES)])
        self.currentAdalineIndex = 0

        self.xmlParser = XMLParser()
        self.examples = self.xmlParser.getAllExamples()

        self.adalines = [
            Adaline(myDigit=i, examples=self.examples, weightsCount=ENTRANCES)
            for i in range(PERCEPTRONS)
        ]
        #for perc in self.adalines:
        #    perc.setWeights(self.xmlParser.getWeights(perc.getMyDigit()))

        self.setupUI()
 def __init__(self):
     from Record import Record
     self._record = Embedded_Record(XMLParser.parseReportUserInput(self.__class__.__name__))
     self._record.__class__ = Record
     self._content = ""
     self._view = None
     self.autoRefreshMillis = 0
     self.fontSize = 7
     self.session = Embedded_Record()
     self.reportid = id(self)
Example #20
0
    def __init__(self, parent=None):
        super(MainWidget, self).__init__(parent)

        self.isCurrExProper = False
        self.pixelMap = np.array([-1.0 for i in range(ENTRANCES)])

        self.xmlParser = XMLParser()
        self.examples = self.xmlParser.getAllExamples()

        self.perceptrons = [
            Perceptron(myDigit=i,
                       examples=self.examples,
                       weightsCount=ENTRANCES) for i in range(PERCEPTRONS)
        ]
        for perc in self.perceptrons:
            perc.setWeights(self.xmlParser.getWeights(perc.getMyDigit()),
                            self.xmlParser.getTheta(perc.getMyDigit()))

        self.setupUI()
Example #21
0
	def __init__(self, filename):
		xml = XMLParser().parsefile(filename)
		self._name = xml["name"]
		self._gridlen = int(xml["grid"])
		self._pieces = [ ]
		for piece in xml.piece:
			(x, y, z) = (int(piece["x"]), int(piece["y"]), int(piece["z"]))
			if (x < 0) or (y < 0) or (z < 0):
				raise Exception("Coordinates in layout (%d, %d, %d) are smaller than zero." % (x, y, z))
			self._pieces.append(GridPiece(dx = x, dy = y, dz = z))
		self._pieces.sort(key = lambda tile: (tile.dx, tile.dz, tile.dy))
Example #22
0
    def do_loadfile(self, line):
        """loadfile <xml-file>
        Loads XML data for people from <xml-file>.
        Loading the file is idempotent. Thus, if data for any person
        already exists it will be overwritten.
        e.g., loadfile myfamilytree.xml"""

        dbgPrint(INF_DBG, "CLI.do_loadfile - entry")

        lstTokens = line.split()
        if len(lstTokens) == 1:
            xmlParser = XMLParser()
            bSuccess, sSuccess, sFailure = xmlParser.loadFile(
                lstTokens[0],  # XML file 
                self.family)  # Family instance to populate from XML file
            print(sSuccess) if bSuccess else print(sFailure)
        else:
            print("loadfile: invalid parameters (try help loadfile)")

        return
Example #23
0
 def __init__(self,cliente):
     self.heigth = 680
     self.width = 1024
     self.heigth_C = 680.0
     self.width_C = 1024.0
     self.heigth_V = float(self.heigth)
     self.width_V = float(self.width)
     XMLP  = XMLParser()
     XMLP.setMapaFile("mapFile")
     XMLP.setPlayersFile("playersFile")
     self.Game = XMLP.reconstruirGame(cliente.nick)
     self.Game.mapa.escalaX = 680.0/520.0
     self.Game.mapa.escalaY = 680.0/520.0
     self.Game.PosicionarPlayer(680,680)
     
     self.Cliente = cliente
     self.Cliente.setWindow(self)
     self.posX_chat = (780.0/self.width_V)*self.width
     self.posY_chat = (300.0 /self.heigth_V)*self.heigth
     self.window = sf.RenderWindow(sf.VideoMode(self.width, self.heigth), "BOMBERMAN")
     self.Evento = sf.Event()      
     self.window.SetFramerateLimit(60)
     self.CrearChat()
     self.CrearCronometro()
     self.FondoCrono("Clock1")
     self.parche()
Example #24
0
	def __init__(self, filename):
		xml = XMLParser().parsefile(filename)
		self._matchingtiles = [ ]
		for matchingtiles in xml.matchingtiles:
			tiles = [ ]
			for tile in matchingtiles.tile:
				tiles.append(Tile(name = tile["name"], tileid = 100 + len(self._matchingtiles), face = tile["name"]))
			if len(tiles) == 1:
				tiles.append(tiles[0])
			elif len(tiles) == 2:
				pass
			else:
				raise Exception(NotImplemented)
			self._matchingtiles.append(tiles)
Example #25
0
	def removeTask(self, removeId):
		xmlParser = XMLParser()
		opened = xmlParser.open(self.TASKS_FILE)
		
		if(opened == True):
			taskNode = xmlParser.root("Task")
			taskId = 1
			
			while(str(taskId) != removeId):
				taskNode = taskNode.nextSiblingElement("Task")
				taskId += 1

			xmlParser.removeRoot(taskNode)
			xmlParser.close()
Example #26
0
 def __init__(self, filename):
     xml = XMLParser().parsefile(filename)
     self._opcodes = []
     for opcode in xml.opcode:
         if opcode.getchild("encoding") is None:
             print(
                 "Warning: Opcode %s has no encoding specificed in line %d."
                 % (opcode["variant"], opcode.getlinenumber()))
             continue
         try:
             opcode = _Opcode(opcode)
             self._opcodes.append(opcode)
         except Exception as e:
             print("Opcode ignored, parsing error: %s" % (e))
     self._opcodes.sort(key=lambda x: (x.priority, x.name))
     self._opcodesbyname = {opcode.name: opcode for opcode in self._opcodes}
Example #27
0
def check_arguments():
    """
    Function that parses inserted arguments and assign them into designed attributes
    argument -i stands for input file
             -o stands for output file
    Function also checks if the input file is in xml or txt format
    """
    global input_file_name, output_file_name, parser

    argument_parser = argparse.ArgumentParser(
        description="XML/TXT parser of enrollment data.")

    required_named = argument_parser.add_argument_group('required arguments')
    required_named.add_argument("-i",
                                dest="input_file",
                                action="store",
                                help="Path to txt/xml input file",
                                required=True)
    argument_parser.add_argument("-o",
                                 dest="output_file",
                                 default=None,
                                 action="store",
                                 help="Path to output file. "
                                 "Default is vysledky-<input-file-name>")
    results = argument_parser.parse_args()

    if results.input_file.endswith(".xml"):
        parser = XMLParser(stats)
    elif results.input_file.endswith(".txt"):
        parser = TXTParser(stats)
    else:
        print("Unknown input file suffix! Terminating!")
        print(SCRIPT_ERROR)
        sys.exit(1)

    input_file_name = results.input_file
    if not results.output_file:
        last_directory_index = input_file_name.rfind('/') + 1
        output_file_name = "vysledky-%s.txt" % input_file_name[
            last_directory_index:-4]
    else:
        output_file_name = results.output_file
Example #28
0
    def read_data(self):
        # Read data from file
        timer = Timer("reading data")
        timer.start()
        parser = XMLParser()

        for filename in self.train_file_en:
            self.train_data_en += parser.parse(filename)
        for filename in self.unlabel_file_cn:
            self.unlabel_data_cn += parser.parse(filename)
        for filename in self.validation_file_cn:
            self.validation_data_cn += parser.parse(filename)
        for filename in self.test_file_cn:
            self.test_data_cn += parser.parse(filename)
        timer.finish()
Example #29
0
class Recipe():
    def __init__(self, xml_filename, metadata):
        self._xml = XMLParser().parsefile(xml_filename)
        self._meta = metadata
        self._shopping_list = self._create_shopping_list()

    def _create_shopping_list(self):
        slist = IngredientList("Shopping List", [], self._meta)
        for ingredient_list in self.ingredient_classes:
            slist += ingredient_list
        return slist

    @property
    def name(self):
        return self._xml["name"]

    @property
    def shopping_list(self):
        return self._shopping_list

    @property
    def ingredient_class_cnt(self):
        return len(
            list(node for node in self._xml.ingredients.getallchildren()
                 if node.getname() != "#cdata"))

    @property
    def ingredient_classes(self):
        for node in self._xml.ingredients.getallchildren():
            if node.getname() != "#cdata":
                yield IngredientList.from_xmlnode(node, self._meta)

    @property
    def serves(self):
        if self._xml.getchild("serves") is not None:
            return [(node["count"], self._meta.getservingname(node["value"]))
                    for node in self._xml.serves.option]

    @property
    def preparation(self):
        return self._xml.preparation
    def getFolderContents(link, typ = 'all', start = 0, maxnumber = 500):
        sync = SugarSyncInstance.instance

        if typ in ['file','folder']:
            typ = '&type=%s' % typ
        else:
            typ = ''
          
        if link[:1] != '/':
            link = '/'+link

        link = '/folder' + link

        response = sync.sendRequest(link+'/contents?start=%i&max=%i%s' % (start,maxnumber,typ), {}, True, False)
        if response is not None:
            raw_data = response.read().decode('utf8')
            data = XMLParser.parse(raw_data)

            return data
        else:
            return None
def get_all_3d_tracks(train, draw_tracks=False, plot_3d=False):

    tracklet_path = './kitti_raw_data'
    # tracklet_files = glob(tracklet_path + '*/*/tracklet_labels.xml') # use this to use all files
    tracklet_files = get_desire_track_files(tracklet_path, train)

    drive_list = []
    track_list = []
    all_3d_tracks = []

    for tracklet_file in tracklet_files:
        parsed = XMLParser.parse(tracklet_file)
        track_keys = parsed[0].keys()

        oxt_path = tracklet_file.replace('tracklet_labels.xml',
                                         'oxts/data/*.txt')
        cur_drive = Drive(oxt_path)
        #print(cur_drive)
        drive_list.append(cur_drive)

        for track_key in track_keys:
            #print(track_key)
            coords = parsed[0][track_key]
            frame_interval = parsed[1][track_key]
            tracklet = Tracklet(coords, track_key, tracklet_file,
                                frame_interval, cur_drive)
            track_list.append(tracklet)
            all_3d_tracks.append(tracklet.get_track_coords_xyz())

        if draw_tracks:
            '''
            Set to True to plot the tracks
            '''
            ax = cur_drive.show_pose(plot_3d=plot_3d)
            drive_tracks = get_drive_tracks(track_list, cur_drive)
            for t in drive_tracks:
                t.show_coords_with_pose(ax, plot_3d=plot_3d)
            # ax.view_init(90, 0)
            #plt.show()
    return all_3d_tracks, drive_list, track_list
Example #32
0
from XMLParser import XMLParser

xmlparser = XMLParser()

xml_root = xmlparser.loads(open('XMLParser/test.xml', 'r').read())

print(xml_root)  # represents the root object
Example #33
0
    def __init__(self,A=None) :
        XMLParser.__init__(self)
        self.setArray(A)
	self.dimensionsNode = None
	self.objectClassNode = None
	self.arrayNode = None
Example #34
0
    def save(self):
        xmlParser = XMLParser()
        opened = xmlParser.open(self.TASKS_FILE)
        
        if(opened == True):
            rootNode = xmlParser.createRoot("Task")
            rootNode.setAttribute("type", "export")
            
            # name
            xmlParser.createChild(rootNode, "Name").setAttribute("val", self.__name)
            
            # files
            for f in self.__files:
                e = xmlParser.createChild(rootNode, "File")
                e.setAttribute("source", "local")
                e.setAttribute("path", f)
            
            # from
            xmlParser.createChild(rootNode, "From").setAttribute("date", self.__from)

            # until
            xmlParser.createChild(rootNode, "Until").setAttribute("date", self.__until)

            # input
            xmlParser.createChild(rootNode, "Input").setAttribute("val", self.__input)
            
            # output
            for o in self.__output:
                xmlParser.createChild(rootNode, "Output").setAttribute("val", o)
            
            # only index file
            if(self.__onlyIndexFile == True):
                xmlParser.createChild(rootNode, "OnlyIndexFile").setAttribute("val", "true")
            else:
                xmlParser.createChild(rootNode, "OnlyIndexFile").setAttribute("val", "false")

            # export directory
            xmlParser.createChild(rootNode, "ExportDir").setAttribute("path", self.__export_dir)
            
            xmlParser.close()
Example #35
0
    def save(self):
        xmlParser = XMLParser()
        opened = xmlParser.open(self.OPTIONS_FILE)
        
        if(opened == True):
            rootNode = None
            if(xmlParser.hasRoot("Logging") == False):
                rootNode = xmlParser.createRoot("Logging")
            else:
                rootNode = xmlParser.root("Logging")

            # logging level
            xmlParser.child(rootNode, "Level").setAttribute("val", self.level)
            
            # status strategy
            s = xmlParser.child(rootNode, "StatusStrategy")
            xmlParser.removeChild(rootNode, s)
            if(self.exportStatusDB == True):
                xmlParser.createChild(rootNode, "StatusStrategy").setAttribute("type", "database")
        
        
            # description strategy
            d = xmlParser.child(rootNode, "DescriptionStrategy")
            xmlParser.removeChild(rootNode, d)
            if(self.exportDescriptionXML == True):
                xmlParser.createChild(rootNode, "DescriptionStrategy").setAttribute("type", "xml")
            
            xmlParser.close()
Example #36
0
 def __init__(self, controller):
     threading.Thread.__init__(self)
     self.controller = controller
     self.html_handler = SeriesInfo()
     self.xml_handler = XMLParser()
     self.db_handler = Database()
Example #37
0
                        edit["right"] = int(attrs["x2"])
                        edit["bottom"] = int(attrs["y2"])

                    elif self.ifIs("chars"):
                        pass
                #assert( contains["start","end","left","top","right","bottom"], edit)
                yield edit

            elif self.ifIs("/element", "EDL"):
                return

    def ifIs(self, *args):
        return self.token[:len(args)] == args


if __name__ == "__main__":
    from Kamaelia.Chassis.Pipeline import Pipeline
    from Kamaelia.Chassis.Graphline import Graphline
    from Kamaelia.Util.Console import ConsoleEchoer
    from XMLParser import XMLParser

    from Kamaelia.File.Reading import RateControlledFileReader

    Pipeline(
        RateControlledFileReader("TestEDL.xml", readmode="lines",
                                 rate=1000000),
        XMLParser(),
        EDLParser(),
        ConsoleEchoer(),
    ).run()
Example #38
0
 def __init__(self) :
     XMLParser.__init__(self)
     self.setMyInformationType(XMLParser.CHECK_INCOMING);
Example #39
0
 def __init__(self, xml_filename, metadata):
     self._xml = XMLParser().parsefile(xml_filename)
     self._meta = metadata
     self._shopping_list = self._create_shopping_list()
Example #40
0
def time():
    return strftime("%Y-%m-%d %H:%M:%S")

#delete output folder
shutil.rmtree("out", ignore_errors=True)

inputpath = sys.argv[1]
print(time()+" ==================================================")
print(time()+" ===================Process start==================")
print(time()+" ==================================================")
print(time()+" input file: " + inputpath)

#parse XML to get all instances
print(time()+" Parsing XML...")
xmlparser = XMLParser()
xmlparser.parse(inputpath)
instances_text_raw = xmlparser.get_raw_text()           #instances_raw contains the (context)entire text between context tags in xml file
instances_text_clean = xmlparser.get_clean_text()       #instances_clean contains the text between context tags in xml file but this text is cleaned-> extra symbols are removed
instances_data_old = xmlparser.get_instances_data()     #instances_data_old contains instance ids and sense ids. Use it to generate key file.
targetword = xmlparser.get_targetword()
print(time()+" Parsing XML finish.")
print(time()+" target word: " + targetword)
print(time() + " "+str(len(instances_text_raw))+" instances found.")

#cluster instances
print(time()+" Clustering instances...")
sense_cluster = SenseCluster()
sense_cluster.cluster(instances_text_clean)
clusters = sense_cluster.get_clusters()
dimensions = sense_cluster.get_dimensions()
    "-gendir",
    metavar="path",
    type=str,
    help=
    "Input directory where generator file are located (default is %(default)s",
    default="generators/")
parser.add_argument(
    "-outdir",
    metavar="path",
    type=str,
    help="Output directory to put files in (default is %(default)s",
    default="outdir/")
args = parser.parse_args(sys.argv[1:])

# Load data from XML
xml = XMLParser().parsefile(args.infile)
hosts = set()
for host in xml.hosts.host:
    hosts.add(Host(xml, host))

networks = set()
for network in xml.networks.network:
    networks.add(Network(xml, network))

# Resolve that every host is in exactly one network
for host in hosts:
    contained = False
    for network in networks:
        if network.contains(host):
            contained = True
            host.setnetwork(network)
Example #42
0
    def __init__(self, parent=None):
        super(MainWidget, self).__init__(parent)

        self.xmlParser = XMLParser()
        self.setupUI()
Example #43
0
	def save(self):
		xmlParser = XMLParser()
		opened = xmlParser.open(self.TASKS_FILE)
		
		if(opened == True):
			rootNode = xmlParser.createRoot("Task")
			rootNode.setAttribute("type", "analyze")
			
			# name
			xmlParser.createChild(rootNode, "Name").setAttribute("val", self.__name)
			
			# files
			for f in self.__files:
				e = xmlParser.createChild(rootNode, "File")
				e.setAttribute("source", "local")
				e.setAttribute("path", f)
			
			# output
			for o in self.__output:
				xmlParser.createChild(rootNode, "Output").setAttribute("val", o)
			
			# override
			if(self.__duplicate == True):
				xmlParser.createChild(rootNode, "Duplicate").setAttribute("val", "true")
			else:
				xmlParser.createChild(rootNode, "Duplicate").setAttribute("val", "false")

			xmlParser.close()
Example #44
0
class UpdateSeries(threading.Thread):
    """Update the series at startup"""

    def __init__(self, controller):
        threading.Thread.__init__(self)
        self.controller = controller
        self.html_handler = SeriesInfo()
        self.xml_handler = XMLParser()
        self.db_handler = Database()

    def run(self):
        self.controller.updateStatus('updating series')
        self.getSeriesUpdates()
        self.controller.updateStatus('done updating series')

    def getServerTime(self):
        """Get the current time from the server

        @return: int - time in seconds

        """
        time_xml = self.html_handler.getServerTime()
        time_sec = self.xml_handler.extractTime(time_xml)

        return int(time_sec)

    def writeLastUpdateTime(self):
        """Write the current time to the db

        """
        time = self.getServerTime()
        self.db_handler.writeTime(time)

    def getSeriesUpdates(self):
        """Fetch the new updates

        """
        last_update = self.db_handler.getLastUpdate()
        updates = self.html_handler.getUpdates(last_update)

        # List containing series and episode updates
        update_list = self.xml_handler.separateSeriesEpisodes(updates)

        # series ids we have locally in our db
        local_series = self.db_handler.getUniqueIDs()
        # episode ids we have locally in our db
        local_episodes = self.db_handler.getEpisodeIDs()

        # Only iterate over series, because we don't need episodes right now
        # update_list[0] contains series
        # update_list[1] contains episodes
        for series in update_list[0]:
            series_id = int(series)

            # update the info, if a remote series was updated, and found locally
            if series_id in local_series:
                self.updateInfo(series_id)

        for episode in update_list[1]:
            episode_id = int(episode)

            if episode_id in local_episodes:
                self.updateEpisode(episode_id)

        self.writeLastUpdateTime()

    def updateEpisode(self, episode_id):
        """Update the episode with the proper id

        """
        whole_data = self.html_handler.getSeriesInfo(episode_id)
        episode_data = self.xml_handler.getSeriesInfo(whole_data)

        self.db_handler.updateEpisodeDate(episode_id, episode_data[1])

    def filterSeasons(self, data):
        """Filter out the seasons, so we only have the seasons in the list

        @param data - list : list full of info
        @return: seasons - list : list of distinct seasons

        """
        seasons = []
        season_counter = 1

        for element in data:
            season = int(element[0])

            if season == season_counter:
                seasons.append(season)
                season_counter += 1

        return seasons

    def updateInfo(self, series_id):
        """Update the info of the local series

        @param series_id - int : id of series
        @return: nothing

        """
        whole_data = self.html_handler.getSeriesInfo(series_id)
        series_data = self.xml_handler.getSeriesInfo(whole_data)

        local_seasons = self.getLocalSeasons(series_id)
        remote_seasons = self.extractSeasons(series_data)

        new_seasons = self.compareLocalRemote(local_seasons, remote_seasons)

        # If there are no new seasons, return
        if not new_seasons:
            return

        name = self.db_handler.getNameFromID(series_id)
        proper_data = self.prepareForDB(name, series_id, new_seasons, series_data)

        self.db_handler.writeData(proper_data)

    def prepareForDB(self, name, series_id, new_seasons, remote_data):
        """Prepare the data to be handled properly by the db

        @param name - string : Name of the series
        @param new_seasons - list : List of seasons to add
        @return: Final list, which the db can process

        """
        episodes = []

        for season in new_seasons:
            for e in remote_data:
                if season == int(e[0]):
                    episodes.append(e)

        whole_data = self.constructDBData(name, series_id, episodes)

        return whole_data

    def extractSeasons(self, data):
        """Extract only the season information

        @param data - list : list of info
        @return: seasons - list :

        """
        seasons = []

        for e in data:
            season = int(e[0])
            if season not in seasons:
                seasons.append(season)

        return seasons

    def constructDBData(self, name, series_id, data):
        """Concstruct the list, so that the db can write it properly

        @param name @todo
        @param data @todo
        @return: @todo

        """
        series_data = []

        for e in data:
            series_data.append([name, series_id] + e)

        return series_data

    def getLocalSeasons(self, series_id):
        """Get the local seasons already in db

        @param id @todo
        @return: @todo

        """
        seasons = self.db_handler.getSeasons(series_id)

        return seasons

    def compareLocalRemote(self, local, remote):
        """Compare both local and remote seaons. If there is a remote season
        not present locally, add it to the db

        @param local list of localy available seasons
        @param remote list of remotely available seasons
        @return: @todo

        """
        # compare the 2 series seasons and add the new seasons to the array
        new_seasons = list(set(remote) - set(local))

        return new_seasons
Example #45
0
from XMLParser import XMLParser as parser
import XMLParser
# import XMLParser

dummy_object = XMLParser.XMLParserObject(
    'D:\Guru\Project\Project Tasks\VBAMacro\ClearEmptyPages\Macro Enabled Word Document - Copy\word\document.xml'
)
string_object = parser.xmlToString(parser_object=dummy_object)
# print(string_object)
parser.generateXmlObject(parser_object=dummy_object)
tag_elements = parser.findElementsByTagName(parser_object=dummy_object,
                                            tag_name='w')
for element in tag_elements:
    print(element)
    def get_image(self, index):
        if index < 0 or index > len(self.images):
            return
        return self.images[index]

    def get_image_index(self, cuda_version_string, cudnn_version_string, caffe_installed, tensorflow_installed):
        """
        get the index of the item we looking for.
        If we won't find. the return -1.
            Paratmeter : the parser who have the flag value
        """
        result_index = -1
        for index, image in enumerate(self.images):
            if image.cuda_strings_version == cuda_version_string and \
                image.cudnn_strings_version == cudnn_version_string:
                if (caffe_installed == False or (caffe_installed == True and image.caffe_installed == True)) and \
                    (tensorflow_installed == False or (tensorflow_installed == True and image.tensorflow_installed == True)):
                    return index
        return result_index

if __name__ == "__main__":
    dm = Docker_Monitor('localhost', 'root', 'tracing')
    dm.get_local_images(Mysql_wrapper("localhost", "root", "tracing"))
    print(dm.images[0].__dict__)
    parser = XMLParser("DockerConfig.xml")
    parser.parse()
    index = dm.get_image_index(parser)
    print(index)
    print (dm.get_image(index).__dict__)
Example #47
0
class MainWidget(QWidget):
    def __init__(self, parent=None):
        super(MainWidget, self).__init__(parent)

        self.xmlParser = XMLParser()
        self.examples = self.xmlParser.getAllExamples()
        self.currentExampleIndex = 0
        self.currentExample = self.examples[self.currentExampleIndex]
        self.hopfield = HopfieldNet(WIDTH, HEIGHT)
        self.hopfield.setWeights(self.xmlParser.getWeights())

        self.setupUI()

    def setupUI(self):
        self.setMinimumSize(MAX_WINDOW * 2 + 200, MAX_WINDOW + 20)

        # user pixel matrix
        self.wid1 = UserPaint(self)
        self.wid1.setGeometry(10, 10, MAX_WINDOW, MAX_WINDOW)
        self.wid1.show()
        self.wid1.setAutoFillBackground(True)

        # net pixel matrix

        self.wid2 = NetPaint(self)
        self.wid2.setGeometry(MAX_WINDOW + 100, 10, MAX_WINDOW, MAX_WINDOW)
        self.wid2.show()
        self.wid2.setAutoFillBackground(True)
        # add example

        self.nextExample = QPushButton(">>", self)
        self.nextExample.setGeometry(MAX_WINDOW + 20, 210, 60, 30)
        self.nextExample.clicked.connect(self.next)

        self.prevExample = QPushButton("<<", self)
        self.prevExample.setGeometry(MAX_WINDOW + 20, 240, 60, 30)
        self.prevExample.clicked.connect(self.prev)

        self.check = QPushButton("CHECK", self)
        self.check.setGeometry(MAX_WINDOW + 20, 270, 60, 30)
        self.check.clicked.connect(self.test)

        self.saveExample = QPushButton("SAVE", self)
        self.saveExample.setGeometry(MAX_WINDOW + 20, 330, 60, 30)
        self.saveExample.clicked.connect(self.save)

        self.clearExample = QPushButton("CLEAR", self)
        self.clearExample.setGeometry(MAX_WINDOW + 20, 500, 60, 30)
        self.clearExample.clicked.connect(self.clear)

        # show test result
        #testLabel = QLabel("<b><FONT SIZE = 4>Rezultat klasyfikacji: </b>", self)
        #testLabel.setGeometry(MAX_WINDOW + 50, 100,250 , 30)

    def next(self):
        self.currentExampleIndex = (self.currentExampleIndex + 1) % len(
            self.examples)
        self.currentExample = self.examples[self.currentExampleIndex]
        self.wid1.setPixelMap(self.currentExample)

    def prev(self):
        self.currentExampleIndex = (self.currentExampleIndex + 1) % len(
            self.examples)
        self.currentExample = self.examples[self.currentExampleIndex]
        self.wid1.setPixelMap(self.currentExample)

    def test(self):
        pixelMap = self.wid1.getPixelMap()
        resultMap = self.hopfield.associate(pixelMap)
        self.wid2.setPixelMap(resultMap)

    def save(self):
        self.xmlParser.addExample(self.wid1.getPixelMap())

    def clear(self):
        self.wid1.clear()
Example #48
0
    def save(self):
        xmlParser = XMLParser()
        opened = xmlParser.open(self.OPTIONS_FILE)
        
        if(opened == True):
            rootNode = None
            if(xmlParser.hasRoot("Database") == False):
                rootNode = xmlParser.createRoot("Database")
            else:
                rootNode = xmlParser.root("Database")

            xmlParser.child(rootNode, "DBDriver").setAttribute("val", self.driver)
            xmlParser.child(rootNode, "DBHost").setAttribute("val", self.host)
            xmlParser.child(rootNode, "DBName").setAttribute("val", self.name)
            xmlParser.child(rootNode, "DBUser").setAttribute("val", self.user)
            xmlParser.child(rootNode, "DBPass").setAttribute("val", self.password)
        
            xmlParser.close()
Example #49
0
	def save(self):
		xmlParser = XMLParser()
		opened = xmlParser.open(self.TASKS_FILE)
		
		if(opened == True):
			rootNode = xmlParser.createRoot("Task")
			rootNode.setAttribute("type", "group")
			
			# name
			xmlParser.createChild(rootNode, "Name").setAttribute("val", self.__name)
			
			# files
			for f in self.__files:
				e = xmlParser.createChild(rootNode, "File")
				e.setAttribute("source", "local")
				e.setAttribute("path", f)
			
			# from
			xmlParser.createChild(rootNode, "From").setAttribute("date", self.__from)

			# until
			xmlParser.createChild(rootNode, "Until").setAttribute("date", self.__until)

			# algorithm
			xmlParser.createChild(rootNode, "Algorithm").setAttribute("name", self.__algorithm)
			
			# context
			for c in self.__context.keys():
				n = xmlParser.createChild(rootNode, "Context")
				n.setAttribute("name", c)
				n.setAttribute("val", self.__context[c])
			
			# input
			xmlParser.createChild(rootNode, "Input").setAttribute("val", self.__input)
			
			# output
			for o in self.__output:
				xmlParser.createChild(rootNode, "Output").setAttribute("val", o)
			
			# override
			if(self.__override == True):
				xmlParser.createChild(rootNode, "Override").setAttribute("val", "true")
			else:
				xmlParser.createChild(rootNode, "Override").setAttribute("val", "false")

			xmlParser.close()
Example #50
0
    def save(self):
        xmlParser = XMLParser()
        opened = xmlParser.open(self.OPTIONS_FILE)
        
        if(opened == True):
            rootNode = None
            if(xmlParser.hasRoot("CoreOptions") == False):
                rootNode = xmlParser.createRoot("CoreOptions")
            else:
                rootNode = xmlParser.root("CoreOptions")

            xmlParser.child(rootNode, "GraphsDir").setAttribute("path", self.graphs_dir)
            xmlParser.child(rootNode, "TmpPcapDir").setAttribute("path", self.tmp_pcap_dir)
            xmlParser.child(rootNode, "TcpflowParams").setAttribute("val", self.tcpflow_params)
            xmlParser.child(rootNode, "EmulationSteps").setAttribute("val", self.emulation_steps)
            if(self.skip_big_files == True):
                xmlParser.child(rootNode, "SkipBigFiles").setAttribute("val", "true")
            else:
                xmlParser.child(rootNode, "SkipBigFiles").setAttribute("val", "false")
            xmlParser.child(rootNode, "SkipBigFiles").setAttribute("size", self.skip_big_files_size)
            if(self.skip_broken_samples == True):
                xmlParser.child(rootNode, "SkipBrokenSamples").setAttribute("val", "true")
            else:
                xmlParser.child(rootNode, "SkipBrokenSamples").setAttribute("val", "false")
            xmlParser.child(rootNode, "SkipBrokenSamples").setAttribute("size", self.skip_broken_samples_size)
            if(self.skip_empty_samples == True):
                xmlParser.child(rootNode, "SkipEmptySamples").setAttribute("val", "true")
            else:
                xmlParser.child(rootNode, "SkipEmptySamples").setAttribute("val", "false")
            if(self.skip_nosyscall_noloop_samples == True):
                xmlParser.child(rootNode, "SkipNoSyscallNoLoopSamples").setAttribute("val", "true")
            else:
                xmlParser.child(rootNode, "SkipNoSyscallNoLoopSamples").setAttribute("val", "false")
        
            xmlParser.close()
Example #51
0
 def get(self):
     xmlParser = XMLParser()
     opened = xmlParser.open(self.STATUS_FILE)
     
     if(opened == True):
         rootNode = None
         if(xmlParser.hasRoot("SystemStatus") == False):
             rootNode = xmlParser.createRoot("SystemStatus")
         else:
             rootNode = xmlParser.root("SystemStatus")
         
         self.version = xmlParser.child(rootNode, "Version").attribute("val")
         self.current_task = xmlParser.child(rootNode, "CurrentTask").attribute("name")
         self.last_error = xmlParser.child(rootNode, "LastError").attribute("desc")
         self.errors_num = xmlParser.child(rootNode, "ErrorsNum").attribute("val")
     
         xmlParser.close()
Example #52
0
            if currWellClassifiedCount > perc.bestResults['count']:
                perc.bestResults['count'] += currWellClassifiedCount
                perc.bestResults['weights'] = perc.currentWeights

            ex = perc.addFFT(randomExample["pixelMap"])
            ex = np.append(ex, [1.0], 0)

            perc.currentWeights += perc.eta * ERR * ex
            if iter % 100 == 0:
                perc.errors.append(perc.error())

        print('Digit: ' + str(perc.myDigit) + ' = ' +
              str(perc.bestResults['count']))
        perc.currentWeights = perc.bestResults['weights']
        return perc


if __name__ == '__main__':
    from XMLParser import XMLParser
    print("Start")
    xmlParser = XMLParser()
    examples = xmlParser.getAllExamples()
    adalines = [
        Adaline(myDigit=i, examples=examples, weightsCount=6 * 7)
        for i in range(10)
    ]
    pool = AdalinePool(adalines, examples)
    #pool.learnPerc()
    pool.learn(pool.adalines[0])
    print("Stop")
Example #53
0
    def __sendToAllBut__(self, data, nick):
        for i in self.clientes:
            if i != nick:
                self.__sendDataTo__(data, i)

    def __sendToTeam__(self, data, nick):
        teamMates = self.game.GetTeamMates(nick)
        for i in teamMates:
            self.__sendDataTo__(data, i)

    def __log__(self, msg):
        pass


if __name__ == "__main__":
    xmlP = XMLParser()
    xmlP.setMapaFile("mapFile")
    xmlP.setPlayersFile("playersInfo")
    game = xmlP.reconstruirGame()
    server = SocketServer()
    server.game = game
    server.start()
    print server.game.GetTeamMates("varus")
    while 1:
        x = raw_input("TYPE STOPSERVER TO STOP SERVER...\n")
        if x=="STOPSERVER":
            break
        elif x=="SENDMAPA":
            server.sendMap('currentGame3.xml')
        elif x == "SENDPLAYERS":
            server.sendPlayerList()