Skip to content

Commit

Permalink
remove Set from cache function
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Mar 29, 2021
1 parent bc2ab72 commit 6c91a1b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 79 deletions.
2 changes: 1 addition & 1 deletion builds/compromise-tokenize.js

Large diffs are not rendered by default.

42 changes: 15 additions & 27 deletions builds/compromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@
}; // avoid stretching a phrase twice.


var unique$6 = function unique(list) {
var unique$5 = function unique(list) {
return list.filter(function (o, i) {
return list.indexOf(o) === i;
});
Expand Down Expand Up @@ -1739,7 +1739,7 @@
toStretch = toStretch.concat(shouldChange);
}); // don't double-count a phrase

toStretch = unique$6(toStretch);
toStretch = unique$5(toStretch);
toStretch.forEach(function (p) {
p.length += newPhrase.length;
});
Expand Down Expand Up @@ -1785,7 +1785,7 @@
main.terms(0).prev = lastTerm.id;
};

var unique$5 = function unique(list) {
var unique$4 = function unique(list) {
return list.filter(function (o, i) {
return list.indexOf(o) === i;
});
Expand All @@ -1811,7 +1811,7 @@
toStretch = toStretch.concat(shouldChange);
}); // don't double-count

toStretch = unique$5(toStretch); // stretch these phrases
toStretch = unique$4(toStretch); // stretch these phrases

toStretch.forEach(function (p) {
p.length += newPhrase.length; // change the start too, if necessary
Expand Down Expand Up @@ -4236,7 +4236,7 @@

var _color = addColors;

var unique$4 = function unique(arr) {
var unique$3 = function unique(arr) {
return arr.filter(function (v, i, a) {
return a.indexOf(v) === i;
});
Expand All @@ -4257,14 +4257,14 @@
} // clean it up


tag.isA = unique$4(tag.isA);
tag.isA = unique$3(tag.isA);
});
return tags;
};

var _isA = inferIsA;

var unique$3 = function unique(arr) {
var unique$2 = function unique(arr) {
return arr.filter(function (v, i, a) {
return a.indexOf(v) === i;
});
Expand Down Expand Up @@ -4294,7 +4294,7 @@
} // clean it up


tag.notA = unique$3(tag.notA);
tag.notA = unique$2(tag.notA);
});
return tags;
};
Expand Down Expand Up @@ -7565,18 +7565,16 @@
exports.lookUp = exports.lookup;
});

var unique$2 = function unique(set) {
return Array.from(set);
};
/** freeze the current state of the document, for speed-purposes*/


var cache = function cache(options) {
var _this = this;

options = options || {};
var words = {};
var tags = {};
this._cache.words = words;
this._cache.tags = tags;
this._cache.set = true;
this.list.forEach(function (p, i) {
p.cache = p.cache || {}; //p.terms get cached automatically

Expand All @@ -7587,29 +7585,19 @@
return; //skip prototype words
}

words[t.reduced] = words[t.reduced] || new Set();
words[t.reduced].add(i);
words[t.reduced] = words[t.reduced] || [];
words[t.reduced].push(i);
Object.keys(t.tags).forEach(function (tag) {
tags[tag] = tags[tag] || new Set();
tags[tag].add(i);
tags[tag] = tags[tag] || [];
tags[tag].push(i);
}); // cache root-form on Term, too

if (options.root) {
t.setRoot(_this.world);
words[t.root] = [i];
}
});
}); // unique the arrays

Object.keys(words).forEach(function (k) {
words[k] = unique$2(words[k]);
});
Object.keys(tags).forEach(function (k) {
tags[k] = unique$2(tags[k]);
});
this._cache.words = words;
this._cache.tags = tags;
this._cache.set = true;
return this;
};
/** un-freezes the current state of the document, so it may be transformed */
Expand Down
2 changes: 1 addition & 1 deletion builds/compromise.min.js

Large diffs are not rendered by default.

42 changes: 15 additions & 27 deletions builds/compromise.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@ var stitchIn$1 = function stitchIn(beforeTerms, newTerms, pool) {
}; // avoid stretching a phrase twice.


var unique$6 = function unique(list) {
var unique$5 = function unique(list) {
return list.filter(function (o, i) {
return list.indexOf(o) === i;
});
Expand Down Expand Up @@ -1733,7 +1733,7 @@ var appendPhrase = function appendPhrase(before, newPhrase, doc) {
toStretch = toStretch.concat(shouldChange);
}); // don't double-count a phrase

toStretch = unique$6(toStretch);
toStretch = unique$5(toStretch);
toStretch.forEach(function (p) {
p.length += newPhrase.length;
});
Expand Down Expand Up @@ -1779,7 +1779,7 @@ var stitchIn = function stitchIn(main, newPhrase, newTerms) {
main.terms(0).prev = lastTerm.id;
};

var unique$5 = function unique(list) {
var unique$4 = function unique(list) {
return list.filter(function (o, i) {
return list.indexOf(o) === i;
});
Expand All @@ -1805,7 +1805,7 @@ var joinPhrase = function joinPhrase(original, newPhrase, doc) {
toStretch = toStretch.concat(shouldChange);
}); // don't double-count

toStretch = unique$5(toStretch); // stretch these phrases
toStretch = unique$4(toStretch); // stretch these phrases

toStretch.forEach(function (p) {
p.length += newPhrase.length; // change the start too, if necessary
Expand Down Expand Up @@ -4230,7 +4230,7 @@ var addColors = function addColors(tags) {

var _color = addColors;

var unique$4 = function unique(arr) {
var unique$3 = function unique(arr) {
return arr.filter(function (v, i, a) {
return a.indexOf(v) === i;
});
Expand All @@ -4251,14 +4251,14 @@ var inferIsA = function inferIsA(tags) {
} // clean it up


tag.isA = unique$4(tag.isA);
tag.isA = unique$3(tag.isA);
});
return tags;
};

var _isA = inferIsA;

var unique$3 = function unique(arr) {
var unique$2 = function unique(arr) {
return arr.filter(function (v, i, a) {
return a.indexOf(v) === i;
});
Expand Down Expand Up @@ -4288,7 +4288,7 @@ var inferNotA = function inferNotA(tags) {
} // clean it up


tag.notA = unique$3(tag.notA);
tag.notA = unique$2(tag.notA);
});
return tags;
};
Expand Down Expand Up @@ -7559,18 +7559,16 @@ var _06Lookup = createCommonjsModule(function (module, exports) {
exports.lookUp = exports.lookup;
});

var unique$2 = function unique(set) {
return Array.from(set);
};
/** freeze the current state of the document, for speed-purposes*/


var cache = function cache(options) {
var _this = this;

options = options || {};
var words = {};
var tags = {};
this._cache.words = words;
this._cache.tags = tags;
this._cache.set = true;
this.list.forEach(function (p, i) {
p.cache = p.cache || {}; //p.terms get cached automatically

Expand All @@ -7581,29 +7579,19 @@ var cache = function cache(options) {
return; //skip prototype words
}

words[t.reduced] = words[t.reduced] || new Set();
words[t.reduced].add(i);
words[t.reduced] = words[t.reduced] || [];
words[t.reduced].push(i);
Object.keys(t.tags).forEach(function (tag) {
tags[tag] = tags[tag] || new Set();
tags[tag].add(i);
tags[tag] = tags[tag] || [];
tags[tag].push(i);
}); // cache root-form on Term, too

if (options.root) {
t.setRoot(_this.world);
words[t.root] = [i];
}
});
}); // unique the arrays

Object.keys(words).forEach(function (k) {
words[k] = unique$2(words[k]);
});
Object.keys(tags).forEach(function (k) {
tags[k] = unique$2(tags[k]);
});
this._cache.words = words;
this._cache.tags = tags;
this._cache.set = true;
return this;
};
/** un-freezes the current state of the document, so it may be transformed */
Expand Down
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ While all _Major_ releases should be reviewed, our only two _large_ releases are
-->
#### 13.10.5 [March 2021]
- **[new]** - support Time-range like '3pm-4pm'

- **[change]** - cleanup some unicode regexes
*plugin-releases*: dates

#### 13.10.4 [March 2021]
- **[fix]** - match syntax tokenization fix
- **[change]** - improved performance monitoring
Expand Down
29 changes: 7 additions & 22 deletions src/Doc/methods/07-cache.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const unique = function (set) {
return Array.from(set)
}

/** freeze the current state of the document, for speed-purposes*/
exports.cache = function (options) {
options = options || {}
let words = {}
let tags = {}

this._cache.words = words
this._cache.tags = tags
this._cache.set = true
this.list.forEach((p, i) => {
p.cache = p.cache || {}
//p.terms get cached automatically
Expand All @@ -17,34 +15,21 @@ exports.cache = function (options) {
if (words[t.reduced] && !words.hasOwnProperty(t.reduced)) {
return //skip prototype words
}
words[t.reduced] = words[t.reduced] || new Set()
words[t.reduced].add(i)

words[t.reduced] = words[t.reduced] || []
words[t.reduced].push(i)
Object.keys(t.tags).forEach(tag => {
tags[tag] = tags[tag] || new Set()
tags[tag].add(i)
tags[tag] = tags[tag] || []
tags[tag].push(i)
})

// cache root-form on Term, too
if (options.root) {
t.setRoot(this.world)
words[t.root] = [i]
}
})
})
// unique the arrays
Object.keys(words).forEach(k => {
words[k] = unique(words[k])
})
Object.keys(tags).forEach(k => {
tags[k] = unique(tags[k])
})
this._cache.words = words
this._cache.tags = tags
this._cache.set = true
return this
}

/** un-freezes the current state of the document, so it may be transformed */
exports.uncache = function () {
this._cache = {}
Expand Down

0 comments on commit 6c91a1b

Please sign in to comment.