how to find most common words in text by matlab
조회 수: 4 (최근 30일)
이전 댓글 표시
how to tag POS on nouns and verbs in MATLAB, Is it related to regular expressions? I know that regular expressions find a pattern in a text, but I want to find the most common words in texts and tag POS on them( I mean the words are nouns or verbs) and then exchange that POS and make an unfamiliar pair of words. how can I find the most common words in texts by MATLAB?is there any solution for that or I should use another software?
댓글 수: 0
채택된 답변
Christopher Creutzig
2017년 11월 2일
편집: Christopher Creutzig
2018년 11월 26일
Finding the most common words is easy with Text Analytics Toolbox:
>> sonnets = extractFileText("sonnets.txt");
>> sonnets = erasePunctuation(sonnets);
>> tokenizedSonnets = tokenizedDocument(lower(sonnets));
>> bag = bagOfWords(tokenizedSonnets);
>> topkwords(bag, 10)
ans =
10×2 table
Word Count
______ _____
"and" 490
"the" 436
"to" 409
"my" 371
"of" 370
"i" 344
"in" 321
"that" 320
"thy" 281
"thou" 234
You probably want to remove some words (check out removeWords and stopWords). POS tagging is supported in release R2018b and later, see addPartOfSpeechDetails.
댓글 수: 2
Christopher Creutzig
2018년 5월 2일
What command(s) did you try to read that file? The error message looks like you tried to read it as a table; try using the commands listed above instead.
추가 답변 (2개)
Sarah Palfreyman
2018년 4월 30일
편집: Sarah Palfreyman
2018년 4월 30일
댓글 수: 2
IORUNDU GABRIEL
2018년 5월 16일
Which version of matlab is the least that supports the Text analytic toolbox?
Charmaine Tan
2018년 11월 26일
Hi, after finding my topkwords (most frequent words), how can I plot a histogram of these?
댓글 수: 2
Christopher Creutzig
2018년 11월 26일
txt = extractFileText('sonnets.txt');
td = tokenizedDocument(lower(txt));
td = erasePunctuation(td);
bow = bagOfWords(td);
top = topkwords(bow,20);
bar(top.Count)
set(gca,'XTick',1:size(top,1),'XTickLabel',top.Word,'XTickLabelRotation',45)
(In general, it's a good idea not to ask a new question as an “answer,” but to open a new question instead. It helps other people searching MATLAB Answers in the future.)
참고 항목
카테고리
Help Center 및 File Exchange에서 Language Support에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!