Main Content

tokenizedDocument

텍스트 분석에 사용되는 토큰화된 문서로 구성된 배열

설명

토큰화된 문서는 텍스트 분석에 사용되는 단어의 모음(토큰이라고도 함)으로 표현되는 문서입니다.

토큰화된 문서를 사용하여 다음과 같은 작업을 수행할 수 있습니다.

  • 텍스트 내의 복합 토큰(예: 웹 주소, 이모티콘, 이모지, 해시태그)을 검출합니다.

  • removeWords 또는 removeStopWords 함수를 사용하여 불용어와 같은 단어를 제거합니다.

  • normalizeWords 함수를 사용하여 어간 추출 또는 표제어 추출 등과 같은 단어 수준의 전처리 작업을 수행합니다.

  • bagOfWordsbagOfNgrams 객체를 사용하여 단어 및 n-gram 빈도를 분석합니다.

  • addSentenceDetailsaddPartOfSpeechDetails 함수를 사용하여 문장 및 품사 세부 정보를 추가합니다.

  • addEntityDetails 함수를 사용하여 엔터티 태그를 추가합니다.

  • addDependencyDetails 함수를 사용하여 문법적 종속 관계 세부 정보를 추가합니다.

  • tokenDetails 함수를 사용하여 토큰에 대한 세부 정보를 표시합니다.

이 함수는 한국어, 영어, 일본어, 독일어 텍스트를 지원합니다. 다른 언어에서 tokenizedDocument 함수를 사용하는 방법을 알아보려면 언어 고려 사항 항목을 참조하십시오.

생성

설명

documents = tokenizedDocument는 토큰이 없는 토큰화된 스칼라 문서를 만듭니다.

예제

documents = tokenizedDocument(str)은 string형 배열의 요소를 토큰화하고 토큰화된 문서 배열을 반환합니다.

예제

documents = tokenizedDocument(str,Name,Value)는 하나 이상의 이름-값 쌍의 인수를 사용하여 옵션을 추가로 지정합니다.

입력 인수

모두 확장

입력 텍스트로, string형 배열, 문자형 벡터, 문자형 벡터로 구성된 셀형 배열 또는 string형 배열로 구성된 셀형 배열로 지정됩니다.

입력 텍스트가 아직 단어로 분할되지 않은 경우 str은 string형 배열, 문자형 벡터, 문자형 벡터로 구성된 셀형 배열 또는 string형 스칼라로 구성된 셀형 배열이어야 합니다.

예: ["an example of a short document";"a second short document"]

예: 'an example of a single document'

예: {'an example of a short document';'a second short document'}

입력 텍스트가 이미 단어로 분할된 경우 'TokenizeMethod''none'으로 지정합니다. str에 단일 문서가 포함되어 있는 경우 이는 단어로 구성된 string형 벡터, 문자형 벡터로 구성된 행 셀형 배열 또는 단어로 구성된 단일 string형 벡터가 포함된 셀형 배열이어야 합니다. str에 여러 문서가 포함되어 있는 경우 이는 string형 배열로 구성된 셀형 배열이어야 합니다.

예: ["an" "example" "document"]

예: {'an','example','document'}

예: {["an" "example" "of" "a" "short" "document"]}

예: {["an" "example" "of" "a" "short" "document"];["a" "second" "short" "document"]}

데이터형: string | char | cell

이름-값 인수

선택적 인수 쌍을 Name1=Value1,...,NameN=ValueN으로 지정합니다. 여기서 Name은 인수 이름이고 Value는 대응값입니다. 이름-값 인수는 다른 인수 뒤에 와야 하지만, 인수 쌍의 순서는 상관없습니다.

R2021a 이전 릴리스에서는 각 이름과 값을 쉼표로 구분하고 Name을 따옴표로 묶으십시오.

예: 'DetectPatterns',{'email-address','web-address'}는 이메일 주소와 웹 주소를 검출합니다.

문서를 토큰화하는 방법으로, 'TokenizeMethod'와 함께 다음 중 하나가 쉼표로 구분되어 지정됩니다.

  • 'unicode' – Unicode® Standard Annex #29[1] 및 ICU 토큰 추출기[2]에 기반한 규칙을 사용하여 입력 텍스트를 토큰화합니다. str이 셀형 배열인 경우 str의 요소는 string형 스칼라 또는 문자형 벡터여야 합니다. 'Language''en' 또는 'de'인 경우 'unicode'가 디폴트 값입니다.

  • 'mecab' – MeCab 토큰 추출기[3]를 사용하여 한국어와 일본어 텍스트를 토큰화합니다. 'Language''ko' 또는 'ja'인 경우 'mecab'이 디폴트 값입니다.

  • mecabOptions 객체 – mecabOptions 객체에 의해 지정된 MeCab 옵션을 사용하여 한국어와 일본어 텍스트를 토큰화합니다.

  • 'none' – 입력 텍스트를 토큰화하지 않습니다.

입력 텍스트가 이미 단어로 분할된 경우 'TokenizeMethod''none'으로 지정합니다. str에 단일 문서가 포함되어 있는 경우 이는 단어로 구성된 string형 벡터, 문자형 벡터로 구성된 행 셀형 배열 또는 단어로 구성된 단일 string형 벡터가 포함된 셀형 배열이어야 합니다. str에 여러 문서가 포함되어 있는 경우 이는 string형 배열로 구성된 셀형 배열이어야 합니다.

검출할 복합 토큰의 패턴으로, 'DetectPatterns'와 함께 'none', 'all' 또는 다음 중 하나 이상이 포함된 문자열 또는 셀형 배열이 쉼표로 구분되어 지정됩니다.

  • 'email-address' – 이메일 주소를 검출합니다. 예를 들어 "user@domain.com"을 단일 토큰으로 처리합니다.

  • 'web-address' – 웹 주소를 검출합니다. 예를 들어 "https://www.mathworks.com"을 단일 토큰으로 처리합니다.

  • 'hashtag' – 해시태그를 검출합니다. 예를 들어 "#MATLAB"을 단일 토큰으로 처리합니다.

  • 'at-mention' – at-멘션을 검출합니다. 예를 들어 "@MathWorks"를 단일 토큰으로 처리합니다.

  • 'emoticon' – 이모티콘을 검출합니다. 예를 들어 ":-D"를 단일 토큰으로 처리합니다.

DetectPatterns'none'인 경우 함수는 복합 토큰 패턴을 검출하지 않습니다. DetectPatterns'all'인 경우 함수는 나열된 모든 복합 토큰 패턴을 검출합니다.

예: 'DetectPatterns','hashtag'

예: 'DetectPatterns',{'email-address','web-address'}

데이터형: char | string | cell

검출할 사용자 지정 토큰으로, 'CustomTokens'와 함께 다음 중 하나가 쉼표로 구분되어 지정됩니다.

  • 사용자 지정 토큰을 포함하는 string형 배열, 문자형 벡터 또는 문자형 벡터로 구성된 셀형 배열.

  • Token 열에 사용자 지정 토큰이 포함되고 Type 열에 해당 토큰 유형이 포함된 테이블.

사용자 지정 토큰을 string형 배열, 문자형 벡터 또는 문자형 벡터로 구성된 셀형 배열로 지정하는 경우 이 함수는 토큰 유형 "custom"을 할당합니다. 사용자 지정 토큰 유형을 지정하려면 테이블 입력을 사용하십시오. 토큰 유형을 표시하려면 tokenDetails 함수를 사용하십시오.

예: 'CustomTokens',["C++" "C#"]

데이터형: char | string | table | cell

검출할 정규 표현식으로, 'RegularExpressions'와 함께 다음 중 하나가 쉼표로 구분되어 지정됩니다.

  • 정규 표현식을 포함하는 string형 배열, 문자형 벡터 또는 문자형 벡터로 구성된 셀형 배열.

  • Pattern 열에 정규 표현식이 포함되고 Type 열에 해당 토큰 유형이 포함된 테이블.

정규 표현식을 string형 배열, 문자형 벡터 또는 문자형 벡터로 구성된 셀형 배열로 지정하는 경우 이 함수는 토큰 유형 "custom"을 할당합니다. 사용자 지정 토큰 유형을 지정하려면 테이블 입력을 사용하십시오. 토큰 유형을 표시하려면 tokenDetails 함수를 사용하십시오.

예: 'RegularExpressions',["ver:\d+" "rev:\d+"]

데이터형: char | string | table | cell

웹 주소 검출에 사용할 최상위 도메인으로, 'TopLevelDomains'와 함께 문자형 벡터, string형 배열 또는 문자형 벡터로 구성된 셀형 배열이 쉼표로 구분되어 지정됩니다. 기본적으로 이 함수는 topLevelDomains의 출력값을 사용합니다.

이 옵션은 'DetectPatterns''all'이거나 'web-address'를 포함하는 경우에만 적용됩니다.

예: 'TopLevelDomains',["com" "net" "org"]

데이터형: char | string | cell

언어로, 'Language'와 함께 다음 중 하나가 쉼표로 구분되어 지정됩니다.

  • 'en' – 영어. 또한 이 옵션은 'TokenizeMethod'에 대한 디폴트 값을 'unicode'로 설정합니다.

  • 'ja' – 일본어. 또한 이 옵션은 'TokenizeMethod'에 대한 디폴트 값을 'mecab'으로 설정합니다.

  • 'de' – 독일어. 또한 이 옵션은 'TokenizeMethod'에 대한 디폴트 값을 'unicode'로 설정합니다.

  • 'ko' – 한국어. 또한 이 옵션은 'TokenizeMethod'에 대한 디폴트 값을 'mecab'으로 설정합니다.

값을 지정하지 않은 경우 이 함수는 corpusLanguage 함수를 사용하여 입력 텍스트에서 언어를 검출합니다.

이 옵션은 토큰의 언어 세부 정보를 지정합니다. 토큰의 언어 세부 정보를 보려면 tokenDetails를 사용하십시오. 이러한 언어 세부 정보에 따라 토큰에서 removeStopWords, addPartOfSpeechDetails, normalizeWords, addSentenceDetailsaddEntityDetails 함수의 동작이 달라집니다.

Text Analytics Toolbox™의 언어 지원에 대한 자세한 내용은 언어 고려 사항 항목을 참조하십시오.

예: 'Language','ja'

속성

모두 확장

문서 내 고유한 단어로, string형 배열로 지정됩니다. 단어가 특정 순서로 나타나지는 않습니다.

데이터형: string

객체 함수

모두 확장

erasePunctuation텍스트 및 문서에서 문장 부호 지우기
removeStopWords문서에서 불용어 제거
removeWords문서 또는 bag-of-words 모델에서 선택한 단어 제거
normalizeWords단어의 어간 또는 표제어 추출
correctSpellingCorrect spelling of words
replaceWords문서 내 단어 바꾸기
replaceNgrams문서 내 n-gram 바꾸기
removeEmptyDocuments토큰화된 문서 배열, bag-of-words 모델 또는 bag-of-n-grams 모델에서 빈 문서 제거
lower문서를 소문자로 변환
upper문서를 대문자로 변환
tokenDetails토큰화된 문서 배열 내 토큰의 세부 정보
addSentenceDetails문서에 문장 번호 추가
addPartOfSpeechDetails문서에 품사 태그 추가
addLanguageDetails문서에 언어 식별자 추가
addTypeDetails문서에 토큰 유형 세부 정보 추가
addLemmaDetails문서에 토큰의 표제어 형태 추가
addEntityDetails문서에 엔터티 태그 추가
addDependencyDetailsAdd grammatical dependency details to documents
writeTextDocument텍스트 파일에 문서 쓰기
doclength문서 배열에 포함된 문서의 길이
context문맥 내의 단어 또는 n-gram이 나오는 경우를 문서에서 검색
contains패턴이 문서 내 부분문자열에서 일치하는지 검사
containsWords단어가 문서에 포함되었는지 검사
containsNgramsn-gram이 문서에 포함되었는지 검사
splitSentences텍스트를 문장으로 분할
joinWords단어를 결합하여 문서를 문자열로 변환
doc2cell문서를 string형 벡터로 구성된 셀형 배열로 변환
string스칼라 문서를 string형 벡터로 변환
plus문서 추가
replace문서 내 부분문자열 바꾸기
docfun문서의 단어에 함수 적용
regexprepReplace text in words of documents using regular expression
wordcloud텍스트, bag-of-words 모델, bag-of-n-grams 모델 또는 LDA 모델에서 워드 클라우드 차트 만들기
sentenceChartPlot grammatical dependency parse tree of sentence

예제

모두 축소

string형 배열에서 토큰화된 문서를 만듭니다.

str = [
    "an example of a short sentence" 
    "a second short sentence"]
str = 2x1 string
    "an example of a short sentence"
    "a second short sentence"

documents = tokenizedDocument(str)
documents = 
  2x1 tokenizedDocument:

    6 tokens: an example of a short sentence
    4 tokens: a second short sentence

문자열 str에서 토큰화된 문서를 만듭니다. 기본적으로 이 함수는 해시태그 "#MATLAB", 이모티콘 ":-D", 웹 주소 "https://www.mathworks.com/help"를 단일 토큰으로 처리합니다.

str = "Learn how to analyze text in #MATLAB! :-D see https://www.mathworks.com/help/";
document = tokenizedDocument(str)
document = 
  tokenizedDocument:

   11 tokens: Learn how to analyze text in #MATLAB ! :-D see https://www.mathworks.com/help/

해시태그만 복합 토큰으로 검출하려면 'DetectPatterns' 옵션을 'hashtag'로만 지정합니다. 그러면 이 함수는 이모티콘 ":-D" 및 웹 주소 "https://www.mathworks.com/help"를 여러 토큰으로 토큰화합니다.

document = tokenizedDocument(str,'DetectPatterns','hashtag')
document = 
  tokenizedDocument:

   24 tokens: Learn how to analyze text in #MATLAB ! : - D see https : / / www . mathworks . com / help /

문서로 구성된 배열에서 removeStopWords를 사용하여 불용어를 제거합니다. tokenizedDocument 함수는 문서가 영어인 것을 검출하며 따라서 removeStopWords는 영어 불용어를 제거합니다.

documents = tokenizedDocument([
    "an example of a short sentence" 
    "a second short sentence"]);
newDocuments = removeStopWords(documents)
newDocuments = 
  2x1 tokenizedDocument:

    3 tokens: example short sentence
    3 tokens: second short sentence

Porter 어간 추출기를 사용하여 문서 배열 내 단어의 어간을 추출합니다.

documents = tokenizedDocument([
    "a strongly worded collection of words"
    "another collection of words"]);
newDocuments = normalizeWords(documents)
newDocuments = 
  2x1 tokenizedDocument:

    6 tokens: a strongli word collect of word
    4 tokens: anoth collect of word

기본적으로 tokenizedDocument 함수는 기호가 포함된 토큰과 단어를 분할합니다. 예를 들어 이 함수는 "C++"와 "C#"을 여러 토큰으로 분할합니다.

str = "I am experienced in MATLAB, C++, and C#.";
documents = tokenizedDocument(str)
documents = 
  tokenizedDocument:

   14 tokens: I am experienced in MATLAB , C + + , and C # .

기호가 포함된 토큰을 함수가 분할하지 않도록 하려면 'CustomTokens' 옵션을 사용하여 사용자 지정 토큰을 지정합니다.

documents = tokenizedDocument(str,'CustomTokens',["C++" "C#"])
documents = 
  tokenizedDocument:

   11 tokens: I am experienced in MATLAB , C++ , and C# .

사용자 지정 토큰의 토큰 유형은 "custom"입니다. 토큰 세부 정보를 표시합니다. Type 열에는 토큰 유형이 포함됩니다.

tdetails = tokenDetails(documents)
tdetails=11×5 table
        Token        DocumentNumber    LineNumber       Type        Language
    _____________    ______________    __________    ___________    ________

    "I"                    1               1         letters           en   
    "am"                   1               1         letters           en   
    "experienced"          1               1         letters           en   
    "in"                   1               1         letters           en   
    "MATLAB"               1               1         letters           en   
    ","                    1               1         punctuation       en   
    "C++"                  1               1         custom            en   
    ","                    1               1         punctuation       en   
    "and"                  1               1         letters           en   
    "C#"                   1               1         custom            en   
    "."                    1               1         punctuation       en   

고유한 토큰 유형을 지정하려면 Token 열에는 토큰이 포함되고 Type 열에는 유형이 포함된 사용자 지정 토큰을 테이블로 입력합니다. 기호가 포함되지 않은 토큰에 사용자 지정 유형을 할당하기 위해 테이블에도 포함시킵니다. 예를 들어 "MATLAB", "C++" 및 "C#"을 "programming-language" 토큰 유형에 할당할 테이블을 만드십시오.

T = table;
T.Token = ["MATLAB" "C++" "C#"]';
T.Type = ["programming-language" "programming-language" "programming-language"]'
T=3×2 table
     Token               Type         
    ________    ______________________

    "MATLAB"    "programming-language"
    "C++"       "programming-language"
    "C#"        "programming-language"

사용자 지정 토큰 테이블을 사용하여 텍스트를 토큰화하고 토큰 세부 정보를 표시합니다.

documents = tokenizedDocument(str,'CustomTokens',T);
tdetails = tokenDetails(documents)
tdetails=11×5 table
        Token        DocumentNumber    LineNumber            Type            Language
    _____________    ______________    __________    ____________________    ________

    "I"                    1               1         letters                    en   
    "am"                   1               1         letters                    en   
    "experienced"          1               1         letters                    en   
    "in"                   1               1         letters                    en   
    "MATLAB"               1               1         programming-language       en   
    ","                    1               1         punctuation                en   
    "C++"                  1               1         programming-language       en   
    ","                    1               1         punctuation                en   
    "and"                  1               1         letters                    en   
    "C#"                   1               1         programming-language       en   
    "."                    1               1         punctuation                en   

tokenizedDocument 함수는 기본적으로 기호가 포함된 토큰과 단어를 분할합니다. 예를 들어 이 함수는 "ver:2" 텍스트를 여러 토큰으로 분할합니다.

str = "Upgraded to ver:2 rev:3.";
documents = tokenizedDocument(str)
documents = 
  tokenizedDocument:

   9 tokens: Upgraded to ver : 2 rev : 3 .

함수가 특정 패턴이 있는 토큰을 분할하지 않도록 하려면 'RegularExpressions' 옵션을 사용하여 해당 패턴을 지정합니다.

버전 및 개정 번호(각각 "ver:""rev:" 뒤에 오는 숫자 문자열)를 나타내는 토큰을 검출하기 위한 정규 표현식을 지정합니다.

documents = tokenizedDocument(str,'RegularExpressions',["ver:\d+" "rev:\d+"])
documents = 
  tokenizedDocument:

   5 tokens: Upgraded to ver:2 rev:3 .

기본적으로 사용자 지정 토큰의 토큰 유형은 "custom"입니다. 토큰 세부 정보를 표시합니다. Type 열에는 토큰 유형이 포함됩니다.

tdetails = tokenDetails(documents)
tdetails=5×5 table
      Token       DocumentNumber    LineNumber       Type        Language
    __________    ______________    __________    ___________    ________

    "Upgraded"          1               1         letters           en   
    "to"                1               1         letters           en   
    "ver:2"             1               1         custom            en   
    "rev:3"             1               1         custom            en   
    "."                 1               1         punctuation       en   

고유한 토큰 유형을 지정하려면 Pattern 열에는 정규 표현식이 포함되고 Type 열에는 토큰 유형이 포함된 정규 표현식을 테이블로 입력합니다.

T = table;
T.Pattern = ["ver:\d+" "rev:\d+"]';
T.Type = ["version" "revision"]'
T=2×2 table
     Pattern        Type   
    _________    __________

    "ver:\d+"    "version" 
    "rev:\d+"    "revision"

사용자 지정 토큰 테이블을 사용하여 텍스트를 토큰화하고 토큰 세부 정보를 표시합니다.

documents = tokenizedDocument(str,'RegularExpressions',T);
tdetails = tokenDetails(documents)
tdetails=5×5 table
      Token       DocumentNumber    LineNumber       Type        Language
    __________    ______________    __________    ___________    ________

    "Upgraded"          1               1         letters           en   
    "to"                1               1         letters           en   
    "ver:2"             1               1         version           en   
    "rev:3"             1               1         revision          en   
    "."                 1               1         punctuation       en   

예제 데이터를 불러옵니다. 파일 sonnetsPreprocessed.txt에는 셰익스피어 소네트의 전처리된 버전이 들어 있습니다. 파일에는 한 줄에 하나씩 소네트가 들어 있으며 단어가 공백으로 구분되어 있습니다. sonnetsPreprocessed.txt에서 텍스트를 추출하고, 추출한 텍스트를 새 줄 문자에서 문서로 분할한 후 그 문서를 토큰화합니다.

filename = "sonnetsPreprocessed.txt";
str = extractFileText(filename);
textData = split(str,newline);
documents = tokenizedDocument(textData);

단어 "life"를 검색합니다.

tbl = context(documents,"life");
head(tbl)
                            Context                             Document    Word
    ________________________________________________________    ________    ____

    "consumst thy self single life ah thou issueless shalt "        9        10 
    "ainted counterfeit lines life life repair times pencil"       16        35 
    "d counterfeit lines life life repair times pencil pupi"       16        36 
    " heaven knows tomb hides life shows half parts write b"       17        14 
    "he eyes long lives gives life thee                    "       18        69 
    "tender embassy love thee life made four two alone sink"       45        23 
    "ves beauty though lovers life beauty shall black lines"       63        50 
    "s shorn away live second life second head ere beautys "       68        27 

해당 단어를 string형 배열로 표시합니다.

tbl.Context
ans = 23x1 string
    "consumst thy self single life ah thou issueless shalt "
    "ainted counterfeit lines life life repair times pencil"
    "d counterfeit lines life life repair times pencil pupi"
    " heaven knows tomb hides life shows half parts write b"
    "he eyes long lives gives life thee                    "
    "tender embassy love thee life made four two alone sink"
    "ves beauty though lovers life beauty shall black lines"
    "s shorn away live second life second head ere beautys "
    "e rehearse let love even life decay lest wise world lo"
    "st bail shall carry away life hath line interest memor"
    "art thou hast lost dregs life prey worms body dead cow"
    "           thoughts food life sweetseasond showers gro"
    "tten name hence immortal life shall though once gone w"
    " beauty mute others give life bring tomb lives life fa"
    "ve life bring tomb lives life fair eyes poets praise d"
    " steal thyself away term life thou art assured mine li"
    "fe thou art assured mine life longer thy love stay dep"
    " fear worst wrongs least life hath end better state be"
    "anst vex inconstant mind life thy revolt doth lie o ha"
    " fame faster time wastes life thou preventst scythe cr"
    "ess harmful deeds better life provide public means pub"
    "ate hate away threw savd life saying                  "
    " many nymphs vowd chaste life keep came tripping maide"

tokenizedDocument를 사용하여 일본어 텍스트를 토큰화합니다. 이 함수는 일본어 텍스트를 자동으로 검출합니다.

str = [
    "恋に悩み、苦しむ。"
    "恋の悩みで苦しむ。"
    "空に星が輝き、瞬いている。"
    "空の星が輝きを増している。"];
documents = tokenizedDocument(str)
documents = 
  4x1 tokenizedDocument:

     6 tokens: 恋 に 悩み 、 苦しむ 。
     6 tokens: 恋 の 悩み で 苦しむ 。
    10 tokens: 空 に 星 が 輝き 、 瞬い て いる 。
    10 tokens: 空 の 星 が 輝き を 増し て いる 。

tokenizedDocument를 사용하여 독일어 텍스트를 토큰화합니다. 이 함수는 독일어 텍스트를 자동으로 검출합니다.

str = [
    "Guten Morgen. Wie geht es dir?"
    "Heute wird ein guter Tag."];
documents = tokenizedDocument(str)
documents = 
  2x1 tokenizedDocument:

    8 tokens: Guten Morgen . Wie geht es dir ?
    6 tokens: Heute wird ein guter Tag .

세부 정보

모두 확장

참고 문헌

[1] Unicode Text Segmentation. https://www.unicode.org/reports/tr29/

[3] MeCab: Yet Another Part-of-Speech and Morphological Analyzer. https://taku910.github.io/mecab/

버전 내역

R2017b에 개발됨

모두 확장