MATLAB 도움말 센터
bag-of-words 모델 또는 bag-of-n-grams 모델에 문서 추가
newBag = addDocument(bag,documents)
newBag = addDocument(bag,documents)는 documents를 bag-of-words 모델 또는 bag-of-n-grams 모델 bag에 추가합니다.
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
텍스트 데이터가 한 폴더 내 여러 파일에 포함되어 있는 경우 파일 데이터저장소를 사용하여 텍스트 데이터를 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형 배열 또는 문자형 벡터로 구성된 셀형 배열로 지정됩니다. 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.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
유럽
아시아 태평양
지역별 지사에 문의