Search for patterns in an NLCST tree.
npm:
npm install nlcst-searchvar search = require('nlcst-search');
var toString = require('nlcst-to-string');
var tree = {
type: 'SentenceNode',
children: [
{
type: 'WordNode',
children: [
{type: 'TextNode', value: 'Don'},
{type: 'PunctuationNode', value: '’'},
{type: 'TextNode', value: 't'}
]
},
{type: 'WhiteSpaceNode', value: ' '},
{
type: 'WordNode',
children: [
{type: 'TextNode', value: 'do'}
]
},
{type: 'WhiteSpaceNode', value: ' '},
{
type: 'WordNode',
children: [
{type: 'TextNode', value: 'Block'},
{type: 'PunctuationNode', value: '-'},
{type: 'TextNode', value: 'level'}
]
}
]
};
search(tree, ['dont'], function (nodes) {
console.log(toString(nodes));
});
// Don’t
search(tree, ['do blocklevel'], function (nodes) {
console.log(toString(nodes));
});
// do Block-levelSearch for patterns in an NLCST tree.
node(Node) — Tree to search inpatterns(Array.<string>orObject) — Patterns to search for. If anObject, uses its keys. Each pattern is a space-delimited list of words, where each word is normalized to remove casing, apostrophes, and dashes. Spaces in a pattern mean zero or more white space nodes in the treehandler(Function) — Handler invoked when a match is foundallowApostrophes(boolean, default:false) — Configuration for nlcst-normalize)options(Object) — Configuration:allowApostrophes(boolean, default:false) — Configuration for nlcst-normalize)allowDashes(boolean, default:false) — Configuration for nlcst-normalize)allowLiterals(boolean, default:false) — Include literal phrases
Error — When not given node or patterns.
Handler invoked when a match is found.
nodes(Array.<Node>) — List of siblings which matchpatternindex(number) — Position at which the match starts inparentparent(Node) — Parent node ofnodespattern(string) — The matched pattern