Skip to content

Commit

Permalink
script for dumping files numexps to CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
andrefs committed Jul 26, 2012
1 parent 123cea7 commit 6021d69
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
43 changes: 43 additions & 0 deletions bin/dump_numexp_csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env perl

use strict; # use warnings;
use Data::Dump qw/dump/;
use feature qw/say/;
use Text::Math::NumExp;
use Text::CSV;
use utf8::all;
#PODNAME: find_nes.pl

my $csv = Text::CSV->new ({
binary => 1,
quote_char => '"',
escape_char => '"',
always_quote => '"',
quote_space => 0,
}) or die "Cannot use CSV: ".Text::CSV->error_diag ();
$csv->column_names (qw/ file offset length text value /);

for my $doc (@ARGV){
open my $fh, '<', $doc;
my $text;
{
local $/;
$text = <$fh>;
}
norm_numexp(\$text);
my $numexp = find_numexp(\$text);
#dump($numexp);
for (@$numexp){
$csv->combine($doc,$_->{offset},$_->{length},$_->{text},$_->{value});
say $csv->string;
}
my $numwords = find_numwords(\$text);
#dump($numwords);
for (@$numwords){
$csv->combine($doc,$_->{offset},$_->{length},$_->{text},$_->{value});
say $csv->string;
}

}


2 changes: 2 additions & 0 deletions lib/Text/Math/NumExp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ sub norm_numexp {
$text =~ s/(\d)[*]10(\d{2})/$1*10^$2/g;
}

$text =~ s//'/g;

if(ref($text_or_ref)) { $$text_or_ref = $text; }
else { return $text; }
return;
Expand Down

0 comments on commit 6021d69

Please sign in to comment.