<commit_before>=head1 NAME

Script::FlatFileToJson::FeatureStream - base class for feature streams
used for handling features inside FlatFileToJson.pm

=cut

package Script::FlatFileToJson::FeatureStream;
use strict;
use warnings;

sub new {
    my $class = shift;
    bless { @_ }, $class;
}

sub flatten_to_feature {
    my ( $self, $f, $class_index ) = @_;
    my @f = ( $class_index || 0,
              @{$f}{qw{ start end strand source phase type }},
              (map $f->{attributes}{$_}[0], qw(ID Name)),
              [ map $self->flatten_to_feature($_,1), @{$f->{child_features}} ],
            );
    # convert start to interbase and numify it
    $f[1] -= 1;
    # numify end
    $f[2] += 0;
    # convert strand to 1/0/-1/undef if necessary
    no warnings 'uninitialized';
    $f[3] = { '+' => 1, '-' => -1 }->{$f[3]} || $f[3] || undef;
    return \@f;
}

sub flatten_to_name {
    my ( $self, $f ) = @_;
    my @namerec = (
        [ grep defined, @{$f->{attributes}{Name}}, @{$f->{attributes}{Alias}} ],
        $self->{track_label},
        $f->{attributes}{Name}[0],
        @{$f}{'seq_id','start','end'},
        $f->{attributes}{ID}[0],
        );
    $namerec[4]--; #< to one-based<commit_msg>fix flatfile-to-json.pl serializing name coords as strings.  sigh.<commit_after>=head1 NAME

Script::FlatFileToJson::FeatureStream - base class for feature streams
used for handling features inside FlatFileToJson.pm

=cut

package Script::FlatFileToJson::FeatureStream;
use strict;
use warnings;

sub new {
    my $class = shift;
    bless { @_ }, $class;
}

sub flatten_to_feature {
    my ( $self, $f, $class_index ) = @_;
    my @f = ( $class_index || 0,
              @{$f}{qw{ start end strand source phase type }},
              (map $f->{attributes}{$_}[0], qw(ID Name)),
              [ map $self->flatten_to_feature($_,1), @{$f->{child_features}} ],
            );
    # convert start to interbase and numify it
    $f[1] -= 1;
    # numify end
    $f[2] += 0;
    # convert strand to 1/0/-1/undef if necessary
    no warnings 'uninitialized';
    $f[3] = { '+' => 1, '-' => -1 }->{$f[3]} || $f[3] || undef;
    return \@f;
}

sub flatten_to_name {
    my ( $self, $f ) = @_;
    my @namerec = (
        [ grep defined, @{$f->{attributes}{Name}}, @{$f->{attributes}{Alias}} ],
        $self->{track_label},
        $f->{attributes}{Name}[0],
        $f->{seq_id},
        (map $_+0, @{$f}{'start','end'}),
        $f->{attributes}{ID}[0],
        );
    $namerec[4]--; #< to one-based
{'fraction_non_alphanumeric': 0.19736842105263158, 'fraction_numerical': 0.01555023923444976, 'mean_word_length': 2.6257225433526012, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '7648170', 'n_tokens_mistral': 918, 'n_tokens_neox': 894, 'n_words': 209}