Main Content

이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.

addDocument

bag-of-words 모델 또는 bag-of-n-grams 모델에 문서 추가

설명

예제

newBag = addDocument(bag,documents)documents를 bag-of-words 모델 또는 bag-of-n-grams 모델 bag에 추가합니다.

예제

모두 축소

토큰화된 문서로 구성된 배열에서 bag-of-words 모델을 만듭니다.

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

          Counts: [2x7 double]
      Vocabulary: ["an"    "example"    "of"    "a"    "short"    "sentence"    "second"]
        NumWords: 7
    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:

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

텍스트 데이터가 한 폴더 내 여러 파일에 포함되어 있는 경우 파일 데이터저장소를 사용하여 텍스트 데이터를 MATLAB으로 가져올 수 있습니다.

예제 소네트 텍스트 파일을 위한 파일 데이터저장소를 만듭니다. 예제 소네트의 파일 이름은 "exampleSonnetN.txt"입니다. 여기서 N은 소네트 번호입니다. extractFileText를 읽기 함수로 지정합니다.

readFcn = @extractFileText;
fds = fileDatastore('exampleSonnet*.txt','ReadFcn',readFcn);

빈 bag-of-words 모델을 만듭니다.

bag = bagOfWords
bag = 
  bagOfWords with properties:

          Counts: []
      Vocabulary: [1x0 string]
        NumWords: 0
    NumDocuments: 0

루프를 사용해 데이터저장소에 있는 파일을 순회하여 각 파일을 읽어옵니다. 각 파일의 텍스트를 토큰화하고 문서를 bag에 추가합니다.

while hasdata(fds)
    str = read(fds);
    document = tokenizedDocument(str);
    bag = addDocument(bag,document);
end

업데이트된 bag-of-words 모델을 표시합니다.

bag
bag = 
  bagOfWords with properties:

          Counts: [4x276 double]
      Vocabulary: ["From"    "fairest"    "creatures"    "we"    "desire"    "increase"    ","    "That"    "thereby"    "beauty's"    "rose"    "might"    "never"    "die"    "But"    "as"    "the"    "riper"    "should"    ...    ] (1x276 string)
        NumWords: 276
    NumDocuments: 4

입력 인수

모두 축소

입력 bag-of-words 모델 또는 bag-of-n-grams 모델로, bagOfWords 객체 또는 bagOfNgrams 객체로 지정됩니다.

입력 문서로, tokenizedDocument 배열, 단어로 구성된 string형 배열 또는 문자형 벡터로 구성된 셀형 배열로 지정됩니다. documentstokenizedDocument 배열이 아닌 경우 이는 단일 문서를 나타내고 각 요소가 단어인 행 벡터여야 합니다. 문서를 여러 개 지정하려면 tokenizedDocument 배열을 사용하십시오.

출력 인수

모두 축소

출력 모델로, bagOfWords 객체 또는 bagOfNgrams 객체로 반환됩니다. newBag의 유형은 bag의 유형과 같습니다.

버전 내역

R2017b에 개발됨