root/tags/FuzzyOcr-3.5.1/FuzzyOcr/Scoring.pm

Revision 125, 2.8 kB (checked in by decoder, 2 years ago)

FuzzyOcr? 3.5.1 tag dir and tarball

Line 
1 use strict;
2 package FuzzyOcr::Scoring;
3
4 use base 'Exporter';
5 our @EXPORT_OK = qw(wrong_ctype corrupt_img known_img_hash wrong_extension);
6
7 use lib qw(..);
8 use FuzzyOcr::Config qw(get_pms get_config);
9 use FuzzyOcr::Logging qw(infolog);
10
11 # Provide custom scoring functions
12
13 sub wrong_ctype {
14     my $conf = get_config();
15     my $pms = get_pms();
16     my ( $format, $ctype ) = @_;
17     if ($conf->{'focr_wrongctype_score'}) {
18         my $debuginfo = "";
19         if ( $conf->{"focr_verbose"} > 0 ) {
20             $debuginfo =
21               ("Image has format \"$format\" but content-type is \"$ctype\"");
22         }
23         infolog($debuginfo);
24         my $ws = sprintf( "%0.3f", $conf->{'focr_wrongctype_score'} );
25         for my $set ( 0 .. 3 ) {
26             $pms->{conf}->{scoreset}->[$set]->{"FUZZY_OCR_WRONG_CTYPE"} = $ws;
27         }
28         $pms->_handle_hit( "FUZZY_OCR_WRONG_CTYPE",
29             $conf->{'focr_wrongctype_score'}, "BODY: ",
30             $pms->{conf}->{descriptions}->{FUZZY_OCR_WRONG_CTYPE} . "\n$debuginfo" );
31     }
32 }
33
34 sub wrong_extension {
35     my $conf = get_config();
36     my $pms = get_pms();
37     my ( $format, $suffix ) = @_;
38     if ($conf->{'focr_wrongext_score'}) {
39         my $debuginfo = "";
40         if ( $conf->{"focr_verbose"} > 0 ) {
41             $debuginfo =
42               ("Image has format \"$format\" but file extension is \"$suffix\"");
43         }
44         infolog($debuginfo);
45         my $ws = sprintf( "%0.3f", $conf->{'focr_wrongext_score'} );
46         for my $set ( 0 .. 3 ) {
47             $pms->{conf}->{scoreset}->[$set]->{"FUZZY_OCR_WRONG_EXTENSION"} = $ws;
48         }
49         $pms->_handle_hit( "FUZZY_OCR_WRONG_EXTENSION",
50             $conf->{'focr_wrongext_score'}, "BODY: ",
51             $pms->{conf}->{descriptions}->{FUZZY_OCR_WRONG_EXTENSION} . "\n$debuginfo" );
52     }
53 }
54
55 sub corrupt_img {
56     my $conf = get_config();
57     my $pms = get_pms();
58     my ($score, $err) = @_;
59     if ($score>0) {
60         my $debuginfo = "";
61         if ( $conf->{"focr_verbose"} > 0 ) {
62             chomp($err);
63             $debuginfo = ("Corrupt image: $err");
64         }
65         infolog($debuginfo);
66         my $ws = sprintf( "%0.3f", $score );
67         for my $set ( 0 .. 3 ) {
68             $pms->{conf}->{scoreset}->[$set]->{"FUZZY_OCR_CORRUPT_IMG"} = $ws;
69         }
70         $pms->_handle_hit( "FUZZY_OCR_CORRUPT_IMG", $score, "BODY: ",
71             $pms->{conf}->{descriptions}->{FUZZY_OCR_CORRUPT_IMG} . "\n$debuginfo" );
72     }
73 }
74
75 sub known_img_hash {
76     my $conf = get_config();
77     my $pms = get_pms();
78     my $score = $_[0] || $conf->{'focr_base_score'};
79     my $dinfo = $_[1] ? "\n$_[1]" : '';
80     my $ws = sprintf( "%0.3f", $score );
81     for my $set ( 0 .. 3 ) {
82         $pms->{conf}->{scoreset}->[$set]->{"FUZZY_OCR_KNOWN_HASH"} = $ws;
83     }
84     $pms->_handle_hit( "FUZZY_OCR_KNOWN_HASH", $score, "BODY: ",
85         $pms->{conf}->{descriptions}->{FUZZY_OCR_KNOWN_HASH} . $dinfo );
86 }
87
88 1;
Note: See TracBrowser for help on using the browser.