Unidom Stapar 统计模式识别模型引擎
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The StAPaR (Statistical Approach of Pattern Recognition) domain model engine includes Classifier, Sample, Feature, Pattern Library, Pattern Library Inclusion, and Pattern Matching models. Unidom (统一领域对象模型)是一系列的领域模型引擎。统计模式识别领域模型引擎包括采样和匹配的模型。
Recent Update
Check out the Road Map to find out what's the next. Check out the Change Log to find out what's new.
Usage in Gemfile
gem 'unidom-stapar'
Run the Database Migration
rake db:migrate
The migration versions start with 200601.
Call the Model
Classifier
matched = nil
similarity_percentage = 0
valve = 60
candidates.each do |candidate|
similarity = recognize input, candidate
if similarity > valve
if similarity > similarity_percentage
matched = candidate
similarity_percentage = similarity
end
end
end
if matched.present?
PatternMatching.match!(input, matched: matched, with: similarity_percentage, above: valve, at: Time.now)
else
false
end
Include the Concerns
include Unidom::Stapar::Concerns::AsSample
include Unidom::Stapar::Concerns::AsFeature
As Feature
The As Feature concern do the following tasks for the includer automatically:
- Define the belongs_to :classifier macro as:
belongs_to :classifier, class_name: 'Unidom::Stapar::Classifier'
- Define the belongs_to :sample macro as:
belongs_to :sample, polymorphic: true
Disable the Model & Migration
If you only need the app components other than models, the migrations should be neglected, and the models should not be loaded.
# config/initializers/unidom.rb
Unidom::Common.configure do ||
[:neglected_namespaces] = %w{
Unidom::Stapar
}
end
RSpec examples
RSpec example manifest (run automatically)
# spec/models/unidom_spec.rb
require 'unidom/stapar/models_rspec'
# spec/types/unidom_spec.rb
require 'unidom/stapar/types_rspec'
# spec/validators/unidom_spec.rb
require 'unidom/stapar/validators_rspec'
RSpec shared examples (to be integrated)
# lib/unidom.rb
def initialize_unidom
Snapshot.class_eval do
include Unidom::Stapar::Concerns::AsSample
include Unidom::Stapar::Concerns::AsFeature
end
end
# spec/rails_helper.rb
require 'unidom'
initialize_unidom
# spec/support/unidom_rspec_shared_examples.rb
require 'unidom/stapar/rspec_shared_examples'
# spec/models/unidom/party/person_spec.rb
describe Snapshot, type: :model do
context do
model_attribtues = {
name: 'Tim'
}
it_behaves_like 'Unidom::Stapar::Concerns::AsSample', model_attribtues
it_behaves_like 'Unidom::Stapar::Concerns::AsFeature', model_attribtues
end
end