Referencia · §8.25

Chunks

chunks, text::sentences, §M14.22 E6

Ez az oldal a nucleus saját dokumentációjából készül, ezért angol nyelvű.

chunks(text, by, size [, overlap [, model]]), a table function: a row a chunk — position (from 1), chunk, start and length (characters, as substr takes them: substr(text, start, length) = chunk), headings (text[]), size. A NULL text has no chunks. A chunk is a run of whole units packed greedily up to size:

  • sentences — UAX #29 sentences (text::sentences: the default rules SB1–SB11 over text::sentence_breaks, generated by scripts/gen-sentence-breaks.py from Unicode 16’s SentenceBreakProperty.txt; all 512 cases of its SentenceBreakTest.txt pass, kept in tests/data/);
  • tokens — UAX #29 word segments (§8.19’s), a window of size;
  • markdown — sections by CommonMark headings (ATX #…###### with up to three spaces before, a closing # run dropped; setext === / --- under a paragraph; none inside a fenced code block), with the path of headings above each (a heading closes the ones of its level and deeper); a chunk never crosses a section; its units are the section’s blocks — the heading line, paragraphs between blank lines, a fenced code block whole.

A unit larger than size is cut finer (a block into sentences, a sentence into word segments) and its pieces are packed only with each other, so a chunk is whole units of one kind or the pieces of one; a word segment over size is a chunk alone. overlap (< size): the next chunk begins with the last units of the one before that fit in overlap, when that leaves room for a unit it did not have. Chunks are trimmed of white space; one that is only white space is left out. Sizes are words (segments with a letter or a digit) — or, with a model, its tokens: models::count_tokens asks the provider (ModelProvider::count_tokens, None by default: 0A000; the local provider counts by its tokenizer, without the prefix and the special tokens), checking USAGE; a chunk is counted again whole and given fewer units while it is over. Tests: chunks.rs’s own, slt/62_chunks.slt, local-models tests/provider.rs.