commonform-phrase-annotator
v2.0.0
Published
create Common Form annotators from lists of words and phrases
Downloads
11
Maintainers
Readme
commonform-phrase-annotator
The module exports a single function that takes an array of strings and a function for generating annotations, returning an annotator function to apply to Common Forms.
var phrases = ['thereof', 'whereof']
The annotation function receives the form in which a string was found, its path within the overall form, and the string that matches. It must return a Common Form Annotations.
function implementation (form, path, string) {
return {
message: '"' + string + '" is archaic',
path: path,
source: 'example-annotator',
url: null
}
}
var phraseAnnotator = require('commonform-phrase-annotator')
var annotator = phraseAnnotator(phrases, implementation)
The library does the job of finding matches and calculating paths.
var assert = require('assert')
assert.deepStrictEqual(
annotator({ content: ['all rights thereof and whereof'] }),
[
{
message: '"thereof" is archaic',
path: ['content', 0],
source: 'example-annotator',
url: null
},
{
message: '"whereof" is archaic',
path: ['content', 0],
source: 'example-annotator',
url: null
}
]
)