Files
obsidian_ollama/debug_test.js
T

31 lines
1.0 KiB
JavaScript

// Debug the exactMatch function
const text = "algorithm";
const query = "algorithm";
function stemToken(token) {
if (token.endsWith('s')) return token.slice(0, -1);
if (token.endsWith('ed')) return token.slice(0, -2);
if (token.endsWith('ing')) return token.slice(0, -3);
return token;
}
function tokenize(text) {
const stopWords = new Set(['the', 'a', 'an', 'and', 'or', 'but', 'is', 'are', 'was', 'were', 'in', 'on', 'at', 'to', 'of', 'for', 'with', 'as', 'by', 'it', 'its', 'that', 'this', 'these', 'those']);
return text
.toLowerCase()
.split(/\W+/)
.filter((token) => token.length > 1 && !stopWords.has(token));
}
function exactMatch(content, token) {
const stemmed = stemToken(token);
const contentTokens = tokenize(content);
return contentTokens.some((ct) => stemToken(ct) === stemmed);
}
console.log("Text:", text);
console.log("Query:", query);
console.log("Tokenized text:", tokenize(text));
console.log("Stemmed query:", stemToken(query));
console.log("Exact match result:", exactMatch(text, query));