source: gs3-extensions/structured-image/trunk/perllib/plugins/GoogleVisionPagedImagePlugin.pm@ 37168

Last change on this file since 37168 was 37168, checked in by davidb, 15 months ago

The old style of http-greenstone:// was found to be not allowed in Fuseki in SPARQL queries (although it could be in a TTL file and ingested). Now chagned to http://ld.greenstone.org

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