MCPcopy
hub / github.com/rsms/inter / getWordsWithPairs

Function getWordsWithPairs

docs/lab/samples.js:1129–1173  ·  view source on GitHub ↗
(pairs, maxWordsPerPair)

Source from the content-addressed store, hash-verified

1127}
1128
1129function getWordsWithPairs(pairs, maxWordsPerPair) {
1130 const wmap = getEnglishWords()
1131 if (!wmap) {
1132 return null
1133 }
1134
1135 const wordSet = new Set()
1136
1137 if (!maxWordsPerPair) {
1138 maxWordsPerPair = 10
1139 } else if (maxWordsPerPair < 1) {
1140 maxWordsPerPair = 1
1141 }
1142
1143 for (const pair of pairs) {
1144 // s.push('(' + comb + ')')
1145 const words = wmap.combIndex.get(pair)
1146 if (words) {
1147 let n = 0
1148 for (const word of words.keys()) {
1149 if (!wordSet.has(word) &&
1150 (!word.endsWith('s') || // rough approximation for "skip plural-form dups"
1151 !wordSet.has(word.substr(0, word.length-1))
1152 )
1153 )
1154 {
1155 wordSet.add(word)
1156 ++n
1157 if (n > maxWordsPerPair) {
1158 break
1159 }
1160 }
1161 }
1162 }
1163 }
1164
1165 // remove duplicates
1166 for (const word of wordSet) {
1167 if (word.endsWith('s') && wordSet.has(word.substr(0, word.length-1))) {
1168 wordSet.delete(word)
1169 }
1170 }
1171
1172 return wordSet
1173}
1174
1175
1176samples.set('────── base combos ──────', null)

Callers 1

toHTMLFunction · 0.85

Calls 3

getEnglishWordsFunction · 0.85
addMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…