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 +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/mindee/documents/custom.rb +26 -5
- data/lib/mindee/fields/{list_field.rb → custom_docs.rb} +13 -0
- data/lib/mindee/fields.rb +1 -1
- data/lib/mindee/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4d5ce164f9e839b743150857ad81fabdcaa4e9659c67ad96a21ecebae30fbf9
|
4
|
+
data.tar.gz: b15a4ebd4162152b8a931bcea424a33f42ea77a04d8f1857da888b5bdff02739
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71252859a8e99d7da7d6eae65020cb0b5652224c00ff9c0b251f971017c95534bb1268f03e9c1612cc22a0ec4c47d6751017de8730fc49155750bc19c00ee42d
|
7
|
+
data.tar.gz: 383864204ffd86207eeb97d0bc48d8d88be9e3112cf68f06c47641ff509d314c4cc1ec2fd6237c9686ec44a87fd4a60b381e20810ef3ec6a3130bf118ca25068
|
data/CHANGELOG.md
CHANGED
@@ -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 =
|
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
data/lib/mindee/version.rb
CHANGED
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.
|
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-
|
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
|