Esempio n. 1
0
def main():
    """Demonstrates the functionality of Converter.py by printing
    converted files output.

    Returns: 
    None
    """

    print Converter.Converter("test.md")
    print "\n\n\n\n\n"
    print Converter.Converter("readme.md")
Esempio n. 2
0
    def __init__(self,
                 svr_cost=32, svr_gamma=0.01, svr_epsilon=0.001, svr_intercept=2, svr_itr=100000, #SVR default
                 kapp_gamma=0.1, kapp_num=100, #KPCA
                 pls_compnum=50, #pls
                 sdc_weight=0.5, predict_weight=3, #IDW
                 lower_limit=10,
                 n_estimators=100,
                 n_jobs=1):
        '''yklearn constructor.

        Set some parameters and data for yklearn.
        '''
        if n_jobs <= 0:
            self.p = Pool()
        elif n_jobs > 1:
            self.p = Pool(n_jobs)
        self.weak_learners = []
        self.converters = []
        self.trainer = Trainer.Trainer()
        self.converters.append(Converter.Converter()) #one converter
        self.param_info = ParamInfo.ParamInfo(svr_cost, svr_gamma, svr_epsilon, svr_intercept, svr_itr,#SVR
                                              kapp_gamma, kapp_num, #KPCA
                                              pls_compnum, #pls
                                              sdc_weight, predict_weight, #IDW
                                              lower_limit,
                                              n_estimators,
                                              n_jobs)
        self.extraction_rate = [] #to evaluate
Esempio n. 3
0
 def from_lat_long(self, lat, long):
     if self.converter is None:
         self.converter = Converter.Converter([lat, long],
                                              type=Converter.LATLON)
     x, y = self.converter.LatLong2UTM(lat, long)
     self.x = x
     self.y = y
     return self
Esempio n. 4
0
 def from_UTM(self, x, y, zone_letter, zone_number):
     if self.converter is None:
         self.converter = Converter.Converter()
         self.converter.zone_letter = zone_letter
         self.converter.zone_number = zone_number
     self.x = x
     self.y = y
     return self
Esempio n. 5
0
    def __init__(self):
        self.conv = Converter.Converter()
        self.root = Tk()
        self.root.title("JPG background remover")
        self.frame = Frame(self.root)
        self.frame.grid(column=0, row=0, sticky=(N, E, W, S))

        self.in_filename = StringVar()
        self.in_image = None
        self.out_filename = StringVar()
        self.out_image = None
        self.last_out_filename = ""
        self.threshold = IntVar()
        self.use_color = IntVar()
        self.conv_image = None
        self.color = (255, 105, 180, 255)

        ttk.Label(self.frame, text="Input file").grid(row=1,
                                                      column=1,
                                                      sticky=N)
        ttk.Entry(self.frame, textvariable=self.in_filename,
                  width=50).grid(row=3, column=1, sticky=N)
        ttk.Button(self.frame, command=self.get_path,
                   text="Open file").grid(row=4, column=1, sticky=N)
        self.cnv_in_image = Canvas(self.frame, width=300, height=300)
        self.cnv_in_image.grid(row=2, column=1, sticky=N)

        ttk.Label(self.frame, text="Output file").grid(row=1,
                                                       column=2,
                                                       sticky=N)
        ttk.Entry(self.frame, textvariable=self.out_filename,
                  width=50).grid(row=3, column=2, sticky=N)
        ttk.Button(self.frame,
                   command=self.get_output_filename,
                   text="Set output file").grid(row=4, column=2, sticky=N)
        self.cnv_out_image = Canvas(self.frame, width=300, height=300)
        self.cnv_out_image.grid(row=2, column=2, sticky=N)

        ttk.Label(self.frame, text="Filter threshold").grid(row=5,
                                                            column=1,
                                                            sticky=N)
        ttk.Scale(self.frame, from_=0, to=254, orient=HORIZONTAL, length=280, variable=self.threshold)\
         .grid(row=5, column=2, sticky=N)

        ttk.Button(self.frame, command=self.convert,
                   text="Convert image").grid(row=6, column=1, sticky=N)
        ttk.Button(self.frame, command=self.save,
                   text="Save as png").grid(row=6, column=2, sticky=N)

        ttk.Checkbutton(self.frame,
                        text="Color Background",
                        variable=self.use_color).grid(row=7,
                                                      column=1,
                                                      sticky=N)
        ttk.Button(self.frame, command=self.get_color,
                   text="Choose Color").grid(row=7, column=2, sticky=N)

        self.frame.mainloop()
Esempio n. 6
0
    def from_gauss_krueger(self, right, height):
        if self.converter is None:
            self.converter = Converter.Converter([right, height],
                                                 type=Converter.GAUSSKRUGER)

        x, y = self.converter.GK2UTM(right, height)
        self.x = x
        self.y = y
        return self
Esempio n. 7
0
 def __init__(self):
     self.Math = Math
     self.lib = test_3d.lib
     self.ffi = test_3d.ffi
     self.max_tex_id = -1
     self.pygame = pygame
     self.map = None
     self.screen_size = (0, 0)
     self.screen = pygame.Surface
     self.Converter = Converter.Converter(self.lib, self.ffi)
     self.Object = Object
     self.EventSystem = EventSystem.EventSystem(self)
     self.Physics = Physics.Physics(self)
Esempio n. 8
0
     def test_changeToCsv(self):
          cv = Converter.Converter()
          readFile = '../../TestFile/BeforeConversion/before.xml'
          writeFile = '../../TestFile/AfterConversion/after.csv'

          cv.conversion(readFile, writeFile)

          with open(writeFile) as rf:
               resultValue = rf.read()

          expectedFilePath = '../../TestFile/ExpectedFile/expected.csv'
          with open(expectedFilePath) as xf:
               expectedValue = xf.read()

          self.assertEqual(expectedValue.strip(), resultValue.strip())
Esempio n. 9
0
    def test_changeToCsvToXml(self):
        cv = Converter.Converter()
        readFile = '../../TestFile/BeforeConversion/before.csv'
        firstWriteFile = '../../TestFile/AfterConversion/after.xml'
        secondWriteFile = '../../TestFile/AfterConversion/after.csv'

        #CSVへの変換
        cv.conversion(readFile, firstWriteFile)
        #XMLへの変換
        cv.conversion(firstWriteFile, secondWriteFile)

        with open(secondWriteFile) as rf:
            resultValue = rf.read()

        expectedFilePath = '../../TestFile/ExpectedFile/expected.csv'
        with open(expectedFilePath) as xf:
            expectedValue = xf.read()

        self.assertEqual(expectedValue.strip(), resultValue.strip())
Esempio n. 10
0
def record():
    form = AddRecordForm(request.form)
    form1 = Converter(request.form)
    print('The method is ' + request.method)

    if request.method == 'POST':
        if form.validate() == 0:
            print('All fields are required.')

        if request.form["btn"] == "Convert":
            convert = Convert(form1.heightconvert.data,
                              form1.weightconvert.data)
            flash('%d cm is %.2f m' %
                  (form1.heightconvert.data, convert.get_heightc()))
            flash('%d lbs is %.2f kg' %
                  (form1.weightconvert.data, convert.get_weightc()))

        elif request.form["btn"] == "Submit":
            recordList = {}
            db = shelve.open('fitness', 'c')

            try:
                recordList = db['Records']

            except:
                print("failed to open database")

            try:
                height = float(form.height.data)
                weight = float(form.weight.data)
                new_record = Record(height, weight, time.strftime("%d/%m/%Y"))
                recordList[session['user_name']] = new_record
                db['Records'] = recordList
                print(db['Records'])
                db.close()

            except ValueError:
                print('Failed to submit form')
                return redirect(url_for('record'))

            return redirect(url_for('summary'))

    return render_template('record.html', form=form)
Esempio n. 11
0
    def __init__(self,node,name,converter=None):
        

        self.name=name
        
        if converter==None:
            converter=Converter()
        symConverter=SchemConverter()

        self.modules=[]
        self.deviceparts= []
        devicesetsLst =[]
        symbolsHash = {}
        
        packages=node.find("packages").findall("package")
        if packages !=None:
            for package in packages:
                self.modules.append(Module(package,converter))
                
        devicesets=node.find("devicesets").findall("deviceset")
        if devicesets!=None:
            for deviceset in devicesets:
                ds = Deviceset(deviceset, symConverter)
                devicesetsLst.append(ds)

        symbols=node.find("symbols").findall("symbol")
        if symbols!=None and  len(devicesetsLst) != 0: #strange if not?
            for symbol in symbols:
                sn = symbol.get("name")
                if sn in symbolsHash:
                    print("The symbol with the same name %s already exists!" % sn)
                else:
                    symbolsHash[sn] = symbol
                    
            for deviceset  in devicesetsLst: #strange if not?
                #just iterater over all posible device packages
                for device in deviceset.getDevices():
                    #we have to create a number of symbols to match diffrent pin configurations
                    #the real name of device is <deviceset> name plus name of <device>
                    #symlink is just a scheme representation of the set of devices or devicessts 
                    device.setFullName(deviceset.name)
                    dp = DevicePart(device, symbolsHash, deviceset.getGates(), symConverter)
                    self.deviceparts.append(dp)
Esempio n. 12
0
from tkinter import *
from tkinter import ttk
from Converter import *

converter = Converter()

window = Tk()

w = 650
h = 300

w_screen = window.winfo_screenwidth()
h_screen = window.winfo_screenheight()

position_x = (w_screen/2) - (w/2)
position_y = (h_screen/2) - (h/2)

window.geometry(f'{w}x{h}+{int(position_x)}+{int(position_y)}')
window.configure(
    background='gray'
)
window.resizable(False, False)


def change_options_menu(event):
    converter.change_options_menu(drop_down_1, drop_down_2, drop_down_3)


def change_label_formula_text(event):
    converter.change_label_formula_text(
        label_formula, drop_down_1, drop_down_2, drop_down_3)
Esempio n. 13
0
def ePubConverter(base_path):
    import epub_conversion as Converter
    converter = Converter(base_path + "/")
    converter.convert("my_succinct_text_file.gz")
Esempio n. 14
0
def main(argv):    
    mem = virtual_memory().total / 1024.**3
    
    workdir = datadir = labelfile = deid = parser = parserdir = ctakessetup = utsname = utspw = \
    ctakesminmem = ctakesmaxmem = convert = model = feature = vec_represent = algorithm = \
    balanced_class = repeat = cv = rpdr = ''
    
    try:
        opts, args = getopt.getopt(argv, "w:d:l:i:p:q:s:n:o:e:g:c:m:f:v:a:b:r:k:x:h", \
        ["workdir=", "datadir=", "labelfile=", "deid=", "parser=", "parserdir=", "ctakessetup=", "utsname=", \
        "utspw=", "ctakesminmem=", "ctakesmaxmem=", "convert=", "model=", "feature=", "vec_represent=", \
        "algorithm=", "balancedclass=", "repeat=", "cv=", "rpdr=", "help"])
    except getopt.GetoptError:
        usage('pipeline.py -wd <workdir> -dd <datadir> -lf <labelfile> -d <T/F> -p <T/F> -pd <parserdir> -cset <T/F> -un <utsname> -upw <utspw> -mnm <ctakesminmem> -mxm <ctakesmaxmem> -c <convert> -m <T/F> -f <feature> -v <vec_represent> -a <algorithm> -bc <T/F> -r <repeat> -cv <cv> -h')
        sys.exit(2)
    
    for opt, arg in opts:
        if opt == ("-h", "--help"):
            usage('pipeline.py -wd <workdir> -dd <datadir> -lf <labelfile> -d <T/F> -p <T/F> -pd <parserdir> -cset <T/F> -un <utsname> -upw <utspw> -mnm <ctakesminmem> -mxm <ctakesmaxmem> -c <convert> -m <T/F> -f <feature> -v <vec_represent> -a <algorithm> -bc <T/F> -r <repeat> -cv <cv> -h')
            sys.exit()
        elif opt in ("-w", "--workdir"):
            workdir = arg
        elif opt in ("-d", "--datadir"):
            datadir = arg
        elif opt in ("-l", "--labelfile"):
            labelfile = arg
        elif opt in ("-i", "--deid"):
            deid = arg
        elif opt in ("-p", "--parser"):
            parser = arg
        elif opt in ("-q", "--parserdir"):
            parserdir = arg
        elif opt in ("-s", "--ctakessetup"):
            ctakessetup = arg
        elif opt in ("-n", "--utsname"):
            utsname = arg
        elif opt in ("-o", "--utspw"):
            utspw = arg
        elif opt in ("-e", "--ctakesminmem"):
            ctakesminmem = arg
        elif opt in ("-g", "--ctakesmaxmem"):
            ctakesmaxmem = arg
        elif opt in ("-c", "--convert"):
            convert = arg
        elif opt in ("-m", "--model"):
            model = arg
        elif opt in ("-f", "--feature"):
            feature = arg
        elif opt in ("-v", "--vec_represent"):
            vec_represent = arg
        elif opt in ("-a", "--algorithm"):
            algorithm = arg
        elif opt in ("-b", "--balancedclass"):
            balanced_class = arg
        elif opt in ("-r", "--repeat"):
            repeat = int(arg)
        elif opt in ("-k", "--cv"):
            cv = int(arg)
        elif opt in ("-x", "--rpdr"):
            xx = arg
    
    print 'Working directory        :', workdir
    print 'Data directory           :', datadir
    print 'Label file location      :', labelfile
    print 'Running deidentification :', deid
    print 'Running concept parser   :', parser
    print 'Concept parser directory :', parserdir
    print 'Setting up cTAKES        :', ctakessetup
    print 'UTS username             :'******'UTS password             :'******'cTAKES minimal memory    :', ctakesminmem
    print 'cTAKES maximal memory    :', ctakesmaxmem
    print 'Data conversion from     :', convert
    print 'Modeling                 :', model
    print 'Selected feature         :', feature
    print 'Vector representation    :', vec_represent
    print 'Algorithm                :', algorithm
    print 'Class balancing          :', balanced_class
    print 'Repeat time              :', repeat
    print 'k-fold cross-validation  :', cv

    if os.path.exists(workdir) == False:
        os.system("mkdir " + workdir + "; cd " + workdir + "; mkdir data; mkdir model; mkdir result; cd ..")
        
    os.chdir(workdir)
    
    if datadir == '' and 'xx' not in locals():
        datadir = workdir + 'data/'
        print "No data provided, use sample data"
        os.system("wget https://github.com/ckbjimmy/ckbjimmy.github.io/raw/master/files/sample.tar.gz; \
        wget https://raw.githubusercontent.com/ckbjimmy/ckbjimmy.github.io/master/files/label.txt; \
        tar -xzf sample.tar.gz; mv sample/ data/xml/; mv label.txt data/label.txt; rm sample.tar.gz")
        labelfile = datadir + 'label.txt'
        
    if deid == "T":
        try: 
            RunDeid(folder=datadir, deidDir=workdir + 'deid-1.1')
        except:
            print "Downloading deid package from physionet"
            os.chdir(workdir)
            os.system("wget https://www.physionet.org/physiotools/sources/deid/deid-1.1.tar.gz; \
        tar -xzf deid-1.1.tar.gz; rm deid-1.1.tar.gz; cd deid-1.1; rm *.txt; cd ..")
            try:
                RunDeid(folder=datadir, deidDir=workdir + 'deid-1.1')
            except:
                print "No free text files for deidentification"
                sys.exit(2)

    if parser == "ctakes":
        if ctakessetup == "T":
            if os.path.exists(parserdir):
                SetupCtakes(parserdir, utsname, utspw, ctakesminmem, ctakesmaxmem)
                RunCtakes(folder=datadir, ctakesDir=parserdir, erisOne=None)
            else:
                print "Please download cTAKES and assign directory"
                sys.exit(2)
        else:
            RunCtakes(folder=datadir, ctakesDir=parserdir, erisOne=None)
    
    if convert == "xml":
        try:
            Converter(workdir=workdir, folder=datadir + 'xml/', format=convert)
        except OSError:
            print "No XML output files inside the folder. Must add argument -p ctakes."
            sys.exit(2)
    elif convert == "txt" or convert == "res":
        Converter(workdir=workdir, folder=datadir, format=convert)
    elif convert == "cas":
        next
    elif convert == "rpdr":
        next

    if model == "T":
        if convert == "idash":
            MLPipeline(path=workdir, data=workdir + 'data/data.txt', label=workdir + 'data/label.txt', \
            vec=vec_represent, alg = algorithm, cwt=balanced_class, feature=feature, rep=repeat, k=cv)
        elif convert == "rpdr":
            rpdr_param = xx.split('+')
            RPDR(path=workdir, lab=rpdr_param[1], num=rpdr_param[2])
            MLPipeline(path=workdir, data=workdir + 'data/data.txt', label=workdir + 'data/label.txt', \
            vec=vec_represent, alg = algorithm, cwt=balanced_class, feature=feature, rep=repeat, k=cv)
        else:
            MLPipeline(path=workdir, data=workdir + 'data/data.txt', label=labelfile, \
            vec=vec_represent, alg = algorithm, cwt=balanced_class, feature=feature, rep=repeat, k=cv)
        
    print "Done!"
Esempio n. 15
0
def get_zone_number(self, lat, lon):
    converter = Converter.Converter([lat, long], type=Converter.LATLON)
    return converter.zone_letter, converter.zone_number