Skip to content

Commit

Permalink
add join delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
benjcal committed Aug 19, 2024
1 parent 4e6efea commit 6197523
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/core/operations/Ngram.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import Operation from "../Operation.mjs";
import {JOIN_DELIM_OPTIONS} from "../lib/Delim.mjs";

/**
* ngram operation
Expand All @@ -29,6 +30,11 @@ class Ngram extends Operation {
type: "number",
value: 3
},
{
"name": "Join delimiter",
"type": "editableOptionShort",
"value": JOIN_DELIM_OPTIONS
}
];
}

Expand All @@ -38,13 +44,15 @@ class Ngram extends Operation {
* @returns {string}
*/
run(input, args) {
const n = args[0];
const nGramSize = args[0],
joinDelim = args[1];

const ngrams = [];
for (let i = 0; i <= input.length - n; i++) {
ngrams.push(input.slice(i, i + n));
for (let i = 0; i <= input.length - nGramSize; i++) {
ngrams.push(input.slice(i, i + nGramSize));
}

return ngrams.join("\n");
return ngrams.join(joinDelim);
}

}
Expand Down

0 comments on commit 6197523

Please sign in to comment.