-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
1117 lines (916 loc) · 47.7 KB
/
main.js
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
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 42);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
module.exports = require("tslib");
/***/ }),
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var _lib_interfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(16);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _lib_interfaces__WEBPACK_IMPORTED_MODULE_0__["a"]; });
/***/ }),
/* 2 */
/***/ (function(module, exports) {
module.exports = require("express");
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = require("node-fetch");
/***/ }),
/* 4 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var _europepmc_parser__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(24);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "b", function() { return _europepmc_parser__WEBPACK_IMPORTED_MODULE_0__["a"]; });
/* harmony import */ var _arxiv_parser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(25);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _arxiv_parser__WEBPACK_IMPORTED_MODULE_1__["a"]; });
/***/ }),
/* 5 */
/***/ (function(module, exports) {
module.exports = require("natural");
/***/ }),
/* 6 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return correlationWeights; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return cutOffs; });
const correlationWeights = {
querySynonymWordFreq: 0.5,
queryWordFreq: 1,
};
const cutOffs = {
minimumWordDistance: 0.85,
maintainScoreWithinPercent: 10,
};
/***/ }),
/* 7 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var _lib_scraper__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(19);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _lib_scraper__WEBPACK_IMPORTED_MODULE_0__["a"]; });
/***/ }),
/* 8 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var _europepmc_parser__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(20);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "b", function() { return _europepmc_parser__WEBPACK_IMPORTED_MODULE_0__["a"]; });
/* harmony import */ var _arxiv_parser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(21);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _arxiv_parser__WEBPACK_IMPORTED_MODULE_1__["a"]; });
/***/ }),
/* 9 */
/***/ (function(module, exports) {
module.exports = require("xml2js");
/***/ }),
/* 10 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var _lib_word_explorer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(22);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _lib_word_explorer__WEBPACK_IMPORTED_MODULE_0__["a"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "b", function() { return _lib_word_explorer__WEBPACK_IMPORTED_MODULE_0__["b"]; });
/***/ }),
/* 11 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return runEuropePMCScrapers; });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _foodmedicine_scraper__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7);
/* harmony import */ var _parsers__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
// eslint-disable-next-line @nrwl/nx/enforce-module-boundaries
/**
* Construct the google scholars url which will be scraped
* @param pageSize - the number of articles to get
*/
function createEuropePMCUrl(query, pageSize, synonym = true) {
return encodeURI(`https://www.ebi.ac.uk/europepmc/webservices/rest/search?query=${query}&synonym=${synonym}&pageSize=${pageSize}`);
}
function runEuropePMCScrapers(query, querySynonyms, pageSize) {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
const queryUrl = createEuropePMCUrl(query, pageSize);
const remedyScraper = new _foodmedicine_scraper__WEBPACK_IMPORTED_MODULE_1__[/* Scraper */ "a"](_parsers__WEBPACK_IMPORTED_MODULE_2__[/* EuropePMCParser */ "b"], {
url: queryUrl,
tag: {
query,
querySynonyms,
},
});
const articleHeads = yield remedyScraper.run();
return articleHeads;
});
}
/***/ }),
/* 12 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return constants; });
const constants = {
MIN_TAB_COUNT: 5,
SENTENCES_PER_PARAGRAPH: 5,
MIN_CHAR_COUNT_PER_PARAGRAPH: 20,
};
/***/ }),
/* 13 */
/***/ (function(module, exports) {
module.exports = require("body-parser");
/***/ }),
/* 14 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return runArxivScrapers; });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _foodmedicine_scraper__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7);
/* harmony import */ var _parsers__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
// eslint-disable-next-line @nrwl/nx/enforce-module-boundaries
/**
* Construct the google scholars url which will be scraped
* @param pageSize - the number of articles to get
*/
function createArxivUrl(query, pageSize) {
return encodeURI(`http://export.arxiv.org/api/query?search_query=all:${query}&start=0&max_results=${pageSize}`);
}
function runArxivScrapers(query, querySynonyms, pageSize) {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
const queryUrl = createArxivUrl(query, pageSize);
const remedyScraper = new _foodmedicine_scraper__WEBPACK_IMPORTED_MODULE_1__[/* Scraper */ "a"](_parsers__WEBPACK_IMPORTED_MODULE_2__[/* ArxivParser */ "a"], {
url: queryUrl,
tag: {
query,
querySynonyms,
},
});
const articleHeads = yield remedyScraper.run();
return articleHeads;
});
}
/***/ }),
/* 15 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return findQueryResults; });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _foodmedicine_interfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
/* harmony import */ var _foodmedicine_scholars_scraper__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(33);
/* harmony import */ var _foodmedicine_article_parser__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(38);
/* harmony import */ var _foodmedicine_word_explorer__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(10);
function groupParagraphsByArticle(articlesStandalone) {
const byIds = {};
articlesStandalone.map((articleStandalone) => {
if (!byIds[articleStandalone.head.id]) {
byIds[articleStandalone.head.id] = [];
}
byIds[articleStandalone.head.id].push(articleStandalone);
});
const parsedByTitle = Object.keys(byIds)
.map((id) => {
var _a;
if (!byIds[id] || ((_a = byIds[id]) === null || _a === void 0 ? void 0 : _a.length) === 0) {
return null;
}
return {
head: byIds[id][0].head,
paragraphs: byIds[id].map((paragraphStandalone) => {
return {
body: paragraphStandalone.body,
correlationScore: paragraphStandalone.correlationScore,
};
}),
};
})
.filter((item) => item !== null);
return parsedByTitle;
}
function sortParagraphsByArticle(a, b) {
const aTotalScore = a.paragraphs.reduce((prev, paragraph) => (prev += paragraph.correlationScore), 0);
const bTotalScore = b.paragraphs.reduce((prev, paragraph) => (prev += paragraph.correlationScore), 0);
return bTotalScore - aTotalScore;
}
function findQueryResults(query, opts) {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
const cleanedQuery = Object(_foodmedicine_word_explorer__WEBPACK_IMPORTED_MODULE_4__[/* cleanString */ "a"])(query);
const articleHeads = yield Object(_foodmedicine_scholars_scraper__WEBPACK_IMPORTED_MODULE_2__[/* runScholarsScraper */ "a"])(cleanedQuery, _foodmedicine_interfaces__WEBPACK_IMPORTED_MODULE_1__[/* ScholarsDB */ "a"].RUN_ALL, (opts === null || opts === void 0 ? void 0 : opts.numberOfArticles) || 25);
const downloadProms = articleHeads.map((articleHead) => Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
const evaluatedArticle = yield _foodmedicine_article_parser__WEBPACK_IMPORTED_MODULE_3__[/* evaluateArticle */ "a"](articleHead);
return evaluatedArticle;
}));
const allEvaluatedArticles = yield Promise.all(downloadProms);
const allParagraphsStandalone = [];
// For each evaluated article paragraph, form the ParsedArticleParagraphStandalone and push
// it to the array of all parsed article paragraphs
allEvaluatedArticles.forEach((article) => {
const standaloneParagraphs = article.paragraphs.map((paragraph) => {
return Object.assign({ head: article.head }, paragraph);
});
allParagraphsStandalone.push(...standaloneParagraphs);
});
const allParagraphsStandaloneFiltered = allParagraphsStandalone.filter((paragraph) => { var _a; return ((_a = paragraph.body) === null || _a === void 0 ? void 0 : _a.trim().length) > 0; });
const filteredByLength = allParagraphsStandaloneFiltered.slice(0, (opts === null || opts === void 0 ? void 0 : opts.maxNumberOfParagraphs) || allParagraphsStandalone.length);
const byArticle = groupParagraphsByArticle(filteredByLength);
// sort the individual paragraphs within an article by correlation score
byArticle.map((article) => article.paragraphs.sort((a, b) => b.correlationScore - a.correlationScore));
return byArticle.sort((a, b) => sortParagraphsByArticle(a, b));
});
}
/***/ }),
/* 16 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ScholarsDB; });
var ScholarsDB;
(function (ScholarsDB) {
ScholarsDB[ScholarsDB["RUN_ALL"] = 0] = "RUN_ALL";
ScholarsDB[ScholarsDB["ARXIV"] = 1] = "ARXIV";
ScholarsDB[ScholarsDB["EUROPE_PMC"] = 2] = "EUROPE_PMC";
})(ScholarsDB || (ScholarsDB = {}));
/***/ }),
/* 17 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var _scraper_scholars_scraper__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(18);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _scraper_scholars_scraper__WEBPACK_IMPORTED_MODULE_0__["a"]; });
/***/ }),
/* 18 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return runScholarsScraper; });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _foodmedicine_interfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
/* harmony import */ var _europepmc_scraper__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11);
/* harmony import */ var _arxiv_scraper__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(14);
/* harmony import */ var _foodmedicine_word_explorer__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(10);
/**
* Find all the PDF urls which could have related articles to the remedy
* @returns an array of PDF urls
*/
function runScholarsScraper(query, db, pageSize) {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
const querySynonyms = yield Object(_foodmedicine_word_explorer__WEBPACK_IMPORTED_MODULE_4__[/* getSynonyms */ "b"])(query);
if (db === _foodmedicine_interfaces__WEBPACK_IMPORTED_MODULE_1__[/* ScholarsDB */ "a"].RUN_ALL) {
// TODO have more intelligent partitioning of pageSize. If a search is more bio related, have there be more weight
// for europepmc. If more computer related, more arxiv weight
const europepmcProm = Object(_europepmc_scraper__WEBPACK_IMPORTED_MODULE_2__[/* runEuropePMCScrapers */ "a"])(query, querySynonyms, Math.ceil(pageSize / 2));
const arxivProm = Object(_arxiv_scraper__WEBPACK_IMPORTED_MODULE_3__[/* runArxivScrapers */ "a"])(query, querySynonyms, Math.ceil(pageSize / 2));
const articlesNested = Promise.all([europepmcProm, arxivProm]);
return (yield articlesNested).flat();
}
else if (db === _foodmedicine_interfaces__WEBPACK_IMPORTED_MODULE_1__[/* ScholarsDB */ "a"].EUROPE_PMC) {
return Object(_europepmc_scraper__WEBPACK_IMPORTED_MODULE_2__[/* runEuropePMCScrapers */ "a"])(query, querySynonyms, pageSize);
}
else if (db === _foodmedicine_interfaces__WEBPACK_IMPORTED_MODULE_1__[/* ScholarsDB */ "a"].ARXIV) {
return Object(_arxiv_scraper__WEBPACK_IMPORTED_MODULE_3__[/* runArxivScrapers */ "a"])(query, querySynonyms, pageSize);
}
return Object(_europepmc_scraper__WEBPACK_IMPORTED_MODULE_2__[/* runEuropePMCScrapers */ "a"])(query, querySynonyms, pageSize);
});
}
/***/ }),
/* 19 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Scraper; });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var node_fetch__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
/* harmony import */ var node_fetch__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(node_fetch__WEBPACK_IMPORTED_MODULE_1__);
/**
* A generalized scraper abstraction class
* This class can scrape different sites of pdfs
* @param IRet - is the return interface for a scraped site or article
*/
class Scraper {
constructor(parser, ...urlsWithTags) {
this.parser = parser;
this.urlsWithTags = urlsWithTags;
}
/**
* Retrieves the source code of a url
*/
getSiteSource(url) {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
const ret = yield node_fetch__WEBPACK_IMPORTED_MODULE_1___default()(url);
return yield ret.text();
});
}
scrapeSiteSinglePage(url, opts) {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
console.info("Scraping for", url);
const source = yield this.getSiteSource(url);
return yield this.parser.parserF(source, opts);
});
}
/**
* Run the scraper for the inputed websites
*/
run() {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
// create an array of promises to concurrently perform web scraping
const pageScrapingProms = this.urlsWithTags.map((urlWithTag) => Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
return yield this.scrapeSiteSinglePage(urlWithTag.url, {
tag: urlWithTag.tag,
});
}));
const scrapedRes = yield Promise.all(pageScrapingProms);
// Because each individual page returns an array of results,
// results will be an array of arrays which should be flattened
return scrapedRes.flat();
});
}
}
/***/ }),
/* 20 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return EuropePMCParser; });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _foodmedicine_interfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
/* harmony import */ var xml2js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9);
/* harmony import */ var xml2js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(xml2js__WEBPACK_IMPORTED_MODULE_2__);
/**
* A parser for https://www.ebi.ac.uk/europepmc/webservices/rest/
*/
const EuropePMCParser = {
parserF: (xml, opts) => Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(void 0, void 0, void 0, function* () {
if (!opts) {
throw 'Options must be passed into this scraper';
}
const parser = new xml2js__WEBPACK_IMPORTED_MODULE_2__["Parser"]();
const jsonRes = yield parser.parseStringPromise(xml);
const allResults = jsonRes.responseWrapper.resultList[0].result;
const parsedHeads = (allResults || []).map((res) => {
return {
id: res.id[0],
title: res.title[0],
fullTextDownloadLink: `https://www.ebi.ac.uk/europepmc/webservices/rest/${res.id[0]}/fullTextXML`,
query: opts.tag.query,
querySynonyms: opts.tag.querySynonyms,
DBType: _foodmedicine_interfaces__WEBPACK_IMPORTED_MODULE_1__[/* ScholarsDB */ "a"].EUROPE_PMC
};
});
return parsedHeads;
}),
};
/***/ }),
/* 21 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ArxivParser; });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _foodmedicine_interfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
/* harmony import */ var xml2js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9);
/* harmony import */ var xml2js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(xml2js__WEBPACK_IMPORTED_MODULE_2__);
/**
* A parser for http://export.arxiv.org/api/query
*/
const ArxivParser = {
parserF: (xml, opts) => Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(void 0, void 0, void 0, function* () {
if (!opts) {
throw 'Options must be passed into this scraper';
}
const parser = new xml2js__WEBPACK_IMPORTED_MODULE_2__["Parser"]();
const jsonRes = yield parser.parseStringPromise(xml);
const allResults = jsonRes.feed.entry || [];
const parsedHeads = (allResults || [])
.map((res) => {
const pdfDownloadLinks = (res.link
.filter((linkItem) => linkItem.$.title === 'pdf') || [])
.map((linkItem) => linkItem.$.href);
const fullTextDownloadLink = pdfDownloadLinks[0] || null;
return {
id: res.id,
title: res.title,
fullTextDownloadLink,
query: opts.tag.query,
querySynonyms: opts.tag.querySynonyms,
DBType: _foodmedicine_interfaces__WEBPACK_IMPORTED_MODULE_1__[/* ScholarsDB */ "a"].ARXIV,
};
})
.filter((parsedHead) => parsedHead.fullTextDownloadLink !== null);
return parsedHeads;
}),
};
/***/ }),
/* 22 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return getSynonyms; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return cleanString; });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var util__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(34);
/* harmony import */ var util__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(util__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var wordnet__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(35);
/* harmony import */ var wordnet__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(wordnet__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var natural__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5);
/* harmony import */ var natural__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(natural__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var contractions__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(36);
/* harmony import */ var contractions__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(contractions__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var stopword__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(37);
/* harmony import */ var stopword__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(stopword__WEBPACK_IMPORTED_MODULE_5__);
const wordnetLookup = util__WEBPACK_IMPORTED_MODULE_1__["promisify"](wordnet__WEBPACK_IMPORTED_MODULE_2__["lookup"]);
function getSynonyms(word) {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
// n is for the nouns
const synonymWordsArrProms = word.split(' ').map((individualWord) => Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
try {
return (yield wordnetLookup(natural__WEBPACK_IMPORTED_MODULE_3__["PorterStemmer"].stem(individualWord))).map((def) => def.meta.words.map((item) => item.word));
}
catch (e) {
console.error('Error finding synonyms for %s. Error %s', individualWord, e);
return [[]];
}
}));
const synonymWordsArr = yield Promise.all(synonymWordsArrProms);
// make sure the items in the array are all truthy
const synonymWords = synonymWordsArr
.flat(Infinity)
.filter((synonym) => synonym && !word.includes(synonym));
if (!synonymWords) {
return [];
}
console.info('Found synonym words for %s:', word, synonymWords);
return synonymWords;
});
}
/**
* Clean a string for preprocessing.
* Remove stop words and contractions
* Ex: I can't believe that it is red becomes I cannot believe it red
*/
function cleanString(s) {
const noContraction = contractions__WEBPACK_IMPORTED_MODULE_4___default.a.expand(s);
const noStopWords = stopword__WEBPACK_IMPORTED_MODULE_5___default.a.removeStopwords(noContraction.split(' ')).join(' ');
return noStopWords;
}
/***/ }),
/* 23 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var _parser__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4);
/* harmony import */ var _correlation_score_correlation_score__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(27);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _correlation_score_correlation_score__WEBPACK_IMPORTED_MODULE_1__["a"]; });
/***/ }),
/* 24 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return EuropePMCParser; });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var node_fetch__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
/* harmony import */ var node_fetch__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(node_fetch__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var cheerio__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(39);
/* harmony import */ var cheerio__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(cheerio__WEBPACK_IMPORTED_MODULE_2__);
function downloadArticle(url) {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
const ret = yield node_fetch__WEBPACK_IMPORTED_MODULE_1___default()(url);
return yield ret.text();
});
}
/**
* A parser for https://www.ebi.ac.uk/europepmc/webservices/rest/
*/
const EuropePMCParser = {
parserF: (xmlDownloadLink, opts) => Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(void 0, void 0, void 0, function* () {
const xml = yield downloadArticle(xmlDownloadLink);
if (!(opts === null || opts === void 0 ? void 0 : opts.parsedArticleHead)) {
throw 'Please add in the parsed head';
}
const $ = cheerio__WEBPACK_IMPORTED_MODULE_2__["load"](xml);
const paragraphTexts = $('p')
.map((i, el) => $(el).text())
.get();
const paragraphs = paragraphTexts.map((paragraphText) => opts.getCorrelationScore(paragraphText, opts.parsedArticleHead.query, opts.parsedArticleHead.querySynonyms));
const article = {
head: opts.parsedArticleHead,
paragraphs,
};
return article;
}),
};
/***/ }),
/* 25 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ArxivParser; });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _foodmedicine_pdf_explorer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(40);
/**
* A parser for https://www.ebi.ac.uk/europepmc/webservices/rest/
*/
const ArxivParser = {
parserF: (fileUrl, opts) => Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(void 0, void 0, void 0, function* () {
if (!(opts === null || opts === void 0 ? void 0 : opts.parsedArticleHead)) {
throw new Error('Please add in the parsed head');
}
const paragraphTexts = yield Object(_foodmedicine_pdf_explorer__WEBPACK_IMPORTED_MODULE_1__[/* getParagraphsFromPDFUrl */ "a"])(fileUrl);
try {
const paragraphs = paragraphTexts.map((paragraphText) => opts.getCorrelationScore(paragraphText, opts.parsedArticleHead.query, opts.parsedArticleHead.querySynonyms));
const article = {
head: opts.parsedArticleHead,
paragraphs,
};
return article;
}
catch (e) {
console.error(`Error parsing article from Arxiv. Skipping the article `, e);
return {
head: opts.parsedArticleHead,
paragraphs: [],
};
}
}),
};
/***/ }),
/* 26 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* unused harmony export splitTextToParagraphs */
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getParagraphsFromPDFUrl; });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var node_fetch__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
/* harmony import */ var node_fetch__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(node_fetch__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var pdf_parse__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(41);
/* harmony import */ var pdf_parse__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(pdf_parse__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _pdf_explorer_constants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(12);
/**
* Check whether the paragraphs contains valid information
*/
function paragraphContainsInformation(body) {
return body.length > _pdf_explorer_constants__WEBPACK_IMPORTED_MODULE_3__[/* constants */ "a"].MIN_CHAR_COUNT_PER_PARAGRAPH && body.includes('.');
}
function getCharCount(text, pattern) {
return (text.match(pattern) || []).length;
}
function groupSentencesIntoParagraphs(sentences) {
let syntheticParagraphsInd = 0;
const syntheticParagraphs = [];
sentences.forEach((sentence, i) => {
if (!syntheticParagraphs[syntheticParagraphsInd]) {
syntheticParagraphs[syntheticParagraphsInd] = sentence + '. ';
}
else {
syntheticParagraphs[syntheticParagraphsInd] += sentence + '. ';
}
if (i % _pdf_explorer_constants__WEBPACK_IMPORTED_MODULE_3__[/* constants */ "a"].SENTENCES_PER_PARAGRAPH === 0) {
syntheticParagraphsInd++;
}
});
return syntheticParagraphs;
}
/**
* Split text into paragraph by first attempting to split by the tab character.
* If the tab character does not appear more than {@code MIN_TAB_COUNT} number of times,
* synthetically create paragraphs by grouping sentences together.
*/
function splitTextToParagraphs(rawText) {
const tabCount = getCharCount(rawText, /\t/g);
if (tabCount > _pdf_explorer_constants__WEBPACK_IMPORTED_MODULE_3__[/* constants */ "a"].MIN_TAB_COUNT) {
return rawText.split('\t').filter(paragraphContainsInformation);
}
const sentences = rawText.split('.');
return groupSentencesIntoParagraphs(sentences).filter(paragraphContainsInformation);
}
function getParagraphsFromPDFUrl(url) {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
const fetchRes = yield node_fetch__WEBPACK_IMPORTED_MODULE_1___default()(url);
const buff = yield fetchRes.buffer();
const pdfData = yield pdf_parse__WEBPACK_IMPORTED_MODULE_2___default()(buff);
return splitTextToParagraphs(pdfData.text);
});
}
/***/ }),
/* 27 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return evaluateArticle; });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _foodmedicine_interfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
/* harmony import */ var _correlation_constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
/* harmony import */ var natural__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5);
/* harmony import */ var natural__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(natural__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _parser__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(4);
const tokenizer = new natural__WEBPACK_IMPORTED_MODULE_3__["WordTokenizer"]();
/**
* Find word frequencies through fuzzy search
*/
function findWordFreqFuzzy(word, paragraph) {
const tokenizedParagraph = tokenizer.tokenize(paragraph);
const overallFreqScore = tokenizedParagraph.reduce((freq, paragraphWord) => {
// distance ranges from 0 to 1. 1 being a perfect match
const distance = natural__WEBPACK_IMPORTED_MODULE_3__["JaroWinklerDistance"](word, paragraphWord);
return freq + (distance > _correlation_constants__WEBPACK_IMPORTED_MODULE_2__[/* cutOffs */ "b"].minimumWordDistance ? distance : 0);
}, 0);
return overallFreqScore;
}
function findWordsFreqFuzzy(words, paragraph) {
return words
.map((word) => findWordFreqFuzzy(word, paragraph))
.reduce((total, score) => total + score, 0);
}
/**
* Compute the correlation score based off of the inputs
* Current features include query frequencies, query synonym frequencies
*/
function computeScore(queryFreq, querySynonymWordFreq) {
const queryScore = queryFreq * _correlation_constants__WEBPACK_IMPORTED_MODULE_2__[/* correlationWeights */ "a"].queryWordFreq;
const querySynonymScore = querySynonymWordFreq * _correlation_constants__WEBPACK_IMPORTED_MODULE_2__[/* correlationWeights */ "a"].querySynonymWordFreq;
return querySynonymScore + queryScore;
}
function stemString(input) {
return natural__WEBPACK_IMPORTED_MODULE_3__["PorterStemmer"].tokenizeAndStem(input).join(' ');
}
function getWholeParagraphCorrelationScore(paragraph, query, querySynonyms) {
const queryStem = stemString(query);
const paragraphStem = stemString(paragraph);
const querySynonymFreq = findWordsFreqFuzzy(querySynonyms, paragraphStem);
const correlationScore = computeScore(findWordFreqFuzzy(queryStem, paragraphStem), querySynonymFreq);
return {
body: paragraph,
correlationScore,
};
}
/**
* Get the correlation score for the segment of a paragraph with the most matches
* Will shorten the paragraph as much as possible while trying to mantain the same correlation score
* + or - {@code maintainWithinPercent}
*/
function getShortestParagraphCorrelationScore(paragraph, query, querySynonyms, maintainWithinPercent = _correlation_constants__WEBPACK_IMPORTED_MODULE_2__[/* cutOffs */ "b"].maintainScoreWithinPercent) {
function calculatePercentageDifference(x, y) {
return Math.abs((x - y) / x) * 100;
}
const sentences = paragraph.split('.');
// remove the last element if it is empty
if (!sentences[sentences.length - 1]) {
sentences.pop();
}
const initScore = getWholeParagraphCorrelationScore(paragraph, query, querySynonyms).correlationScore;
let currentScore = initScore;
let leftInd = 0;
let rightIndNonInclusive = sentences.length;
// Attempts to remove sentences from the beginning of the paragraph
// while having the correlation score stay within half of the {@code maintainWithinPercent}
while (calculatePercentageDifference(initScore, currentScore) <=
maintainWithinPercent / 2 &&
leftInd != rightIndNonInclusive) {
currentScore = getWholeParagraphCorrelationScore(sentences.slice(leftInd, rightIndNonInclusive).join('.'), query, querySynonyms).correlationScore;
leftInd++;
}
// Attempts to remove sentences from the end of the paragraph
// while having the correlation score stay within {@code maintainWithinPercent}
while (calculatePercentageDifference(initScore, currentScore) <=
maintainWithinPercent &&
leftInd != rightIndNonInclusive) {
currentScore = getWholeParagraphCorrelationScore(sentences.slice(leftInd, rightIndNonInclusive).join('.'), query, querySynonyms).correlationScore;
rightIndNonInclusive--;
}
// Increment {@code rightIndNonInclusive} because the new correlation score may be
// over the alloted percentage range after the prior loop. Thus, the last sentence removed
// is added back
rightIndNonInclusive =
rightIndNonInclusive < sentences.length
? rightIndNonInclusive + 1
: rightIndNonInclusive;
return {
correlationScore: currentScore,
body: sentences.slice(leftInd, rightIndNonInclusive).join('.'),
};
}
function evaluateArticle(articleHead) {
return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function* () {
console.info(`Downloaded data for ${articleHead.query} with url ${articleHead.fullTextDownloadLink}`);
const db = articleHead.DBType;
if (db === _foodmedicine_interfaces__WEBPACK_IMPORTED_MODULE_1__[/* ScholarsDB */ "a"].EUROPE_PMC) {
const parser = _parser__WEBPACK_IMPORTED_MODULE_4__[/* EuropePMCParser */ "b"];
return (yield parser.parserF(articleHead.fullTextDownloadLink, {
parsedArticleHead: articleHead,
getCorrelationScore: getShortestParagraphCorrelationScore,
}));
}
else if (db === _foodmedicine_interfaces__WEBPACK_IMPORTED_MODULE_1__[/* ScholarsDB */ "a"].ARXIV) {
const parser = _parser__WEBPACK_IMPORTED_MODULE_4__[/* ArxivParser */ "a"];
return (yield parser.parserF(articleHead.fullTextDownloadLink, {
parsedArticleHead: articleHead,
getCorrelationScore: getShortestParagraphCorrelationScore,
}));
}
const parser = _parser__WEBPACK_IMPORTED_MODULE_4__[/* EuropePMCParser */ "b"];
return (yield parser.parserF(articleHead.fullTextDownloadLink, {
parsedArticleHead: articleHead,
getCorrelationScore: getShortestParagraphCorrelationScore,
}));
});
}
/***/ }),
/* 28 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(express__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var body_parser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(13);
/* harmony import */ var body_parser__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(body_parser__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var cors__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(29);
/* harmony import */ var cors__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(cors__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _controllers__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(30);
const app = express__WEBPACK_IMPORTED_MODULE_0__();
app.use(cors__WEBPACK_IMPORTED_MODULE_2__());
app.use(body_parser__WEBPACK_IMPORTED_MODULE_1__["json"]());
app.use(body_parser__WEBPACK_IMPORTED_MODULE_1__["urlencoded"]({ extended: true }));
app.use('/api', _controllers__WEBPACK_IMPORTED_MODULE_3__[/* default */ "a"]);
/* harmony default export */ __webpack_exports__["a"] = (app);
/***/ }),
/* 29 */
/***/ (function(module, exports) {
module.exports = require("cors");
/***/ }),
/* 30 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(express__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _search__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(31);
const router = express__WEBPACK_IMPORTED_MODULE_0__["Router"]();
router.use('/search', _search__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"]);
/* harmony default export */ __webpack_exports__["a"] = (router);
/***/ }),
/* 31 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(tslib__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(express__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _daos__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(32);
const router = express__WEBPACK_IMPORTED_MODULE_1__["Router"]();
/**
* Search the database for correlated paragraphs
* @query q - query string
* @query db - which db to use
* @query maxNumberOfParagraphs - optional max number of paragraphs
* @query numberOfArticles - optional number of articles to search