Can anyone help resolve this issue?

조회 수: 1 (최근 30일)
Brian Leon
Brian Leon 2020년 4월 15일
답변: Cris LaPierre 2020년 8월 2일
I currently have a 960x17 char array that consists of cleaned words with no punctuation, special characters, spaces and digits.
I then have a function that is suppose to take in that char array (newWords1) with a cell array (stopWords) to take out the stopWords from my char array.
function stopWord = isStopWord(stopWords, word)
%determines if a word is a stopword
%Input: stopWords: is a Cell Array that contains all the words from
% the file stopWords.txt
% word: is a Character Array
%Return:
% stopWord: is logical(1)/TRUE if word IS a stopword otherwise it is
% logical(0)/FALSE if it is NOT a stopword
hasWord = ismember(stopWords,word);
stopWord = any(hasWord);
end
This is the code i am running to use this function
%removing the stopwords from the story files (isStopWord)
fid = fopen('stopWords.txt');
stopWords = textscan(fid,'%s');
stopWords = stopWords{1};
stopWord = isStopWord(stopWords,newWords1);
end
The problem is that when I run this, instead of recieivng a structure array with the stopWords removed from my char array, I just recieve a variable stopWord with a logical 1 statement. Any tips on how to resolve this?
  댓글 수: 3
Brian Leon
Brian Leon 2020년 4월 15일
Oh i see now. Is there any way I can make my char array stopWords1 plug each word into my fucntion to remove the stopwords? My goal is to remove stopwords from my stopWords1 variable from my list of stopWords.
Geoff Hayes
Geoff Hayes 2020년 4월 15일
Are you replacing the stopWords from your newWords1 with something else (blank spaces) or just removing altogether? A problem with just removing them is that now you are reducing the number of characters in one or more rows so newWords1 will no longer be 960x17. If each line corresponds to a line of text, then it might be better to convert this character array to a 960 element cell array where each cell corresponds to one of these lines of text, and the length of each line does not have to be identical.

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2020년 8월 2일
Do you have access to the Text Analytics Toolbox? If so, consider using the removeWords function.

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by