默认情况下,如果nargin == 2 % bigram mode is default mode = 'bigram',则该函数使用一个bigram模型;end isBiMode = ismember(mode, {'bigram', 'bi'});% if stringcmp (class(mdl), 'bigramClass')) % if bigramClass biMdl = mdl.mdl;strcmp(class(mdl), 'trigramClass')) % if它有一个模型else;%它有两个模型end if isBiMode % if bigram mode = strcmp(mdl. xml . xml . xml . xml . xml . xml . xml . xml . xml . xml . xml . xml . xml . xml。unigrams上一页);% select unigram index isCandidate = biMdl(row,:) > 0;% select非零值prob = biMdl(row, isCandidate);% if trigram mode = strcmp(mdl. txt, mdl. txt, mdl. txt, mdl. txt)三元、上一页);% select bigram index isCandidate = triMdl(row,:) > 0; % select non-zero values prob = triMdl(row, isCandidate); % extract probabilities end candidates = mdl.unigrams(isCandidate); % extract candidate words samples = round(prob * 10000); % create 10000 samples % based on probabilities % round it to an integer csum = [0 cumsum(samples)]; % cumulative sum of samples try pick = randsample(csum(end), 1); % randomly pick a sample idx = find(csum >= pick, 1); % find where it falls in csum nextw = candidates{idx - 1}; % get the corresponding word catch % an error ocurred nextw = '';%返回作为下一个单词结束结束