Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Help/markdown/NLP_PP_Stuff/AT-POST_Actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
1 change: 1 addition & 0 deletions Help/markdown/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
52 changes: 52 additions & 0 deletions Help/markdown/makeliteral.md
Original file line number Diff line number Diff line change
@@ -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)
Loading