-
Notifications
You must be signed in to change notification settings - Fork 32
/
QueryView.jsx
958 lines (884 loc) · 30.4 KB
/
QueryView.jsx
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
/**
* @license
* Copyright 2019 Fast Forward Labs.
* Written by / Contact : https://github.com/victordibia
* NeuralQA - NeuralQA: Question Answering on Large Datasets with BERT.
* Licensed under the MIT License (the "License");
* =============================================================================
*/
import React, { Component } from "react";
import {
Button,
Select,
Toggle,
Modal,
SelectItem,
TextInput,
TextArea,
Loading,
} from "carbon-components-react";
import {
postJSONData,
abbreviateString,
} from "../helperfunctions/HelperFunctions";
import ExplainView from "../explainview/ExplainView";
import ExpandView from "../expandview/ExpandView";
import "./queryview.css";
class QueryView extends Component {
constructor(props) {
super(props);
// console.log(props.data);
this.options = props.data.options;
this.state = {
apptitle: props.data.intro.title,
appsubtitle: props.data.intro.subtitle,
passages: { took: 0, highlights: [] },
answers: { took: 0, answers: [] },
passageIsLoading: false,
answerIsLoading: false,
errorStatus: "",
maxdocuments: this.options.maxdocuments.selected,
reader: this.options.reader.selected,
fragmentsize: this.options.fragmentsize.selected,
chunkStride: this.options.stride.selected,
retriever: this.options.retriever.selected,
expander: this.options.expander.selected,
relsnip: this.options.relsnip.selected,
sampleQA: this.options.samples,
selectedExplanation: 0,
selectedSampleIndex: 0,
explanations: {},
showAdvancedView: false,
showExplanationsView: props.data.views.explanations,
showPassagesView: props.data.views.passages,
showExpander: true, //props.data.views.expander,
expansions: null,
// showAdvanced: props.data.views.advanced,
openAdvancedConfigDrawer: true,
showSamples: props.data.views.samples,
showAllAnswers: props.data.views.allanswers,
showIntro: props.data.views.intro,
showInfoModal: false,
showExplainerModal: false,
};
this.serverBasePath =
window.location.protocol + "//" + window.location.host;
this.serverBasePath = "http://localhost:5000";
this.passageEndpoint = "/api/documents";
this.answerEndpoint = "/api/answers";
this.explainEndpoint = "/api/explain";
this.expandEndpoint = "/api/expand";
this.interfaceTimedDelay = 400;
this.maxStatusElasped = 6; // Remove error/status msgs after maxStatusElasped secs
this.documentTitleLength = 150; // Number of characters to display as the title of the snippets
this.advancedOptionsDescriptions = [
{
title: "Retriever",
value: "retriever",
description:
"A list of search indexes that will be used to retrieve documents that match the search query. If set to None, the interface will let you provide a document/passage in addition to your question",
},
{
title: "Reader",
value: "reader",
description:
"A Question Answering model that will take in your question and retrieved documents (or provided passsage) and extract an answer to the question if it exists in the document.",
},
{
title: "Token Stride",
value: "chunkStride",
description:
"Token stride specifies the overlap between document chunks. QA reader models have limitations on the maximum size of text tokens they can process in a single pass. Lengthy documents are typically broken down in to smaller document chunks and iteratively processed by the model. ",
},
{
title: "Max Documents",
value: "maxdocuments",
description: "Number of documents to return for a retriever query.",
},
{
title: "Expander",
value: "expander",
description:
"Methods for identifying additional query terms that can improve recall.",
},
{
title: "RelSnip",
value: "relsnip",
description:
"Relevant Snippets (RelSnip) is a method for constructing smaller documents from lengthy documents and is implemented as follows. For each retrieved document, we apply a highlighter (Lucene Unified Highlighter) which breaks the document into fragments and uses the BM25 algorithm to score each fragment as if they were individual documents in the corpus. Next, we concatenate the top n (default 5) fragments as a new document which is then processed by the reader. When Relsnip is set to false, the reader reads the entire document by breaking it into chunks. To maintain decent user experience, we process a maximum of 5 chunks.",
},
{
title: "Fragment Size",
value: "fragmentsize",
description:
"The size (number of characters) of each highlight fragment.",
},
];
}
componentDidMount() {
this.askQuestion();
}
resetAnswer() {
this.setState({
passages: { took: 0, highlights: [] },
answers: { took: 0, answers: [] },
errorStatus: "",
explanations: {},
expansions: null,
});
}
resetExplanations() {
this.setState({
explanations: {},
});
}
askQuestion() {
this.resetExplanations();
let question = document.getElementById("queryinput").value;
let context = document.getElementById("contextinput")
? document.getElementById("contextinput").value
: null;
let postData = {
max_documents: this.state.maxdocuments,
context: context || this.state.sampleQA[0].context,
query: question || this.state.sampleQA[0].question,
fragment_size: this.state.fragmentsize,
reader: this.state.reader,
retriever: this.state.retriever,
tokenstride: this.state.chunkStride,
relsnip: this.state.relsnip,
expander: this.state.expander,
};
if (this.state.retriever !== "none") {
this.getPassages(postData);
}
this.getAnswers(postData);
this.lastAsked = new Date();
}
getAnswers(postData) {
// this.setState({ answers: { "took": 0, answers: [] } })
let self = this;
this.setState({ answerIsLoading: true });
let answerUrl = this.serverBasePath + this.answerEndpoint;
let answers = postJSONData(answerUrl, postData);
answers
.then((data) => {
if (data) {
// console.log(data.query);
this.setState({
answers: data,
errorStatus: "",
expansions: data.query,
});
setTimeout(() => {
this.setState({ answerIsLoading: false });
}, this.interfaceTimedDelay);
}
})
.catch(function (err) {
console.log("Failed to fetch answers", err);
self.setState({
answerIsLoading: false,
errorStatus:
"Reader failed to fetch answer. Reader server may need to be restarted. Error msg : " +
err,
});
});
}
getPassages(postData) {
let self = this;
this.setState({ passageIsLoading: true });
let passageUrl = this.serverBasePath + this.passageEndpoint;
let passages = postJSONData(passageUrl, postData);
passages
.then((data) => {
// console.log(data);
if (data.status) {
this.setState({ passages: data });
// console.log(Object.keys(data));
} else {
}
let errorStatus = data.status
? ""
: "Error Fetching Passages. \n" + data.errormsg;
setTimeout(() => {
this.setState({ passageIsLoading: false, errorStatus: errorStatus });
}, this.interfaceTimedDelay);
})
.catch(function (err) {
console.log("Fetch Error :-S", err);
self.setState({
passageIsLoading: false,
errorStatus:
"Retriever to fetch documents. Retriever server may need to be restarted.",
});
});
}
askQuestionButtonClick(e) {
this.askQuestion();
}
inputKeyPress(e) {
if (e.keyCode === 13) {
this.askQuestion();
}
}
toggleSearchConfig(e) {
this.setState({
openAdvancedConfigDrawer: !this.state.openAdvancedConfigDrawer,
});
}
clickInfo(e) {
this.setState({ showInfoModal: !this.state.showInfoModal });
}
clickSampleQuestion(e) {
this.setState(
{
passages: { took: 0, highlights: [] },
answers: { took: 0, answers: [] },
selectedSampleIndex: e.target.getAttribute("qindex"),
},
() => {
this.askQuestion();
}
);
}
getExplanation(selectedAnswerId) {
let self = this;
let answerData = this.state.answers.answers[selectedAnswerId];
// console.log(answerData);
let postData = {
query: answerData.question,
context: answerData.context,
};
// console.log(postData);
this.setState({ answerIsLoading: true });
let explainUrl = this.serverBasePath + this.explainEndpoint;
let explanation = postJSONData(explainUrl, postData);
explanation
.then((data) => {
if (data) {
let explanationHolder = this.state.explanations;
explanationHolder[selectedAnswerId] = data;
this.setState({ explanations: explanationHolder });
// console.log(data);
setTimeout(() => {
this.setState({ answerIsLoading: false });
}, this.interfaceTimedDelay);
}
})
.catch(function (err) {
console.log("Fetch Error :-S", err);
self.setState({
answerIsLoading: false,
errorStatus:
"Failed to fetch explainations. Explaination server may need to be restarted.",
});
});
}
getExpansion() {
let self = this;
let query = document.getElementById("queryinput").value;
let postData = {
query: query,
expander: this.state.expander,
};
// this.setState({ answerIsLoading: true });
let expandUrl = this.serverBasePath + this.expandEndpoint;
let expansion = postJSONData(expandUrl, postData);
expansion
.then((data) => {
if (data) {
console.log(data);
// let explanationHolder = this.state.explanations;
// explanationHolder[selectedAnswerId] = data;
this.setState({ expansions: data });
// console.log(data);
// setTimeout(() => {
// this.setState({ answerIsLoading: false });
// }, this.interfaceTimedDelay);
}
})
.catch(function (err) {
console.log("Fetch Error :-S", err);
// self.setState({
// answerIsLoading: false,
// errorStatus:
// "Failed to fetch explainations. Explaination server may need to be restarted.",
// });
});
}
closeExplainerModal() {
this.setState({
showExplainerModal: false,
});
}
clickExplainButton(e) {
let selectedAnswerId = e.target.getAttribute("id");
this.getExplanation(selectedAnswerId);
this.setState({
showExplainerModal: true,
selectedExplanation: selectedAnswerId,
});
}
expandButtonClick(e) {
this.getExpansion();
}
updateConfigSelectParams(e) {
// console.log(e.target.options);
let configType = e.target.options[e.target.selectedIndex].getAttribute(
"type"
);
let selectedValue = e.target.options[e.target.selectedIndex].value;
// console.log(configType, selectedValue);
switch (configType) {
case "maxdocuments":
this.setState({ maxdocuments: selectedValue });
break;
case "reader":
this.setState({ reader: selectedValue });
break;
case "stride":
this.setState({ chunkStride: selectedValue });
break;
case "fragmentsize":
this.setState({ fragmentsize: selectedValue });
break;
case "retriever":
this.setState({ retriever: selectedValue });
break;
case "relsnip":
this.setState({ relsnip: selectedValue });
break;
case "expander":
this.setState({ expander: selectedValue });
break;
default:
break;
}
this.resetAnswer();
}
getOptionItems(option, defaultValue) {
let selectItems = this.options[option].options.map((data, i) => {
return (
<SelectItem
key={"select" + option + i}
value={data.value}
text={data.name + ""}
type={option}
/>
);
});
let selectElement = (
<Select
id={option + "select"}
defaultValue={this.options[option].selected}
hideLabel={true}
style={{ width: "100%" }}
onChange={this.updateConfigSelectParams.bind(this)}
>
{selectItems}
</Select>
);
return selectElement;
}
toggleAdvancedOptions(e) {
this.setState({ showAdvancedView: !this.state.showAdvancedView });
}
componentDidUpdate(prevProps, prevState, snapshot) {}
render() {
let loadingStatus =
this.state.passageIsLoading || this.state.answerIsLoading;
// Whats this/info box
let infoBox = this.advancedOptionsDescriptions.map((data, index) => {
return (
<div
className="infodescrow underline pb10 pt5"
key={"infodesc" + index}
>
<div className=" infodesctitle">
<span className="boldtext"> {data.title}</span>{" "}
{this.state[data.value] + ""}
</div>
<div className=" infodescdesc"> {data.description}</div>
</div>
);
});
//Expanded query
let queryExpansionList = [];
if (this.state.expansions && this.state.expansions.terms) {
queryExpansionList = this.state.expansions.terms.map((data, index) => {
return (
<div key={"expansionterm" + index} className="smalldesc iblock mr5">
{data.token}
</div>
);
});
}
// Create a list view for passages
let passageList = this.state.passages["highlights"].map((data, index) => {
let dataTitle = data.substring(0, this.documentTitleLength);
// if (data.highlight["name"] !== undefined) {
// for (let title of data.highlight["name"]) {
// dataTitle = dataTitle + " ... " + title;
// }
// } else {
// dataTitle = data._source.name;
// }
// let caseHighlight =
// data.highlight["casebody.data.opinions.text"] || "No highlight.";
return (
<div className="passagerow flex" key={"passagerow" + index}>
<div className="answerrowtitletag mr10"> D{index} </div>
<div className="flexfull">
<div
className="passagetitle highlightsection mb10 underline lhmedium"
dangerouslySetInnerHTML={{ __html: dataTitle }}
/>
<span
className="highlightsection iblock lhmedium "
dangerouslySetInnerHTML={{
__html:
"<span class='excerpttitle mediumdesc'> All highlights: </span> <span class='lhmedium mediumdesc'>" +
data +
"</span>",
}}
/>
</div>
</div>
);
});
// Create list view for answers
let answerList = this.state.answers.answers
.slice(
0,
this.state.showAllAnswers ? this.state.answers.answers.length : 1
)
.map((data, index) => {
return (
<div
className={
"flex p10 answerrow " + (index === 0 ? "topanswer" : "")
}
key={"answerrow" + index}
>
<div className="answerrowtitletag mr10"> A{data.index} </div>
<div className="flexfull mediumdesc lhmedium">
<div>
<div className="smalldesc pt5">
Time: {data.took.toFixed(3)}s |{" "}
{(data.probability * 1).toFixed(4)}
{/* | Total Probability {(data.probability * 1).toFixed(4)} [ {((data.start_probability * 1) / 2).toFixed(4)} | {((data.end_probability * 1) / 2).toFixed(4)} ] */}
</div>
<div className="boldtext">
{" "}
<span className="answerquote">“</span> {data.answer}{" "}
<span className="pt10 answerquote">”</span>{" "}
</div>
{
<div>
<div
className="p10 mt10 mb10 contextrow lightgreyhighlight"
dangerouslySetInnerHTML={{ __html: data.context }}
/>
{this.state.showExplanationsView && (
<Button
id={index}
onClick={this.clickExplainButton.bind(this)}
size="small"
>
Explain
</Button>
)}
</div>
}
</div>
</div>
</div>
);
});
// Create sample qa passages for None QA
let qaSamples = this.state.sampleQA.map((data, index) => {
return (
<div
qindex={index}
onClick={this.clickSampleQuestion.bind(this)}
key={"qasample" + index}
className={
"samplequestionrow mediumdesc clickable iblock " +
(this.state.selectedSampleIndex + "" === index + ""
? " selected "
: " ")
}
>
{data.question}
</div>
);
});
let askedElapsed =
(new Date() - this.lastAsked) / 1000 > this.maxStatusElasped;
// Create configuration bar
let configBar = (
<div
ref="modelconfigbar"
style={{ zIndex: 100 }}
className={"w100 pl10 pb10 unselectable greyhighlight modelconfigbar"}
>
<div className="positionrelative ">
<div className=" pt10 pb10 underline">
Select QA model configuration.
</div>
<div
className="whatsthis clickable"
onClick={this.clickInfo.bind(this)}
>
<span className="infocircle"> ?</span> info
</div>
</div>
<div className="w100 displayblock ">
<div className=" iblock mr10">
<div className="mediumdesc pb7 pt5">
{" "}
{this.options.retriever.title}{" "}
<span className="boldtext"> {this.state.retriever} </span>{" "}
</div>
{this.getOptionItems("retriever", "")}
</div>
<div className="pl10 borderleftdash iblock mr10">
<div className="mediumdesc pb7 pt5">
{" "}
{this.options.reader.title}{" "}
<span className="boldtext">
{" "}
{abbreviateString(this.state.reader, 16)}{" "}
</span>{" "}
</div>
{this.getOptionItems("reader", "")}
</div>
<div className="iblock mr10">
<div className="mediumdesc pb7 pt5">
{" "}
{this.options.stride.title}
<span className="boldtext"> {this.state.chunkStride} </span>{" "}
</div>
{this.getOptionItems("stride", "")}
</div>
{/* show IR search pipeline config is dataset is not None */}
{this.state.retriever !== "none" && (
<div className="pl10 borderleftdash iblock mr10 ">
<div className="mediumdesc pb7 pt5">
{" "}
{this.options.maxdocuments.title}{" "}
<span className="boldtext"> {this.state.maxdocuments} </span>{" "}
</div>
{this.getOptionItems("maxdocuments", "")}
</div>
)}
{this.state.showExpander && (
<div className=" iblock mr10">
<div className="mediumdesc pb7 pt5">
{" "}
{this.options.expander.title}{" "}
<span className="boldtext">
{" "}
{abbreviateString(this.state.expander + "", 16)}{" "}
</span>{" "}
</div>
{this.getOptionItems("expander", "")}
</div>
)}
{this.state.retriever !== "none" && (
<div className="iblock mr10 ">
<div className="mediumdesc pb7 pt5">
{" "}
{this.options.fragmentsize.title}{" "}
<span className="boldtext"> {this.state.fragmentsize} </span>{" "}
</div>
{this.getOptionItems("fragmentsize", "")}
</div>
)}
{this.state.retriever !== "none" && (
<div className=" iblock mr10">
<div className="mediumdesc pb7 pt5">
{" "}
{this.options.relsnip.title}{" "}
<span className="boldtext">
{" "}
{abbreviateString(this.state.relsnip + "", 16)}{" "}
</span>{" "}
</div>
{this.getOptionItems("relsnip", "")}
</div>
)}
</div>
</div>
);
return (
<div>
<Modal
open={this.state.showInfoModal}
modalHeading={"Description of advanced options"}
passiveModal={true}
size={"lg"}
aria-label={"Info Modal"}
modalAriaLabel={"Info Modal"}
onRequestClose={this.clickInfo.bind(this)}
hasScrollingContent={true}
// secondaryButtonText={"Cancel"}
>
{infoBox}
</Modal>
<Modal
open={this.state.showExplainerModal}
modalHeading={"Model Explanation"}
passiveModal={true}
size={"lg"}
aria-label={"Explaination Modal"}
modalAriaLabel={"Explanation Modal"}
onRequestClose={this.closeExplainerModal.bind(this)}
hasScrollingContent={true}
// secondaryButtonText={"Cancel"}
>
{Object.keys(this.state.explanations).length > 0 && (
<ExplainView
explanationData={
this.state.explanations[this.state.selectedExplanation]
}
selectedExplanation={this.state.selectedExplanation}
></ExplainView>
)}
</Modal>
{/* <ExpandView data={this.state.expansions}></ExpandView> */}
{this.state.showIntro && (
<div className="clearfix mynotif positionrelative mt10 h100 lh10 lightbluehightlight maxh16 mb10">
{this.props.data.views.advanced && (
<div className=" floatright lightgreyhighlight ml10 pr10 pl10 pb10 ">
{/* <div className="mediumdesc boldtext"> Advanced Options</div> */}
<div className="boldtext iblock ">
<Toggle
id="advancedoptionstoggle"
className="smalldesc boldtext mr10"
labelA="Off"
labelB="On"
defaultToggled={this.state.showAdvancedView}
// onChange action('onChange'),
onToggle={this.toggleAdvancedOptions.bind(this)}
></Toggle>
</div>
<div className="mediumdesc boldtext"> Advanced Options</div>
</div>
)}
<span className="boldtext mb5">{this.state.apptitle}</span>
<br />
{this.state.appsubtitle}
</div>
)}
<div
className={
" mb10" + (this.state.showAdvancedView ? "" : " displaynone")
}
>
{/* config panel and content */}
<div
onClick={this.toggleSearchConfig.bind(this)}
className="unselectable mt10 p10 clickable flex greymoreinfo"
>
<div className="iblock flexfull minwidth485">
<strong>
{" "}
{!this.state.openAdvancedConfigDrawer && (
<span>▼ </span>
)}{" "}
{this.state.openAdvancedConfigDrawer && <span>▲ </span>}{" "}
</strong>
Advanced Options
</div>
<div className="iblock ">
<div className="iblock mr5">
{" "}
<span className="boldtext"> </span>
</div>
<div className="iblock">
<div className="smalldesc">
{" "}
{this.state.maxdocuments} Results |{" "}
{this.state.reader.toUpperCase()}{" "}
</div>
</div>
</div>
</div>
{
<div
className={
"flex underline p10 modelconfigdiv w100 " +
(this.state.openAdvancedConfigDrawer ? "" : " displaynone")
}
>
{/* <div> Advanced configuration settings </div> */}
<div className="w100"> {configBar}</div>
</div>
}
</div>
{this.state.retriever === "none" && this.state.showSamples && (
<div className=" mb10">
<div className="smalldesc p5">
{" "}
Select any sample question/passage pair below{" "}
</div>
{qaSamples}
</div>
)}
<div className="mt5 mt10 mb10 mediumdesc"> Enter question </div>
<div className="flex searchbar">
<div
key={"queryinput" + this.state.selectedSampleIndex}
className="flexfull"
>
<TextInput
id="queryinput"
defaultValue={
this.state.sampleQA[this.state.selectedSampleIndex].question
}
hideLabel={true}
labelText="Hi there"
onKeyDown={this.inputKeyPress.bind(this)}
placeholder="Enter question. e.g. Which cases cite dwayne vs the united states."
></TextInput>
</div>
<div>
{" "}
<Button
className="mr2"
onClick={this.expandButtonClick.bind(this)}
size="field"
>
{" "}
Expand
</Button>
<Button
onClick={this.askQuestionButtonClick.bind(this)}
size="field"
>
{" "}
Get Answer{" "}
</Button>
</div>
</div>
{this.state.expansions && this.state.expansions.terms && (
<div className=" pt5">
<span className="boldtext">suggested expansion terms: </span>{" "}
{queryExpansionList}
<ExpandView data={this.state.expansions}></ExpandView>
</div>
)}
{/* {this.state.sampleQA[this.state.selectedSampleIndex].context} */}
{this.state.retriever === "none" && (
<div
key={"contexttextarea" + this.state.selectedSampleIndex}
className="mt10"
>
<div className="mt5 mb10 mediumdesc"> Enter passage </div>
<TextArea
id="contextinput"
className="contextinputarea"
defaultValue={
this.state.sampleQA[this.state.selectedSampleIndex].context
}
labelText="Enter a passage"
hideLabel={true}
></TextArea>
</div>
)}
<div className="mediumdesc pt7 pb7">
{this.state.answerIsLoading && (
<span> Asking BERT for answers ... </span>
)}
</div>
{!askedElapsed && this.state.errorStatus.length > 1 && (
<div className="errormessage">{this.state.errorStatus}</div>
)}
{answerList.length > 0 && (
<div>
{/* <Loading
active={this.state.answerIsLoading}
description="Active loading indicator" withOverlay={true}
/> */}
<div className="flex mt10 ">
<div
className="loaderbox"
style={{
opacity: loadingStatus ? 1 : 0,
width: loadingStatus ? "34px" : "0px",
}}
>
<Loading
className=" "
active={true}
small={true}
withOverlay={false}
>
{" "}
</Loading>
</div>
<div className="flexfull sectionheading">
<span className="boldtext">
{" "}
{answerList.length} Answer{answerList.length > 1 ? "s" : ""}{" "}
returned{" "}
</span>
{!this.state.answerIsLoading && (
<span className="mediumdesc">
{" "}
{this.state.answers["took"].toFixed(3)} seconds.{" "}
</span>
)}
</div>
<div className="lh2m">
{this.state.answerIsLoading && (
<span className="mediumdesc"> Loading answers ... </span>
)}
</div>
</div>
<div>{answerList}</div>
</div>
)}
{/* { !askedElapsed &&} */}
{answerList.length === 0 && !this.state.answerIsLoading && (
<div className="p10 orangehighlight">No answers found.</div>
)}
{(this.state.showPassagesView && passageList.length) > 0 && (
<div>
<div className="mt10 mb10">
<span className="boldtext">
{" "}
{this.state.passages["highlights"].length} Documents returned.{" "}
</span>
{this.state.passageIsLoading && (
<span className="mediumdesc"> Loading passages ... </span>
)}
{!this.state.passageIsLoading && (
<span className="mediumdesc">
{" "}
{this.state.passages["took"] / 1000} seconds{" "}
</span>
)}
</div>
<div className="passagebox mt10">{passageList}</div>
</div>
)}
{!askedElapsed &&
passageList.length === 0 &&
this.state.retriever !== "none" &&
!this.state.passageIsLoading && (
<div className="p10 mt5 orangehighlight">
Your query did not match any passages. Try a different query.
</div>
)}
{/* {askedElapsed + ""} bingo */}
<br />
<br />
<br />
</div>
);
}
}
export default QueryView;