メインコンテンツ

removeDocument

R2026b

bag-of-words モデルまたは bag-of-n-grams モデルから文書を削除する

説明

newBag = removeDocument(bag,idx) は、idx によって指定されたインデックスをもつ文書を bag-of-words モデルまたは bag-of-n-grams モデル bag から削除します。削除された文書に、残りの文書には出現しない単語または n-gram が含まれている場合、この関数はこれらの単語または n-gram も bag から削除します。

例

例

すべて折りたたむ

選択した文書を bag-of-words モデルから削除します。

documents = tokenizedDocument([ ...
    "an example of a short sentence" 
    "a second short sentence"
    "a third example"
    "a final sentence"]);
bag = bagOfWords(documents)
bag = 
  bagOfWords with properties:

        NumWords: 9
          Counts: [4×9 double]
      Vocabulary: ["an"    "example"    "of"    "a"    "short"    "sentence"    "second"    "third"    "final"]
    NumDocuments: 4

1 番目と 3 番目の文書を bag から削除します。

idx = [1 3];
newBag = removeDocument(bag,idx)
newBag = 
  bagOfWords with properties:

        NumWords: 5
          Counts: [2×5 double]
      Vocabulary: ["a"    "short"    "sentence"    "second"    "final"]
    NumDocuments: 2

logical インデックスを使用して、同じ文書を削除します。

idx = logical([1 0 1 0]);
newBag = removeDocument(bag,idx)
newBag = 
  bagOfWords with properties:

        NumWords: 5
          Counts: [2×5 double]
      Vocabulary: ["a"    "short"    "sentence"    "second"    "final"]
    NumDocuments: 2

入力引数

すべて折りたたむ

入力の bag-of-words モデルまたは bag-of-n-grams モデル。bagOfWords オブジェクトまたは bagOfNgrams オブジェクトとして指定します。

削除する文書のインデックス。数値インデックスのベクトルまたは logical インデックスのベクトルとして指定します。

例: [2 4 6]

例: [0 1 0 1 0 1]

出力引数

すべて折りたたむ

出力モデル。bagOfWords オブジェクトまたは bagOfNgrams オブジェクトとして返されます。newBag の型は bag の型と同じです。

バージョン履歴

R2017b で導入