blib/lib/XML/XCES.pm

filter: Statementstmt 19.7% 14 / 71 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 40.0% 4 / 10 Podpod 100% 1 / 1 totaltotal 17.4% 19 / 109 CC 12 SCAR 28.3
CC
12
Cov
15%
align2pair
30.0
__ANON__
30.0
__ANON__
12.0
CRAP 17.0
↑ Summary
1 package XML::XCES;
2  
3 2 ▶use XML::DT;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 XML::XCES - Perl module to handle XCES xml files
12  
13 =head1 VERSION
14  
15 Version 0.01
16  
17 =cut
18  
19 2 our $VERSION = '0.01';
20  
21 =head1 SYNOPSIS
22  
23 use XML::XCES;
24  
25 XML::XCES->align2pair("File.xml", "prefix");
26  
27 =head1 FUNCTIONS
28  
29 XML::XCES provides the following functions:
30  
31 =head2 align2pair
32  
33 This function receives an XCES xml filename with sentence alignment
34 content, and, optionally, a prefix for the output files.
35  
36 Note that the aligned files paths should be absolute or relative to
37 the command issue directory.
38  
39 =cut
40  
41 0 ▶sub align2pair {
Subroutine align2pair: not called CC=5 SCAR=34.0
Pod documented
42 0 ▶ shift if ($_[0] eq "XML::XCES");
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] eq "XML::XCES" 0 0 0
43 0 my $xces = shift;
44 0 ▶ my $prefix = shift || $xces;
Condition0%0/3
shift() || $xces
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $xces
shift() $xces
Truth table0%0/3
A || B
A= shift()B= $xces
ABresult
1X1
011
000
45  
46 0 my $tuCount = 0;
47  
48 0 ▶ open S, ">$prefix-source.nat" or die;
Branch: 1 branch
BranchTrueFalseTotal
open S, ">$prefix-source.nat" or die 0 0 0
49 0 ▶ open T, ">$prefix-target.nat" or die;
Branch: 1 branch
BranchTrueFalseTotal
open T, ">$prefix-target.nat" or die 0 0 0
50  
51 my %handler = (
52 -type => { linkGrp => 'SEQ' },
53  
54 0 ▶ 'link' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 0 my ($s, $t) = split /\s*;\s*/, $v{xtargets};
56 0 my @s = grep { /./ } split /\s+/, $s;
57 0 my @t = grep { /./ } split /\s+/, $t;
58 0 return [[@s],[@t],$v{certainty}];
59 },
60  
61 0 ▶ 'linkGrp' => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
62 0 my ($source,$target) = ($v{fromDoc},$v{toDoc});
63 0 ▶ return unless -f $source and -f $target;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $source and -f $target 0 0 0
Condition0%0/3
-f $source and -f $target
!ll&&!rl&&r
000
MC/DC0%0/2
-f $source and -f $target
-f $source -f $target
Truth table0%0/3
A and B
A= -f $sourceB= -f $target
ABresult
0X0
100
111
64  
65 0 my $cont = $c;
66 0 printf STDERR "+ %s * %s ", _last26($source), _last26($target);
67  
68 0 my (%s,%t);
69 0 my $ACTIVE;
70 my %h2 = (
71 -type => { linkGrp => 'SEQ' },
72  
73 -outputenc => 'iso-8859-1',
74  
75 0 ▶ -default => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
76 0 $c = _trim($c);
77 0 ▶ if ($v{id} && exists($ACTIVE->{$v{id}})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($XML::XCES::v{"id"} and exists $$ACTIVE{$XML::XCES::v{"id"}}) 0 0 0
Condition0%0/3
$XML::XCES::v{"id"} and exists $$ACTIVE{$XML::XCES::v{"id"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$XML::XCES::v{"id"} and exists $$ACTIVE{$XML::XCES::v{"id"}}
$XML::XCES::v{"id"} exists $$ACTIVE{$XML::XCES::v{"id"}}
Truth table0%0/3
A and B
A= $XML::XCES::v{"id"}B= exists $$ACTIVE{$XML::XCES::v{"id"}}
ABresult
0X0
100
111
78 0 $ACTIVE->{$v{id}} = $c;
79 }
80 $c
81 0 });
82  
83 0 my $tu = 0;
84 0 for my $link (@$cont) {
85 0 $tu++;
86 0 @s{@{$link->[0]}} = 1 x @{$link->[0]};
87 0 @t{@{$link->[1]}} = 1 x @{$link->[1]};
88 }
89 0 print STDERR "($tu TUs)\n";
90 0 $tuCount+=$tu;
91  
92 0 $ACTIVE = \%s;
93 0 dt($source, %h2);
94  
95 0 $ACTIVE = \%t;
96 0 dt($target, %h2);
97  
98 0 for my $link (@$cont) {
99 0 print S (map { "$_\n" } (@s{@{$link->[0]}},'$'));
100 0 print T (map { "$_\n" } (@t{@{$link->[1]}},'$'));
101 }
102 },
103 0 );
104  
105 0 dt($xces, %handler);
106  
107 0 return $tuCount;
108 }
109  
110  
111 0 ▶sub _trim {
Subroutine _trim: not called CC=1 SCAR=6.9
112 0 my $x = shift;
113 0 $x =~ s/\s+/ /g;
114 0 $x =~ s/^\s+//;
115 0 $x =~ s/\s+$//;
116 0 return $x;
117 }
118  
119 0 ▶sub _last26 {
Subroutine _last26: not called CC=2 SCAR=17.9
120 0 my $x = shift;
121 0 ▶ if (length($x)>26) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $x > 26) { } 0 0 0
122 0 return "...".substr($x,-23,23);
123 } else {
124 0 return $x
125 }
126 }
127  
128  
129  
130 =head1 AUTHOR
131  
132 Alberto Simoes, C<< <ambs@cpan.org> >>
133  
134 =head1 BUGS
135  
136 Please report any bugs or feature requests to
137 C<bug-xml-xces@rt.cpan.org>, or through the web interface at
138 L<http://rt.cpan.org>. I will be notified, and then you'll automatically
139 be notified of progress on your bug as I make changes.
140  
141 =head1 ACKNOWLEDGEMENTS
142  
143 =head1 COPYRIGHT & LICENSE
144  
145 Copyright 2004-2005 Alberto Simoes, All Rights Reserved.
146  
147 This program is free software; you can redistribute it and/or modify it
148 under the same terms as Perl itself.
149  
150 =cut
151  
152 2 1; # End of XML::XCES
↑ Summary