Module: Abstractor::CustomNlpProvider

Defined in:
lib/abstractor/custom_nlp_provider.rb

Class Method Summary collapse

Class Method Details

.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.

Parameters:

  • custom_nlp_provider (String)

    The name of the custom NLP provider whose endpoint should be determined.

Returns:



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.

Examples:

Example of body prepared by Abstractor to submit to an custom NLP provider

{
  "abstractor_abstraction_schema_id":1,
  "abstractor_abstraction_schema_uri":"https://moomin.com/abstractor_abstraction_schemas/1",
  "abstractor_abstraction_id":1,
  "abstractor_abstraction_source_id":1,
  "source_type":  "PathologyCase",
  "source_method": "note_text",
  "text": "The patient has a diagnosis of glioblastoma.  GBM does not have a good prognosis.  But I can't rule out meningioma."
}

Parameters:

  • abstractor_abstraction (Abstractor::AbstractorAbstraction)

    The abstractor abstraction to be formated for submission to a custom nlp provider endpoint.

  • abstractor_abstraction_source (Abstractor::AbstractorAbstractionSource)

    The abstractor abstraction source to be formated for submission to a custom nlp provider endpoint.

  • abstractor_text (String)

    The text be formated for submission to a custom nlp provider endpoint.

  • source (Hash)

    The hash of values representing the source for submission to a custom nlp provider endpoint.

Returns:

  • (Hash)

    The formatted body.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/abstractor/custom_nlp_provider.rb', line 35

def self.format_body_for_suggestion_endpoint(abstractor_abstraction, abstractor_abstraction_source, abstractor_text, source)
  {
    abstractor_abstraction_schema_id: abstractor_abstraction.abstractor_subject.abstractor_abstraction_schema.id,
    abstractor_abstraction_schema_uri: Abstractor::Engine.routes.url_helpers.abstractor_abstraction_schema_url(abstractor_abstraction.abstractor_subject.abstractor_abstraction_schema,  format: :json),
    abstractor_abstraction_abstractor_suggestions_uri: Abstractor::Engine.routes.url_helpers.abstractor_abstraction_abstractor_suggestions_url(abstractor_abstraction, format: :json),
    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
  }
end