@thi.ng/text-analysis 0.1.0

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.
package/xform.js ADDED
@@ -0,0 +1,30 @@
1
+ import { comp } from "@thi.ng/transducers/comp";
2
+ import { filter } from "@thi.ng/transducers/filter";
3
+ import { map } from "@thi.ng/transducers/map";
4
+ import { stemWord } from "./stem.js";
5
+ const RE_NON_ALPHA = /[^A-Za-z\u00c0-\u017f]/g;
6
+ const RE_NON_ALPHANUM = /[^0-9A-Za-z\u00c0-\u017f]/g;
7
+ const lowercase = map((x) => x.toLowerCase());
8
+ const collapseWS = map((x) => x.replace(/\s+/g, " "));
9
+ const removeEmpty = filter((x) => !/^\s*$/.test(x));
10
+ const removeNonAlpha = comp(
11
+ map((x) => x.replace(RE_NON_ALPHA, "")),
12
+ removeEmpty
13
+ );
14
+ const removeNonAlphaNum = comp(
15
+ map((x) => x.replace(RE_NON_ALPHANUM, "")),
16
+ removeEmpty
17
+ );
18
+ const minMaxLength = (min, max) => filter((x) => x.length >= min && x.length <= max);
19
+ const stemOnly = map(stemWord);
20
+ const vocabOnly = (vocab) => filter((x) => vocab.has(x));
21
+ export {
22
+ collapseWS,
23
+ lowercase,
24
+ minMaxLength,
25
+ removeEmpty,
26
+ removeNonAlpha,
27
+ removeNonAlphaNum,
28
+ stemOnly,
29
+ vocabOnly
30
+ };