主要内容

docfun

将函数应用于文档中的单词

描述

例子

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

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

  • 如果函数接受两个输入参数,然后words ofnewDocuments(我)的输出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 token: na elpmax fo a trohs ecnetnes 4 token: a dnoces trohs ecnetnes

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

创建第一个tokenizedDocument数组中。删除标点符号并将文本转换为小写。

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

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

documents2 = tokenizedDocument ([“名词_prep _det _形容词_名词”“名词”])
documents2 = 2x1 tokenizedDocument: 6个标记:_det _名词_prep _det _形容词_名词4个标记:_det _adj _形容词_名词
func = @plus;newDocuments = docfun (func documents1 documents2)
newDocuments = 2x1 tokenizedDocument: 6个token: an_det example_名词of_prep a_det short_adj sentence_名词4个token: a_det second_adj short_adj sentence_名词

输出与调用是不同的+直接在文件上。

+ (documents1 documents2)
ans = 2x1 tokenizedDocument: 12个标记:一个短句_det _名词_prep _det _adj .名词8个标记:第二个短句_det _adj . adj .名词

输入参数

全部折叠

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

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

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

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

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

例子:@reverse

数据类型:function_handle

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

输出参数

全部折叠

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

版本历史

介绍了R2017b

Baidu
map