Loop database SQL query through array cell - Text analytics

can someone help me, I can't loop the database through array cell. I'm new in matlab toolbox text analytics. The problem is in the for loop at end but its good to show the all code.
str = get(handles.edit1,'String');
% Erase the punctuation
a = erasePunctuation(str);
% Convert to lowercase
b = lower(a);
% Tokenize the text.
documents = tokenizedDocument(b);
% Remove a list of stop words.
documents = removeWords(documents,stopWords);
% Normalize the words using the Porter stemmer.
documents = normalizeWords(documents);
%convert to cell array
C = doc2cell(documents);
meaning = C{1};
%Show the result to WordList
set(handles.listbox1, 'String', meaning);
% connect to database
dbname = 'database';
username = 'root';
password = 'root';
conn = database(dbname, username, password);
%Here is the problem begin
for i = 1:length(meaning)
% Matching word
sqlquery = ['SELECT meaning FROM translate WHERE meaning LIKE ',meaning{i},''];
curs = exec(conn,sqlquery);
curs = fetch(curs, 1);
word = curs.Data;
set(handles.listbox2, 'String', word);
end

4 Comments

Since we have no way to test your code. What exactly is the problem. You're not getting the result you expect? If so, what result do you get and what did you expect instead? You're getting an error? If so, what is the error message? The problem is something else? If so, what?
Please use, the {}Code button to format your code appropriately. It should look like this rather than the unreadable mess that you have:
str = get(handles.edit1,'String');
% Erase the punctuation
a = erasePunctuation(str);
I want to match this cell array one by one in a database, but I don't know what wrong this code.
for i = 1:length(meaning)
% Matching word
sqlquery = ['SELECT meaning FROM translate WHERE meaning LIKE ',meaning{i},''];
curs = exec(conn,sqlquery);
curs = fetch(curs, 1);
word = curs.Data;
set(handles.listbox2, 'String', word);
end
Again, What exactly is the problem?
  • You're not getting the result you expect? If so, what result do you get and what did you expect instead?
  • You're getting an error? If so, what is the error message?
  • The problem is something else? If so, what?
Again, we have no way to test your code since we don't have access to your database, nor do we have your inputs.
That the problem it does not return anything that mean something is wrong in loop bcs I don't know how to loop an array cell to match with database. So ether the loop is wrong or the sqlquery or the
set(handles.listbox2, 'String', word);
I' m expecting an output in listbox2 but it does not return anything.

Sign in to comment.

Answers (0)

Asked:

on 8 Nov 2017

Commented:

on 8 Nov 2017

Community Treasure Hunt

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

Start Hunting!