#!/usr/bin/perl -s

use common::sense;
use utf8;
use Text::Ngram 'ngram_counts';
use File::Slurp;
use Data::Dumper;

require "tools/features.pl";

our $o;

our $n   ||= 3;

while (my $file = shift @ARGV) {

	print STDERR "Processing $file...\n";

	my $out = $file;
	$out =~ s/txt$/dmp/;
    $out =~ s{/}{/$n-};

	my $str = read_file $file, binmode => ':utf8';
	my $hash = features($str, $n);

	$o ||= $out;

	open my $f, ">:utf8", $o or die "Can't create '$o': $!";
	print $f "use utf8;\n";
	print $f Dumper($hash);
	close $f;

	$o = undef; # -o will only work for one input file... so...
}


