コード例 #1
0
def extractTitle(inStr):
	# print("Parsing: '%s'" % inStr)
	p    = TitleParser(inStr)
	vol  = p.getVolume()
	chp  = p.getChapter()
	frag = p.getFragment()
	post = p.getPostfix()
	return vol, chp, frag, post
コード例 #2
0
def test():
	count = 0
	mismatch = 0
	for key, value in test_data:
		# if not "  " in key:
		# 	continue

		# print(key, value)
		p = TitleParser(key)
		vol, chp, frag, post = p.getVolume(), p.getChapter(), p.getFragment(), p.getPostfix()

		if frag != None:
			consolidated_chp = (frag / 100.0) + 0 if chp == None else chp
		else:
			consolidated_chp = chp
		if len(value) == 2:
			e_chp, e_vol = value
			if e_chp == 0.0 and consolidated_chp == None:
				e_chp = None
			if vol != e_vol or consolidated_chp != e_chp:
				mismatch += 1
				print(p)
				print("Parsed: v{}, c{}".format(vol, consolidated_chp))
				print("Expect: v{}, c{}".format(e_vol, e_chp))
				print()
		elif len(value) == 4:
			e_vol, e_chp, e_frag, e_post = value
			if e_chp == 0.0 and chp == None:
				e_chp = None
			if vol != e_vol or chp != e_chp or frag != e_frag:
				mismatch += 1
				print(p)
				print("Parsed: v{}, c{}, f{}".format(vol, chp, frag))
				print("Expect: v{}, c{}, f{}".format(e_vol, e_chp, e_frag))
				print()
			if e_post != post:
				mismatch += 1
				print(p)
				print("Parsed: {}".format(post))
				print("Expect: {}".format(e_post))
			# for number in p.getNumbers():
			# 	print(number)
			# 	print("Preceeded by:", number.lastData())
		count += 1


		# if len(value) == 2:
		# 	assert value == extractChapterVol(key), "Wat? Values: '{}', '{}', '{}'".format(key, value, extractChapterVol(key))
		# elif len(value) == 4:
		# 	assert value == extractVolChapterFragmentPostfix(key), "Wat? Values: '{}', '{}', '{}'".format(key, value, extractVolChapterFragmentPostfix(key))
		# else:
		# 	print("Wat?")
		# 	print(key, value)
	# print("All matches passed!")
	print("{} Items with parsed output".format(count))
	print("{} Items mismatch in new parser".format(mismatch))
	print("Total items: {}".format(len(test_data)))
コード例 #3
0
def load_items():
    feed_items = db.get_db_session().query(db.FeedItems) \
      .order_by(db.FeedItems.srcname)           \
      .order_by(db.FeedItems.title)           \
      .all()

    with open("tests/title_test_data_two.py", 'w') as fp:
        fp.write("data = [\n")
        for row in feed_items:
            title = row.title

            try:
                p = TP(title)
                fp.write(
                    format_row(title, p.getVolume(), p.getChapter(),
                               p.getFragment(), p.getPostfix()))
            except ValueError:
                fp.write(format_row(title, 0, 0, 0, ''))

        fp.write("]\n")
コード例 #4
0
def test():
    count = 0
    mismatch = 0
    for key, value in test_data:
        # if not "  " in key:
        # 	continue

        # print(key, value)
        p = TitleParser(key)
        vol, chp, frag, post = p.getVolume(), p.getChapter(), p.getFragment(
        ), p.getPostfix()

        if frag != None:
            consolidated_chp = (frag / 100.0) + 0 if chp == None else chp
        else:
            consolidated_chp = chp
        if len(value) == 2:
            e_chp, e_vol = value
            if e_chp == 0.0 and consolidated_chp == None:
                e_chp = None
            if vol != e_vol or consolidated_chp != e_chp:
                mismatch += 1
                print(p)
                print("Parsed: v{}, c{}".format(vol, consolidated_chp))
                print("Expect: v{}, c{}".format(e_vol, e_chp))
                print()
        elif len(value) == 4:
            e_vol, e_chp, e_frag, e_post = value
            if e_chp == 0.0 and chp == None:
                e_chp = None
            if vol != e_vol or chp != e_chp or frag != e_frag:
                mismatch += 1
                print(p)
                print("Parsed: v{}, c{}, f{}".format(vol, chp, frag))
                print("Expect: v{}, c{}, f{}".format(e_vol, e_chp, e_frag))
                print()
            if e_post != post:
                mismatch += 1
                print(p)
                print("Parsed: {}".format(post))
                print("Expect: {}".format(e_post))
            # for number in p.getNumbers():
            # 	print(number)
            # 	print("Preceeded by:", number.lastData())
        count += 1

        # if len(value) == 2:
        # 	assert value == extractChapterVol(key), "Wat? Values: '{}', '{}', '{}'".format(key, value, extractChapterVol(key))
        # elif len(value) == 4:
        # 	assert value == extractVolChapterFragmentPostfix(key), "Wat? Values: '{}', '{}', '{}'".format(key, value, extractVolChapterFragmentPostfix(key))
        # else:
        # 	print("Wat?")
        # 	print(key, value)
    # print("All matches passed!")
    print("{} Items with parsed output".format(count))
    print("{} Items mismatch in new parser".format(mismatch))
    print("Total items: {}".format(len(test_data)))