コード例 #1
0
 def test_new(self):
     php = PHP()
     dt = php.new('DateTime')
     ts = dt.getTimestamp()
     php.echo(ts)
     output = str(php)
     self.assertAlmostEquals(int(output), time(), delta=10)
コード例 #2
0
ファイル: test_php.py プロジェクト: dnet/ppcg
	def test_new(self):
		php = PHP()
		dt = php.new('DateTime')
		ts = dt.getTimestamp()
		php.echo(ts)
		output = str(php)
		self.assertAlmostEquals(int(output), time(), delta=10)
コード例 #3
0
def fuzzymatch(string1):
    #note:  fuzzymatch.php must be in php path, e.g.  /usr/lib/php/!!!
    #put in a cron job that runs every half hour for new entries?
    
    entities = Session.query(Entity)
    
    
    matches = []
    
    ##string1 = string1.decode('utf8')
    
    for entity in entities:
        php = PHP("require 'fuzzymatch.php';")
        #php = PHP()
        #print "testing " + entity.label.encode('utf8') + " against " + string1.encode('utf8') + "\n"
        
        code = '$string1 = utf8_decode("' + string1.encode('utf8') + '");'
        
        #code = code + "$string2 = '" + entity.label.encode('latin-1', 'replace') + "';"
        #code = code + "print $string1; print $string2;"
        #print code + '$string2 = utf8_decode("' + entity.label.encode('utf8') + '");'
        code = code + '$string2 = utf8_decode("' + entity.label.encode('utf8') + '");'
        code = code + """print fuzzy_match($string1, $string2, 2);"""
        
        verdict = php.get_raw(code)
        #print "verdict is " + verdict + "\n"
    
        if float(verdict)>=.5:
            #print entity.label + " is a match!\n"
            entity.matchvalue = verdict
            matches.append(entity)
    
    return matches
コード例 #4
0
ファイル: searchstring.py プロジェクト: etboggs/inphosite
def fuzzymatch(string1):
    #note:  fuzzymatch.php must be in php path, e.g.  /usr/lib/php/!!!
    #put in a cron job that runs every half hour for new entries?

    entities = Session.query(Entity)

    matches = []

    ##string1 = string1.decode('utf8')

    for entity in entities:
        php = PHP("require 'fuzzymatch.php';")
        #php = PHP()
        #print "testing " + entity.label.encode('utf8') + " against " + string1.encode('utf8') + "\n"

        code = '$string1 = utf8_decode("' + string1.encode('utf8') + '");'

        #code = code + "$string2 = '" + entity.label.encode('latin-1', 'replace') + "';"
        #code = code + "print $string1; print $string2;"
        #print code + '$string2 = utf8_decode("' + entity.label.encode('utf8') + '");'
        code = code + '$string2 = utf8_decode("' + entity.label.encode(
            'utf8') + '");'
        code = code + """print fuzzy_match($string1, $string2, 2);"""

        verdict = php.get_raw(code)
        #print "verdict is " + verdict + "\n"

        if float(verdict) >= .5:
            #print entity.label + " is a match!\n"
            entity.matchvalue = verdict
            matches.append(entity)

    return matches
コード例 #5
0
ファイル: searchstring.py プロジェクト: etboggs/inphosite
def fuzzymatchtest(string1, string2):
    #note:  fuzzymatch.php must be in php path, e.g.  /usr/lib/php/!!!
    php = PHP("require 'fuzzymatch.php';")
    #php = PHP()

    code = "$string1 = '" + string1 + "';"
    code = code + "$string2 = '" + string2.encode('latin-1', 'replace') + "';"
    #code = code + "print $string1; print $string2;"
    code = code + """print fuzzy_match($string1, $string2, 2);"""

    return php.get_raw(code)
コード例 #6
0
def fuzzymatchtest(string1, string2):
    #note:  fuzzymatch.php must be in php path, e.g.  /usr/lib/php/!!!
    php = PHP("require 'fuzzymatch.php';")
    #php = PHP()
    
    code = "$string1 = '" + string1 + "';"
    code = code + "$string2 = '" + string2.encode('latin-1', 'replace') + "';"
    #code = code + "print $string1; print $string2;"
    code = code + """print fuzzy_match($string1, $string2, 2);"""
    
    return php.get_raw(code)
コード例 #7
0
 def test_dict(self):
     php = PHP()
     values = php.array_values(self.TEST_DICT)
     php.sort(values)
     php.echo(php.implode(',', values))
     expected = ','.join(sorted(self.TEST_DICT.itervalues()))
     self.assertEquals(str(php), expected)
コード例 #8
0
 def test_dyn_getitem(self):
     php = PHP()
     array_params = range(self.TEST_RANGE)
     array = php.array(*array_params)
     php.shuffle(array)
     php.echo(array[array[0]])
     self.assertIn(int(str(php)), array_params)
コード例 #9
0
ファイル: test_php.py プロジェクト: dnet/ppcg
	def test_dict(self):
		php = PHP()
		values = php.array_values(self.TEST_DICT)
		php.sort(values)
		php.echo(php.implode(',', values))
		expected = ','.join(sorted(self.TEST_DICT.itervalues()))
		self.assertEquals(str(php), expected)
コード例 #10
0
ファイル: tcpdf_example.py プロジェクト: dnet/ppcg
def main():
	php = PHP()
	php.include('tcpdf/config/lang/eng.php')
	php.include('tcpdf/tcpdf.php')

	pdf = php.new('TCPDF', 'P', 'mm', 'A4', True, 'UTF-8')
	
	pdf.setFontSubsetting(False)
	pdf.setAuthor('VSzA')
	pdf.setCreator('PPCG')
	pdf.setTitle('TCPDF in Python!?')
	pdf.setPrintHeader(False)
	pdf.setMargins(10, 10)

	pdf.AddPage()
	pdf.SetFont('dejavusans', 'B', 12)
	pdf.Cell(0, 0, 'Hello Python')
	pdf.Ln()

	x = pdf.GetX()
	y = pdf.GetY()
	pdf.setXY(30, 30)
	pdf.Cell(0, 0, 'GOTOs are bad')
	pdf.setXY(x, y + 2.5)
	pdf.Cell(0, 0, 'I can has PHP variables')

	pdf.Output()
	pdf_data = str(php)

	with file('output.pdf', 'wb') as pdf_file:
		pdf_file.write(pdf_data)
	print '{0} bytes of PDF have been written'.format(len(pdf_data))
コード例 #11
0
ファイル: test_php.py プロジェクト: dnet/ppcg
	def test_dyn_getitem(self):
		php = PHP()
		array_params = range(self.TEST_RANGE)
		array = php.array(*array_params)
		php.shuffle(array)
		php.echo(array[array[0]])
		self.assertIn(int(str(php)), array_params)
コード例 #12
0
 def test_repr(self):
     php = PHP()
     self.assertEquals(repr(php), '<PHP object with 0 statement(s)>')
コード例 #13
0
 def test_list(self):
     php = PHP()
     php.echo(php.count(range(self.TEST_RANGE)))
     output = str(php)
     self.assertEquals(output, str(self.TEST_RANGE))
コード例 #14
0
 def test_number(self):
     php = PHP()
     php.var_dump(5)
     self.assertEquals(str(php), 'int(5)\n')
コード例 #15
0
 def test_deep_compose(self):
     php = PHP()
     php.echo(php.strlen(php.strrev(self.TEST_STRING)))
     output = str(php)
     self.assertEquals(output, str(len(self.TEST_STRING)))
コード例 #16
0
def fuzzymatchall(SEPEntrieslist):
    #takes outputs from addlist() and saves all fuzzy match IDs to SEPEntry.fuzzymatch with verdicts (percent of words matched)
    #now change so that it only updates ones that don't currently have a fuzzymatchlist
    
    #clear out fuzzymatch table--otherwise old fuzzies will accumulate, and nobody wants that
    delquery = Session.query(Fuzzymatch)
    delquery.delete()
    Session.flush()
    Session.commit()
    
    
    for SEPEntry in SEPEntrieslist:
            print "working on " + SEPEntry.title.encode('utf-8') + "\n"
            entities = Session.query(Entity)
            
            #exclude journals and nodes from fuzzy matching
            entities = entities.filter(Entity.typeID != 2)
            entities = entities.filter(Entity.typeID != 4)
            
            #reset fuzzymatches for that entry
            #SEPEntry.fuzzymatches = ""
    
            
            ##string1 = string1.decode('utf8')
            
            for entity in entities:
                php = PHP("set_include_path('/usr/lib/php/');")
                php = PHP("require 'fuzzymatch.php';")
                #php = PHP()
                #print "testing " + entity.label.encode('utf8') + " against " + string1.encode('utf8') + "\n"
                
                code = '$string1 = utf8_decode("' + SEPEntry.title.encode('utf8') + '");'
                
                #code = code + "$string2 = '" + entity.label.encode('latin-1', 'replace') + "';"
                #code = code + "print $string1; print $string2;"
                #print code + '$string2 = utf8_decode("' + entity.label.encode('utf8') + '");'
                code = code + '$string2 = utf8_decode("' + entity.label.encode('utf8') + '");'
                code = code + """print fuzzy_match($string1, $string2, 2);"""
                
                verdict = php.get_raw(code)
                #print "verdict is " + verdict + "\n"
                verdict = verdict.split(',')
            
                if float(verdict[0])>=.20:
                    #print entity.label + " is a match!\n"
                    #entity.matchvalue = verdict
                    #string = SEPEntry.fuzzymatches + "|" + str(entity.ID) + "," + verdict
                    
                    #if len(string) < 400:
                    #    SEPEntry.fuzzymatches = SEPEntry.fuzzymatches + "|" + str(entity.ID) + "," + verdict
                    #else:
                    #    print "sorry, too many matches!  Can't add " + str(entity.ID) + " to fuzzy matches; over 400 chars."
                    fmatch = Fuzzymatch(entity.ID)
                    fmatch.sep_dir = SEPEntry.sep_dir
                    fmatch.strength = verdict[0]
                    fmatch.edits = verdict[1]
                    
                    SEPEntry.fmatches.append(fmatch)
                    
                    
            Session.flush()
            Session.commit()
コード例 #17
0
 def test_null(self):
     php = PHP()
     php.var_dump(None)
     self.assertEquals(str(php), 'NULL\n')
コード例 #18
0
 def test_echo(self):
     php = PHP()
     php.echo(self.TEST_STRING)
     self.assertEquals(str(php), self.TEST_STRING)
コード例 #19
0
 def test_error(self):
     php = PHP()
     php.nonexistant_method()
     with self.assertRaises(PhpError):
         str(php)
コード例 #20
0
ファイル: test_php.py プロジェクト: dnet/ppcg
	def test_add(self):
		php = PHP()
		array = php.range(1, self.TEST_RANGE)
		php.echo(php.count(array) + self.TEST_VALUE)
		self.assertEquals(str(php), str(self.TEST_VALUE + self.TEST_RANGE))
コード例 #21
0
ファイル: test_php.py プロジェクト: dnet/ppcg
	def test_echo(self):
		php = PHP()
		php.echo(self.TEST_STRING)
		self.assertEquals(str(php), self.TEST_STRING)
コード例 #22
0
ファイル: test_php.py プロジェクト: dnet/ppcg
	def test_error(self):
		php = PHP()
		php.nonexistant_method()
		with self.assertRaises(PhpError):
			str(php)
コード例 #23
0
ファイル: test_php.py プロジェクト: dnet/ppcg
	def test_null(self):
		php = PHP()
		php.var_dump(None)
		self.assertEquals(str(php), 'NULL\n')
コード例 #24
0
ファイル: test_php.py プロジェクト: dnet/ppcg
	def test_number(self):
		php = PHP()
		php.var_dump(5)
		self.assertEquals(str(php), 'int(5)\n')
コード例 #25
0
ファイル: test_php.py プロジェクト: dnet/ppcg
	def test_list(self):
		php = PHP()
		php.echo(php.count(range(self.TEST_RANGE)))
		output = str(php)
		self.assertEquals(output, str(self.TEST_RANGE))
コード例 #26
0
ファイル: test_php.py プロジェクト: dnet/ppcg
	def test_deep_compose(self):
		php = PHP()
		php.echo(php.strlen(php.strrev(self.TEST_STRING)))
		output = str(php)
		self.assertEquals(output, str(len(self.TEST_STRING)))
コード例 #27
0
 def test_getitem(self):
     php = PHP()
     array_params = range(self.TEST_RANGE)
     array = php.array(*array_params)
     php.echo(array[0])
     self.assertEquals(str(php), str(array_params[0]))
コード例 #28
0
ファイル: test_php.py プロジェクト: dnet/ppcg
	def test_getitem(self):
		php = PHP()
		array_params = range(self.TEST_RANGE)
		array = php.array(*array_params)
		php.echo(array[0])
		self.assertEquals(str(php), str(array_params[0]))
コード例 #29
0
 def test_add(self):
     php = PHP()
     array = php.range(1, self.TEST_RANGE)
     php.echo(php.count(array) + self.TEST_VALUE)
     self.assertEquals(str(php), str(self.TEST_VALUE + self.TEST_RANGE))
コード例 #30
0
ファイル: searchstring.py プロジェクト: etboggs/inphosite
def fuzzymatchall(SEPEntrieslist):
    #takes outputs from addlist() and saves all fuzzy match IDs to SEPEntry.fuzzymatch with verdicts (percent of words matched)
    #now change so that it only updates ones that don't currently have a fuzzymatchlist

    #clear out fuzzymatch table--otherwise old fuzzies will accumulate, and nobody wants that
    delquery = Session.query(Fuzzymatch)
    delquery.delete()
    Session.flush()
    Session.commit()

    for SEPEntry in SEPEntrieslist:
        print "working on " + SEPEntry.title.encode('utf-8') + "\n"
        entities = Session.query(Entity)

        #exclude journals and nodes from fuzzy matching
        entities = entities.filter(Entity.typeID != 2)
        entities = entities.filter(Entity.typeID != 4)

        #reset fuzzymatches for that entry
        #SEPEntry.fuzzymatches = ""

        ##string1 = string1.decode('utf8')

        for entity in entities:
            php = PHP("set_include_path('/usr/lib/php/');")
            php = PHP("require 'fuzzymatch.php';")
            #php = PHP()
            #print "testing " + entity.label.encode('utf8') + " against " + string1.encode('utf8') + "\n"

            code = '$string1 = utf8_decode("' + SEPEntry.title.encode(
                'utf8') + '");'

            #code = code + "$string2 = '" + entity.label.encode('latin-1', 'replace') + "';"
            #code = code + "print $string1; print $string2;"
            #print code + '$string2 = utf8_decode("' + entity.label.encode('utf8') + '");'
            code = code + '$string2 = utf8_decode("' + entity.label.encode(
                'utf8') + '");'
            code = code + """print fuzzy_match($string1, $string2, 2);"""

            verdict = php.get_raw(code)
            #print "verdict is " + verdict + "\n"
            verdict = verdict.split(',')

            if float(verdict[0]) >= .20:
                #print entity.label + " is a match!\n"
                #entity.matchvalue = verdict
                #string = SEPEntry.fuzzymatches + "|" + str(entity.ID) + "," + verdict

                #if len(string) < 400:
                #    SEPEntry.fuzzymatches = SEPEntry.fuzzymatches + "|" + str(entity.ID) + "," + verdict
                #else:
                #    print "sorry, too many matches!  Can't add " + str(entity.ID) + " to fuzzy matches; over 400 chars."
                fmatch = Fuzzymatch(entity.ID)
                fmatch.sep_dir = SEPEntry.sep_dir
                fmatch.strength = verdict[0]
                fmatch.edits = verdict[1]

                SEPEntry.fmatches.append(fmatch)

        Session.flush()
        Session.commit()