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

2 views (last 30 days)
Samyukta Ramnath on 26 Jun 2013
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

Lokesh Ravindranathan on 26 Jun 2013
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 CommentsShowHide 1 older comment
Lokesh Ravindranathan on 26 Jun 2013
You could use the cell array inside a cell array.
Tag{i}{1} = 'NN'
This will ensure you have various tags and for the count, you could simply do
numel(Tag{i}{:})

Muthu Annamalai on 26 Jun 2013
@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.