MATLAB ヘルプ センター
bag-of-words モデルまたは bag-of-n-grams モデルに文書を追加する
newBag = addDocument(bag,documents)
newBag = addDocument(bag,documents) は、bag-of-words モデルまたは bag-of-n-grams モデル bag に documents を追加します。
newBag
bag
documents
例
すべて折りたたむ
トークン化された文書の配列から bag-of-words モデルを作成します。
documents = tokenizedDocument([ "an example of a short sentence" "a second short sentence"]); bag = bagOfWords(documents)
bag = bagOfWords with properties: NumWords: 7 Counts: [2×7 double] Vocabulary: ["an" "example" "of" "a" "short" "sentence" "second"] NumDocuments: 2
文書をトークン化してもう一つ配列を作成し、同じ bag-of-words モデルに追加します。
documents = tokenizedDocument([ "a third example of a short sentence" "another short sentence"]); newBag = addDocument(bag,documents)
newBag = bagOfWords with properties: NumWords: 9 Counts: [4×9 double] Vocabulary: ["an" "example" "of" "a" "short" "sentence" "second" "third" "another"] NumDocuments: 4
テキスト データが 1 つのフォルダー内の複数のファイルに含まれている場合、ファイル データストアを使用してテキスト データを MATLAB にインポートできます。
この例のソネット テキスト ファイル用のファイル データストアを作成します。例のソネット集のファイル名は "exampleSonnetN.txt" です。ここで、N はソネットの番号です。読み取り関数を extractFileText に指定します。
exampleSonnetN.txt
N
extractFileText
readFcn = @extractFileText; fds = fileDatastore('exampleSonnet*.txt','ReadFcn',readFcn);
空の bag-of-words モデルを作成します。
bag = bagOfWords
bag = bagOfWords with properties: NumWords: 0 Counts: [] Vocabulary: [1×0 string] NumDocuments: 0
データストア内のファイルをループ処理して、各ファイルを読み取ります。各ファイルのテキストをトークン化し、文書を bag に追加します。
while hasdata(fds) str = read(fds); document = tokenizedDocument(str); bag = addDocument(bag,document); end
更新された bag-of-words モデルを表示します。
bag = bagOfWords with properties: NumWords: 276 Counts: [4×276 double] Vocabulary: ["From" "fairest" "creatures" "we" "desire" "increase" "," "That" "thereby" "beauty's" "rose" "might" "never" "die" "But" "as" "the" "riper" "should" "by" … ] (1×276 string) NumDocuments: 4
bagOfWords
bagOfNgrams
入力の bag-of-words モデルまたは bag-of-n-grams モデル。bagOfWords オブジェクトまたは bagOfNgrams オブジェクトとして指定します。
tokenizedDocument
入力文書。tokenizedDocument 配列、単語の string 配列、または文字ベクトルの cell 配列として指定します。documents は、tokenizedDocument 配列でない場合、各要素が単語である単一の文書を表す行ベクトルでなければなりません。複数の文書を指定するには、tokenizedDocument 配列を使用します。
出力モデル。bagOfWords オブジェクトまたは bagOfNgrams オブジェクトとして返されます。newBag の型は bag の型と同じです。
R2017b で導入
bagOfWords | bagOfNgrams | removeDocument | removeEmptyDocuments | tokenizedDocument
removeDocument
removeEmptyDocuments
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
ヨーロッパ
アジア太平洋地域
最寄りの営業オフィスへのお問い合わせ