Search for patterns in an NLCST tree.
npm:
npm install nlcst-search
var 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-level
Search for patterns in an NLCST tree.
Error
— When not given node
or patterns
.
Tree to search in (Node
).
Patterns to search for (Array.<string>
or Object
).
If an Object
, 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 tree.
Handler invoked when a match is found (Function
).
Treated as options.allowApostrophes
.
Passed to nlcst-normalize
(boolean
, default: false
).
Passed to nlcst-normalize
(boolean
, default: false
).
Include literal phrases (boolean
, default: false
).
Handler invoked when a match is found.
List of siblings which match pattern
(Array.<Node>
).
Position at which the match starts in parent
(number
).
Parent node of nodes
(Node
).
The matched pattern (string
).
See contributing.md
in syntax-tree/nlcst
for ways to get
started.
This organisation has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.