Changeset 37000
- Timestamp:
- 2022-12-09T00:16:02+13:00 (12 months ago)
- 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 50 50 } 51 51 52 my $arguments = 53 [ { 'name' => "enable_image_labelling", 54 'desc' => "{GoogleVisionAPIConverter.enable_image_labelling}", 55 'type' => "flag", 56 'reqd' => "no" }, 52 my $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" }, 57 63 { '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" }, 61 67 { '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" } 65 71 ]; 66 72 … … 113 119 } 114 120 115 sub run_ convert {121 sub run_gv_convert { 116 122 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(); 120 126 121 127 my $verbosity = $self->{'verbosity'}; 122 128 my $outhandle = $self->{'outhandle'}; 123 print $outhandle "----- GoogleVisionAPIConveter run_ convert -----\n";129 print $outhandle "----- GoogleVisionAPIConveter run_gv_convert -----\n"; 124 130 # print STDERR "*****", $self->{'enable_document_ocr'}, "\n"; 125 131 … … 143 149 my $ofilename = &FileUtils::filenameConcatenate($cached_image_dir,"google-vision-output.json"); 144 150 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'}); 146 152 147 153 if ($vision_type_length == 1) { … … 192 198 }; 193 199 194 my $cursection = $doc_obj->get_top_section(); # get top section for text append200 #my $cursection = $doc_obj->get_top_section(); # get top section for text append 195 201 196 202 my $decoded_json = from_json($json_text); … … 198 204 if ($vision_type eq "enable_document_ocr" || $vision_type eq "enable_image_ocr") { 199 205 $ocr_text = $decoded_json->{textAnnotations}[0]{description}; # access full ocr content 200 $doc_obj->add_utf8_text( $ cursection, $ocr_text); # append text to section206 $doc_obj->add_utf8_text( $section, $ocr_text); # append text to section 201 207 202 208 my $blocks = $decoded_json->{fullTextAnnotation}{pages}[0]{blocks}; … … 216 222 } 217 223 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{$_}); 219 225 } 220 226 … … 224 230 foreach my $label (@{ $ocr_text }) { 225 231 # 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}); 230 236 # 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}); 235 241 236 242 } -
gs3-extensions/structured-image/trunk/perllib/plugins/GoogleVisionImagePlugin.pm
r36989 r37000 83 83 my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'}); 84 84 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); 86 86 87 87 $self->SUPER::process(@_); -
gs3-extensions/structured-image/trunk/perllib/plugins/GoogleVisionPagedImagePlugin.pm
r36989 r37000 93 93 my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'}); 94 94 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); 96 96 97 97 return $self->SUPER::process_image(@_);
Note:
See TracChangeset
for help on using the changeset viewer.