Module: Abstractor::CustomNlpProvider
- Defined in:
- lib/abstractor/custom_nlp_provider.rb
Class Method Summary collapse
-
.abstractor_object_values(abstractor_subject) ⇒ Hash
Formats the object values and object value variants for the passed in Abstractor::AbstractorSubject.
-
.determine_suggestion_endpoint(custom_nlp_provider) ⇒ String
Determines the suggestion endpoint for the passed in custom NLP provider.
-
.format_body_for_suggestion_endpoint(abstractor_abstraction, abstractor_abstraction_source, abstractor_text, source) ⇒ Hash
Formats the JSON body in preparation for submision to a custom NLP provider endpoint.
Class Method Details
.abstractor_object_values(abstractor_subject) ⇒ Hash
Formats the object values and object value variants for the passed in Abstractor::AbstractorSubject.
Preperation for submision to a custom NLP provider endpoint.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/abstractor/custom_nlp_provider.rb', line 49 def self.abstractor_object_values(abstractor_subject) object_values = [] abstractor_subject.abstractor_abstraction_schema.abstractor_object_values.each do |abstractor_object_value| object_value = {} object_value[:value] = abstractor_object_value.value object_value[:object_value_variants] = [] abstractor_object_value.abstractor_object_value_variants.each do |abstractor_object_value_variant| object_value[:object_value_variants] << { value: abstractor_object_value_variant.value } end object_values << object_value end object_values end |
.determine_suggestion_endpoint(custom_nlp_provider) ⇒ String
Determines the suggestion endpoint for the passed in custom NLP provider.
The endpoint is assumed to be configured in config/abstractor/custom_nlp_providers.yml. A template configratuon file can be generated in the host application by calling the rake task abstractor:custom_nlp_provider.
11 12 13 |
# File 'lib/abstractor/custom_nlp_provider.rb', line 11 def self.determine_suggestion_endpoint(custom_nlp_provider) suggestion_endpoint = YAML.load_file("#{Rails.root}/config/abstractor/custom_nlp_providers.yml")[custom_nlp_provider]['suggestion_endpoint'][Rails.env] end |
.format_body_for_suggestion_endpoint(abstractor_abstraction, abstractor_abstraction_source, abstractor_text, source) ⇒ Hash
Formats the JSON body in preparation for submision to a custom NLP provider endpoint.
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/abstractor/custom_nlp_provider.rb', line 98 def self.format_body_for_suggestion_endpoint(abstractor_abstraction, abstractor_abstraction_source, abstractor_text, source) object_values = CustomNlpProvider.abstractor_object_values(abstractor_abstraction.abstractor_subject) { abstractor_abstraction_schema_id: abstractor_abstraction.abstractor_subject.abstractor_abstraction_schema.id, abstractor_abstraction_id: abstractor_abstraction.id, abstractor_abstraction_source_id: abstractor_abstraction_source.id, source_id: source[:source_id], source_type: source[:source_type].to_s, source_method: source[:source_method], text: abstractor_text, object_values: object_values } end |