Beispiel #1
0
def test_rule_match_tricky_input():

    # The address matched by it must have a even number.
    rule  = Rule('信義路一段雙全')

    addr1 = Address('信義路一段')
    addr2 = Address('信義路一段1號')
    addr3 = Address('信義路一段2號')

    assert not rule.match(addr1)
    assert not rule.match(addr2)
    assert     rule.match(addr3)
Beispiel #2
0
def test_rule_match_tricky_input():

    # The address matched by it must have a even number.
    rule = Rule('信義路一段雙全')

    addr1 = Address('信義路一段')
    addr2 = Address('信義路一段1號')
    addr3 = Address('信義路一段2號')

    assert not rule.match(addr1)
    assert not rule.match(addr2)
    assert rule.match(addr3)
Beispiel #3
0
def test_rule_match_gradual_address():

    # standard rule w/ gradual addresses

    rule = Rule('臺北市中正區丹陽街全')
    assert not rule.match(Address('臺北市'))
    assert not rule.match(Address('臺北市中正區'))
    assert not rule.match(Address('臺北市中正區仁愛路1段'))
    assert not rule.match(Address('臺北市中正區仁愛路1段1號'))

    rule = Rule('臺北市,中正區,仁愛路1段,    1號')
    assert not rule.match(Address('臺北市'))
    assert not rule.match(Address('臺北市中正區'))
    assert not rule.match(Address('臺北市中正區仁愛路1段'))
    assert rule.match(Address('臺北市中正區仁愛路1段1號'))
Beispiel #4
0
def test_rule_match_gradual_address():

    # standard rule w/ gradual addresses

    rule = Rule('臺北市中正區丹陽街全')
    assert not rule.match(Address('臺北市'))
    assert not rule.match(Address('臺北市中正區'))
    assert not rule.match(Address('臺北市中正區仁愛路1段'))
    assert not rule.match(Address('臺北市中正區仁愛路1段1號'))

    rule = Rule('臺北市,中正區,仁愛路1段,    1號')
    assert not rule.match(Address('臺北市'))
    assert not rule.match(Address('臺北市中正區'))
    assert not rule.match(Address('臺北市中正區仁愛路1段'))
    assert     rule.match(Address('臺北市中正區仁愛路1段1號'))
Beispiel #5
0
def test_rule_match_gradual_address():

    # standard rule w/ gradual addresses

    rule = Rule("臺北市中正區丹陽街全")
    assert not rule.match(Address("臺北市"))
    assert not rule.match(Address("臺北市中正區"))
    assert not rule.match(Address("臺北市中正區仁愛路1段"))
    assert not rule.match(Address("臺北市中正區仁愛路1段1號"))

    rule = Rule("臺北市,中正區,仁愛路1段,    1號")
    assert not rule.match(Address("臺北市"))
    assert not rule.match(Address("臺北市中正區"))
    assert not rule.match(Address("臺北市中正區仁愛路1段"))
    assert rule.match(Address("臺北市中正區仁愛路1段1號"))
Beispiel #6
0
def test_rule_match_rule_all():

    # Be careful of the 全! It will bite you!

    rule = Rule('臺北市,中正區,八德路1段,全')
    assert rule.match(Address('臺北市中正區八德路1段1號'))
    assert rule.match(Address('臺北市中正區八德路1段9號'))
    assert not rule.match(Address('臺北市中正區八德路2段1號'))
    assert not rule.match(Address('臺北市中正區八德路2段9號'))

    rule = Rule('臺北市,中正區,三元街,單全')
    assert rule.match(Address('臺北市中正區三元街1號'))
    assert not rule.match(Address('臺北市中正區三元街2號'))
    assert not rule.match(Address('臺北市中正區大埔街1號'))

    rule = Rule('臺北市,大同區,哈密街,   45巷全')
    assert rule.match(Address('臺北市大同區哈密街45巷1號'))
    assert rule.match(Address('臺北市大同區哈密街45巷9號'))
    assert not rule.match(Address('臺北市大同區哈密街46巷1號'))
    assert not rule.match(Address('臺北市大同區哈密街46巷9號'))
Beispiel #7
0
def test_rule_match_rule_all():

    # Be careful of the 全! It will bite you!

    rule = Rule('臺北市,中正區,八德路1段,全')
    assert     rule.match(Address('臺北市中正區八德路1段1號'))
    assert     rule.match(Address('臺北市中正區八德路1段9號'))
    assert not rule.match(Address('臺北市中正區八德路2段1號'))
    assert not rule.match(Address('臺北市中正區八德路2段9號'))

    rule = Rule('臺北市,中正區,三元街,單全')
    assert     rule.match(Address('臺北市中正區三元街1號'))
    assert not rule.match(Address('臺北市中正區三元街2號'))
    assert not rule.match(Address('臺北市中正區大埔街1號'))

    rule = Rule('臺北市,大同區,哈密街,   45巷全')
    assert     rule.match(Address('臺北市大同區哈密街45巷1號'))
    assert     rule.match(Address('臺北市大同區哈密街45巷9號'))
    assert not rule.match(Address('臺北市大同區哈密街46巷1號'))
    assert not rule.match(Address('臺北市大同區哈密街46巷9號'))
Beispiel #8
0
def test_rule_match_subno():

    rule = Rule('臺北市,中正區,杭州南路1段,   14號含附號')
    assert not rule.match(Address('臺北市中正區杭州南路1段13號'))
    assert not rule.match(Address('臺北市中正區杭州南路1段13-1號'))
    assert rule.match(Address('臺北市中正區杭州南路1段14號'))
    assert rule.match(Address('臺北市中正區杭州南路1段14-1號'))
    assert not rule.match(Address('臺北市中正區杭州南路1段15號'))
    assert not rule.match(Address('臺北市中正區杭州南路1段15-1號'))

    rule = Rule('臺北市,大同區,哈密街,   47附號全')
    assert not rule.match(Address('臺北市大同區哈密街46號'))
    assert not rule.match(Address('臺北市大同區哈密街46-1號'))
    assert not rule.match(Address('臺北市大同區哈密街47號'))
    assert rule.match(Address('臺北市大同區哈密街47-1號'))
    assert not rule.match(Address('臺北市大同區哈密街48號'))
    assert not rule.match(Address('臺北市大同區哈密街48-1號'))

    rule = Rule('臺北市,大同區,哈密街,雙  68巷至  70號含附號全')
    assert not rule.match(Address('臺北市大同區哈密街66號'))
    assert not rule.match(Address('臺北市大同區哈密街66-1巷'))
    assert not rule.match(Address('臺北市大同區哈密街67號'))
    assert not rule.match(Address('臺北市大同區哈密街67-1巷'))
    assert rule.match(Address('臺北市大同區哈密街68巷'))
    assert rule.match(Address('臺北市大同區哈密街68-1號'))
    assert not rule.match(Address('臺北市大同區哈密街69號'))
    assert not rule.match(Address('臺北市大同區哈密街69-1巷'))
    assert rule.match(Address('臺北市大同區哈密街70號'))
    assert rule.match(Address('臺北市大同區哈密街70-1號'))
    assert not rule.match(Address('臺北市大同區哈密街71號'))
    assert not rule.match(Address('臺北市大同區哈密街71-1號'))

    rule = Rule('桃園縣,中壢市,普義,連  49號含附號以下')
    assert rule.match(Address('桃園縣中壢市普義48號'))
    assert rule.match(Address('桃園縣中壢市普義48-1號'))
    assert rule.match(Address('桃園縣中壢市普義49號'))
    assert rule.match(Address('桃園縣中壢市普義49-1號'))
    assert not rule.match(Address('桃園縣中壢市普義50號'))
    assert not rule.match(Address('桃園縣中壢市普義50-1號'))

    rule = Rule('臺中市,西屯區,西屯路3段西平南巷,    2之   3號及以上附號')
    assert not rule.match(Address('臺中市西屯區西屯路3段西平南巷1號'))
    assert not rule.match(Address('臺中市西屯區西屯路3段西平南巷1-1號'))
    assert not rule.match(Address('臺中市西屯區西屯路3段西平南巷2號'))
    assert not rule.match(Address('臺中市西屯區西屯路3段西平南巷2-2號'))
    assert rule.match(Address('臺中市西屯區西屯路3段西平南巷2-3號'))
    assert rule.match(Address('臺中市西屯區西屯路3段西平南巷3號'))
    assert rule.match(Address('臺中市西屯區西屯路3段西平南巷3-1號'))
    assert rule.match(Address('臺中市西屯區西屯路3段西平南巷4號'))
    assert rule.match(Address('臺中市西屯區西屯路3段西平南巷4-1號'))
Beispiel #9
0
def test_rule_match_subno():

    rule = Rule('臺北市,中正區,杭州南路1段,   14號含附號')
    assert not rule.match(Address('臺北市中正區杭州南路1段13號'))
    assert not rule.match(Address('臺北市中正區杭州南路1段13-1號'))
    assert     rule.match(Address('臺北市中正區杭州南路1段14號'))
    assert     rule.match(Address('臺北市中正區杭州南路1段14-1號'))
    assert not rule.match(Address('臺北市中正區杭州南路1段15號'))
    assert not rule.match(Address('臺北市中正區杭州南路1段15-1號'))

    rule = Rule('臺北市,大同區,哈密街,   47附號全')
    assert not rule.match(Address('臺北市大同區哈密街46號'))
    assert not rule.match(Address('臺北市大同區哈密街46-1號'))
    assert not rule.match(Address('臺北市大同區哈密街47號'))
    assert     rule.match(Address('臺北市大同區哈密街47-1號'))
    assert not rule.match(Address('臺北市大同區哈密街48號'))
    assert not rule.match(Address('臺北市大同區哈密街48-1號'))

    rule = Rule('臺北市,大同區,哈密街,雙  68巷至  70號含附號全')
    assert not rule.match(Address('臺北市大同區哈密街66號'))
    assert not rule.match(Address('臺北市大同區哈密街66-1巷'))
    assert not rule.match(Address('臺北市大同區哈密街67號'))
    assert not rule.match(Address('臺北市大同區哈密街67-1巷'))
    assert     rule.match(Address('臺北市大同區哈密街68巷'))
    assert     rule.match(Address('臺北市大同區哈密街68-1號'))
    assert not rule.match(Address('臺北市大同區哈密街69號'))
    assert not rule.match(Address('臺北市大同區哈密街69-1巷'))
    assert     rule.match(Address('臺北市大同區哈密街70號'))
    assert     rule.match(Address('臺北市大同區哈密街70-1號'))
    assert not rule.match(Address('臺北市大同區哈密街71號'))
    assert not rule.match(Address('臺北市大同區哈密街71-1號'))

    rule = Rule('桃園縣,中壢市,普義,連  49號含附號以下')
    assert     rule.match(Address('桃園縣中壢市普義48號'))
    assert     rule.match(Address('桃園縣中壢市普義48-1號'))
    assert     rule.match(Address('桃園縣中壢市普義49號'))
    assert     rule.match(Address('桃園縣中壢市普義49-1號'))
    assert not rule.match(Address('桃園縣中壢市普義50號'))
    assert not rule.match(Address('桃園縣中壢市普義50-1號'))

    rule = Rule('臺中市,西屯區,西屯路3段西平南巷,    2之   3號及以上附號')
    assert not rule.match(Address('臺中市西屯區西屯路3段西平南巷1號'))
    assert not rule.match(Address('臺中市西屯區西屯路3段西平南巷1-1號'))
    assert not rule.match(Address('臺中市西屯區西屯路3段西平南巷2號'))
    assert not rule.match(Address('臺中市西屯區西屯路3段西平南巷2-2號'))
    assert     rule.match(Address('臺中市西屯區西屯路3段西平南巷2-3號'))
    assert     rule.match(Address('臺中市西屯區西屯路3段西平南巷3號'))
    assert     rule.match(Address('臺中市西屯區西屯路3段西平南巷3-1號'))
    assert     rule.match(Address('臺中市西屯區西屯路3段西平南巷4號'))
    assert     rule.match(Address('臺中市西屯區西屯路3段西平南巷4-1號'))
Beispiel #10
0
    #print r.tokens

    #a = Address('市府路1號')
    #print a.tokens
    #print r.match(a)

    #a = Address('台北市信義區市府路1號')
    #print a.tokens
    #print r.match(a)

    r = Rule('新北市,中和區,景平路,雙  64號以下')
    print r.tokens

    a = Address('新北市景平路64巷13弄13號')
    print a.tokens
    print r.match(a)

########NEW FILE########
__FILENAME__ = zipcodetw_server
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import zipcodetw
from flask import Flask, render_template, request, jsonify

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('finder.html')
Beispiel #11
0
    #print r.tokens

    #a = Address('市府路1號')
    #print a.tokens
    #print r.match(a)

    #a = Address('台北市信義區市府路1號')
    #print a.tokens
    #print r.match(a)

    r = Rule('新北市,中和區,景平路,雙  64號以下')
    print r.tokens

    a = Address('新北市景平路64巷13弄13號')
    print a.tokens
    print r.match(a)

########NEW FILE########
__FILENAME__ = zipcodetw_server
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import zipcodetw
from flask import Flask, render_template, request, jsonify

app = Flask(__name__)


@app.route('/')
def index():
    return render_template('finder.html')
Beispiel #12
0
        assert self.dir_.find('中正區') == ''

        assert self.dir_.find('大埔街') == ''
        assert self.dir_.find('台北市大埔街') == '10068'
        assert self.dir_.find('苗栗縣大埔街') == '36046'

if __name__ == '__main__':
    import uniout                                       #Python 的 List 要印出 中文 編碼
    #test_dir = TestDirectory()
    #test_dir.setup()
    #test_dir.test_find_middle_token()

    #r = Rule('台北市信義區市府路10號以下')
    #print r.tokens

    #a = Address('市府路1號')
    #print a.tokens
    #print r.match(a)

    #a = Address('台北市信義區市府路1號')
    #print a.tokens
    #print r.match(a)

    r = Rule('新北市,中和區,景平路,雙  64號以下')
    print (r.tokens)

    a = Address('新北市景平路64巷13弄13號')
    print (a.tokens)
    print (r.match(a))