NLCST Affix Emoticon Modifier

3.0.0 · active · verified Sun Apr 19

nlcst-affix-emoticon-modifier is a utility within the unified ecosystem designed to process Natural Language Concrete Syntax Tree (NLCST) nodes. Its primary function is to identify and re-position emoticons that appear at the beginning of a sentence, moving them to the end of the preceding sentence. This addresses common linguistic patterns where users place emoticons as a reaction to the previous thought, even after terminal punctuation. The current stable version is 3.0.0, which requires Node.js 16+. While a low-level utility, it forms a crucial part of more abstracted tools like `retext-emoji`. The project follows semver for releases, with significant breaking changes in major versions, particularly the move to ESM-only in v2 and further API adjustments in v3.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to parse a sentence with an initial emoticon and then use `affixEmoticonModifier` to move it into the previous sentence in the NLCST tree.

import {affixEmoticonModifier} from 'nlcst-affix-emoticon-modifier'
import {emoticonModifier} from 'nlcst-emoticon-modifier'
import {ParseEnglish} from 'parse-english'
import {inspect} from 'unist-util-inspect'

const parser = new ParseEnglish()
// Register emoticonModifier to tokenize emoticons into EmoticonNodes
parser.tokenizeSentencePlugins.unshift(emoticonModifier)
// Register affixEmoticonModifier to move these nodes after terminal punctuation
parser.tokenizeParagraphPlugins.unshift(affixEmoticonModifier)

const text = 'Hey. :) How is it going?'
const tree = parser.parse(text)

console.log(inspect(tree))
/* Expected output will show ' :)' moved into the first sentence. */

view raw JSON →