<commit_before>package MediaWords::Util::CrfExtractor;
use Modern::Perl "2012";
use MediaWords::CommonLibs;

use strict;

use Data::Dumper;
use List::Util qw(first max maxstr min minstr reduce shuffle sum);

#use List::MoreUtils qw( :all);
use List::Compare::Functional qw (get_unique get_complement get_union_ref );
use IPC::Open2;
use CRF::CrfUtils;
use Text::Trim;

use Moose;

with 'MediaWords::Util::Extractor';


sub getScoresAndLines
{
   my ( $self, $line_info, $preprocessed_lines ) = @_;

   my $extracted_lines = get_extracted_lines_with_crf( $line_info, $preprocessed_lines );

   return {
       included_line_numbers => $extracted_lines,
       scores                => [],
   };
}

sub getExtractedLines
{
    my ( $self, $line_infos, $preprocessed_lines  ) = @_;

    my $scores_and_lines = $self->getScoresAndLines( $line_infos, $preprocessed_lines );

    return $scores_and_lines->{ included_line_numbers };<commit_msg>Shoe horn into the expected format for the test classes by inlcuding a scores array ref.<commit_after>package MediaWords::Util::CrfExtractor;
use Modern::Perl "2012";
use MediaWords::CommonLibs;

use strict;

use Data::Dumper;
use List::Util qw(first max maxstr min minstr reduce shuffle sum);

#use List::MoreUtils qw( :all);
use List::Compare::Functional qw (get_unique get_complement get_union_ref );
use IPC::Open2;
use CRF::CrfUtils;
use Text::Trim;

use Moose;

with 'MediaWords::Util::Extractor';


sub getScoresAndLines
{
   my ( $self, $line_info, $preprocessed_lines ) = @_;

   my $extracted_lines = get_extracted_lines_with_crf( $line_info, $preprocessed_lines );

   my $scores = [];

   my %extracted_lines_hash = map { $_ => 1 } @ { $extracted_lines };

   foreach my $line ( @ { $line_info } )
   {
       my $score = {};

       $score->{ line_number } = $line->{ line_number } ;
       $score->{ is_story }    = defined( $extracted_lines_hash{ $line->{ line_number } } ) ? 1 : 0 ;

       push $scores, $score;
   }

   return {
       included_line_numbers => $extracted_lines,
       scores                => $scores,
   };
}

sub getExtractedLines
{
    my ( $self, $line_infos, $preprocessed_lines  ) = @_;

    my $scores_and_lines = $self->getScoresAndLines( $line_infos, $preprocessed_lines );

    return $scores_and_lines->{ included_line_numbers };
{'fraction_non_alphanumeric': 0.12878133102852204, 'fraction_numerical': 0.0056179775280898875, 'mean_word_length': 4.155902004454343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '4210307', 'n_tokens_mistral': 846, 'n_tokens_neox': 786, 'n_words': 184}