From b51137379fab2d5579e0caeada5389c682ec3cc5 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Mon, 5 Aug 2013 22:29:24 +0200 Subject: Use a Needleman-Wunsch type algorithm for text alignment --- compare.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'compare.py') diff --git a/compare.py b/compare.py index aeb9092..c37cde9 100644 --- a/compare.py +++ b/compare.py @@ -1,12 +1,15 @@ +# -*- coding: utf-8 -*- + from wikisource import get_page from parsedjvutext import parse_page_sexp -from string_utils import LCS, printDiff +import string_utils as su -wikibook = "Villiers de L'Isle-Adam - Tribulat Bonhomet, 1908.djvu" +wikibook = "Bloy - Le Sang du pauvre, Stock, 1932.djvu".replace(" ", "_") +# wikibook = "Villiers de L'Isle-Adam - Tribulat Bonhomet, 1908.djvu".replace(" ", "_") -n = 42 +n = 79 ocrpage = parse_page_sexp(wikibook, n) l1 = ocrpage['words'] -l2 = get_page(wikibook, n).split() -C = LCS(l1, l2) -printDiff(C, l1, l2, len(l1), len(l2)) +l2 = get_page(wikibook, n).replace(u"’", u"'").split() +C = su.align(l2, l1) +su.print_alignment(l2, l1, C[1]) -- cgit v1.2.3-70-g09d2