Count the number of times a word begins with "co" in a text using Text Analytics Toolbox

1 回表示 (過去 30 日間)
Dear community,
I have a pdf with news headlines, and I need to count the number of words each title has and the number of times the words starting with "co" and the word "price" appear in each title. I have not much experience using the Text Analytics Toolbox in Matlab. As far as I can see, "tokenizedDocument" already gives you the total number of words (or tokens) per headline, and "context" counts a specific word. However, I do not know how to ask Matlab to look for words starting with "co". Also, how do I get this information displayed in a table?
I leave my pdf and my code.
I really appreciate any help you can provide!
filename = "Factiva_sample_headlines_1.pdf";
str = extractFileText(filename);
textData = split(str,[newline newline]); %split the text into separate news using split
textData = textData(cellfun(@(s)isempty(regexp(s,'Page')),textData)); %Erase data related to number of page
cleanedDocuments = tokenizedDocument(textData); %Create an array of tokenized documents.
  12 件のコメント
Angelavtc
Angelavtc 2022 年 4 月 22 日
Oh la la, it seems more complex than expected :( perhaps I should move to another software 😭. In any case, thank you very much @Stephen!
Angelavtc
Angelavtc 2022 年 4 月 23 日
@Stephen Sorry for the inconvenience again, but I have managed to transform the file to html format (https://drive.google.com/file/d/1Z5bW98_gWohr2appS8zKgxCC1_mlLpzc/view?usp=sharing) Now the problem is that when I use :
filename = "Factiva_1.html";
str = extractFileText(filename);
I only get one article loaded. Any idea how to make matlab read all of them and classify them by title, date and body?
Thank you very much!

サインインしてコメントする。

採用された回答

Jonas
Jonas 2022 年 4 月 21 日
編集済み: Jonas 2022 年 4 月 21 日
are your searching for something like in this example, applied to your textData?
a={'cotrol', 'alcotro','conect','trial','co'};
cellfun(@(in) strcmp(in(1:2),'co'),a)
ans =
1×5 logical array
1 0 1 0 1
you can sum that array to get the total number of words starting with "co"
  8 件のコメント
Walter Roberson
Walter Roberson 2022 年 4 月 25 日
See also contains() and patternarray
(but I am old fashioned and find regexp easier to work with... but it can get tricky!)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by