<commit_before>#!/usr/bin/perl
use strict;
use warnings;
$|++;
use Data::Dumper;
use Date::Parse;
use DBI;
use JSON; our $JSON = JSON->new()->utf8(1)->pretty(1)->canonical(1); # TODO utf8
use utf8;

# http://github.com/ohait/perl-dbi-sugar.git
use lib 'perl-dbi-sugar/lib';
use DBI::Sugar;
BEGIN {
    # find Koha's Perl modules
    use FindBin;
    eval { require "$FindBin::Bin/usr/share/koha/bin/kohalib.pl" };
}
use C4::Context;
alarm(280);

my $output = $ARGV[0] or die("missing filename");

DBI::Sugar::factory {
    my $dbh = C4::Context->dbh;
    return $dbh, SELECT_TIME => sub {
        my ($q, $b, $dt) = @_;
        print STDERR Dumper(\@_) if $dt > 0.5;
    };
};


sub category {
    my (%meta) = @_;
    my $mt = $meta{mediatypes};
    my $fmt = $meta{loc_format}; # 090$b
    my $dewey = $meta{loc_dewey}; # 090$c
    my $location = $meta{location}//'';

    if ($mt =~ m{^(Film|Spill|Tegneserie|Noter|Lydbok|Musikkopptak)$}) {
        return $mt;
    }
    if ($mt eq 'Andre') {
        return 'Annen';
    }

    if ($fmt =~ m{^\w*[bu]} or $location =~ m{^(BARNEFAG|UNG|UNGFAG)$}) {
        if ($dewey or $fmt =~ m{E}) {
            return 'Fag barn';
        } else {
            return 'Skjønn barn';
        }
    } else {
        if ($dewey) {
            return 'Fag voksen';
        } else {
            return 'Skjønn voksen';
        }
    }
    warn "unknown category, using Annen: ".Dumper(\%meta)."...";
    return 'Annen';<commit_msg>plukkliste: better guess at fiction/nonfiction category<commit_after>#!/usr/bin/perl
use strict;
use warnings;
$|++;
use Data::Dumper;
use Date::Parse;
use DBI;
use JSON; our $JSON = JSON->new()->utf8(1)->pretty(1)->canonical(1); # TODO utf8
use utf8;

# http://github.com/ohait/perl-dbi-sugar.git
use lib 'perl-dbi-sugar/lib';
use DBI::Sugar;
BEGIN {
    # find Koha's Perl modules
    use FindBin;
    eval { require "$FindBin::Bin/usr/share/koha/bin/kohalib.pl" };
}
use C4::Context;
alarm(280);

my $output = $ARGV[0] or die("missing filename");

DBI::Sugar::factory {
    my $dbh = C4::Context->dbh;
    return $dbh, SELECT_TIME => sub {
        my ($q, $b, $dt) = @_;
        print STDERR Dumper(\@_) if $dt > 0.5;
    };
};


sub category {
    my (%meta) = @_;
    my $mt = $meta{mediatypes};
    my $fmt = $meta{loc_format}; # 090$b
    my $dewey = $meta{loc_dewey}; # 090$c
    my $location = $meta{location}//'';
    my $fiction = $meta{fiction};

    if ($mt =~ m{^(Film|Spill|Tegneserie|Noter|Lydbok|Musikkopptak)$}) {
        return $mt;
    }
    if ($mt eq 'Andre') {
        return 'Annen';
    }

    if ($fmt =~ m{^\w*[bu]} or $location =~ m{^(BARNEFAG|UNG|UNGFAG)$}) {
        if ($fiction eq "0") {
            return 'Fag barn';
        } else {
            return 'Skjønn barn';
        }
    } else {
        if ($fiction eq "0") {
            return 'Fag voksen';
        } else {
            return 'Skjønn voksen';
        }
    }
    warn "unknown category, using Annen: ".Dumper(\%meta)."...";
    return 'Annen';
{'fraction_non_alphanumeric': 0.1906187624750499, 'fraction_numerical': 0.013972055888223553, 'mean_word_length': 2.4682814302191467, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6062896', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1172, 'n_words': 264}