MCPcopy
hub / github.com/benhmoore/Knwl / Dates

Function Dates

default_plugins/dates.js:2–407  ·  view source on GitHub ↗
(knwl)

Source from the content-addressed store, hash-verified

1/* Date Parser */
2function Dates(knwl) {
3
4 this.languages = {
5 'english': true,
6 };
7
8 this.year = {};
9 this.year.lookForYear = function(pos) {
10
11 /*
12 Attempts to find year in string through ranking:
13 1. Proximity to trigger source
14 2. Punctuation syntax
15 */
16
17 var potential = [];
18
19 var fall = 1.0; //ranking fall
20
21
22 for (var ee = pos; ee > pos - 20; ee--) {
23 if (dates.db.wordsWithPunc[ee] === undefined) {
24 break;
25 }
26 if (dates.db.wordsWithPunc[ee].search(/[,;:]/g) !== -1) { //rank lower if comma seperates results
27 fall += 4;
28 } else if (dates.db.wordsWithPunc[ee].search(/[.?!]/g) !== -1) { //rank much lower if in another sentence
29 fall += 72;
30 }
31 var curWord = dates.db.wordsWithPunc[ee].replace(/[.,!?\(\)]/g, ''); //cleanup
32 if (isNaN(parseInt(curWord)) === false) {
33 var parsedWord = parseInt(curWord);
34 if (parsedWord.toString().length === 4) {
35 potential.push({
36 offset: (pos - ee) * fall,
37 year: parseInt(curWord)
38 });
39 break;
40 }
41 }
42 };
43
44 fall = 1.0; //reset ranking fall
45
46 for (var ee = pos; ee < pos + 20; ee++) {
47 if (dates.db.wordsWithPunc[ee] === undefined) {
48 break;
49 }
50 var curWord = dates.db.wordsWithPunc[ee].replace(/[.,!?\(\)]/g, ''); //cleanup
51 if (isNaN(parseInt(curWord)) === false) {
52 var parsedWord = parseInt(curWord);
53 if (parsedWord.toString().length === 4) {
54 potential.push({
55 offset: (ee - pos) * fall,
56 year: parseInt(curWord)
57 });
58 break;
59 }
60 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected