noahsettersten commited on
Commit
10eac7e
1 Parent(s): 682498c

chore: Include atom for each weighting result

Browse files
lib/medical_transcription/coding.ex CHANGED
@@ -90,12 +90,11 @@ defmodule MedicalTranscription.Coding do
90
  Enum.reduce(relevant_feedbacks, code_vector_match, fn feedback, acc ->
91
  new_attributes = weight_code_vector_similarity(acc.cosine_similarity, feedback)
92
 
93
- Map.merge(acc, new_attributes)
94
  end)
95
  end
96
  end
97
 
98
- # TODO: How to combine multiple weighting symbols into the result?
99
  defp weight_code_vector_similarity(_similarity, nil), do: %{weighting: :none}
100
 
101
  defp weight_code_vector_similarity(similarity, %{response: true}) do
@@ -112,6 +111,12 @@ defmodule MedicalTranscription.Coding do
112
  }
113
  end
114
 
 
 
 
 
 
 
115
  # Remove matches that don't exceed a given threshold.
116
  defp filter_below_threshold(code_vector_matches, similarity_threshold) do
117
  Enum.filter(
@@ -135,7 +140,8 @@ defmodule MedicalTranscription.Coding do
135
  id: v.id,
136
  code: v.code,
137
  description: v.description,
138
- cosine_similarity: 1 - cosine_distance(v.description_vector, ^search_vector)
 
139
  }
140
  )
141
  end
@@ -153,7 +159,8 @@ defmodule MedicalTranscription.Coding do
153
  id: v.id,
154
  code: v.code,
155
  description: v.description,
156
- cosine_similarity: 1 - cosine_distance(v.description_vector, ^search_vector)
 
157
  }
158
  )
159
  end
 
90
  Enum.reduce(relevant_feedbacks, code_vector_match, fn feedback, acc ->
91
  new_attributes = weight_code_vector_similarity(acc.cosine_similarity, feedback)
92
 
93
+ Map.merge(acc, new_attributes, &merge_code_vector_match_attributes/3)
94
  end)
95
  end
96
  end
97
 
 
98
  defp weight_code_vector_similarity(_similarity, nil), do: %{weighting: :none}
99
 
100
  defp weight_code_vector_similarity(similarity, %{response: true}) do
 
111
  }
112
  end
113
 
114
+ defp merge_code_vector_match_attributes(:weighting, value1, value2) do
115
+ value1 ++ [value2]
116
+ end
117
+
118
+ defp merge_code_vector_match_attributes(_key, _value1, value2), do: value2
119
+
120
  # Remove matches that don't exceed a given threshold.
121
  defp filter_below_threshold(code_vector_matches, similarity_threshold) do
122
  Enum.filter(
 
140
  id: v.id,
141
  code: v.code,
142
  description: v.description,
143
+ cosine_similarity: 1 - cosine_distance(v.description_vector, ^search_vector),
144
+ weighting: []
145
  }
146
  )
147
  end
 
159
  id: v.id,
160
  code: v.code,
161
  description: v.description,
162
+ cosine_similarity: 1 - cosine_distance(v.description_vector, ^search_vector),
163
+ weighting: []
164
  }
165
  )
166
  end
test/medical_transcription/coding_test.exs CHANGED
@@ -2,7 +2,7 @@ defmodule MedicalTranscription.CodingTest do
2
  use MedicalTranscription.DataCase
3
 
4
  alias MedicalTranscription.Coding
5
- alias MedicalTranscription.Coding.{CodeVector, CodeVectorMatch}
6
  alias MedicalTranscription.Feedback.CodeFeedback
7
 
8
  def create_code_vector!(code, description) do
@@ -65,7 +65,7 @@ defmodule MedicalTranscription.CodingTest do
65
  results = Coding.process_chunk(@input_text)
66
 
67
  assert Enum.map(results, & &1.code) == ["74685", "41412", "V717", "V812", "V4589"]
68
- assert Enum.map(results, & &1.weighting) == [:none, :none, :none, :none, :positive]
69
  end
70
 
71
  test "Codes are unweighted when no prior feedback" do
@@ -80,7 +80,7 @@ defmodule MedicalTranscription.CodingTest do
80
  results = Coding.process_chunk(@input_text)
81
 
82
  assert Enum.map(results, & &1.code) == ["V717", "74685", "41412", "V812"]
83
- assert Enum.map(results, & &1.weighting) == [:positive, :none, :none, :none]
84
  end
85
 
86
  test "Code is ranked lower when prior negative feedback" do
@@ -88,7 +88,7 @@ defmodule MedicalTranscription.CodingTest do
88
  results = Coding.process_chunk(@input_text)
89
 
90
  assert Enum.map(results, & &1.code) == ["41412", "V717", "V812", "74685"]
91
- assert Enum.map(results, & &1.weighting) == [:none, :none, :none, :negative]
92
  end
93
 
94
  test "Code with low similarity score is removed from result when prior negative feedback" do
 
2
  use MedicalTranscription.DataCase
3
 
4
  alias MedicalTranscription.Coding
5
+ alias MedicalTranscription.Coding.CodeVector
6
  alias MedicalTranscription.Feedback.CodeFeedback
7
 
8
  def create_code_vector!(code, description) do
 
65
  results = Coding.process_chunk(@input_text)
66
 
67
  assert Enum.map(results, & &1.code) == ["74685", "41412", "V717", "V812", "V4589"]
68
+ assert Enum.map(results, & &1.weighting) == [:none, :none, :none, :none, [:positive]]
69
  end
70
 
71
  test "Codes are unweighted when no prior feedback" do
 
80
  results = Coding.process_chunk(@input_text)
81
 
82
  assert Enum.map(results, & &1.code) == ["V717", "74685", "41412", "V812"]
83
+ assert Enum.map(results, & &1.weighting) == [[:positive], :none, :none, :none]
84
  end
85
 
86
  test "Code is ranked lower when prior negative feedback" do
 
88
  results = Coding.process_chunk(@input_text)
89
 
90
  assert Enum.map(results, & &1.code) == ["41412", "V717", "V812", "74685"]
91
+ assert Enum.map(results, & &1.weighting) == [:none, :none, :none, [:negative]]
92
  end
93
 
94
  test "Code with low similarity score is removed from result when prior negative feedback" do