unidom-stapar 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e673f9b0f1c435abff99992f0c6296037a091ed93400b6e52fa23c7099b354f1
4
- data.tar.gz: 191a261f084087107fd4133eab25fa1a950bb3dd930aff585e685f7700db4e21
3
+ metadata.gz: 6ec81f2342288a8bcc6f131f291b216b7bebf172ae99bfddad0e4a36fe3a9f65
4
+ data.tar.gz: 6cf88d8b259a16dc31e039966b49424e37e6fb35033845edf5aa5ef421450cd5
5
5
  SHA512:
6
- metadata.gz: 5cae2006e5fc7102d04907bbaccc32bab0776906ce6eb819f1d96c135e265b181afff2f6f54409f939827fc36aa6ef97eab2de136b1522e780426cc0818ff533
7
- data.tar.gz: bcb8049fc2361c057064016e2c2cb8e4bda7aa568ed62b81087f272bf0d366c20737f94770ac3cd49f26d619518e92e8e645673f0b1f8fc9d12d99c0049612d4
6
+ metadata.gz: 504031fe67a904d4ea134ca88fe67c0e1708a60aed953a9d10e06bc41f46c61bc103638a32522ea68a6b98c712aeac10bade466f42090ef2ae422551489da04a
7
+ data.tar.gz: a83b0baaeb4ec60c697f0f7f591a57827749183bd9c11dd2b669c723dd25012bf6b79683655f702487a77328097b3684f207079363ab5fe80bc0049e9224719e
data/README.md CHANGED
@@ -38,7 +38,26 @@ The migration versions start with 200601.
38
38
  ## Call the Model
39
39
 
40
40
  ```ruby
41
- PatternMatching
41
+ Classifier
42
+
43
+ matched = nil
44
+ similarity_percentage = 0
45
+ valve = 60
46
+ candidates.each do |candidate|
47
+ similarity = recognize input, candidate
48
+ if similarity > valve
49
+ if similarity > similarity_percentage
50
+ matched = candidate
51
+ similarity_percentage = similarity
52
+ end
53
+ end
54
+ end
55
+
56
+ if matched.present?
57
+ PatternMatching.match!(input, matched: matched, with: similarity_percentage, above: valve, at: Time.now)
58
+ else
59
+ false
60
+ end
42
61
  ```
43
62
 
44
63
 
@@ -54,10 +73,8 @@ include Unidom::Stapar::Concerns::AsFeature
54
73
 
55
74
  The As Feature concern do the following tasks for the includer automatically:
56
75
 
57
- 1. Define the has_many :stapar_carts macro as: ``has_many :stapar_carts, class_name: 'Unidom::stapar::staparCart', as: :shopper``
58
- 2. Define the #get_cart! method as: ``get_cart!(from: nil, at: Time.now)``
59
- 3. Define the #get_cart? method as: ``get_cart?(from: nil, at: Time.now)``
60
-
76
+ 1. Define the belongs_to :classifier macro as: ``belongs_to :classifier, class_name: 'Unidom::Stapar::Classifier'``
77
+ 2. Define the belongs_to :sample macro as: ``belongs_to :sample, polymorphic: true``
61
78
 
62
79
 
63
80
  ## Disable the Model & Migration
@@ -1,7 +1,8 @@
1
1
  ##
2
2
  # Classifier 表示模式识别分类器。
3
3
 
4
- class Unidom::Stapar::Classifier < Unidom::Stapar::ApplicationRecord
4
+ module Unidom::Stapar
5
+ class Classifier < ApplicationRecord
5
6
 
6
7
  self.table_name = 'unidom_classifiers'
7
8
 
@@ -22,4 +23,5 @@ class Unidom::Stapar::Classifier < Unidom::Stapar::ApplicationRecord
22
23
  scope :data_format_version_is, -> (data_format_version) { where data_format_version: data_format_version }
23
24
  scope :applied_species_is, -> (applied_species) { where applied_species: applied_species }
24
25
 
25
- end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Stapar::Classifier'
26
+ end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Stapar::Classifier'
27
+ end
@@ -22,10 +22,6 @@ module Unidom::Stapar::Concerns::AsFeature
22
22
 
23
23
  module ClassMethods
24
24
 
25
- def classify!(sample, by: nil, extracted: nil, into: nil, at: Time.now)
26
- create! sample: sample, classifier: by, extracted_link: extracted, feature_link: into, opened_at: at
27
- end
28
-
29
25
  end
30
26
 
31
27
  end
@@ -14,9 +14,14 @@ module Unidom::Stapar::Concerns::AsSample
14
14
 
15
15
  scope :raw_data_link_is, -> (raw_data_link) { where raw_data_link: raw_data_link }
16
16
 
17
+ def is_classified!(into: nil, per: nil, by: nil, at: Time.now)
18
+ create! sample: self, classifier: by, extracted_link: per, feature_link: into, opened_at: at
19
+ end
20
+
17
21
  end
18
22
 
19
23
  module ClassMethods
24
+
20
25
  end
21
26
 
22
27
  end
@@ -0,0 +1,26 @@
1
+ ##
2
+ # Pattern Matching 表示模式识别匹配记录。
3
+
4
+ module Unidom::Stapar
5
+ class PatternMatching < ApplicationRecord
6
+
7
+ self.table_name = 'unidom_pattern_matchings'
8
+
9
+ include Unidom::Common::Concerns::ModelExtension
10
+ include ProgneTapera::EnumCode
11
+
12
+ belongs_to :matched, polymorphic: true
13
+ belongs_to :input, polymorphic: true
14
+
15
+ validates :similarity_percentage, presence: true, numericality: { greater_than: 0, less_than_or_equal_to: 100 }
16
+ validates :valve_percentage, presence: true, numericality: { greater_than: 0, less_than_or_equal_to: 100, only_integer: true }
17
+
18
+ scope :matched_is, -> (matched) { where matched: matched }
19
+ scope :input_is, -> (input) { where input: input }
20
+
21
+ def self.match!(input, matched: nil, with: 0.0, above: 0, at: Time.now)
22
+ create! matched: matched, input: input, valve_percentage: above, similarity_percentage: with, opened_at: at
23
+ end
24
+
25
+ end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Stapar::PatternMatching'
26
+ end
@@ -0,0 +1,33 @@
1
+ class CreateUnidomPatternMatchings < ActiveRecord::Migration[6.0]
2
+
3
+ def change
4
+
5
+ create_table :unidom_pattern_matchings, id: :uuid do |t|
6
+
7
+ t.references :matched, type: :uuid, null: false,
8
+ polymorphic: { null: false, default: '', limit: 200 }
9
+ t.references :input, type: :uuid, null: false,
10
+ polymorphic: { null: false, default: '', limit: 200 }
11
+
12
+ t.decimal :similarity_percentage, null: false, default: 0.0, precision: 12, scale: 2
13
+ t.integer :valve_percentage, null: false, default: 0
14
+
15
+ t.text :instruction
16
+ t.text :description
17
+
18
+ t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
19
+ t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
20
+ t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
21
+ t.boolean :defunct, null: false, default: false
22
+ t.jsonb :notation, null: false, default: {}
23
+
24
+ t.timestamps null: false
25
+
26
+ end
27
+
28
+ add_index :unidom_pattern_matchings, :input_id
29
+ add_index :unidom_pattern_matchings, :matched_id
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,37 @@
1
+ require 'rails_helper'
2
+
3
+ describe Unidom::Stapar::PatternMatching, type: :model do
4
+
5
+ before :each do
6
+ end
7
+
8
+ after :each do
9
+ end
10
+
11
+ context do
12
+
13
+ classifier = Unidom::Stapar::Classifier.first_or_create! supplier_name: 'Intelligent Works',
14
+ algorithm_name: 'FR Pro',
15
+ data_format_version: 1,
16
+ applied_species: 'Homo sapiens',
17
+ applied_field_code: 'FACE'
18
+ matched = classifier
19
+ input = classifier
20
+
21
+ model_attributes = {
22
+ matched: matched,
23
+ input: input,
24
+ similarity_percentage: 91.35,
25
+ valve_percentage: 60
26
+ }
27
+
28
+ it_behaves_like 'Unidom::Common::Concerns::ModelExtension', model_attributes
29
+
30
+ it_behaves_like 'validates numericality', model_attributes, :similarity_percentage,
31
+ range: 0..100, minimum_inclusive: false, maximum_inclusive: true, only_integer: false
32
+ it_behaves_like 'validates numericality', model_attributes, :valve_percentage,
33
+ range: 0..100, minimum_inclusive: false, maximum_inclusive: true, only_integer: true
34
+
35
+ end
36
+
37
+ end
@@ -1 +1,2 @@
1
- require 'rspec/models/unidom/stapar/classifier_spec' unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Stapar::Classifier'
1
+ require 'rspec/models/unidom/stapar/classifier_spec' unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Stapar::Classifier'
2
+ require 'rspec/models/unidom/stapar/pattern_matching_spec' unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Stapar::PatternMatching'
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Stapar
3
- VERSION = '0.2'
3
+ VERSION = '0.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-stapar
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
@@ -46,15 +46,18 @@ files:
46
46
  - app/models/unidom/stapar/classifier.rb
47
47
  - app/models/unidom/stapar/concerns/as_feature.rb
48
48
  - app/models/unidom/stapar/concerns/as_sample.rb
49
+ - app/models/unidom/stapar/pattern_matching.rb
49
50
  - app/types/unidom/stapar/applied_field.rb
50
51
  - app/views/layouts/unidom/stapar/application.html.erb
51
52
  - config/enum.yml
52
53
  - config/locales/enum.zh-CN.yml
53
54
  - config/routes.rb
54
55
  - db/migrate/20060101000000_create_unidom_classifiers.rb
56
+ - db/migrate/20060102000000_create_unidom_pattern_matchings.rb
55
57
  - lib/rspec/models/unidom/stapar/classifier_spec.rb
56
58
  - lib/rspec/models/unidom/stapar/concerns/as_feature_shared_examples.rb
57
59
  - lib/rspec/models/unidom/stapar/concerns/as_sample_shared_examples.rb
60
+ - lib/rspec/models/unidom/stapar/pattern_matching_spec.rb
58
61
  - lib/rspec/types/unidom/stapar/applied_field_spec.rb
59
62
  - lib/tasks/unidom/stapar_tasks.rake
60
63
  - lib/unidom/stapar.rb