how to find most common words in text by matlab

4 Ansichten (letzte 30 Tage)
bita hallajian
bita hallajian am 28 Okt. 2017
Kommentiert: Charmaine Tan am 26 Nov. 2018
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?

Akzeptierte Antwort

Christopher Creutzig
Christopher Creutzig am 2 Nov. 2017
Bearbeitet: Christopher Creutzig am 26 Nov. 2018
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 Kommentare
bita hallajian
bita hallajian am 2 Dez. 2017
Bearbeitet: bita hallajian am 2 Dez. 2017
With great thanks for your help I'll try the helpful points you directed me I created a text document with the name "sonnets.txt" and loaded it in command window but there is an error : "Number of columns on line 2 of ASCII file sonnets.txt must be the same as previous lines." Can you give me useful advice to eliminate this error?
Christopher Creutzig
Christopher Creutzig am 2 Mai 2018
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Sarah Palfreyman
Sarah Palfreyman am 30 Apr. 2018
Bearbeitet: Sarah Palfreyman am 30 Apr. 2018
  2 Kommentare
IORUNDU GABRIEL
IORUNDU GABRIEL am 16 Mai 2018
Which version of matlab is the least that supports the Text analytic toolbox?
Rik
Rik am 16 Mai 2018
R2017b

Melden Sie sich an, um zu kommentieren.


Charmaine Tan
Charmaine Tan am 26 Nov. 2018
Hi, after finding my topkwords (most frequent words), how can I plot a histogram of these?
  2 Kommentare
Christopher Creutzig
Christopher Creutzig am 26 Nov. 2018
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)
Screen Shot 2018-11-26 at 09.23.48.png
(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.)
Charmaine Tan
Charmaine Tan am 26 Nov. 2018
Noted, I'll do that. Thanks a lot!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Language Support finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by