Module: Abstractor::CustomNlpProvider

Defined in:
lib/abstractor/custom_nlp_provider.rb

Class Method Summary collapse

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.

Examples:

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

{
  "abstractor_abstraction_schema_id":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.",
  "object_values": [
    { "value": "glioblastoma, nos",
      "object_value_variants":[
        { "value": "glioblastoma" },
        { "value": "gbm" },
        { "value": "spongioblastoma multiforme"}
      ]
    },
    { "value": "meningioma, nos",
      "object_value_variants":[
        { "value": "meningioma" },
        { "value": "leptomeningioma" },
        { "value": "meningeal fibroblastoma" }
      ]
    }
  ]
}

Parameters:

Returns:

  • (Hash)


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.

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_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.",
  "object_values": [
    { "value": "glioblastoma, nos",
      "object_value_variants":[
        { "value": "glioblastoma" },
        { "value": "gbm" },
        { "value": "spongioblastoma multiforme"}
      ]
    },
    { "value": "meningioma, nos",
      "object_value_variants":[
        { "value": "meningioma" },
        { "value": "leptomeningioma" },
        { "value": "meningeal fibroblastoma" }
      ]
    }
  ]
}

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.



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