From c423f495ad29bd21ce85fbc577e70df5b2aec5a0 Mon Sep 17 00:00:00 2001 From: David de Hilster Date: Wed, 14 Oct 2026 20:20:36 -0400 Subject: [PATCH] Help: makeliteral (engine 4.2.28, #450) Co-Authored-By: Claude Opus 5.5 --- Help/markdown/NLP_PP_Stuff/AT-POST_Actions.md | 1 + Help/markdown/index.md | 1 + Help/markdown/makeliteral.md | 52 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 Help/markdown/makeliteral.md diff --git a/Help/markdown/NLP_PP_Stuff/AT-POST_Actions.md b/Help/markdown/NLP_PP_Stuff/AT-POST_Actions.md index efcec5d..cc9c00c 100644 --- a/Help/markdown/NLP_PP_Stuff/AT-POST_Actions.md +++ b/Help/markdown/NLP_PP_Stuff/AT-POST_Actions.md @@ -40,6 +40,7 @@ Actions available in the POST Region are provided in the table below.  For exam | [**singler(num1,num2)**](../singler.md) | Single-tier reduce of a range of rule elements. eg, if finding a period to be end-of-sentence in context, we only want to reduce the period to end-of-sentence, not the whole context. | | [**singlex(num1,num2)**](../singlex.md) | Single-tier reduce of a range of rule elements. All nodes not in the range are EXCISED. eg, if matching a keyword html tag, we only want to reduce the keywords and to zap the rest of the tag. | | [**singlezap()**](../singlezap.md) | Single-tier reduce. Excise all the nodes in the matched phrase. | +| [**makeliteral(num1,num2,text[,type])**](../makeliteral.md) | Replace rule elements num1 through num2 with one token whose text is *text*, typed as the tokenizer would (or as *type* says). E.g., turn OCR's "7O" into the number token "70". **NEW 4.2.28** | | [**merge()**](../merge.md) | Single-tier reduce that DISSOLVES each top-level node in the matched phrase. | | [**merger(num1,num2)**](../merger.md) | Single-tier reduce that DISSOLVES each top-level node in the matched range. | | [**listadd(olist,oitem [, keep])**](../listadd.md) | Add a new node to a list node's children. If the item occurs after the list (***olist*** < ***oitem***), it is added as the last child. If the item occurs before the list, it is added as the first child. The optional keep arg can be "true" or "false". If "true", it keeps the nodes between the list and the item as children of list. If "false", it excises all the intervening nodes. | diff --git a/Help/markdown/index.md b/Help/markdown/index.md index 27c2fb6..a7387f5 100644 --- a/Help/markdown/index.md +++ b/Help/markdown/index.md @@ -221,6 +221,7 @@ to a topic. - [singler](singler.md) - [singlex](singlex.md) - [singlezap](singlezap.md) + - [makeliteral](makeliteral.md) - [splice](splice.md) - **Print Actions** - [fprintgvar](fprintgvar.md) diff --git a/Help/markdown/makeliteral.md b/Help/markdown/makeliteral.md new file mode 100644 index 0000000..504fe5d --- /dev/null +++ b/Help/markdown/makeliteral.md @@ -0,0 +1,52 @@ +[← Help Contents](index.md) | [📘 NLP++ Textbook](NLP++_Textbook.md) + +# makeliteral + +## Purpose + +Replace a range of rule elements with one token whose text you give. Later passes treat it like any token of its type. + +## Syntax + +``` +makeliteral(startNum, endNum, textStr) +makeliteral(startNum, endNum, textStr, typeStr) +``` + +``` +startNum - type: int, first rule element to replace +endNum - type: int, last rule element to replace +textStr - type: str, the new token's text +typeStr - type: str (optional): num, alpha, punct, white, ctrl, emoji or node +``` + +## Returns + +Nothing is returned to NLP++. As a side effect, the nodes matching rule elements *startNum* through *endNum* are replaced by one token. Its name and `$text` are *textStr*. It keeps the offsets of the nodes it replaced, so it still points at the original text in the input. + +## Remarks + +Without *typeStr*, the token gets the type the tokenizer would give *textStr*: all digits makes **num**, all whitespace makes **white**, a single punctuation character makes **punct**, and anything else makes **alpha**. + +Like [singlezap](singlezap.md), **makeliteral** removes the nodes it replaces, so it should be the last action in the POST region. + +**NEW 4.2.28** + +## Example + +OCR sometimes reads the number 70 as "7O", with a letter O. This turns it back into a number: + +``` +@POST + makeliteral(1, 2, "70"); +@RULES +_xNIL <- 7 O @@ +``` + +Later passes see a **num** token "70". A rule such as `_money <- _xNUM _xWHITE [s] dollars @@` matches it, and its `$text` is "70". + +To force a type, give it as a fourth argument, as in `makeliteral(1, 1, "USA", "alpha")`. + +## See Also + +[singlezap](singlezap.md), [singler](singler.md), [single](single.md), [POST Actions](NLP_PP_Stuff/AT-POST_Actions.md#table_of_@POST_Actions)