class IiifGoogleCv::Client
Constants
- SCALE_FACTOR
Attributes
manifest[R]
manifest_url[R]
Public Class Methods
new(manifest_url: nil, manifest: nil)
click to toggle source
# File lib/iiif_google_cv/client.rb, line 13 def initialize(manifest_url: nil, manifest: nil) unless manifest_url || manifest raise( ArgumentError, 'manifest_url or manifest must be provided' ) end @manifest_url = manifest_url @manifest = manifest end
Public Instance Methods
annotations()
click to toggle source
# File lib/iiif_google_cv/client.rb, line 36 def annotations puts "Annotating #{image_resources}" @annotations ||= [*vision.annotate( *image_resources, faces: true, labels: true, landmarks: true, logos: true, text: true )] end
canvas_id(idx)
click to toggle source
# File lib/iiif_google_cv/client.rb, line 62 def canvas_id(idx) iiif_manifest.sequences.map do |s| s.canvases[idx]['@id'] end.flatten.compact.first end
iiif_annotations(i)
click to toggle source
# File lib/iiif_google_cv/client.rb, line 89 def iiif_annotations(i) IiifGoogleCv::Annotations.new(self).iiif_annotations(i) end
iiif_manifest()
click to toggle source
# File lib/iiif_google_cv/client.rb, line 68 def iiif_manifest @iiif_manifest ||= IIIF::Service.parse(manifest_body) end
iiif_manifest_with_annotations()
click to toggle source
# File lib/iiif_google_cv/client.rb, line 73 def iiif_manifest_with_annotations @iiif_manifest_with_annotations ||= iiif_manifest.clone @iiif_manifest_with_annotations['@id'] = url @iiif_manifest_with_annotations.sequences.map do |s| s.canvases.map.with_index do |c, i| c.other_content = [ { '@id' => iiif_annotations(i), '@type' => 'sc:AnnotationList' } ] end end putson.put(@iiif_manifest_with_annotations) end
image_resources()
click to toggle source
# File lib/iiif_google_cv/client.rb, line 52 def image_resources iiif_manifest.sequences.collect do |s| s.canvases.collect do |c| c.images.collect do |i| i.resource['@id'].gsub('full/0', "pct:#{(SCALE_FACTOR * 100).to_i}/0") end end end.flatten.compact end
manifest_body()
click to toggle source
# File lib/iiif_google_cv/client.rb, line 93 def manifest_body return manifest if manifest @manifest = Faraday.get(manifest_url).body @manifest end
process()
click to toggle source
# File lib/iiif_google_cv/client.rb, line 48 def process annotations end
putson()
click to toggle source
# File lib/iiif_google_cv/client.rb, line 24 def putson @putson ||= Putson::Client.new end
url()
click to toggle source
# File lib/iiif_google_cv/client.rb, line 28 def url putson.url || putson.post({}) end
vision()
click to toggle source
# File lib/iiif_google_cv/client.rb, line 32 def vision @vision ||= Google::Cloud::Vision.new end