source: gs3-extensions/structured-image/trunk/perllib/plugins/GoogleVisionImagePlugin.pm

Last change on this file was 38287, checked in by davidb, 7 months ago

work with site and collection when forming LD URLs; also look to see if environment variable set for PREFIX to use

File size: 3.8 KB
Line 
1######################################################################
2#
3# GoogleVisionImagePlugin.pm -- plugin that extends the capability of
4# ImagePlugin to use Google Vision API allowing for: metadata labelling
5# of objects within a scene; OCR text recognition.
6#
7# A component of the Greenstone digital library software
8# from the New Zealand Digital Library Project at the
9# University of Waikato, New Zealand.
10#
11# Copyright (C) 1999 New Zealand Digital Library Project
12#
13# This program is free software; you can redistribute it and/or modify
14# it under the terms of the GNU General Public License as published by
15# the Free Software Foundation; either version 2 of the License, or
16# (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26#
27###########################################################################
28
29package GoogleVisionImagePlugin;
30
31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
33no strict 'subs';
34
35use utf8;
36use JSON qw( from_json );
37use Digest::MD5 qw( md5_hex );
38
39use gsprintf;
40use FileUtils;
41
42use ImagePlugin;
43use GoogleVisionAPIConverter;
44
45
46sub BEGIN {
47 @GoogleVisionImagePlugin::ISA = ('ImagePlugin', 'GoogleVisionAPIConverter');
48}
49
50my $arguments = [];
51
52
53my $options = { 'name' => "GoogleVisionImagePlugin",
54 'desc' => "{GoogleVisionImagePlugin.desc}",
55 'abstract' => "no",
56 'inherits' => "yes",
57 'args' => $arguments };
58
59sub new {
60 my ($class) = shift (@_);
61 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
62 push(@$pluginlist, $class);
63
64 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
65 push(@{$hashArgOptLists->{"OptList"}},$options);
66
67 new GoogleVisionAPIConverter($pluginlist, $inputargs, $hashArgOptLists, 1);
68 my $self = new ImagePlugin($pluginlist, $inputargs, $hashArgOptLists);
69
70 return bless $self, $class;
71}
72
73
74# do plugin specific processing of doc_obj
75sub process {
76 my $self = shift (@_);
77 # options??
78 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
79
80 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
81 my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path);
82 my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
83
84 $self->{'gv-dococr-json-filename-recs'} = [];
85
86 $self->run_gv_convert($filename_full_path,$url_encoded_filename,$doc_obj);
87
88 $self->SUPER::process(@_);
89}
90
91sub post_process_doc_obj {
92 my $self = shift (@_);
93 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
94
95 my $ret_val_ok = $self->SUPER::post_process_doc_obj(@_);
96
97 if ($ret_val_ok) {
98 $ret_val_ok = $self->opt_run_gen_openannotation($doc_obj);
99 #$ret_val_ok = $self->opt_run_gen_webannotation($doc_obj);
100 }
101
102 # Compute SimpleAnnotationServer short_id (md5_hex hash on OID)
103 # and store as metadata for later use
104 my $OID= $doc_obj->get_OID();
105
106 # my $sas_manifest_url = "http://ld.greenstone.org/intermuse/programmes-and-performers/$OID/manifest";
107 my $sas_manifest_url = $self->get_openannotation_ld_prefix("$OID/manifest");
108
109 my $sas_short_id = md5_hex($sas_manifest_url);
110
111 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(),"SASShortID",$sas_short_id);
112
113 return $ret_val_ok;
114}
115
1161;
117
118
119
120
121
122
123
124
125
126
127
Note: See TracBrowser for help on using the repository browser.