<commit_before>package Mappings::MapConfig;

use strict;
use warnings;
use base 'Mappings::Rules';



sub actual_nginx_config {
    my $self = shift;
    
    my $config_or_error_type;
    my $suggested_links_type;
    my $config_line;
    my $suggested_links;
    my $archive_link;
    my $mapping_status = '';
    
    if ( defined $self->{'old_url_parts'}{'query'} ) {
        $mapping_status = lc $self->{'whole_tag'}
            if defined $self->{'whole_tag'};
        
        my $map_key = $self->{'old_url_parts'}{'query'};
        if ( defined $map_key ) {
            if ( defined $self->{'duplicates'}{$map_key} ) {
                $config_or_error_type = 'duplicate_entry_error';
                $config_line = $self->{'old_url'} . "\n";
            }
            elsif ( '410' eq $self->{'status'} ) {
                # 410 Gone
                $config_or_error_type = 'gone_map';
                $config_line = "~${map_key} 410;\n";
                $suggested_links_type = 'suggested_links_map';
                $suggested_links = $self->get_suggested_link($map_key, 1);
                $archive_link = $self->get_archive_link($map_key);
            }
            elsif ( '301' eq $self->{'status'} ) {
                if ( length $self->{'new_url'}) {
                    # 301 Moved Permanently
                    $config_or_error_type   = 'redirect_map';
                    $config_line = "~${map_key} $self->{'new_url'};\n";
                } 
                else {
                    $config_or_error_type = 'no_destination_error';
                    $config_line = "$self->{'old_url'}\n";
                }
            }
            $self->{'duplicates'}{$map_key} = 1;
        }
        else {
            $config_or_error_type = 'no_map_key_error'; 
            $config_line = "$self->{'old_url'}\n"; 
        }
        
        return(
            $self->{'old_url_parts'}{'host'},
            $config_or_error_type,
            $config_line,
            $suggested_links_type,
            $suggested_links,
            $archive_link
        );
    }
    # if no query string, we treat it as a furl
    else {
        return $self->location_config();
    }    
    
}
sub get_suggested_link {
    my $self   = shift;
    my $lookup = shift;
    my $is_map = shift;
    
    return unless defined $self->{'suggested'} && length $self->{'suggested'};
    <commit_msg>We've already established it has a query string by this point<commit_after>package Mappings::MapConfig;

use strict;
use warnings;
use base 'Mappings::Rules';



sub actual_nginx_config {
    my $self = shift;
    
    my $config_or_error_type;
    my $suggested_links_type;
    my $config_line;
    my $suggested_links;
    my $archive_link;
    my $mapping_status = '';
    

    $mapping_status = lc $self->{'whole_tag'}
        if defined $self->{'whole_tag'};
    
    my $map_key = $self->{'old_url_parts'}{'query'};
    if ( defined $map_key ) {
        if ( defined $self->{'duplicates'}{$map_key} ) {
            $config_or_error_type = 'duplicate_entry_error';
            $config_line = $self->{'old_url'} . "\n";
        }
        elsif ( '410' eq $self->{'status'} ) {
            # 410 Gone
            $config_or_error_type = 'gone_map';
            $config_line = "~${map_key} 410;\n";
            $suggested_links_type = 'suggested_links_map';
            $suggested_links = $self->get_suggested_link($map_key, 1);
            $archive_link = $self->get_archive_link($map_key);
        }
        elsif ( '301' eq $self->{'status'} ) {
            if ( length $self->{'new_url'}) {
                # 301 Moved Permanently
                $config_or_error_type   = 'redirect_map';
                $config_line = "~${map_key} $self->{'new_url'};\n";
            } 
            else {
                $config_or_error_type = 'no_destination_error';
                $config_line = "$self->{'old_url'}\n";
            }
        }
        $self->{'duplicates'}{$map_key} = 1;
    }
    else {
        $config_or_error_type = 'no_map_key_error'; 
        $config_line = "$self->{'old_url'}\n"; 
    }
    
    return(
        $self->{'old_url_parts'}{'host'},
        $config_or_error_type,
        $config_line,
        $suggested_links_type,
        $suggested_links,
        $archive_link
    );
   
    
}
sub get_suggested_link {
    my $self   = shift;
    my $lookup = shift;
    my $is_map = shift;
    
    return unless defined $self->{'suggested'} && length $self->{'suggested'};
    
{'fraction_non_alphanumeric': 0.14228546020453534, 'fraction_numerical': 0.00755891507336594, 'mean_word_length': 1.8601398601398602, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, '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': '3363087', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1450, 'n_words': 256}