Changeset 37000


Ignore:
Timestamp:
2022-12-09T00:16:02+13:00 (12 months ago)
Author:
davidb
Message:

Changes after testing

Location:
gs3-extensions/structured-image/trunk/perllib/plugins
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/structured-image/trunk/perllib/plugins/GoogleVisionAPIConverter.pm

    r36989 r37000  
    5050}
    5151
    52 my $arguments =
    53     [ { 'name' => "enable_image_labelling",
    54     'desc' => "{GoogleVisionAPIConverter.enable_image_labelling}",
    55     'type' => "flag",
    56     'reqd' => "no" },
     52my $arguments = [
     53    { 'name' => "google_application_credentials",
     54      'desc' => "{GoogleVisionAPIConverter.google_applicatio_credentials}",
     55      'type' => "string",
     56      'reqd' => "no",
     57      'deft' => "google-sa-credentials-key.json"
     58    },
     59    { 'name' => "enable_image_labelling",
     60      'desc' => "{GoogleVisionAPIConverter.enable_image_labelling}",
     61      'type' => "flag",
     62      'reqd' => "no" },
    5763    { 'name' => "enable_image_ocr",
    58     'desc' => "{GoogleVisionAPIConverter.enable_image_ocr}",
    59     'type' => "flag",
    60     'reqd' => "no" },
     64      'desc' => "{GoogleVisionAPIConverter.enable_image_ocr}",
     65      'type' => "flag",
     66      'reqd' => "no" },
    6167    { 'name' => "enable_document_ocr",
    62     'desc' => "{GoogleVisionAPIConverter.enable_document_ocr}",
    63     'type' => "flag",
    64     'reqd' => "no" }
     68      'desc' => "{GoogleVisionAPIConverter.enable_document_ocr}",
     69      'type' => "flag",
     70      'reqd' => "no" }
    6571];
    6672
     
    113119}
    114120
    115 sub run_convert {
     121sub run_gv_convert {
    116122    my $self = shift (@_);
    117     my ($filename,$file,$doc_obj) = @_;
    118    
    119     my $section = $doc_obj->get_top_section();
     123    my ($filename,$file,$doc_obj,$opt_section) = @_;
     124   
     125    my $section = (defined $opt_section) ? $opt_section : $doc_obj->get_top_section();
    120126   
    121127    my $verbosity = $self->{'verbosity'};
    122128    my $outhandle = $self->{'outhandle'};
    123     print $outhandle "----- GoogleVisionAPIConveter run_convert -----\n";
     129    print $outhandle "----- GoogleVisionAPIConveter run_gv_convert -----\n";
    124130    # print STDERR "*****", $self->{'enable_document_ocr'}, "\n";
    125131
     
    143149        my $ofilename = &FileUtils::filenameConcatenate($cached_image_dir,"google-vision-output.json");
    144150        my $collect_dir = $ENV{'GSDLCOLLECTDIR'};
    145         my $credentials_filename = &FileUtils::filenameConcatenate($collect_dir, "etc", "atea-storage-cd63a39dfeb5.json");
     151        my $credentials_filename = &FileUtils::filenameConcatenate($collect_dir, "etc", $self->{'google_application_credentials'});
    146152
    147153        if ($vision_type_length == 1) {
     
    192198    };
    193199
    194     my $cursection = $doc_obj->get_top_section(); # get top section for text append
     200    #my $cursection = $doc_obj->get_top_section(); # get top section for text append
    195201   
    196202    my $decoded_json = from_json($json_text);
     
    198204    if ($vision_type eq "enable_document_ocr" || $vision_type eq "enable_image_ocr") {
    199205        $ocr_text = $decoded_json->{textAnnotations}[0]{description}; # access full ocr content
    200         $doc_obj->add_utf8_text( $cursection, $ocr_text); # append text to section
     206        $doc_obj->add_utf8_text( $section, $ocr_text); # append text to section
    201207
    202208        my $blocks = $decoded_json->{fullTextAnnotation}{pages}[0]{blocks};
     
    216222        }
    217223        for (keys %text_and_language) {
    218             $doc_obj->add_utf8_metadata ($cursection, "z_" . $_, $text_and_language{$_});
     224            $doc_obj->add_utf8_metadata ($section, "z_" . $_, $text_and_language{$_});
    219225        }
    220226
     
    224230        foreach my $label (@{ $ocr_text }) {
    225231            # write to metadata : 'description'='Book' 'score'='0.9' 'topicality'='0.9' 'mid'='/m/0123'
    226             $doc_obj->add_utf8_metadata ($cursection, "description", $label->{description});
    227             $doc_obj->add_utf8_metadata ($cursection, "score", $label->{score});
    228             $doc_obj->add_utf8_metadata ($cursection, "topicality", $label->{topicality});
    229             $doc_obj->add_utf8_metadata ($cursection, "mid", $label->{mid});
     232            $doc_obj->add_utf8_metadata ($section, "description", $label->{description});
     233            $doc_obj->add_utf8_metadata ($section, "score", $label->{score});
     234            $doc_obj->add_utf8_metadata ($section, "topicality", $label->{topicality});
     235            $doc_obj->add_utf8_metadata ($section, "mid", $label->{mid});
    230236            # write to metadata : 'descriptions'='Book' 'Book_score'='0.9' 'Book_topicality'='0.9' 'Book_mid'='/m/0123'
    231             $doc_obj->add_utf8_metadata ($cursection, "descriptions", $label->{description});
    232             $doc_obj->add_utf8_metadata ($cursection, $label->{description} . "_score", $label->{score});
    233             $doc_obj->add_utf8_metadata ($cursection, $label->{description} . "_topicality", $label->{topicality});
    234             $doc_obj->add_utf8_metadata ($cursection, $label->{description} . "_mid", $label->{mid});
     237            $doc_obj->add_utf8_metadata ($section, "descriptions", $label->{description});
     238            $doc_obj->add_utf8_metadata ($section, $label->{description} . "_score", $label->{score});
     239            $doc_obj->add_utf8_metadata ($section, $label->{description} . "_topicality", $label->{topicality});
     240            $doc_obj->add_utf8_metadata ($section, $label->{description} . "_mid", $label->{mid});
    235241
    236242        }
  • gs3-extensions/structured-image/trunk/perllib/plugins/GoogleVisionImagePlugin.pm

    r36989 r37000  
    8383    my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
    8484   
    85     $self->run_convert($filename_full_path,$url_encoded_filename,$doc_obj);
     85    $self->run_gv_convert($filename_full_path,$url_encoded_filename,$doc_obj);
    8686   
    8787    $self->SUPER::process(@_);
  • gs3-extensions/structured-image/trunk/perllib/plugins/GoogleVisionPagedImagePlugin.pm

    r36989 r37000  
    9393    my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
    9494   
    95     $self->run_convert($filename_full_path,$url_encoded_filename,$doc_obj);
     95    $self->run_gv_convert($filename_full_path,$url_encoded_filename,$doc_obj,$section);
    9696
    9797    return $self->SUPER::process_image(@_);
Note: See TracChangeset for help on using the changeset viewer.