Published
Edited
Sep 13, 2020
2 forks
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
trie.find_prefix_node("shubh")
Insert cell
Insert cell
Insert cell
alphanumeric = {
//const alphanumeric = new RegExp('[\\.,-\\/#!$%\\^&\\*;:{}=\\-_`~()@\\+\\?><\\[\\]\+ \n]');
const alphanumeric = new RegExp(data.word_boundary_regex);
//regexObj.compile('new foo', 'g');
return alphanumeric;
}
Insert cell
alphanumeric.test(",")
Insert cell
function aho_corasick(input_text, word_boundary=false, case_sensitive=false){
const text = case_sensitive ? input_text : input_text.toLowerCase();
let node = trie;
let prev_index = 0;
let best_match = -1;
let best_match_value = null;
let matches = new Array();
function add_match(best_match, prev_index, best_match_value){
if(best_match > -1){
console.log([text.slice(prev_index, best_match+1), prev_index, best_match+1, best_match_value]);
console.log(
word_boundary, prev_index, text[prev_index-1], best_match, text[best_match+1],
(prev_index > 0 && !alphanumeric.test(text[prev_index-1])),
(best_match < text.length-1 && !alphanumeric.test(text[best_match+1]))
)
if(word_boundary){
if((prev_index > 0 && !alphanumeric.test(text[prev_index-1]))){
return;
} else if((best_match < text.length-1 && !alphanumeric.test(text[best_match+1]))){
return;
}
}
matches.push([text.slice(prev_index, best_match+1), prev_index, best_match+1, best_match_value]);
}
}
for(let i=0; i<text.length; i++){
const c = text[i];
if(node.children && node.children.has(c)){
node = node.children.get(c);
if(node.found){
best_match = i;
best_match_value = node.value;
}
continue;
}
add_match(best_match, prev_index, best_match_value);
best_match = -1;
best_match_value = null;
node = trie;
if(node.children && node.children.has(c)){
i = i-1;
}
prev_index = i+1;
}
add_match(best_match, prev_index, best_match_value);
return matches;
}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more