Changeset 34804 for gs3-extensions


Ignore:
Timestamp:
2021-02-03T22:43:17+13:00 (3 years ago)
Author:
davidb
Message:

Plugin code extended to extract AV values from CSV file and associate it with doc as JSON data

Location:
gs3-extensions/mars-src/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/mars-src/trunk/perllib/plugins/EssentiaPlugin.pm

    r34411 r34804  
    119119    my $outhandle = $self->{'outhandle'};
    120120    my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
    121 
     121   
    122122    my $top_section = $doc_obj->get_top_section();
    123123
     
    143143                 $hpcp_mime_type, $top_section);
    144144
     145    # Arousal + Valence (AV)
     146    my $av_filename_full_path = $filename_full_path;
     147    $av_filename_full_path =~ s/\..*?$/_essentiafeatures_frames_AV.csv/;
     148   
     149    my $av_features_filename = $self->extract_av_features($av_filename_full_path);
     150    my ($av_features_ext) = ($av_features_filename =~ m/\.([^.]+)$/);
    145151
    146 
     152    my $av_mime_type = ($av_features_ext eq "json") ? "application/json" : "text/plain";
     153    $doc_obj->associate_file($av_features_filename, "av.$features_ext",
     154                 $av_mime_type, $top_section); 
    147155    }
    148156
  • gs3-extensions/mars-src/trunk/perllib/plugins/pEssentiaExtractor.pm

    r34411 r34804  
    331331    return ($target_file_path);
    332332}
    333    
     333
     334
     335   
     336sub extract_av_features
     337{
     338    my $self = shift(@_);
     339    my $source_file_path = shift(@_);
     340    my $convert_options  = shift(@_) || "";
     341
     342    my $outhandle = $self->{'outhandle'};
     343    my $verbosity = $self->{'verbosity'};
     344
     345    my $source_file_no_path = &File::Basename::basename($source_file_path);
     346   
     347    $self->init_cache_for_file($source_file_path);
     348
     349    # Determine the full name and path of the output file
     350    my $target_file_type="json";
     351    my $target_file_path;
     352
     353    if ($self->{'enable_cache'}) {
     354    my $cached_dir = $self->{'cached_dir'};
     355    my $file_root = $self->{'cached_file_root'};
     356
     357    my $target_file = "$file_root-av.$target_file_type";
     358
     359    $target_file_path = &util::filename_cat($cached_dir,$target_file);
     360    }
     361    else {
     362    $target_file_path = &util::get_tmp_filename($target_file_type);
     363    }
     364
     365    my $essentia_output_directory = $self->{'essentia_output_directory'};
     366   
     367    my $av_cmd = "csv-extract-av-to-json.pl $convert_options \"$source_file_path\" \"$target_file_path\"";
     368   
     369    # Test the execution path
     370    print("EXECUTION CMD: $av_cmd\n");
     371   
     372    my $print_info = { 'message_prefix' => "AV",
     373               'message'        => "Extracting Arousal+Valence (AV) features from $source_file_no_path" };
     374   
     375    my ($regenerated,$result,$had_error)
     376    = $self->autorun_general_cmd($av_cmd,$source_file_path,$target_file_path,$print_info);
     377   
     378
     379    return ($target_file_path);
     380}
    334381
    335382
Note: See TracChangeset for help on using the changeset viewer.