主要内容

docfun

将功能应用于文档中的单词

描述

例子

newDocuments= docfun (函数文档调用由函数句柄指定的函数函数并传递文档作为单词的字符串向量。

  • 如果函数只接受一个输入参数,然后是newDocuments(我)func (string(文档(i)))

  • 如果函数接受两个输入参数,然后是newDocuments(我)func (string(文档(i)),详细信息),在那里细节由输出的对应令牌详细信息tokenDetails

  • 如果函数然后更改文档中的字数docfun从该文档中删除令牌细节。

docfun不执行调用功能函数以特定的顺序。

例子

newDocuments= docfun (函数、documents1 documentsN……)调用由函数句柄指定的函数函数并传递documents1,…,documentsN作为单词的字符串向量,其中N是函数的输入数吗函数.的话说newDocuments(我)func (string (documents1(我)),…,字符串(documentsN(我)))

每个人documents1,…,documentsN必须是相同的尺寸。

例子

全部折叠

应用反向指向文档数组中的每个单词。

文件= tokenizedDocument ([...一个短句的例子第二个短句])
documents = 2x1 tokenizedDocument: 6个token:一个短句的例子4个token:第二个短句
func = @reverse;newDocuments = docfun(函数、文件)
newDocuments = 2x1 tokenizedDocument: 6 tokens: na elpmaxe fo a trohs ecnetnes 4 tokens: a dnoces trohs ecnetnes

使用string函数将来自一个文档数组的单词与另一个文档数组的单词组合在一起,从而标记单词+

创建第一个tokenizedDocument数组中。擦掉标点符号并将文本转换为小写字母。

str = [...“一个短句的例子。”第二个简短的句子。];str = erasePunctuation (str);str =低(str);documents1 = tokenizedDocument (str)
documents1 = 2x1 tokenizedDocument: 6个令牌:一个短句的例子4个令牌:第二个短句

创建第二个tokenizedDocument数组中。文档的字数与相应文档的字数相同documents1.的话说documents2是对应单词的POS标签。

documents2 = tokenizedDocument ([...名词prep名词" det adj . adj .名词"])
documents2 = 2x1 tokenizedDocument: 6 token: _det _noun _prep _det _adj _noun 4 token: _det _adj _noun
func = @plus;newDocuments = docfun (func documents1 documents2)
newDocuments = 2x1 tokenizedDocument: 6 tokens: an_det example_noun of_prep a_det short_adj sentence_noun 4 tokens: a_det second_adj short_adj sentence_noun

输出与调用不一样+直接在文件上。

+ (documents1 documents2)
ans = 2x1 tokenizedDocument: 12 tokens: an example of a short sentence _det _noun _prep _det _adj _名词8 tokens: a second short sentence _det _adj _名词

输入参数

全部折叠

接受的函数句柄N字符串数组作为字符串数组的输入和输出。函数必须接受字符串(documents1 (i)),…,字符串(documentsN(我))作为输入。

函数句柄应用于文档中的单词。该函数必须具有以下语法之一:

  • newWords = func(字),在那里单词是单个文档的单词的字符串数组。

  • newWords = func(话说,细节),在那里单词是由单个文档的单词组成的字符串数组,并且细节对应的令牌细节表是由tokenDetails

  • newWords = func (wordsN words1…),在那里words1,…,wordsN是单词的字符串数组。

例子:@reverse

数据类型:function_handle

输入文档,指定为tokenizedDocument数组中。

输出参数

全部折叠

输出文档,作为tokenizedDocument数组中。

介绍了R2017b