我想保留标记为NA的单词。如果有多个这样的单词组合在一起,我希望将它们组合成一个单词。
示例:
%if i have
a='[The/D, handle/NA, of/NS, the/NaAq, hair/NA, brush/NA, is/NaAZ broken/A]'
% the output I want:
output={'handle', 'hair brush'}我尝试搜索/NA,但问题是有误报,即the、is。
目前我的代码是:
g=split(a(2:end-1));
b= strfind(g,'/NA');
g(~cellfun(@isempty, b))有什么想法可以继续吗?如果可能的话,任何一行正则表达式都是非常有用的。
发布于 2017-08-11 21:51:43
看起来是个不错的NLP问题。也许这能让你开始:
a='[The/D, handle/NA, of/NS, the/NaAq, hair/NA, brush/NA, is/NaAZ broken/A]';
output={'handle', 'hair brush'};
expr = '(\S+/NA, )+'; % look for words followed by '/NA, '
match = regexp(a,expr,'match');
output = strtrim(strrep(match,'/NA,','')) % strrep: get rid of tag - strtrim: get rid of tailing blank请注意,如果最后一个单词被标记为/NA,则此方法将失败。不过,您可以独立地捕捉这种情况。
https://stackoverflow.com/questions/45636297
复制相似问题