コード例 #1
0
ファイル: RuleSet.py プロジェクト: atiti/ocr-tools
	def runRule(self, buf, index, r):
		curindex = index
		sm = StringMatcher()
		dm = DateMatcher()
		tm = TimeMatcher()
		ri = RuleInstance(r)
		if r.getType() == 'stringmatch':
			p = sm.seek_until_keys(buf[curindex:], r.getKeys(), r.getExpectedConfidence())
			if p[0] != -1: # Found something
				ri.addMatchedKeys(r.getType(), [p[1], p[2], curindex+p[0], curindex+(p[0]+len(p[1]))])
				curindex += (p[0]+len(p[1]))
		elif r.getType() == 'datematch':
			p = dm.locate_date(buf[curindex:], r.getExpectedConfidence())
			if p[0] != -1:
				condate = ""
				for v in p[1]:
					condate += v[0]+" "

				ri.addMatchedKeys(r.getType(), [p[1], p[2], curindex+p[0], curindex+p[0]+len(condate)])
				curindex += p[0]
		elif r.getType() == 'timematch':
			p = tm.locate_time(buf[curindex:], r.getExpectedConfidence())
			if p[0] != -1:
				contime = ""
				for v in p[1]:
					contime += v[0]+" "
				print "Time offset: ",curindex," and ",p[0]," = ", curindex+p[0]+len(contime)
				ri.addMatchedKeys(r.getType(), [p[1], p[2], curindex+p[0], curindex+p[0]+len(contime)])
				curindex += p[0]

		return (curindex, ri)
コード例 #2
0
ファイル: RuleSet.py プロジェクト: atiti/ocr-tools
    def runRule(self, buf, index, r):
        curindex = index
        sm = StringMatcher()
        dm = DateMatcher()
        tm = TimeMatcher()
        ri = RuleInstance(r)
        if r.getType() == 'stringmatch':
            p = sm.seek_until_keys(buf[curindex:], r.getKeys(),
                                   r.getExpectedConfidence())
            if p[0] != -1:  # Found something
                ri.addMatchedKeys(r.getType(), [
                    p[1], p[2], curindex + p[0], curindex + (p[0] + len(p[1]))
                ])
                curindex += (p[0] + len(p[1]))
        elif r.getType() == 'datematch':
            p = dm.locate_date(buf[curindex:], r.getExpectedConfidence())
            if p[0] != -1:
                condate = ""
                for v in p[1]:
                    condate += v[0] + " "

                ri.addMatchedKeys(r.getType(), [
                    p[1], p[2], curindex + p[0], curindex + p[0] + len(condate)
                ])
                curindex += p[0]
        elif r.getType() == 'timematch':
            p = tm.locate_time(buf[curindex:], r.getExpectedConfidence())
            if p[0] != -1:
                contime = ""
                for v in p[1]:
                    contime += v[0] + " "
                print "Time offset: ", curindex, " and ", p[
                    0], " = ", curindex + p[0] + len(contime)
                ri.addMatchedKeys(r.getType(), [
                    p[1], p[2], curindex + p[0], curindex + p[0] + len(contime)
                ])
                curindex += p[0]

        return (curindex, ri)