mindee 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cdb0922b8ea540511c91a760d0b9d76dd5ba87f5e85b88b6008511077fe852b
4
- data.tar.gz: 01a40229234d445a1838d71e945e7eacff7c8afdba2da09bb20fbf14670b21da
3
+ metadata.gz: d4d5ce164f9e839b743150857ad81fabdcaa4e9659c67ad96a21ecebae30fbf9
4
+ data.tar.gz: b15a4ebd4162152b8a931bcea424a33f42ea77a04d8f1857da888b5bdff02739
5
5
  SHA512:
6
- metadata.gz: cfecb4fc1da99567aa086e2af214544b294e6be7525984fab2775ff19877116203b0739bd1d8b9c66ef23205dbe8dcd277e89a149884cffd8bd10e133d3f8e46
7
- data.tar.gz: f5f389e634f5c8ec8637b9d3a051f44248500f7553bad550da0dc0f3d8e49a2f68c2d0251868f89b37f2d465efce92b55a4bdd65422f64a36cedf8e3e0932667
6
+ metadata.gz: 71252859a8e99d7da7d6eae65020cb0b5652224c00ff9c0b251f971017c95534bb1268f03e9c1612cc22a0ec4c47d6751017de8730fc49155750bc19c00ee42d
7
+ data.tar.gz: 383864204ffd86207eeb97d0bc48d8d88be9e3112cf68f06c47641ff509d314c4cc1ec2fd6237c9686ec44a87fd4a60b381e20810ef3ec6a3130bf118ca25068
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # Mindee Ruby API Library Changelog
2
2
 
3
- ## v1.0.0 (2022-07-28)
3
+ ## v1.1.0 - 2022-08-04
4
+ ### Changes
5
+ * :sparkles: Add support for custom API classification field (#5)
6
+
7
+ ## v1.0.0 - 2022-07-28
4
8
  * :tada: First release!
@@ -6,9 +6,12 @@ require_relative 'base'
6
6
  module Mindee
7
7
  # Custom document object.
8
8
  class CustomDocument < Document
9
- # All fields in the document
9
+ # All value fields in the document
10
10
  # @return [Hash<Symbol, Mindee::ListField>]
11
11
  attr_reader :fields
12
+ # All classifications in the document
13
+ # @return [Hash<Symbol, Mindee::ClassificationField>]
14
+ attr_reader :classifications
12
15
 
13
16
  # @param document_type [String]
14
17
  # @param prediction [Hash]
@@ -17,12 +20,10 @@ module Mindee
17
20
  def initialize(document_type, prediction, input_file: nil, page_id: nil)
18
21
  super(document_type, input_file: input_file)
19
22
  @fields = {}
23
+ @classifications = {}
20
24
  prediction.each do |field_name, field_prediction|
21
25
  field_sym = field_name.to_sym
22
- complete_field = ListField.new(field_prediction, page_id)
23
-
24
- # Add the field to the `fields` array
25
- @fields[field_sym] = complete_field
26
+ complete_field = set_field(field_sym, field_prediction, page_id)
26
27
 
27
28
  # Create a dynamic accessor function for the field
28
29
  singleton_class.module_eval { attr_accessor field_sym }
@@ -34,11 +35,31 @@ module Mindee
34
35
  out_str = String.new
35
36
  out_str << "----- #{@document_type} -----"
36
37
  out_str << "\nFilename: #{@filename}".rstrip
38
+ @classifications.each do |name, info|
39
+ out_str << "\n#{name}: #{info}".rstrip
40
+ end
37
41
  @fields.each do |name, info|
38
42
  out_str << "\n#{name}: #{info}".rstrip
39
43
  end
40
44
  out_str << "\n----------------------"
41
45
  out_str
42
46
  end
47
+
48
+ private
49
+
50
+ # @param field_prediction [Hash]
51
+ def set_field(field_sym, field_prediction, page_id)
52
+ # Currently two types of fields possible in a custom API response:
53
+ # fields having a list of values, and classification fields.
54
+ # Here we use the fact that only value lists have the 'values' attribute.
55
+
56
+ if field_prediction.key? 'values'
57
+ @fields[field_sym] = ListField.new(field_prediction, page_id)
58
+ elsif field_prediction.key? 'value'
59
+ @classifications[field_sym] = ClassificationField.new(field_prediction)
60
+ else
61
+ throw 'Unknown API field type'
62
+ end
63
+ end
43
64
  end
44
65
  end
@@ -1,6 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mindee
4
+ # Document classification (custom docs)
5
+ class ClassificationField
6
+ # @param prediction [Hash]
7
+ def initialize(prediction)
8
+ @value = prediction['value']
9
+ @confidence = prediction['confidence']
10
+ end
11
+
12
+ def to_s
13
+ @value
14
+ end
15
+ end
16
+
4
17
  # Field in a list.
5
18
  class ListFieldItem
6
19
  # The confidence score, value will be between 0.0 and 1.0
data/lib/mindee/fields.rb CHANGED
@@ -8,4 +8,4 @@ require_relative 'fields/locale'
8
8
  require_relative 'fields/orientation'
9
9
  require_relative 'fields/payment_details'
10
10
  require_relative 'fields/tax'
11
- require_relative 'fields/list_field'
11
+ require_relative 'fields/custom_docs'
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Mindee
4
4
  module Mindee
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
 
7
7
  def self.find_platform
8
8
  host = RbConfig::CONFIG['host_os']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mindee
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mindee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-26 00:00:00.000000000 Z
11
+ date: 2022-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: marcel
@@ -87,8 +87,8 @@ files:
87
87
  - lib/mindee/fields/amount.rb
88
88
  - lib/mindee/fields/base.rb
89
89
  - lib/mindee/fields/company_registration.rb
90
+ - lib/mindee/fields/custom_docs.rb
90
91
  - lib/mindee/fields/datefield.rb
91
- - lib/mindee/fields/list_field.rb
92
92
  - lib/mindee/fields/locale.rb
93
93
  - lib/mindee/fields/orientation.rb
94
94
  - lib/mindee/fields/payment_details.rb