MCPcopy Index your code
hub / github.com/tensorflow/tfjs-examples / searchForKeywords

Function searchForKeywords

electron/image_classifier.js:209–239  ·  view source on GitHub ↗
(classNamesAndProbs, filePaths, targetWords)

Source from the content-addressed store, hash-verified

207 * All matches to the target words.
208 */
209export function searchForKeywords(classNamesAndProbs, filePaths, targetWords) {
210 // Filter through the output class names and probilities to look for
211 // matches.
212 const foundItems = [];
213 for (let i = 0; i < classNamesAndProbs.length; ++i) {
214 const namesAndProbs = classNamesAndProbs[i];
215 let matchWord = null;
216 for (const nameAndProb of namesAndProbs) {
217 const classTokens = nameAndProb.className.toLowerCase().trim()
218 .replace(/[,\/]/g, ' ')
219 .split(' ').filter(x => x.length > 0);
220 for (const word of targetWords) {
221 if (classTokens.indexOf(word) !== -1) {
222 matchWord = word;
223 break;
224 }
225 }
226 if (matchWord != null) {
227 break;
228 }
229 }
230 if (matchWord != null) {
231 foundItems.push({
232 filePath: filePaths[i],
233 matchWord,
234 topClasses: namesAndProbs,
235 });
236 }
237 }
238 return foundItems;
239}
240
241/**
242 * Is the current environment Node.js?

Callers 1

searchFromFilesMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected