MCPcopy Create free account
hub / github.com/CommE2E/comm / segmentAndStem

Function segmentAndStem

keyserver/src/database/search-utils.js:17–36  ·  view source on GitHub ↗
(message: string)

Source from the content-addressed store, hash-verified

15const { stopwords } = natural;
16
17function segmentAndStem(message: string): string {
18 const segmentsIterator = segmenter.segment(message.toLowerCase());
19
20 const stemmedSegments = [];
21 for (const segmentObj of segmentsIterator) {
22 const { segment } = segmentObj;
23 if (segment.match(whiteSpacesRegex) || stopwords.indexOf(segment) !== -1) {
24 continue;
25 }
26 const stemmedSegment = natural.PorterStemmer.stem(segment).replaceAll(
27 punctuationRegex,
28 '',
29 );
30 stemmedSegments.push(stemmedSegment);
31 }
32
33 return stemmedSegments
34 .filter(segment => !segment.match(whiteSpacesRegex))
35 .join(' ');
36}
37
38async function processMessagesForSearch(
39 messages: $ReadOnlyArray<RawMessageInfo | ProcessedForSearchRow>,

Callers 3

processMessagesForSearchFunction · 0.85
processQueryForSearchFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected