-
Notifications
You must be signed in to change notification settings - Fork 16
/
NimbleMiner.R
3989 lines (3212 loc) · 220 KB
/
NimbleMiner.R
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# NimbleMiner: a software that allows clinicians to interact with word embedding models (skip-gram models - word2vec by package wordVectors and GloVe) to rapidly create lexicons of similar terms.
# version: 0.52 (Models building, Search of similar terms, Negations (with exceptions), Irrelevant terms, Machine learning by SVM and LSTM)
#####################################
library(shiny)
library(stringi)
library(data.table)
library(DT)
library(shinythemes)
library(ggplot2)
library(readr)
library(wordVectors)
library(shinyTree)
library(shinyjs)
library(RTextTools)
library(tm)
library(xtable)
library(keras)
library(rword2vec)
library(text2vec)
library(tokenizers)
library(NimbleMiner)
# User interface
ui <- fluidPage(
theme = shinytheme("cerulean"),
includeCSS("styles.css"),
useShinyjs(),
mainPanel(
width = 12,
div(id = "header-div","NimbleMiner"),
navbarPage(id="headerNavBar", "NimbleMiner",
tabPanel("Change the category", icon = icon("folder-open"),
wellPanel(
textInput(inputId = 'newCategory_input', label = 'Enter the new category name'),
actionButton("addSiblinsCategory_click", "Add category", icon = icon("plus")),
actionButton("addSubCategory_click", "Add subcategory", icon = icon("plus")),
hr(),
shinyTree("simclins_tree_settings", theme="proton"),
tags$hr(),
actionButton("renameCategory_click", "Rename selected category", icon = icon("edit")),
actionButton("deleteCategory_click", "Delete selected category", icon = icon("trash")),
actionButton("deleteCategoryWithSimclins_click", "Delete selected category with simclins", icon = icon("trash"))
)
),
tabPanel("1. Model builder",
tags$h3(paste0('1. Please, upload train.txt file with one column data to the NimbleMiner folder.')),
img(src = "folder_with_txt_file.JPG"),
tags$hr(),
tags$h3(paste0
('2. Please, check the setting.')),
fluidRow(
column(4,sliderInput(inputId = "setting_window",
label = "Set a word window width:",
value = 10, min = 1, max = 10)),
column(6,img(src = "window_width_img.JPG"))
),
sliderInput(inputId = "setting_min_count",
label = "Set a minimum count:",
value = 20, min = 1, max = 100),
sliderInput(inputId = "setting_similar_terms_count",
label = "How many similar terms should be presented for every simclin?",
value = 50, min = 5, max = 200),
fluidRow(
column(8,
selectInput('buildModel_startStep_input', 'Choose the start step:', c("1. Text preprocessing (train.txt file is expected in app folder)" = "TP", "2. Vocabulary bulding (train1.txt file is expected in app folder)" = "VB"), width = "100%")
)
),
tags$hr(),
actionButton("buildModel_word2vec_click", "Build word2vec model", icon = icon("play")),
actionButton("buildModel_GloVe_click", "Build GloVe model", icon = icon("play")),
tags$hr(),
#actionButton("ExportVocabulary_click", "Export vocabulary", icon = icon("save")),
icon = icon("cogs")
),
tabPanel("2. Simclin explorer",
wellPanel(
navbarPage("Simclins",
tabPanel("Enter new simclin",
textInput(inputId = 'newWord_input', label = 'Enter new simclin'),
actionButton("addNewWord_click", "Add", icon = icon("plus")),
icon = icon("keyboard-o")
),
tabPanel("Load new simclins from file",
fileInput("loadNewSimclinsFromCSV", label = "Please, upload .csv file with one column of simclins for every category. Specify category title in the column",accept = c("text/csv",".csv")),
actionButton("loadNewSimclinsFromCSV_click", "Upload", icon = icon("upload")),
icon = icon("file-text-o")
)
),
hr(),
wellPanel(
DT::dataTableOutput(outputId = 'simclins_table')
),
fluidRow(
column(8,
selectInput("select_model_method", label = h4("Select method of search"),
choices = list("Keep model in the memory (faster simclin search but memory demanding)" = 1, "Keep model on disk (slower simclin search but no expected memory issues) " = 2),
selected = 1))
),
fluidRow(
column(4,actionButton("findSimilar_terms_click", "Find similar terms for new simclins", icon = icon("search-plus"))),
column(4,actionButton("deleteSimclin_click", "Delete selected simclins", icon = icon("trash")))
),
verbatimTextOutput("selectedCategory")
),
wellPanel(
div(id="div_similar_terms",
h1('New similar terms'),
hr(),
actionButton("selectAllSimilar_terms_click", "Select all", icon = icon("list")),
actionButton("deselectAllSimilar_terms_click", "Deselect all", icon = icon("bars")),
actionButton("selectLexicalVariants_click", "Select lexical variants of simclins", icon = icon("list")),
hr(),
DT::dataTableOutput(outputId = 'similar_terms_table')
),
h5("Preview of selected terms:"),
verbatimTextOutput('selected_terms_label'),
verbatimTextOutput('selected_terms'),
actionButton("saveAsSimclins_click", "Save selected similar terms as simclins", icon = icon("arrow-up")),
actionButton("clearSimilar_terms_click", "Clear all unselected similar terms", icon = icon("trash")),
hr(),
actionButton("nextSearch_click", "Save & search again", icon = icon("search-plus")),
textInput( inputId = 'lastClickId', label = 'lastClickId' ),
textInput( inputId = 'lastClickSimilarTermId', label = 'lastClickSimilarTermId' )
),
icon = icon("search-plus", class = NULL, lib = "font-awesome")
),
tabPanel("3. Irrelevant similar terms explorer",
wellPanel(
h1('New irrelevant similar terms'),
textInput(inputId = 'newIrrSimilarTerm_input', label = 'Enter new irrelevant term'),
actionButton("addNewIrrSimilarTerm_click", "Add irrelevant term", icon = icon("plus")),
hr(),
wellPanel(DT::dataTableOutput(outputId = 'irrelevant_similar_terms_table')),
hr(),
actionButton("moveToSimclins_click", "Move selected irrelevant terms to simclins\' list", icon = icon("undo")),
actionButton("deleteIrrSimilarTerm_click", "Delete selected irrelevant terms", icon = icon("eraser")),
tags$div(class="clear-both")
)
,icon = icon("search-minus", class = NULL, lib = "font-awesome")
),
tabPanel("4. Negation explorer",
wellPanel(
navbarPage("Negations",
tabPanel("Pre & post negations",
fluidRow(column(5,textInput(inputId = 'newPrepNegation_input', label = 'Enter new negation BEFORE simclin:')),
column(2,p(id="simclinLabel","Simclin")),
column(5,textInput(inputId = 'newPostNegation_input', label = 'Enter new negation AFTER simclin:'))),
fluidRow(column(12,actionButton("addNewNegation_click", "Add negation(s)"))),
hr(),
tabsetPanel( id = "negationCategory",
tabPanel('General',
hr(),
DT::dataTableOutput(outputId = 'negations_table'),
actionButton("deleteNegation_click", "Delete selected negations", icon = icon("eraser"))
),
tabPanel('For current category',
hr(),
DT::dataTableOutput(outputId = 'curr_category_negations_table'),
actionButton("deleteCurrCategoryNegation_click", "Delete selected negations", icon = icon("eraser"))
)
),
hr(),
sliderInput(inputId = "distance_between_simclin_and_negation",
label = "Distance to negation:",
value = 2, min = 0, max = 10)
),
tabPanel("Exceptions",
h1('New exception'),
textInput(inputId = 'newException_input', label = 'Enter new exception:'),
actionButton("addNewException_click", "Add exception", icon = icon("plus")),
hr(),
tabsetPanel( id = "exceptionCategory",
tabPanel('General',
hr(),
DT::dataTableOutput(outputId = 'exceptions_table'),
actionButton("deleteException_click", "Delete selected exceptions", icon = icon("eraser"))
),
tabPanel('For current category',
hr(),
DT::dataTableOutput(outputId = 'curr_category_exceptions_table'),
actionButton("deleteCurrCategoryException_click", "Delete selected exceptions", icon = icon("eraser"))
)
)
)
)
)
,icon = icon("times-circle")
),
tabPanel("5. Assign and review labels",
wellPanel(
h1('Data labeling'),
fileInput(inputId = 'fileEHR_input','Please, upload .csv file with column "Note":',accept = c("text/csv","text/comma-separated-values,text/plain",".csv"), multiple = FALSE),
fluidRow(
column(4,selectInput("language", label = h4("Select language of notes"), choices = list("English" = 1, "Hebrew" = 2), selected = 1, width = "200px")),
column(4,selectInput("unit_type_to_label", label = h4("Select unit type"), choices = list("Document" = 1, "Paragraph" = 2, "Sentence" = 3), selected = 1, width = "200px"))
),
actionButton("makeLabels_click","Assign labels",icon = icon("tags")),
hr(),
navbarPage("Labeled data",
tabPanel("With simclins",
wellPanel(
DT::dataTableOutput(outputId = 'posLabeledData_table')
),
icon = icon("search-plus")
),
tabPanel("With irrelevant similar terms",
wellPanel(
DT::dataTableOutput(outputId = 'posIrrelevantLabeledData_table')
),
icon = icon("search-minus")
),
tabPanel("With negations",
wellPanel(
actionButton("exportToHTML_click","Export to HTML",icon = icon("code")),
hr(),
DT::dataTableOutput(outputId = 'posNegatedLabeledData_table')
),icon = icon("times-circle")
),
tabPanel("Visualization",
wellPanel(
h1('Labeling statistics'),
fluidRow(
column(2,'Total of notes'),
column(2,'Total of positive notes'),
column(3,'Total of notes with negated simclins'),
column(3,'Total of notes with irrelevant terms'),
column(2,'Total of negative notes')
),
fluidRow(
column(2,textInput(inputId = "totalNotes",label = '')),
column(2,textInput(inputId = "totalPositiveNotes",label = '')),
column(3,textInput(inputId = "totalNegatedPositiveNotes",label = '')),
column(3,textInput(inputId = "totalIrrelevantPositiveNotes",label = '')),
column(2,textInput(inputId = "totalNegativeNotes",label = ''))
)
),
wellPanel(
fluidRow(
column(6,
#plotlyOutput("distPlot")
plotOutput("allLabelsPlot")),
column(6,
plotOutput("posLabelsPlot"))
)
),icon = icon("stats", lib = "glyphicon")
)
)
),
icon = icon("tags")
),
tabPanel("6. Machine learning",
wellPanel(
h1("1. Train corpus from labeled data"),
helpText("Please, specify the number of notes from every class (positive, negative and negated) in the corpus:"),
fluidRow(
column(4,sliderInput(inputId = "notes_of_positive_class", label = "Positive class:", value = 50, min = 10, max = 100)),
column(4,sliderInput(inputId = "notes_of_negative_class",label = 'Negative class:', value = 30, min = 10, max = 100)),
column(4,sliderInput(inputId = "notes_of_negated_class",label = 'Negated class:', value = 20, min = 10, max = 100))
),
actionButton("generateCorpus_click", "Generate train corpus", icon = icon("play"))
),
# Sidebar with a slider input
wellPanel(
h1("2. Learn model"),
selectInput('mlModel_input', 'Choose the algorithm:', c("Support Vector Machine (SVM)" = "SVM", "Neural network (LSTM)" = "NNET")),
hr(),
actionButton("learnModel_click", "Learn model", icon = icon("play")),
hr(),
h3("Model testing summary:"),
DT::dataTableOutput(outputId = 'algorythms_summary_table')
),
# Show a plot of the generated distribution
wellPanel(
h1("3. Predict labels"),
selectInput('mlModelToPredict_input', 'Choose the algorithm:', c("Support Vector Machine (SVM)" = "SVM", "Neural network (LSTM)" = "NNET")),
fileInput(inputId = 'notesToPredictFile','Please, upload .csv file with column "note":',accept = c("text/csv","text/comma-separated-values,text/plain",".csv"), multiple = FALSE),
actionButton("predictNotes_click", "Predict", icon = icon("search-plus")),
h3("Predicted results:"),
DT::dataTableOutput(outputId = 'predicted_results_table')
),
icon = icon("bolt", class = NULL, lib = "font-awesome")
),
tabPanel("Settings",
navbarPage("Settings",
tabPanel("User data",
tags$hr(),
actionButton("clearData_click", "Clear all previous simclins' data", icon = icon("eraser")),
tags$hr(),
icon = icon("search-plus")
)
),icon = icon("cogs")
),
tabPanel("Log ",
wellPanel(
h1('System efficacy'),
textInput(inputId = "trueSimilarTerms",label = 'Number of simclins'),
textInput(inputId = "suggestedSimilarTerms",label = 'Number of suggested similar terms'),
textInput(inputId = "systemEfficacy",label = 'System efficacy (number of simclins/Number of suggested similar terms)')
),
wellPanel(
h1('Log'),
DT::dataTableOutput(outputId = 'log_table'),
actionButton("saveAsFile_click", "Save log in file", icon = icon("save")),
actionButton("clearLog_click", "Clear log", icon = icon("eraser"))),
icon = icon("archive")
)
)
)
)
# Server part
server <- function(input, output, session) {
##########################################################################################
# Function getSavedSelectedCategory - return selected category from saved categories tree
##########################################################################################
getSavedSelectedCategory <- function(){
#read the current tree as dataframe
filename <- paste0(app_dir,"simclins_tree.csv")
simclins_tree_json <- readLines(filename,encoding="UTF-8")
simclins_tree_df<-jsonlite::fromJSON(simclins_tree_json)
if(nrow(simclins_tree_df)>0)
for(i in 1:nrow(simclins_tree_df))
if (simclins_tree_df[i,'state']$selected==TRUE)
return(simclins_tree_df[i,'text'])
return ("")
}
############################################################################################################
# Function getNewSelectedCategory - returns the just selected category from the tree structure
# (is called after user clicked any node of the tree)
############################################################################################################
getNewSelectedCategory <- function(treeId = input$simclins_tree_settings){
if (is.null(treeId)){
selectedCategory_str <- ""
} else{
selectedCategory_ls <- get_selected(treeId)
if(length(selectedCategory_ls)>0){
selectedCategory_str <- unlist(selectedCategory_ls)
} else{
selectedCategory_str <- ""
}
}
return(selectedCategory_str)
}
#############################################################################################################
# Function getSelectedCategory - returns the current selected category from the global variable
#############################################################################################################
getSelectedCategory <- function(treeId = input$simclins_tree_settings){
return (userSettings$selectedCategory)
}
#############################################################################################################
# Function closestByLevenstein - returns vector of of elements (indeces) of argument vector_of_words,
# which are closed by Levenstein maximum distance <= argument max to argument word
#############################################################################################################
closestByLevenstein <- function(word,vector_of_words,max,min_word_length = 4){
if (nchar(word)<min_word_length)
return (character(0))
else {
distance_matrix <- adist(word,vector_of_words,ignore.case = TRUE)
return (distance_matrix<=max)
}
}
#############################################################################################################
# Function getDuplicatedTerms - check terms from vector df_new_terms for there duplicates in df_simclins (if check_simclins = TRUE),
# df_similar_terms (if check_similar_terms = TRUE) and df_irrelevant_terms (if check_irrelevant_terms = TRUE).
# Returns vector of indexes of duplicated elements from df_new_terms
#############################################################################################################
getDuplicatedTerms<-function(df_new_terms,check_simclins = TRUE,check_similar_terms = TRUE, check_irrelevant_terms = TRUE){
result_list = vector()
if (nrow(df_new_terms)>0)
for(i in 1:nrow(df_new_terms)){
result_list[i] <- FALSE
curr_similar_term <- df_new_terms[i,'Similar_term']
curr_category <- df_new_terms[i,'Category']
if (check_simclins & nrow(df_simclins)>0){
if (nrow(df_simclins[df_simclins$Simclins==curr_similar_term & df_simclins$Category==curr_category,] )>0) {
result_list[i] <-TRUE
next
}
}
if (!result_list[i] & check_similar_terms & nrow(df_similar_terms)>0){
if (nrow(df_similar_terms[df_similar_terms$Similar_term==curr_similar_term & df_similar_terms$Category==curr_category,])>0) {
result_list[i] <-TRUE
next
}
}
if (!result_list[i] & check_irrelevant_terms & nrow(df_irrelevant_terms)>0){
if (nrow(df_irrelevant_terms[df_irrelevant_terms$Similar_term==curr_similar_term & df_irrelevant_terms$Category==curr_category,])>0) {
result_list[i] <-TRUE
next
}
}
}
result_list
}
#############################################################################################################
# Function tree2df - read json from csv-file and convert to the list structure (via data frame)
#############################################################################################################
tree2df <-function(){
filename <- paste0(app_dir,"simclins_tree.csv")
simclins_tree_json <- readLines(filename,encoding="UTF-8")
simclins_tree_df<-jsonlite::fromJSON(simclins_tree_json)
result_list<-treedf2list(simclins_tree_df)
result_list
}
#############################################################################################################
# Function saveCategoryTree_settings - save list structure of tree to the csv - file
#############################################################################################################
saveCategoryTree_settings <- function(tree_list){
filename <- paste0(app_dir,"simclins_tree.csv")
treeAsJson<-as.character(jsonlite::toJSON(get_flatList(tree_list), auto_unbox = T))
treeAsJson<-enc2utf8(treeAsJson)
writeLines(treeAsJson,filename,useBytes = TRUE)
}
#############################################################################################################
# Function loadSystemMetrics - read system metrics of simclins search from the log and display it
#############################################################################################################
loadSystemMetrics <-function(){
df_trueSimilarTerms_rows<-(subset(df_log, (df_log$Operation=='Update System Metrics' & df_log$Parameters=='trueSimilarTerms')))
df_trueSimilarTerms_rows<-df_trueSimilarTerms_rows[ order(df_trueSimilarTerms_rows$DateTime, na.last = TRUE, decreasing = TRUE), ]
if (nrow(df_trueSimilarTerms_rows)>0) num_trueSimilarTerms <-as.numeric(df_trueSimilarTerms_rows[1,6])
else num_trueSimilarTerms <- 0
df_suggestedSimilarTerms_rows<-(subset(df_log, (df_log$Operation=='Update System Metrics' & df_log$Parameters=='suggestedSimilarTerms')))
df_suggestedSimilarTerms_rows<-df_suggestedSimilarTerms_rows[ order(df_suggestedSimilarTerms_rows$DateTime, na.last = TRUE, decreasing = TRUE), ]
if (nrow(df_suggestedSimilarTerms_rows)>0) num_suggestedSimilarTerms <-as.numeric(df_suggestedSimilarTerms_rows[1,6])
else num_suggestedSimilarTerms <- 0
if (length(num_suggestedSimilarTerms)>0 & (!is.null(num_suggestedSimilarTerms)) & num_suggestedSimilarTerms>0)
systemEfficacy = num_trueSimilarTerms / num_suggestedSimilarTerms
else systemEfficacy = 0
updateTextInput(session,"trueSimilarTerms",label = "Number of true similar terms", value = as.character(num_trueSimilarTerms))
updateTextInput(session,"suggestedSimilarTerms",label = "Number of suggested similar terms", value = as.character(num_suggestedSimilarTerms))
updateTextInput(session,"systemEfficacy",label = 'System Efficacy', value = as.character(round(systemEfficacy,2)))
rm(df_trueSimilarTerms_rows)
rm(df_suggestedSimilarTerms_rows)
}
#############################################################################################################
# Function loadLabelingStatistics - read labeling statistics from the log and display it to user
#############################################################################################################
loadLabelingStatistics <-function(){
df_totalNotes_rows<-(subset(df_log, (df_log$Operation=='Labeling' & df_log$Parameters=='totalNotes')))
df_totalNotes_rows<-df_totalNotes_rows[ order(df_totalNotes_rows$DateTime, na.last = TRUE, decreasing = TRUE), ]
if (nrow(df_totalNotes_rows)>0) num_totalNotes <-as.numeric(df_totalNotes_rows[1,6])
else num_totalNotes <- 0
df_positiveNotes_rows<-(subset(df_log, (df_log$Operation=='Labeling' & df_log$Parameters=='totalPositiveNotes')))
df_positiveNotes_rows<-df_positiveNotes_rows[ order(df_positiveNotes_rows$DateTime, na.last = TRUE, decreasing = TRUE), ]
if (nrow(df_positiveNotes_rows)>0) num_totalPositiveNotes <-as.numeric(df_positiveNotes_rows[1,6])
else num_totalPositiveNotes <- 0
df_negatedNotes_rows<-(subset(df_log, (df_log$Operation=='Labeling' & df_log$Parameters=='totalNegatedPositiveNotes')))
df_negatedNotes_rows<-df_negatedNotes_rows[ order(df_negatedNotes_rows$DateTime, na.last = TRUE, decreasing = TRUE), ]
if (nrow(df_negatedNotes_rows)>0) num_totalNegatedPositiveNotes <-as.numeric(df_negatedNotes_rows[1,6])
else num_totalNegatedPositiveNotes <- 0
df_irrelevantNotes_rows<-(subset(df_log, (df_log$Operation=='Labeling' & df_log$Parameters=='totalIrrelevantPositiveNotes')))
df_irrelevantNotes_rows<-df_irrelevantNotes_rows[ order(df_irrelevantNotes_rows$DateTime, na.last = TRUE, decreasing = TRUE), ]
if (nrow(df_irrelevantNotes_rows)>0) num_totalIrrelevantPositiveNotes <-as.numeric(df_irrelevantNotes_rows[1,6])
else num_totalIrrelevantPositiveNotes <- 0
df_negativeNotes_rows<-(subset(df_log, (df_log$Operation=='Labeling' & df_log$Parameters=='totalNegativeNotes')))
df_negativeNotes_rows<-df_negativeNotes_rows[ order(df_negativeNotes_rows$DateTime, na.last = TRUE, decreasing = TRUE), ]
if (nrow(df_negativeNotes_rows)>0) num_totalNegativeNotes <-as.numeric(df_negativeNotes_rows[1,6])
else num_totalNegativeNotes <- 0
updateTextInput(session,"totalNotes",value = as.character(num_totalNotes))
updateTextInput(session,"totalPositiveNotes",value = as.character(num_totalPositiveNotes))
updateTextInput(session,"totalIrrelevantPositiveNotes",value = as.character(num_totalIrrelevantPositiveNotes))
updateTextInput(session,"totalNegatedPositiveNotes",value = as.character(num_totalNegatedPositiveNotes))
updateTextInput(session,"totalNegativeNotes",value = as.character(num_totalNegativeNotes))
rm(df_totalNotes_rows)
rm(df_positiveNotes_rows)
rm(df_negatedNotes_rows)
rm(df_irrelevantNotes_rows)
rm(df_negativeNotes_rows)
sum_pos_total = num_totalPositiveNotes + num_totalNegativeNotes
percent_totalPositiveNotes = round(num_totalPositiveNotes/sum_pos_total*100,2)
percent_num_totalNegativeNotes = round(100 - percent_totalPositiveNotes,2)
df_statistics_all_labels <- data.frame(
Label = c("Positive", "Negative"),
total = c(percent_totalPositiveNotes, percent_num_totalNegativeNotes)
)
sum_pos_total = num_totalPositiveNotes + num_totalNegatedPositiveNotes + num_totalIrrelevantPositiveNotes
percent_totalPositiveNotes = round(num_totalPositiveNotes/sum_pos_total*100,2)
percent_totalNegatedPositiveNotes = round(num_totalNegatedPositiveNotes/sum_pos_total*100,2)
percent_totalIrrelevantPositiveNotes = round(100-percent_totalPositiveNotes-percent_totalNegatedPositiveNotes,2)
df_statistics_pos_labels <- data.frame(
Label = c("Positive", "Negated positive", "Irrelevant positive"),
total = c(percent_totalPositiveNotes, percent_totalNegatedPositiveNotes, percent_totalIrrelevantPositiveNotes),
text = c(paste0(percent_totalPositiveNotes,"%"),paste0(percent_totalNegatedPositiveNotes,"%"),paste0(percent_totalIrrelevantPositiveNotes,"%"))
)
output$allLabelsPlot <- renderPlot({
bp<- ggplot(data = df_statistics_all_labels, aes(x = "", y = total, fill = Label)) +
geom_bar(stat = "identity") +
geom_text(aes(label = paste0(total,"%")), position = position_stack(vjust = 0.5),size=6,fontface = "bold",colour = "#525760") +
coord_polar(theta = "y")+
theme(panel.background = element_blank(),
text = element_text(size=14),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
plot.title = element_text(face = "bold", hjust = 0.5, color="#317eac"),
legend.text=element_text(size=14))+
ggtitle("Notes with positive and negative labels")+
labs(size=14)+
scale_fill_manual(values = (c("#F08080","#3CB371")))
bp
})
output$posLabelsPlot <- renderPlot({
bp<- ggplot(df_statistics_pos_labels, aes(x="", y=total, fill=Label))+
geom_bar(width = 1, stat = "identity") +
geom_text(aes(label = paste0(total,"%")), position = position_stack(vjust = 0.5),size=6, fontface="bold",colour = "#525760") +
theme(panel.background = element_blank(),
text = element_text(size=14),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
plot.title = element_text(face = "bold", hjust = 0.5, color="#317eac"),
legend.text=element_text(size=14))+
ggtitle("Ratio of notes with true, negated and irrelevant positive labels")+
labs(size=14)+
scale_fill_manual(values = (c("#ff6600","#F08080","#3CB371")))
bp
})
}
#############################################################################################################
# Function readFileByChunks - read chars from the file by chunks
# The function is used to set pointer in large text
#############################################################################################################
readFileByChunks <-function(in_file, nchar,length_of_text_chunk = 5e7){
while (nchar>length_of_text_chunk){
readChar(in_file,length_of_text_chunk)
nchar <- nchar - length_of_text_chunk
}
if(nchar>1)
readChar(in_file,nchar)
}
#############################################################################################################
# Function setCursorInTextFile - set file pointer to the new_pos position
# The function is used for preprocessing of large texts
#############################################################################################################
setCursorInTextFile<-function (in_file, fileName, curr_pos, new_pos, length_of_text_chunk = 5e7){
if (curr_pos == new_pos)
return()
if(new_pos<curr_pos){
close(in_file)
in_file = file(fileName, "r")
open(in_file)
curr_pos <- 1
}
if (new_pos>1){
if (new_pos>curr_pos)
readFileByChunks(in_file,new_pos-curr_pos,length_of_text_chunk)
else readFileByChunks(in_file,new_pos,length_of_text_chunk)
}
}
#############################################################################################################
# Function getExamples - returns string with 10 examples of appearance "pattern" string in "source_txt" text.
# The search of matches begins from the "last_pos" position in source_txt in forward direction (direction=1) or reverse direction (direction=0)
#############################################################################################################
getExamples <- function(direction,pattern, last_pos,control_id,length_of_text_chunk=2e7){
# txt file for examples
if (n_grams==1)
fileName <- paste0(app_dir,"train.txt")
else if(n_grams==2)
fileName <- paste0(app_dir,"train2.txt")
else if(n_grams==4)
fileName <- paste0(app_dir,"train4.txt")
example_str <- NimbleMiner::getExamples(pattern, fileName, control_id, last_pos,direction,length_of_text_chunk)
return (example_str)
}
#############################################################################################################
# Function getExamples_negatedNotes - returns positive notes negated by this negation
#############################################################################################################
getExamples_negatedNotes <- function(negation){
df_negatedNotes = df_negatedPosLabels[ grepl(negation,df_negatedPosLabels$Negation),]
examples_str <- ""
if (nrow(df_negatedNotes)<200)
examples_count <- nrow(df_negatedNotes)
else examples_count <- 200
for (i in 1:examples_count){
examples_str <- paste0(examples_str,"<div class='example-text'>",df_negatedNotes[i,"Note"],"</div>")
}
return (examples_str)
}
#############################################################################################################
# Function getExamples_irrelevantNotes - returns notes with irrelevant simclins
#############################################################################################################
getExamples_irrelevantNotes <- function(irrelevant_term){
df_irrelevantNotes = df_irrelevantPosLabels[df_irrelevantPosLabels$Similar_term==irrelevant_term,]
examples_str <- ""
if (nrow(df_irrelevantNotes)<200)
examples_count <- nrow(df_irrelevantNotes)
else examples_count <- 200
for (i in 1:examples_count){
examples_str <- paste0(examples_str,"<div class='example-text'>",df_irrelevantNotes[i,"Note"],"</div>")
}
return (examples_str)
}
#############################################################################################################
# Function logAction - adds the new record to the log
#############################################################################################################
logAction <- function(actionDataTime=Sys.time(),userId,operation,parameters="",valueBefore="",valueAfter="",actionDuration=""){
valueBefore <- ifelse(is.null(valueBefore),"",valueBefore)
valueAfter <- ifelse(is.null(valueAfter),"",valueAfter)
df_new_record <- data.frame(DateTime=format(actionDataTime, "%Y-%m-%d %H:%M:%S"), UserId = userId, Operation = operation, Parameters = parameters, ValueBefore=valueBefore,
ValueAfter=valueAfter,Duration=actionDuration, stringsAsFactors=FALSE)
df_log <<- rbind(df_log,df_new_record)
refreshTable('log')
}
#############################################################################################################
# Function addNewSimclin - adds the new record to the simclin's list
#############################################################################################################
addNewSimclin <- function(new_simclin_str,df_new_simclins,category = NULL,fl_show_msg_about_duplicates = TRUE, fl_from_file = FALSE ){
original_simclin_str = new_simclin_str
# trim the new simclin
new_simclin_str = enc2utf8(new_simclin_str)
new_simclin_str = gsub("_", " ", trimws(new_simclin_str))
new_simclin_str = removePunctuation(new_simclin_str,preserve_intra_word_contractions = FALSE,preserve_intra_word_dashes = FALSE,ucp = TRUE)
new_simclin_str = gsub("[[:space:]]", "_", trimws(new_simclin_str))
new_simclin_str=stri_trans_tolower(new_simclin_str)
if(nrow(df_simclins)>0 && any(df_simclins[df_simclins[,'Category']==category,]$Simclins==new_simclin_str)) {
if (fl_show_msg_about_duplicates)
showModal(modalDialog(title = "Error message", paste0("The simclin \"",new_simclin_str,"\" is in the list already!"),easyClose = TRUE))
print(paste0("Duplicated simclin: ",original_simclin_str," to existing simclin ", new_simclin_str," with same category ",category))
return(FALSE)
} else {
if(new_simclin_str=="") {
if (fl_show_msg_about_duplicates)
showModal(modalDialog(title = "Error message", paste0("The simclin is empty!"),easyClose = TRUE))
return(FALSE)
}
df_simclins<<-NimbleMiner::addNewSimclin(new_simclin_str,df_simclins,category)
#clean the input control
if(!fl_from_file){
updateTextInput(session,"newWord_input", value = " ")
refreshTable('simclins')
}
return(TRUE)
}
}
#############################################################################################################
# Function getLexicalOrigin - check if current term (x[1]) includes substring from regex pattern (argument pattern).
# For example, term "duodenal_perforation" is lexical variation of the "perforation". So, the
# x[1] = "duodenal_perforation", pattern = "\b("perforation")|(...)(?!/w)"
# argument x should be the vector with 2 elements - x[1] with term and x[2] with category,
# the x[2] is optional - only for the case the argument selectedCategory = NULL
#############################################################################################################
getLexicalOrigin <- function(x,pattern,selectedCategory = NULL){
curr_similar_term <- x[1] #$Similar_term
if (!is.null(selectedCategory)){
curr_category <- as.character(x[2]) #$category
if (curr_category!=selectedCategory) return(NA)
}
curr_similar_term <- enc2utf8(curr_similar_term)
curr_similar_term<-gsub("_","",curr_similar_term)
pattern <- enc2utf8(pattern)
pattern <- gsub("\\+","",pattern)
pattern<-gsub("_","",pattern)
list_simclins = stri_locate_all(curr_similar_term, regex = pattern, opts_regex=stri_opts_regex(case_insensitive=TRUE))
pos_start = list_simclins[[1]][1,'start']
pos_end = list_simclins[[1]][1,'end']
if(!is.na(pos_start) & !is.na(pos_end)) {
print(paste0(x[1]," - lexical variant of ",substring(curr_similar_term,pos_start,pos_end)))
return(substring(curr_similar_term,pos_start,pos_end))
} else return(NA)
}
#############################################################################################################
# Function getLevensteinOrigin - check if current term (x[1]) is closed by Levenstein metrics to any item
# from curr_simclins
#############################################################################################################
getLevensteinOrigin <- function(x,curr_simclins,selectedCategory,max){
curr_similar_term <- x[1] #$Similar_term
if (!is.null(selectedCategory)){
curr_category <- as.character(x[2]) #$category
if (curr_category!=selectedCategory) return(NA)
}
curr_similar_term <- enc2utf8(curr_similar_term)
curr_similar_term<-gsub("_","",curr_similar_term)
closest_by_lv <- closestByLevenstein (curr_similar_term, gsub("_","",curr_simclins$Simclins), max = max)
if (length(closest_by_lv)>0 & any(closest_by_lv)){
print(paste0(x[1]," - close by Levenstein to: ",paste(curr_simclins[closest_by_lv,'Simclins'],collapse = ",")))
if(is.na(x['Lexical_variant']))
return(paste(curr_simclins[closest_by_lv,'Simclins'],collapse = ","))
else if(grepl(paste0("\\b(",x['Lexical_variant'],")(?!\\w)"),curr_simclins[closest_by_lv,'Simclins'],ignore.case = T,perl=T))
return(paste(curr_simclins[closest_by_lv,'Simclins'],collapse = ","))
else return(paste0(x['Lexical_variant'],", ",paste(curr_simclins[closest_by_lv,'Simclins'],collapse = ",")))
} else return(x['Lexical_variant'])
}
#############################################################################################################
# Handler of event of click button 'Select lexical variants of simclins' (tab 2. SImclins explorer)
# Select similar terms, which are close by Levenstein, or are lexical variants of current simclins
#############################################################################################################
observeEvent(input$selectLexicalVariants_click, {
selectedCategory_str<- getSelectedCategory(input$simclins_tree_settings)
df_simclins_of_cat <- df_simclins[df_simclins$Category==selectedCategory_str,]
df_similar_terms_of_cat <- df_similar_terms[df_similar_terms$Category==selectedCategory_str,]
pattern_str <- paste(df_simclins_of_cat$Simclins,collapse = "|")
pattern_str <- gsub("_","",df_simclins_of_cat$Simclins)
df_similar_terms_of_cat$Lexical_variant <- gsub("_","",df_similar_terms_of_cat$Lexical_variant)
df_similar_terms_of_cat$Lexical_variant<-apply(df_similar_terms_of_cat,1,getLexicalOrigin,pattern_str,selectedCategory_str)
df_similar_terms_of_cat$Lexical_variant<-apply(df_similar_terms_of_cat,1,getLevensteinOrigin, df_simclins_of_cat, selectedCategory_str, max = 2)
is_lexical_variant_rownames <- rownames(df_similar_terms_of_cat[!is.na(df_similar_terms_of_cat$Lexical_variant),])
df_similar_terms[is_lexical_variant_rownames,'Lexical_variant']<<-df_similar_terms_of_cat[is_lexical_variant_rownames,'Lexical_variant']
is_lexical_variant_indx <- match(is_lexical_variant_rownames,rownames(df_similar_terms))
# is_from_several_models_rownames <- rownames(df_similar_terms_of_cat[grepl(',',df_similar_terms_of_cat$Model),])
# is_from_several_models_indx <- match(is_from_several_models_rownames,rownames(df_similar_terms))
selected_rows <- c(is_lexical_variant_indx)
selected_rows <- unique(selected_rows)
selected_rows <-sort(selected_rows)
output$similar_terms_table = DT::renderDataTable({DT::datatable(df_similar_terms,selection = list(target = 'row', selected=selected_rows),
filter = list(position = 'top', clear = FALSE),
options = list(order=list(list(4,'asc')),pageLength = 100,columnDefs = list(list(targets = c(2,3,4,5,6), searchable = FALSE))
,searchCols = list(NULL, list(search = selectedCategory_str),NULL,NULL,NULL,NULL,NULL)
)
,callback=DT::JS('table.on("page.dt",function() {var topPos = document.getElementById("div_similar_terms").offsetTop; window.scroll(0,topPos);})')
,colnames = c("Similar terms","Category","Distance","By simclins",'Lexical variant of',"Model","Examples"),rownames=FALSE, escape = FALSE)})
write.csv(df_similar_terms, file = paste0(app_dir,"similar_terms.csv"))
})
#############################################################################################################
# Function refreshTable - outputs data from dataframe to the table and save data to csv-file
#############################################################################################################
refreshTable <- function(tableName, saveSelection = FALSE){
if (tableName=='similar_terms') {
selectedCategory_str<- getSelectedCategory(input$simclins_tree_settings)
df_simclins_of_cat <- df_simclins[df_simclins$Category==selectedCategory_str,]
df_similar_terms_of_cat <- df_similar_terms[df_similar_terms$Category==selectedCategory_str,]
#update value of "lexical variant of"
pattern_str <- paste(df_simclins_of_cat$Simclins,collapse = "|")
df_similar_terms_of_cat$Lexical_variant<-apply(df_similar_terms_of_cat,1,getLexicalOrigin,pattern_str,selectedCategory_str)
df_similar_terms_of_cat$Lexical_variant<-apply(df_similar_terms_of_cat,1,getLevensteinOrigin, df_simclins_of_cat, selectedCategory_str, max = 2)
is_lexical_variant_rownames <- character(0)
is_lexical_variant_indx <- integer(0)
# if it's the first view of the search results - get rownames for selecting
if(fl_first_view_of_search_results) {
if(nrow(df_similar_terms_of_cat)>0){
is_lexical_variant_rownames <- rownames(df_similar_terms_of_cat[!is.na(df_similar_terms_of_cat$Lexical_variant),])
df_similar_terms[is_lexical_variant_rownames,'Lexical_variant']<<-df_similar_terms_of_cat[is_lexical_variant_rownames,'Lexical_variant']
is_lexical_variant_indx <- match(is_lexical_variant_rownames,rownames(df_similar_terms))
}
}
if((saveSelection & !is.null(input$similar_terms_table_rows_selected)) | length(is_lexical_variant_indx)>0 | fl_selectAllSimilar_terms | fl_deselectAllSimilar_terms){
if (fl_selectAllSimilar_terms){
fl_selectAllSimilar_terms <<- FALSE
selected_rows <- match(rownames(df_similar_terms_of_cat),rownames(df_similar_terms))
} else if (fl_deselectAllSimilar_terms){
fl_deselectAllSimilar_terms <<- FALSE
selected_rows <- NULL
} else{
if (fl_next_search_in_process)
selected_rows <- c(is_lexical_variant_indx)
else selected_rows <- c(input$similar_terms_table_rows_selected,is_lexical_variant_indx)
selected_rows <- unique(selected_rows)
selected_rows <-sort(selected_rows)
}
df_similar_terms$Category <- factor(df_similar_terms$Category)
output$similar_terms_table = DT::renderDataTable(df_similar_terms,selection = list(target = 'row', selected=selected_rows),
filter = list(position = 'top', clear = FALSE),
options = list(order=list(list(4,'asc'),list(2,'desc')),pageLength = 100,columnDefs = list(list(targets = c(2,3,4,5,6), searchable = FALSE))
,searchCols = list(NULL, list(search = paste0('["',selectedCategory_str,'"]')),NULL,NULL,NULL,NULL,NULL)
)
,callback=DT::JS('table.on("page.dt",function() {var topPos = document.getElementById("div_similar_terms").offsetTop; window.scroll(0,topPos);})')
,colnames = c("Similar terms","Category","Distance","By simclins",'Lexical variant of',"Model","Examples"),rownames=FALSE, escape = FALSE)
write.csv(df_similar_terms, file = paste0(app_dir,"similar_terms.csv"))
} else {
df_similar_terms$Category <- factor(df_similar_terms$Category)
output$similar_terms_table = DT::renderDataTable(df_similar_terms,
filter = list(position = 'top', clear = FALSE),
options = list(order=list(list(4,'asc'),list(2,'desc')),pageLength = 100,columnDefs = list(list(targets = c(2,3,4,5,6), searchable = FALSE))
,searchCols = list(NULL, list(search = paste0('["',selectedCategory_str,'"]')),NULL,NULL,NULL,NULL,NULL)
)
,callback=DT::JS('table.on("page.dt",function() {var topPos = document.getElementById("div_similar_terms").offsetTop; window.scroll(0,topPos);})')
,colnames = c("Similar terms","Category","Distance","By simclins",'Lexical variant of',"Model","Examples"),rownames=FALSE, escape = FALSE)
write.csv(df_similar_terms, file = paste0(app_dir,"similar_terms.csv"))
}
}
else if (tableName=='simclins') {
selectedCategory_str<- getSelectedCategory(input$simclins_tree_settings)
# update tables
if(saveSelection & !is.null(input$simclins_table_rows_selected)){
df_simclins$Category <- factor(df_simclins$Category)
output$simclins_table = DT::renderDataTable(df_simclins,selection = list(selected=input$simclins_table_rows_selected),
filter = list(position = 'top', clear = FALSE),
options = list(order=list(0, 'asc'),pageLength = 10,columnDefs = list(list(targets = c(2,3), searchable = FALSE))
,searchCols = list(NULL, list(search = paste0('["',selectedCategory_str,'"]')),NULL,NULL)
),colnames = c("Simclins","Category","Processed","Examples"),rownames=FALSE, escape = FALSE)
} else {
df_simclins$Category <- factor(df_simclins$Category)
output$simclins_table = DT::renderDataTable(df_simclins,
filter = list(position = 'top', clear = FALSE),
options = list(order=list(0, 'asc'),pageLength = 10,columnDefs = list(list(targets = c(2,3), searchable = FALSE))
,searchCols = list(NULL, list(search =paste0('["',selectedCategory_str,'"]')),NULL,NULL)
),colnames = c("Simclins","Category","Processed","Examples"),rownames=FALSE, escape = FALSE)
}
write.csv(df_simclins, file = paste0(app_dir,"simclins.csv"), fileEncoding = "UTF-8")
} else if (tableName=='log'){
output$log_table <- DT::renderDataTable({DT::datatable(df_log,options = list(order=list(0,'desc')),colnames = c("Date & time","User Id","Operation","Parameters","Value before","Value after","Duration"),rownames=FALSE, escape = FALSE)})
write.csv(df_log, file = paste0(app_dir,"log.csv"), fileEncoding = "UTF-8")
} else if (tableName=='irrelevant_terms'){
selectedCategory_str<- getSelectedCategory(input$simclins_tree_settings)
#df_irrelevant_terms <<- df_irrelevant_terms[!is.na(df_irrelevant_terms$Similar_term),]
df_irrelevant_terms$Category <- factor(df_irrelevant_terms$Category)
if(saveSelection & !is.null(input$irrelevant_similar_terms_table_rows_selected)){
output$irrelevant_similar_terms_table = DT::renderDataTable(df_irrelevant_terms,selection = list(selected=input$irrelevant_similar_terms_table_rows_selected),
filter = list(position = 'top', clear = FALSE),
options = list(order=list(0, 'asc'),pageLength = 10,columnDefs = list(list(targets = c(2,3), searchable = FALSE))
,searchCols = list(NULL, list(search = paste0('["',selectedCategory_str,'"]')),NULL,NULL)
),colnames = c("Similar terms","Category","Frequency","Examples"),rownames=FALSE, escape = FALSE)
} else {
output$irrelevant_similar_terms_table = DT::renderDataTable(df_irrelevant_terms,
filter = list(position = 'top', clear = FALSE),
options = list(order=list(0, 'asc'),pageLength = 10,columnDefs = list(list(targets = c(2,3), searchable = FALSE))
,searchCols = list(NULL, list(search = paste0('["',selectedCategory_str,'"]')),NULL,NULL)
),colnames = c("Similar terms","Category","Frequency","Examples"),rownames=FALSE, escape = FALSE)
}
write.csv(df_irrelevant_terms, file = paste0(app_dir,"irrelevant_terms.csv"), fileEncoding = "UTF-8")
} else if (tableName=='negations'){
output$negations_table <- DT::renderDataTable(df_negations,
filter = list(position = 'top', clear = FALSE),
options = list(order=list(3,'desc'),pageLength = 10,columnDefs = list(list(targets = c(0,1,3,4), searchable = FALSE))
,searchCols = list(NULL,NULL,list(search = "General"),NULL,NULL)),
colnames = c('Negation','Type','Category','Frequency (%)','Examples'),rownames=FALSE, escape = FALSE)
output$curr_category_negations_table <- DT::renderDataTable(df_negations,
filter = list(position = 'top', clear = FALSE),
options = list(order=list(3,'desc'),pageLength = 10,columnDefs = list(list(targets = c(0,1,3,4), searchable = FALSE))
,searchCols = list(NULL,NULL,list(search = userSettings$selectedCategory),NULL,NULL)),
colnames = c('Negation','Type','Category','Frequency (%)','Examples'),rownames=FALSE, escape = FALSE)
write.csv(df_negations, file = paste0(app_dir,"negations.csv"), fileEncoding = "UTF-8")
} else if (tableName=='exceptions'){
output$exceptions_table <- DT::renderDataTable(df_exceptions,
filter = list(position = 'top', clear = FALSE),
options = list(order=list(2,'desc'),pageLength = 10,columnDefs = list(list(targets = c(0,2,3), searchable = FALSE))
,searchCols = list(NULL,list(search = "General"),NULL,NULL)),
colnames = c('Exception','Category','Frequency (%)','Examples'),rownames=FALSE, escape = FALSE)
output$curr_category_exceptions_table <- DT::renderDataTable(df_exceptions,
filter = list(position = 'top', clear = FALSE),