From 39727674afb002653dbc5bfeef68256c109efaaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scheibe?= Date: Thu, 28 May 2015 00:55:31 +0200 Subject: enable creating intermediary files again via option -i --- bin/ninka | 6 ++++-- lib/Ninka.pm | 23 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/bin/ninka b/bin/ninka index a09ba51..4732cbe 100755 --- a/bin/ninka +++ b/bin/ninka @@ -7,20 +7,22 @@ use Ninka; my %opts = parse_cmdline_parameters(); my $input_file = $ARGV[0]; +my $create_intermediary_files = exists $opts{i}; my $verbose = exists $opts{v}; -my $license_result = Ninka::process_file($input_file, $verbose); +my $license_result = Ninka::process_file($input_file, $create_intermediary_files, $verbose); print "$input_file;$license_result\n"; exit 0; sub parse_cmdline_parameters { my %opts = (); - if (!getopts('v', \%opts) || scalar(@ARGV) == 0) { + if (!getopts('iv', \%opts) || scalar(@ARGV) == 0) { print STDERR "Ninka v${Ninka::VERSION} Usage: $0 [options] Options: + -i create intermediary files -v verbose\n"; exit 1; diff --git a/lib/Ninka.pm b/lib/Ninka.pm index 1816549..dc9fbff 100644 --- a/lib/Ninka.pm +++ b/lib/Ninka.pm @@ -12,7 +12,7 @@ use Ninka::SentenceTokenizer; our $VERSION = '1.3'; sub process_file { - my ($input_file, $verbose) = @_; + my ($input_file, $create_intermediary_files, $verbose) = @_; print STDERR "analysing file [$input_file]\n" if $verbose; @@ -41,9 +41,27 @@ sub process_file { my %parameters_step5 = (%common_parameters, license_tokens => $license_tokens_ref); my $license_result = Ninka::LicenseMatcher->new(%parameters_step5)->execute(); + if ($create_intermediary_files) { + create_intermediary_file($input_file, 'comments', $comments); + create_intermediary_file($input_file, 'sentences', join("\n", @$sentences_ref)); + create_intermediary_file($input_file, 'goodsent', join("\n", @$good_sentences_ref)); + create_intermediary_file($input_file, 'badsent', join("\n", @$bad_sentences_ref)); + create_intermediary_file($input_file, 'senttok', join("\n", @$license_tokens_ref)); + create_intermediary_file($input_file, 'license', $license_result); + } + return $license_result; } +sub create_intermediary_file { + my ($input_file, $output_extension, $content) = @_; + + my $output_file = "$input_file.$output_extension"; + open my $output_fh, '>', $output_file or die "can't create output file [$output_file]: $!"; + print $output_fh $content; + close $output_fh; +} + 1; __END__ @@ -57,9 +75,10 @@ Ninka - Find licenses in source files. use Ninka; my $input_file = 'some/path/file_of_interest'; + my $create_intermediary_files = 0; my $verbose = 0; - my $license_result = Ninka::process_file($input_file, $verbose); + my $license_result = Ninka::process_file($input_file, $create_intermediary_files, $verbose); =head1 DESCRIPTION -- cgit v1.2.1