主要内容

word2ind

将单词映射到编码索引

描述

例子

= word2ind (内附单词返回单词在编码内附.对于不在编码词汇表中的单词,函数返回.缺省情况下,该函数区分大小写。

例子

= word2ind (内附单词“IgnoreCase”,真的)使用前面的任何语法返回忽略大小写的索引。如果编码中的多个单词仅在case中不同,则该函数返回对应于其中一个单词的索引,而不返回任何特定的索引。

例子

全部折叠

加载示例数据。该文件sonnetsPreprocessed.txt包含了经过预处理的莎士比亚十四行诗。该文件每行包含一首十四行诗,单词之间用空格分隔。将文本从sonnetsPreprocessed.txt,将文本以换行符分割为文档,然后标记文档。

文件名=“sonnetsPreprocessed.txt”;str = extractFileText(文件名);textData =分裂(str,换行符);文件= tokenizedDocument (textData);文档(1:10)
ans = 10x1 tokenizedDocument: 70 token:美丽的生物欲望增加从而美丽玫瑰可能永远不会死成熟时间流逝的记忆交给娇嫩的后嗣收缩你的明亮的眼睛feedst你灯火焰selfsubstantial燃料使饥荒丰富是你自我你的敌人你甜蜜的自我残酷的艺术世界新鲜点缀春天华丽使者你自己的花蕾埋葬你知足的温柔的粗鲁的人浪费了吝啬的怜悯,否则贪婪的吃了世界应有的坟墓,你的71个记号:四十冬天围攻你的眉毛挖深沟你的美容领域你年轻人骄傲制服盯着tatterd杂草小值得问你的美丽谎言珍惜你说你自己的深凹的眼睛的日夜alleating羞愧浪费的赞美赞美deservd你的美丽你能够回答我公平的孩子应当和计数使老借口证明美丽继承你的新,你的旧,你的血液温暖,你的感觉寒冷,看你的玻璃告诉脸你查看时间脸形成另一个新鲜的修复17你欺骗世博会unbless母亲的子宫uneard不屑走旁人走过耕作你饲养喜欢墓selflove停止后人你是你母亲的玻璃你电话回可爱的4月最佳窗口你年龄要尽管皱纹你的黄金时间活着,记住,独自死去,你的形象死去,你的象征。unthrifty可爱为什么你花在你的自我你美丽遗产性质遗赠给了什么难道借弗兰克借自由美丽的吝啬鬼为什么你虐待你慷慨的慷慨给无益的高利贷者为什么你伟大的金额总和还能实时路况你自我孤独你自我你甜蜜的自我欺骗内急你消失了你能把你那未用过的美留在坟墓里吗?小时温柔的工作框架可爱的眼睛凝视每个难道住打暴君一样不公平很难道excel neverresting时间导致夏天可怕的冬天混淆sap检查霜精力充沛的叶子很美丽了oersnowed赤裸每个夏天蒸馏液体离开囚禁囚犯墙玻璃美容效果美丽失去也没有鲜花和纪念 distilld though winter meet leese show substance still lives sweet 68 tokens: let winters ragged hand deface thee thy summer ere thou distilld make sweet vial treasure thou place beautys treasure ere selfkilld forbidden usury happies pay willing loan thats thy self breed another thee ten times happier ten ten times thy self happier thou art ten thine ten times refigurd thee death thou shouldst depart leaving thee living posterity selfwilld thou art fair deaths conquest make worms thine heir 64 tokens: lo orient gracious light lifts up burning head eye doth homage newappearing sight serving looks sacred majesty climbd steepup heavenly hill resembling strong youth middle age yet mortal looks adore beauty still attending golden pilgrimage highmost pitch weary car like feeble age reeleth day eyes fore duteous converted low tract look another way thou thyself outgoing thy noon unlookd diest unless thou get son 70 tokens: music hear why hearst thou music sadly sweets sweets war joy delights joy why lovst thou thou receivst gladly else receivst pleasure thine annoy true concord welltuned sounds unions married offend thine ear sweetly chide thee confounds singleness parts thou shouldst bear mark string sweet husband another strikes mutual ordering resembling sire child happy mother pleasing note sing whose speechless song many seeming sings thee thou single wilt prove none 70 tokens: fear wet widows eye thou consumst thy self single life ah thou issueless shalt hap die world wail thee like makeless wife world thy widow still weep thou form thee hast left behind every private widow well keep childrens eyes husbands shape mind look unthrift world doth spend shifts place still world enjoys beautys waste hath world end kept unused user destroys love toward others bosom sits murdrous shame commits 69 tokens: shame deny thou bearst love thy self art unprovident grant thou wilt thou art belovd many thou none lovst evident thou art possessd murderous hate gainst thy self thou stickst conspire seeking beauteous roof ruinate repair thy chief desire o change thy thought change mind shall hate fairer lodgd gentle love thy presence gracious kind thyself least kindhearted prove make thee another self love beauty still live thine thee

创建一个单词编码。

内附= wordEncoding(文档)
enc = wordEncoding with properties: NumWords: 3092 Vocabulary: [" fairrest " "creatures" "desire"…]

将“玫瑰”,“爱”和“美丽”这些词映射到编码索引中word2ind函数。

话说= [“玫瑰”“爱”“美”];话说idx = word2ind (enc)
idx =1×37 387 79

输入参数

全部折叠

输入字编码,指定为wordEncoding对象。

输入字,指定为字符串向量、字符向量或字符向量的单元格数组。如果您指定单词作为字符向量,函数将参数视为单个单词。

数据类型:字符串|字符|细胞

输出参数

全部折叠

字编码索引向量,返回为正整数或值。

对于不在编码词汇表中的单词,函数返回

介绍了R2018b