필터 지우기
필터 지우기

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

조회 수: 3 (최근 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
Lokesh Ravindranathan 2013년 6월 26일
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
Lokesh Ravindranathan 2013년 6월 26일
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에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by