tokenizedDocument — Create tokenized document objects for Text Analytics workflows.
tokenizedDocument(str) tokenizes text into a lightweight RunMat tokenizedDocument object. This slice supports English and German Unicode-style tokenization, pre-tokenized word input through TokenizeMethod, "none", and documented custom-token and regular-expression tokenization tables.
Syntax
documents = tokenizedDocument
documents = tokenizedDocument(str)
documents = tokenizedDocument(str, Name, Value, ...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
str | Any | Yes | — | Input text or pre-tokenized words. |
NameValue | Any | Variadic | — | Name-value options: TokenizeMethod, Language, DetectPatterns, TopLevelDomains, CustomTokens, RegularExpressions. |
Returns
| Name | Type | Description |
|---|---|---|
documents | Any | Tokenized document object. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:textAnalyticsDocuments:InvalidInput | Inputs do not match a supported Text Analytics document or model helper form. | Text Analytics document helper received invalid input |
How tokenizedDocument works
tokenizedDocumentwith no input creates a scalartokenizedDocumentcompatibility object containing one empty document.strmay be a string scalar, string array, character vector, multi-row character array, or cell array of scalar text.- String arrays and cell arrays preserve their document-array shape in the object's
Shapeproperty. Character matrices are treated as one document per row. tokenizedDocument(str, 'TokenizeMethod', 'unicode')tokenizes text into words and simple punctuation tokens.tokenizedDocument(words, 'TokenizeMethod', 'none')accepts a string array, character vector, or cell form as pre-tokenized words. A cell array of string arrays represents multiple pre-tokenized documents.Languageaccepts"en"or"de". Japanese and Korean require MeCab-compatible tokenization and remain tracked by the Text Analytics umbrella issue.DetectPatternsaccepts"all","none", or a string/cell vector containing one or more of"email-address","web-address","hashtag","at-mention", and"emoticon". RunMat only keeps enabled complex patterns as single tokens.TopLevelDomainsaccepts a character vector, string array, or cell array of character vectors and controls web-address recognition whenDetectPatternsincludes"web-address". RunMat stores normalized TLD labels and uses custom lists for bare domains,www.addresses, andhttp:///https://addresses; with the default list, explicitwww.and scheme URLs are accepted when the host has a valid domain shape.CustomTokensaccepts a character vector, string scalar/vector, cell text vector, or table with a requiredTokenvariable and optionalTypevariable. Custom tokens are kept as single tokens, conflicting matches use the longest token, and missing or empty tableTypevalues default to"custom".RegularExpressionsaccepts a character vector, string scalar/vector, cell text vector, or table with a requiredPatternvariable and optionalTypevariable. Patterns are matched at the current tokenizer position, invalid or empty-matching patterns are rejected, conflicting regular-expression matches use the last matching pattern, and regular-expression tokens take precedence over custom tokens.- The returned object stores
Vocabularyplus RunMat compatibility metadata properties:Documents,NumDocuments,DocumentLengths,Shape,TokenizeMethod,Language,DetectPatterns, andTopLevelDomains. WhenCustomTokensorRegularExpressionsare used, RunMat also storesTypeDetailssotokenDetailsreturns the custom type labels.tokenDetailsderives common token type and language columns from metadata; pre-tokenizedTokenizeMethod,"none"documents needaddTypeDetailsbefore aTypecolumn is returned. - RunMat represents a MATLAB tokenizedDocument array as one scalar object carrying document cells and shape metadata because generic first-class MATLAB object arrays are not yet available for this class.
- Full MathWorks
topLevelDomainscorpus parity, exact ICU/MeCab tokenization, exact statistical sentence/part-of-speech/entity/dependency model parity, and object-array identity parity remain tracked in the broader Text Analytics compatibility issue.
GPU memory and residency
tokenizedDocument tokenizes host-resident text and has no provider kernel.
Examples
Tokenize Text
documents = tokenizedDocument(["A short document"; "Another document"])Expected output:
`documents.NumDocuments` is `2`, and `documents.Vocabulary` contains the unique tokens in first-seen order.Use Pre-Tokenized Words
documents = tokenizedDocument(["alpha" "beta" "alpha"], "TokenizeMethod", "none")Expected output:
`documents.DocumentLengths` is `3` for the single pre-tokenized document.Choose Complex Token Patterns
documents = tokenizedDocument("Mail a@example.com #MATLAB at https://example.com", "DetectPatterns", ["email-address" "hashtag"])Expected output:
The email address and hashtag stay as single tokens; the web address is tokenized as ordinary text and punctuation.Configure Web Address Domains
documents = tokenizedDocument("See example.zz", "TopLevelDomains", "zz")Expected output:
`example.zz` is recognized as a web-address token.Use Custom Token Types
rules = table(["Na+"; "H2O"], ["ion"; "formula"], 'VariableNames', ["Token" "Type"])
documents = tokenizedDocument("Na+ in H2O", "CustomTokens", rules)Expected output:
`Na+` and `H2O` stay as single tokens, and `tokenDetails(documents)` reports `ion` and `formula` type labels for those tokens.Use Regular Expression Tokens
patterns = table(["[a-z]+\\d+"; "abc\\d+"], ["alnum"; "code"], 'VariableNames', ["Pattern" "Type"])
documents = tokenizedDocument("abc123 xyz9", "RegularExpressions", patterns)Expected output:
`abc123` and `xyz9` stay as single tokens. The later matching `abc\\d+` pattern supplies the `code` type for `abc123`.Using tokenizedDocument with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how tokenizedDocument changes the result.
Run a small tokenizedDocument example, explain the result, then change one input and compare the output.
FAQ
Is RunMat's tokenizedDocument a full MATLAB object array?⌄
No. It is a scalar compatibility object with document cells and a Shape property. First-class object-array behavior remains a runtime infrastructure gap tracked by the Text Analytics umbrella.
Does tokenizedDocument support Japanese or Korean tokenization?⌄
No. RunMat rejects Japanese/Korean language or MeCab tokenization forms in this slice and keeps that work in the remaining Text Analytics queue.
Does tokenizedDocument execute on the GPU?⌄
No. Tokenization is host text processing and has no runmat-accelerate provider path.
Does RunMat ship the full MathWorks topLevelDomains list?⌄
Not yet. RunMat supports user-specified TopLevelDomains, a compact built-in default list for common bare domains, and permissive default handling for explicit www./scheme URLs; full default corpus parity remains tracked.
Related Strings functions
Text Analytics
addDependencyDetails · addEntityDetails · addLemmaDetails · addPartOfSpeechDetails · addSentenceDetails · addTypeDetails · bagOfNgrams · bagOfWords · cosineSimilarity · doc2sequence · encode · extractFileText · extractHTMLText · fastTextWordEmbedding · findElement · getAttribute · htmlTree · ind2word · isVocabularyWord · normalizeWords · readWordEmbedding · removeLongWords · removeShortWords · removeStopWords · removeWords · stopWords · tokenDetails · trainWordEmbedding · vaderSentimentScores · vec2word · word2ind · word2vec · wordEncoding · writeWordEmbedding
Transform
append · deblank · erase · eraseBetween · erasePunctuation · eraseURLs · extractAfter · extractBefore · extractBetween · insertAfter · insertBefore · join · lower · pad · replace · replaceBetween · reverse · split · splitlines · strcat · strip · strjoin · strjust · strrep · strsplit · strtrim · upper
Core
blanks · char · compose · convertCharsToStrings · convertContainedStringsToChars · convertStringsToChars · genvarname · int2str · isletter · isspace · isStringScalar · isstrprop · mat2str · native2unicode · newline · num2str · sprintf · sscanf · str2double · str2num · strcmp · strcmpi · string · string.empty · strings · strlength · strncmp · strncmpi · strtok · unicode2native
Search
contains · endsWith · matches · startsWith · strfind
Pattern
digitsPattern · lettersPattern · pattern · regexpPattern · textBoundary · wildcardPattern
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how tokenizedDocument is executed, line by line, in Rust.
- View the source for tokenizedDocument in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.