How do I make MATLAB list the various sequences possible for a specific purpose?

5 次查看(过去 30 天)
I need to find a way to list all the possible sequences of a sentence, for example if I have a set of 8 possible attributes of a certain word, and I have a sentence which is just a combination of words. I need to find a way to list the various possible sequence of attributes for that sentence. For example, I have the sentence 'the shark killed the man'. I know that 'the' has the attribute 'DD', and I know that the word which follows a word with attribute 'DD' has the attrbute 'NN' or 'ADJ'. So how do I get MATLAB to list the sequences : DD NN ? DD NN DD ADJ ? DD ADJ DD NN ? DD ADJ DD ADJ ? DD NN In other words, I want to say that the attribute of the second word (let's say T2) is either NN or ADJ, and the same for the fourth word (T4).
This doesn't work :
if true
% code
Tag = cell(1,size_string);
for i = 1:size_string
for j = 1:size_art
if strcmp(string(i),art{j})
disp(string(i+1));
(Tag(i+1) = 'NN') || (Tag(i+1) = 'ADJ');
disp(' ');
disp(string(i));
disp('is an article');
end
end
end
end

回答(2 个)

Lokesh Ravindranathan
I think there could be couple of issues in the code. I could not execute your code completely, since I do not have access to your variables.
You define Tag as a cell and you are trying to assign using a normal circular parentheses. You should assign variables using curly parentheses.
Tag{i} = 'NN'
would work in your case. When using logical OR operator (), you should have a lhs and rhs which could be converted of type logical type.
Even otherwise, when you are using |, in your case, you should expect the lhs and rhs of equal sizes.
In your case, I am not sure what you are expecting of your code.
  2 个评论
Samyukta Ramnath
Samyukta Ramnath 2013-6-26
I basically want it to have two possibilities, that the tag could be NN and it could also be ADJ. Should I use a matrix for this? But I also have to get MATLAB to recognize that there could be different possible tags for every word in the sentence. The number of possibilities are subject to certain rules.
Lokesh Ravindranathan
You could use the cell array inside a cell array.
Tag{i}{1} = 'NN'
Tag{i}{2} = 'ADP'
This will ensure you have various tags and for the count, you could simply do
numel(Tag{i}{:})

请先登录,再进行评论。


Muthu Annamalai
Muthu Annamalai 2013-6-26
@Samyukta you seem to need a 'generative grammar'. You can do this via mutually recursive functions. You should type the following in MATLAB and watch the program
>> for i = 1:10, why; pause(1); end
>> edit why
While my favorite demo doesn't directly solve your problem, you can definitely see how to build a generative grammar.

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by