-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.rb
More file actions
53 lines (47 loc) · 1.77 KB
/
Copy pathserver.rb
File metadata and controls
53 lines (47 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'sinatra'
require 'json'
require 'byebug'
require_relative "lib/watson4fluxnotes.rb"
require_relative "lib/meddra4fluxnotes.rb"
require_relative "lib/chunker.rb"
require_relative "lib/findings_collector.rb"
require_relative "lib/disease_status_extractor.rb"
require_relative "lib/fluxnotes_integration.rb"
get '/' do
'Post text to the /watson end point as a "text" param to run watson NLP'
end
post '/watson' do
# Chunk data into multiple lines
text = params['text']
chunkSize = params['chunkSize'] || 110
chunkerToxicity = Chunker.new :toxicity, chunkSize
chunkerDiseaseStatus = Chunker.new :disease_status, chunkSize
watson = Watson4Fluxnotes.new
extractor = DiseaseStatusExtractor.new
chunkerToxicity.run text
chunkerDiseaseStatus.run text
toxicityResults = chunkerToxicity.chunks.map do |chunk|
watson.analyze_text(chunk)
end
diseaseResults = chunkerDiseaseStatus.chunks.map do |chunk|
extractor.analyze_text(chunk)
end
content_type :json
flux_notes_messages = []
diseaseResults.each do |res|
res.each do |concept|
flux_notes_messages << FluxNotes.build_structured_phrase('disease status', [{name: 'status', value: concept[:status][:normalized]}])
end
end
toxicityResults.each do |tox|
tox['concepts'].each do |concept|
flux_notes_messages << FluxNotes.build_structured_phrase('toxicity', [{name: 'adverseEvent', value: concept['text']}])
# "flux_command('insert-structured-phrase', {phrase:'toxicity', fields: [{name:'adverseEvent', value: '#{concept['text']}'}]})"
end
end
return {
diseaseStatus: diseaseResults,
toxicity: toxicityResults,
fluxCommands: flux_notes_messages.uniq
}.to_json
end