@vannizhang/living-atlas-content-validator 1.5.13 → 1.5.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/data/TitleSummaryMatchingPatterns.json +1901 -0
  2. package/dist/index.d.ts +5 -1
  3. package/dist/index.js +9 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/layers/scoringConfig.js +1 -1
  6. package/dist/lib/recommendedText/checkRecommendedText.d.ts +15 -0
  7. package/dist/lib/recommendedText/checkRecommendedText.js +95 -0
  8. package/dist/lib/recommendedText/checkRecommendedText.js.map +1 -0
  9. package/dist/lib/recommendedText/helpers.d.ts +8 -0
  10. package/dist/lib/recommendedText/helpers.js +44 -0
  11. package/dist/lib/recommendedText/helpers.js.map +1 -0
  12. package/dist/lib/recommendedText/matchDateTimeInfo.d.ts +9 -0
  13. package/dist/lib/recommendedText/matchDateTimeInfo.js +80 -0
  14. package/dist/lib/recommendedText/matchDateTimeInfo.js.map +1 -0
  15. package/dist/lib/recommendedText/matchLocationInfo.d.ts +9 -0
  16. package/dist/lib/recommendedText/matchLocationInfo.js +744 -0
  17. package/dist/lib/recommendedText/matchLocationInfo.js.map +1 -0
  18. package/dist/lib/recommendedText/matchSourceInfo.d.ts +9 -0
  19. package/dist/lib/recommendedText/matchSourceInfo.js +31 -0
  20. package/dist/lib/recommendedText/matchSourceInfo.js.map +1 -0
  21. package/dist/lib/recommendedText/matchTopicInfo.d.ts +9 -0
  22. package/dist/lib/recommendedText/matchTopicInfo.js +31 -0
  23. package/dist/lib/recommendedText/matchTopicInfo.js.map +1 -0
  24. package/dist/lib/recommendedText/scoringConfig.d.ts +11 -0
  25. package/dist/lib/recommendedText/scoringConfig.js +16 -0
  26. package/dist/lib/recommendedText/scoringConfig.js.map +1 -0
  27. package/dist/lib/ssl/scoringConfig.js +1 -1
  28. package/dist/lib/tags/scoringConfig.js +1 -1
  29. package/dist/lib/tags/scoringConfig.js.map +1 -1
  30. package/dist/lib/thumbnail/scoringConfig.js +1 -1
  31. package/dist/lib/userProfileDescription/scoringConfig.js +9 -9
  32. package/dist/lib/userProfileName/scoringConfig.js +3 -3
  33. package/dist/lib/userProfileThumbnail/scoringConfig.js +1 -1
  34. package/dist/lib/util/getScoringRules.d.ts +8 -0
  35. package/dist/lib/util/getScoringRules.js +28 -1
  36. package/dist/lib/util/getScoringRules.js.map +1 -1
  37. package/dist/lib/util/isLayer.d.ts +12 -0
  38. package/dist/lib/util/isLayer.js +26 -0
  39. package/dist/lib/util/isLayer.js.map +1 -0
  40. package/dist/lib/util/shouldValidateByBetaRules.d.ts +10 -0
  41. package/dist/lib/util/shouldValidateByBetaRules.js +53 -0
  42. package/dist/lib/util/shouldValidateByBetaRules.js.map +1 -0
  43. package/dist/lib/validate/validate.js +5 -0
  44. package/dist/lib/validate/validate.js.map +1 -1
  45. package/dist/locale/de.json +11 -1
  46. package/dist/locale/en.json +10 -0
  47. package/dist/locale/es.json +10 -0
  48. package/dist/locale/fr.json +10 -0
  49. package/dist/locale/ja.json +10 -0
  50. package/dist/locale/pt-br.json +10 -0
  51. package/dist/package-info.json +1 -1
  52. package/dist/types/index.d.ts +4 -0
  53. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -14,5 +14,9 @@ import { isValidUserProfileName } from './lib/userProfileName/isValidUserProfile
14
14
  import { isValidUserProfileThumbnail } from './lib/userProfileThumbnail/isValidUserProfileThumbnail';
15
15
  import { isDeprecated } from './lib/deprecated/isDeprecated';
16
16
  import { validate, meetMinimumTotalScore } from './lib/validate/validate';
17
+ import { matchLocationInfo } from './lib/recommendedText/matchLocationInfo';
18
+ import { matchDateTimeInfo } from './lib/recommendedText/matchDateTimeInfo';
19
+ import { matchSourceInfo } from './lib/recommendedText/matchSourceInfo';
20
+ import { matchTopicInfo } from './lib/recommendedText/matchTopicInfo';
17
21
  import { setStrings, getStringsConfig, ValidationRulesStringJSON } from './lib/util/stringsConfig';
18
- export { ValidationMessage, ValidationInfo, ValidationResult, ValidationRulesStringJSON, setStrings, getStringsConfig, validate, meetMinimumTotalScore, isValidTitle, isValidAccessInformation, isValidDescription, isValidLayerCount, isValidLicenseInfo, isValidAccess, isValidSSL, isValidSummary, isValidTags, isValidThumbnail, isValidUserProfileDescription, isValidUserProfileName, isValidUserProfileThumbnail, isDeprecated, };
22
+ export { ValidationMessage, ValidationInfo, ValidationResult, ValidationRulesStringJSON, setStrings, getStringsConfig, validate, meetMinimumTotalScore, isValidTitle, isValidAccessInformation, isValidDescription, isValidLayerCount, isValidLicenseInfo, isValidAccess, isValidSSL, isValidSummary, isValidTags, isValidThumbnail, isValidUserProfileDescription, isValidUserProfileName, isValidUserProfileThumbnail, isDeprecated, matchLocationInfo, matchDateTimeInfo, matchSourceInfo, matchTopicInfo, };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDeprecated = exports.isValidUserProfileThumbnail = exports.isValidUserProfileName = exports.isValidUserProfileDescription = exports.isValidThumbnail = exports.isValidTags = exports.isValidSummary = exports.isValidSSL = exports.isValidAccess = exports.isValidLicenseInfo = exports.isValidLayerCount = exports.isValidDescription = exports.isValidAccessInformation = exports.isValidTitle = exports.meetMinimumTotalScore = exports.validate = exports.getStringsConfig = exports.setStrings = void 0;
3
+ exports.matchTopicInfo = exports.matchSourceInfo = exports.matchDateTimeInfo = exports.matchLocationInfo = exports.isDeprecated = exports.isValidUserProfileThumbnail = exports.isValidUserProfileName = exports.isValidUserProfileDescription = exports.isValidThumbnail = exports.isValidTags = exports.isValidSummary = exports.isValidSSL = exports.isValidAccess = exports.isValidLicenseInfo = exports.isValidLayerCount = exports.isValidDescription = exports.isValidAccessInformation = exports.isValidTitle = exports.meetMinimumTotalScore = exports.validate = exports.getStringsConfig = exports.setStrings = void 0;
4
4
  const isValidTitle_1 = require("./lib/title/isValidTitle");
5
5
  Object.defineProperty(exports, "isValidTitle", { enumerable: true, get: function () { return isValidTitle_1.isValidTitle; } });
6
6
  const isValidAccessInformation_1 = require("./lib/accessInformation/isValidAccessInformation");
@@ -32,6 +32,14 @@ Object.defineProperty(exports, "isDeprecated", { enumerable: true, get: function
32
32
  const validate_1 = require("./lib/validate/validate");
33
33
  Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return validate_1.validate; } });
34
34
  Object.defineProperty(exports, "meetMinimumTotalScore", { enumerable: true, get: function () { return validate_1.meetMinimumTotalScore; } });
35
+ const matchLocationInfo_1 = require("./lib/recommendedText/matchLocationInfo");
36
+ Object.defineProperty(exports, "matchLocationInfo", { enumerable: true, get: function () { return matchLocationInfo_1.matchLocationInfo; } });
37
+ const matchDateTimeInfo_1 = require("./lib/recommendedText/matchDateTimeInfo");
38
+ Object.defineProperty(exports, "matchDateTimeInfo", { enumerable: true, get: function () { return matchDateTimeInfo_1.matchDateTimeInfo; } });
39
+ const matchSourceInfo_1 = require("./lib/recommendedText/matchSourceInfo");
40
+ Object.defineProperty(exports, "matchSourceInfo", { enumerable: true, get: function () { return matchSourceInfo_1.matchSourceInfo; } });
41
+ const matchTopicInfo_1 = require("./lib/recommendedText/matchTopicInfo");
42
+ Object.defineProperty(exports, "matchTopicInfo", { enumerable: true, get: function () { return matchTopicInfo_1.matchTopicInfo; } });
35
43
  const stringsConfig_1 = require("./lib/util/stringsConfig");
36
44
  Object.defineProperty(exports, "setStrings", { enumerable: true, get: function () { return stringsConfig_1.setStrings; } });
37
45
  Object.defineProperty(exports, "getStringsConfig", { enumerable: true, get: function () { return stringsConfig_1.getStringsConfig; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAWA,2DAAwD;AAwCpD,6FAxCK,2BAAY,OAwCL;AAvChB,+FAA4F;AAwCxF,yGAxCK,mDAAwB,OAwCL;AAvC5B,6EAA0E;AAwCtE,mGAxCK,uCAAkB,OAwCL;AAvCtB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CpB,8GAA2G;AA4CvG,8GA5CK,6DAA6B,OA4CL;AA3CjC,yFAAsF;AA4ClF,uGA5CK,+CAAsB,OA4CL;AA3C1B,wGAAqG;AA4CjG,4GA5CK,yDAA2B,OA4CL;AA3C/B,gEAA6D;AA4CzD,6FA5CK,2BAAY,OA4CL;AA3ChB,sDAA0E;AA4BtE,yFA5BK,mBAAQ,OA4BL;AACR,sGA7Be,gCAAqB,OA6Bf;AA5BzB,+EAA4E;AA2CxE,kGA3CK,qCAAiB,OA2CL;AA1CrB,+EAA4E;AA2CxE,kGA3CK,qCAAiB,OA2CL;AA1CrB,2EAAwE;AA2CpE,gGA3CK,iCAAe,OA2CL;AA1CnB,yEAAsE;AA2ClE,+FA3CK,+BAAc,OA2CL;AAzClB,4DAIkC;AAgB9B,2FAnBA,0BAAU,OAmBA;AACV,iGAnBA,gCAAgB,OAmBA"}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.scoringConfig = void 0;
5
5
  exports.scoringConfig = {
6
- weight: 8,
6
+ weight: 1,
7
7
  weightFactors: {
8
8
  DEFAULT: {
9
9
  LAYER_COUNT_BEST_FACTOR: 1,
@@ -0,0 +1,15 @@
1
+ import { IItem, ValidationInfo } from '../../types';
2
+ /**
3
+ * Check for required and recommended text in items' title and summary text.
4
+ * We want Title and Summary to do a great job establishing the 4 key things: topic from a source for year and region.
5
+ *
6
+ * Title/summary text are required to state what the thing is, e.g. "Earthquakes" or "Public Health Dashboard"
7
+ * Title/summary text often benefit from having words like "Global" or "World" to indicate the area included.
8
+ * Title/summary text often benefit from having a source indicated (unless the source name is very long)
9
+ * Title/summary text often benefit from having a version, vintage or year indicated
10
+ *
11
+ *
12
+ * @see https://devtopia.esri.com/kenn4005/Curator_Suggestions/issues/9
13
+ *
14
+ */
15
+ export declare const checkRecommendedText: (item: IItem) => ValidationInfo;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkRecommendedText = void 0;
4
+ const stringsConfig_1 = require("../util/stringsConfig");
5
+ const isLayer_1 = require("../util/isLayer");
6
+ const getScoringRules_1 = require("../util/getScoringRules");
7
+ const matchLocationInfo_1 = require("./matchLocationInfo");
8
+ const matchDateTimeInfo_1 = require("./matchDateTimeInfo");
9
+ const matchSourceInfo_1 = require("./matchSourceInfo");
10
+ const matchTopicInfo_1 = require("./matchTopicInfo");
11
+ const scoringConfig_1 = require("./scoringConfig");
12
+ const shouldValidateByBetaRules_1 = require("../util/shouldValidateByBetaRules");
13
+ /**
14
+ * Check for required and recommended text in items' title and summary text.
15
+ * We want Title and Summary to do a great job establishing the 4 key things: topic from a source for year and region.
16
+ *
17
+ * Title/summary text are required to state what the thing is, e.g. "Earthquakes" or "Public Health Dashboard"
18
+ * Title/summary text often benefit from having words like "Global" or "World" to indicate the area included.
19
+ * Title/summary text often benefit from having a source indicated (unless the source name is very long)
20
+ * Title/summary text often benefit from having a version, vintage or year indicated
21
+ *
22
+ *
23
+ * @see https://devtopia.esri.com/kenn4005/Curator_Suggestions/issues/9
24
+ *
25
+ */
26
+ const checkRecommendedText = (item) => {
27
+ const localeByCultreProperty = (0, getScoringRules_1.getScoringRulesLocale)(item.culture);
28
+ const localeByItemOwner = (0, getScoringRules_1.getScoringRulesLocaleByItemOwner)(item.owner);
29
+ const isEnglishedBased = localeByCultreProperty === 'en' && localeByItemOwner === 'en';
30
+ const stringsConfig = (0, stringsConfig_1.getStringsConfig)();
31
+ const weightFactors = scoringConfig_1.scoringConfig.weightFactors.DEFAULT;
32
+ /**
33
+ * Jim Herris has confirmed that we should only check the recommend text for items meeting the following criteria:
34
+ * 1. The item is a layer
35
+ * 2. The item is English-based
36
+ * 3. The item is qualified for validation under beta rule (this is a temporary condition for the beta release of this rule)
37
+ */
38
+ const shouldCheckRecommendedText = (0, isLayer_1.isLayer)(item) && isEnglishedBased && (0, shouldValidateByBetaRules_1.shouldValidateByBetaRules)(item);
39
+ const validationResult = {
40
+ property: 'recommendedTextInTitleAndSummary',
41
+ label: stringsConfig.recommendedTextInTitleAndSummary.LABEL,
42
+ title: stringsConfig.recommendedTextInTitleAndSummary.TITLE,
43
+ maxScore: 0,
44
+ score: 0,
45
+ messages: [],
46
+ weight: scoringConfig_1.scoringConfig.weight,
47
+ weightFactor: 0,
48
+ critical: true,
49
+ };
50
+ // Return the validationResult with a weight of 0 (so this rule does not contribute to the final score)
51
+ // if the recommended text does not need to be checked.
52
+ if (shouldCheckRecommendedText === false) {
53
+ return Object.assign(Object.assign({}, validationResult), { weight: 0, critical: false });
54
+ }
55
+ const matchedLocationInfo = (0, matchLocationInfo_1.matchLocationInfo)(item);
56
+ const matchedTimeInfo = (0, matchDateTimeInfo_1.matchDateTimeInfo)(item);
57
+ const matchedSourceInfo = (0, matchSourceInfo_1.matchSourceInfo)(item);
58
+ const matchedTopicInfo = (0, matchTopicInfo_1.matchTopicInfo)(item);
59
+ if (!matchedLocationInfo.length) {
60
+ validationResult.messages.push({
61
+ message: stringsConfig.recommendedTextInTitleAndSummary
62
+ .ADD_LOCATION_INFO,
63
+ });
64
+ }
65
+ else {
66
+ validationResult.weightFactor += weightFactors.CONTAINS_LOCATION_INFO;
67
+ }
68
+ if (!matchedTimeInfo.length) {
69
+ validationResult.messages.push({
70
+ message: stringsConfig.recommendedTextInTitleAndSummary.ADD_TIME_INFO,
71
+ });
72
+ }
73
+ else {
74
+ validationResult.weightFactor += weightFactors.CONTAINS_TIME_INFO;
75
+ }
76
+ if (!matchedSourceInfo.length) {
77
+ validationResult.messages.push({
78
+ message: stringsConfig.recommendedTextInTitleAndSummary.ADD_SOURCE_INFO,
79
+ });
80
+ }
81
+ else {
82
+ validationResult.weightFactor += weightFactors.CONTAINS_SOURCE_INFO;
83
+ }
84
+ if (!matchedTopicInfo.length) {
85
+ validationResult.messages.push({
86
+ message: stringsConfig.recommendedTextInTitleAndSummary.ADD_TOPIC_INFO,
87
+ });
88
+ }
89
+ else {
90
+ validationResult.weightFactor += weightFactors.CONTAINS_TOPIC_INFO;
91
+ }
92
+ return validationResult;
93
+ };
94
+ exports.checkRecommendedText = checkRecommendedText;
95
+ //# sourceMappingURL=checkRecommendedText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkRecommendedText.js","sourceRoot":"","sources":["../../../src/lib/recommendedText/checkRecommendedText.ts"],"names":[],"mappings":";;;AAGA,yDAAyD;AAEzD,6CAA0C;AAC1C,6DAGiC;AACjC,2DAAwD;AACxD,2DAAwD;AACxD,uDAAoD;AACpD,qDAAkD;AAClD,mDAAgD;AAChD,iFAA8E;AAE9E;;;;;;;;;;;;GAYG;AACI,MAAM,oBAAoB,GAAG,CAAC,IAAW,EAAkB,EAAE;IAChE,MAAM,sBAAsB,GAAG,IAAA,uCAAqB,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAEnE,MAAM,iBAAiB,GAAG,IAAA,kDAAgC,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEvE,MAAM,gBAAgB,GAClB,sBAAsB,KAAK,IAAI,IAAI,iBAAiB,KAAK,IAAI,CAAC;IAElE,MAAM,aAAa,GAAG,IAAA,gCAAgB,GAAE,CAAC;IAEzC,MAAM,aAAa,GAAG,6BAAa,CAAC,aAAa,CAAC,OAAO,CAAC;IAE1D;;;;;OAKG;IACH,MAAM,0BAA0B,GAC5B,IAAA,iBAAO,EAAC,IAAI,CAAC,IAAI,gBAAgB,IAAI,IAAA,qDAAyB,EAAC,IAAI,CAAC,CAAC;IAEzE,MAAM,gBAAgB,GAAmB;QACrC,QAAQ,EAAE,kCAAkC;QAC5C,KAAK,EAAE,aAAa,CAAC,gCAAgC,CAAC,KAAK;QAC3D,KAAK,EAAE,aAAa,CAAC,gCAAgC,CAAC,KAAK;QAC3D,QAAQ,EAAE,CAAC;QACX,KAAK,EAAE,CAAC;QACR,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,6BAAa,CAAC,MAAM;QAC5B,YAAY,EAAE,CAAC;QACf,Q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B,OAAO,EACH,aAAa,CAAC,gCAAgC,CAAC,cAAc;SACpE,CAAC,CAAC;KACN;SAAM;QACH,gBAAgB,CAAC,YAAY,IAAI,aAAa,CAAC,mBAAmB,CAAC;KACtE;IAED,OAAO,gBAAgB,CAAC;AAC5B,CAAC,CAAC;AAtFW,QAAA,oBAAoB,wBAsF/B"}
@@ -0,0 +1,8 @@
1
+ export declare const removeOverlapped: (arr: string[]) => string[];
2
+ /**
3
+ * Removes duplicate strings from an array, ignoring case sensitivity.
4
+ *
5
+ * @param arr - The array of strings to deduplicate.
6
+ * @returns A new array with duplicates removed, preserving the original case of the first occurrence.
7
+ */
8
+ export declare const deduplicate: (arr: string[]) => string[];
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deduplicate = exports.removeOverlapped = void 0;
4
+ const removeOverlapped = (arr) => {
5
+ const output = [];
6
+ arr.sort((a, b) => b.length - a.length);
7
+ for (const candidate of arr) {
8
+ let shouldNotInclude = false;
9
+ for (const word of output) {
10
+ if (word.toLocaleLowerCase().includes(candidate.toLowerCase())) {
11
+ shouldNotInclude = true;
12
+ break;
13
+ }
14
+ }
15
+ if (shouldNotInclude) {
16
+ continue;
17
+ }
18
+ output.push(candidate);
19
+ }
20
+ return output;
21
+ };
22
+ exports.removeOverlapped = removeOverlapped;
23
+ /**
24
+ * Removes duplicate strings from an array, ignoring case sensitivity.
25
+ *
26
+ * @param arr - The array of strings to deduplicate.
27
+ * @returns A new array with duplicates removed, preserving the original case of the first occurrence.
28
+ */
29
+ const deduplicate = (arr) => {
30
+ if (!arr || arr.length === 0) {
31
+ return [];
32
+ }
33
+ const seen = new Set();
34
+ return arr.filter((str) => {
35
+ const lowerStr = str.toLocaleLowerCase();
36
+ if (seen.has(lowerStr)) {
37
+ return false;
38
+ }
39
+ seen.add(lowerStr);
40
+ return true;
41
+ });
42
+ };
43
+ exports.deduplicate = deduplicate;
44
+ //# sourceMappingURL=helpers.js.map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IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAfW,QAAA,WAAW,eAetB"}
@@ -0,0 +1,9 @@
1
+ import { IItem } from '../../types';
2
+ /**
3
+ * Matches date and time information from the title and snippet of an item.
4
+ *
5
+ * @param {IItem} item - The item containing title and snippet to be matched against.
6
+ * @param {string[]} [customMatchingPattenrs] - Optional custom matching patterns to be included in the regex.
7
+ * @returns {string[]} - An array of matched date and time information strings.
8
+ */
9
+ export declare const matchDateTimeInfo: (item: IItem, customMatchingPattenrs?: string[]) => string[];
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.matchDateTimeInfo = void 0;
7
+ const helpers_1 = require("./helpers");
8
+ const TitleSummaryMatchingPatterns_json_1 = __importDefault(require("../../data/TitleSummaryMatchingPatterns.json"));
9
+ /**
10
+ * Match time intervals relative to the present moment rather than specifying an absolute date or time
11
+ * - `\b`: Word boundary to ensure we match whole words and not substrings.
12
+ * - `(?:(last|past|next|current|latest|every)\s+)?`: A non-capturing group to optionally match words like "last", "past", "next", "current", "latest", and "every" followed by one or more spaces (\s+). The ? at the end makes this group optional.
13
+ * - `(\d+)?`: An optional capturing group to match one or more digits. This covers patterns like "7", "14", "48", etc.
14
+ * - `\s*`: Zero or more spaces. This handles cases where there might or might not be spaces between the number and the time unit.
15
+ * - `(year|month|week|day|hour|minute)s?`: A capturing group to match the time units: "year", "month", "week", "day", "hour", and "minute". The s? makes the "s" optional to handle both singular and plural forms (e.g., "day" and "days").
16
+ */
17
+ const relativeDateTimeRegex = /\b(?:(last|past|next|current|latest|every)\s+)(\d+)?\s*(year|month|week|day|hour|minute)s?\b/gi;
18
+ /**
19
+ * A regular expression that matches time duration: e.g. '10-months', '5 Year', '3 hours'
20
+ */
21
+ const timeDurationRegEx = /\b(\d+)(?:-)?\s*(year|month|week|day|hour|minute)s?\b/gi;
22
+ /**
23
+ * A regular expression that matches the provided year-related patterns. e.g. '2022', '2020-2024', '1950 to 2050'
24
+ * Here's a breakdown of the regular expression:
25
+ *
26
+ * - `\b`: Word boundary to ensure we match whole words and not substrings.
27
+ * - `(?:\d{4}|present)`: A non-capturing group to match either a four-digit year (\d{4}) or the word "present".
28
+ * - `(?:\s*(?:-|and|to)\s*(?:\d{4}|present))?`: An optional non-capturing group to match a range or conjunction with:
29
+ * - `(?:-|and|to)`: A non-capturing group to match a hyphen (-), the word "and", or the word "to".
30
+ * - `(?:\d{4}|present)`: A non-capturing group to match either a four-digit year or the word "present".
31
+ * - `\b`: Word boundary to ensure we match whole words and not substrings.
32
+ */
33
+ const yearRangeRegEx = /\b(?:\d{4}|present)(?:\s*(?:-|and|to)\s*(?:\d{4}|present))?\b/gi;
34
+ /**
35
+ * Match text like '20th century'
36
+ */
37
+ const centuryRegEx = /\b(\d{1,2}(?:st|nd|rd|th)\s+century)\b/gi;
38
+ const additionalPatterns = /\b(once\s+a\s+day|monthly|daily|hourly|annual)\b/gi;
39
+ let matchingPatterns = TitleSummaryMatchingPatterns_json_1.default.time.join('|');
40
+ /**
41
+ * Matches date and time information from the title and snippet of an item.
42
+ *
43
+ * @param {IItem} item - The item containing title and snippet to be matched against.
44
+ * @param {string[]} [customMatchingPattenrs] - Optional custom matching patterns to be included in the regex.
45
+ * @returns {string[]} - An array of matched date and time information strings.
46
+ */
47
+ const matchDateTimeInfo = (item, customMatchingPattenrs) => {
48
+ // const regex = new RegExp(regex1, 'gi')
49
+ const title = item.title || '';
50
+ const snippet = item.snippet || '';
51
+ const combined = [
52
+ relativeDateTimeRegex,
53
+ timeDurationRegEx,
54
+ yearRangeRegEx,
55
+ centuryRegEx,
56
+ additionalPatterns,
57
+ ];
58
+ if (customMatchingPattenrs) {
59
+ matchingPatterns = `${matchingPatterns}|${customMatchingPattenrs.join('|')}`;
60
+ }
61
+ const patternsFromTextLabelingData = new RegExp(`\\b(${matchingPatterns})\\b`, 'gi');
62
+ // console.log(dateInfoText, patternsFromTextLabelingData)
63
+ combined.push(patternsFromTextLabelingData);
64
+ let candidates = [];
65
+ for (const regex of combined) {
66
+ const matchedLocationsFromTitle = title.match(regex) || [];
67
+ const matchedLocationsFromSnippet = snippet.match(regex) || [];
68
+ const matched = [
69
+ ...matchedLocationsFromTitle,
70
+ ...matchedLocationsFromSnippet,
71
+ ];
72
+ for (const text of matched) {
73
+ candidates.push(text);
74
+ }
75
+ }
76
+ candidates = (0, helpers_1.deduplicate)(candidates);
77
+ return (0, helpers_1.removeOverlapped)(candidates);
78
+ };
79
+ exports.matchDateTimeInfo = matchDateTimeInfo;
80
+ //# sourceMappingURL=matchDateTimeInfo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchDateTimeInfo.js","sourceRoot":"","sources":["../../../src/lib/recommendedText/matchDateTimeInfo.ts"],"names":[],"mappings":";;;;;;AACA,uCAA0D;AAC1D,qHAAwF;AAExF;;;;;;;GAOG;AACH,MAAM,qBAAqB,GACvB,gGAAgG,CAAC;AAErG;;GAEG;AACH,MAAM,iBAAiB,GACnB,yDAAyD,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,cAAc,GAChB,iEAAiE,CAAC;AAEtE;;GAEG;AACH,MAAM,YAAY,GAAG,0CAA0C,CAAC;AAEhE,MAAM,kBAAkB,GAAG,oDAAoD,CAAC;AAEhF,IAAI,gBAAgB,GAAG,2CAA4B,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEnE;;;;;;GAMG;AACI,MAAM,iBAAiB,GAAG,CAC7B,IAAW,EACX,sBAAiC,EACzB,EAAE;IACV,yCAAyC;IAEzC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;IAC/B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;IAEnC,MAAM,QAAQ,GAAG;QACb,qBAAqB;QACrB,iBAAiB;QACjB,cAAc;QACd,YAAY;QACZ,kBAAkB;KACrB,CAAC;IAEF,IAAI,sBAAsB,EAAE;QACxB,gBAAgB,GAAG,GAAG,gBAAgB,IAAI,sBAAsB,CAAC,IAAI,CACjE,GAAG,CACN,EAAE,CAAC;KACP;IAED,MAAM,4BAA4B,GAAG,IAAI,MAAM,CAC3C,OAAO,gBAAgB,MAAM,EAC7B,IAAI,CACP,CAAC;IACF,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IAE5C,IAAI,UAAU,GAAa,EAAE,CAAC;IAE9B,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE;QAC1B,MAAM,yBAAyB,GAAa,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QACrE,MAAM,2BAA2B,GAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAE/B,MAAM,OAAO,GAAG;YACZ,GAAG,yBAAyB;YAC5B,GAAG,2BAA2B;SACjC,CAAC;QAEF,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE;YACxB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACzB;KACJ;IAED,UAAU,GAAG,IAAA,qBAAW,EAAC,UAAU,CAAC,CAAC;IAErC,OAAO,IAAA,0BAAgB,EAAC,UAAU,CAAC,CAAC;AACxC,CAAC,CAAC;AAlDW,QAAA,iBAAiB,qBAkD5B"}
@@ -0,0 +1,9 @@
1
+ import { IItem } from '../../types';
2
+ /**
3
+ * Matches location information from an item's title and snippet using predefined or custom matching patterns.
4
+ *
5
+ * @param {IItem} item - The item containing title and snippet to search for location information.
6
+ * @param {string[]} [customMatchingPattenrs] - Optional custom matching patterns to be included in the search.
7
+ * @returns {string[]} - An array of matched location strings after deduplication and removing overlaps.
8
+ */
9
+ export declare const matchLocationInfo: (item: IItem, customMatchingPattenrs?: string[]) => string[];