Main Content

context

문맥 내의 단어 또는 n-gram이 나오는 경우를 문서에서 검색

설명

예제

T = context(documents,word)documents에서 한 단어가 나오는 경우를 검색하고 위치와 함께 해당 word를 문맥 내에서 보여주는 테이블을 반환합니다. 이 함수는 기본적으로 대/소문자를 구분합니다.

예제

T = context(documents,ngram)documents에 나오는 n-gram을 검색합니다. 이 함수는 기본적으로 대/소문자를 구분합니다.

예제

T = context(___,contextLength)는 위에 열거된 구문 중 하나를 사용하여 반환할 문맥의 길이를 지정합니다.

예제

T = context(___,Name,Value)는 위에 열거된 구문 중 하나를 사용하여 하나 이상의 이름-값 쌍의 인수를 사용해 옵션을 추가로 지정합니다.

예제

모두 축소

예제 데이터를 불러옵니다. 파일 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"

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

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

바이그램 "dost thou"를 검색합니다.

ngram = ["dost" "thou"];
tbl = context(documents,ngram);
head(tbl)
                               Context                               Document      Word  
    _____________________________________________________________    ________    ________

    "unthrifty loveliness why dost thou spend upon thy self thy "        4        4     5
    "ee beauteous niggard why dost thou abuse bounteous largess "        4       25    26
    "ve profitless usurer why dost thou great sum sums yet canst"        4       35    36
    "eavy eyelids weary night dost thou desire slumbers broken s"       61       10    11
    "            sweet lovely dost thou make shame like canker f"       95        3     4
    "hy budding name o sweets dost thou thy sins enclose tongue "       95       19    20
    "ruth beauty love depends dost thou therein dignified make a"      101       16    17
    "    thou blind fool love dost thou mine eyes behold know be"      137        5     6

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

tbl.Context
ans = 10x1 string
    "unthrifty loveliness why dost thou spend upon thy self thy "
    "ee beauteous niggard why dost thou abuse bounteous largess "
    "ve profitless usurer why dost thou great sum sums yet canst"
    "eavy eyelids weary night dost thou desire slumbers broken s"
    "            sweet lovely dost thou make shame like canker f"
    "hy budding name o sweets dost thou thy sins enclose tongue "
    "ruth beauty love depends dost thou therein dignified make a"
    "    thou blind fool love dost thou mine eyes behold know be"
    "h rebel powers array why dost thou pine suffer dearth paint"
    "y large cost short lease dost thou upon thy fading mansion "

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

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

단어 "life"를 검색하고 이 단어 앞뒤의 문맥 15자와 함께 각 단어를 반환합니다.

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

    "hy self single life ah thou issuel"        9        10 
    "nterfeit lines life life repair ti"       16        35 
    "eit lines life life repair times p"       16        36 
    "ows tomb hides life shows half par"       17        14 
    "ng lives gives life thee          "       18        69 
    "assy love thee life made four two "       45        23 
    " though lovers life beauty shall b"       63        50 
    "ay live second life second head er"       68        27 

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

tbl.Context
ans = 23x1 string
    "hy self single life ah thou issuel"
    "nterfeit lines life life repair ti"
    "eit lines life life repair times p"
    "ows tomb hides life shows half par"
    "ng lives gives life thee          "
    "assy love thee life made four two "
    " though lovers life beauty shall b"
    "ay live second life second head er"
    " let love even life decay lest wis"
    "all carry away life hath line inte"
    "ast lost dregs life prey worms bod"
    " thoughts food life sweetseasond s"
    "hence immortal life shall though o"
    "te others give life bring tomb liv"
    "ing tomb lives life fair eyes poet"
    "self away term life thou art assur"
    "t assured mine life longer thy lov"
    "t wrongs least life hath end bette"
    "nconstant mind life thy revolt dot"
    "er time wastes life thou preventst"
    "l deeds better life provide public"
    "way threw savd life saying        "
    "hs vowd chaste life keep came trip"

문맥을 표시할 소스 텍스트를 지정합니다.

sonnets.txt 데이터를 불러오고 이를 별도의 문서로 분할합니다.

txt = extractFileText("sonnets.txt");
paragraphs = split(txt,[newline newline]);

paragraphs에서 소네트를 추출합니다. 첫 번째 소네트는 단락의 다섯 번째 요소이며 나머지 소네트는 이후 두 번째 요소마다 나옵니다.

sonnets = paragraphs(5:2:end);
documents = tokenizedDocument(sonnets);

텍스트를 정규화한 다음 단어 "life"를 검색합니다.

documentsNormalized = normalizeWords(documents);
T = context(documentsNormalized,"life")
T=23×3 table
                            Context                             Document    Word
    ________________________________________________________    ________    ____

    "sum'st thy self in singl life ? ah ! if thou issueless"        9        18 
    " : so should the line of life that life repair , which"       16        73 
    "ld the line of life that life repair , which thi , tim"       16        75 
    "s a tomb which hide your life , and show not half your"       17        34 
    " live thi , and thi give life to thee .               "       18       128 
    "ssi of love to thee , my life , be made of four , with"       45        53 
    "eauti , though my lover' life : hi beauti shall in the"       63       100 
    " awai , to live a second life on second head ; er beau"       68        59 
    "t your love even with my life decai ; lest the wise wo"       71       118 
    "shall carri me awai , my life hath in thi line some in"       74        18 
    "ast but lost the dreg of life , the prei of worm , my "       74        83 
    "to my thought as food to life , or as sweet-season'd s"       75        10 
    "ur name from henc immort life shall have , though i , "       81        42 
    " , when other would give life , and bring a tomb . the"       83       108 
    "a tomb . there live more life in on of your fair ey th"       83       118 
    "yself awai , for term of life thou art assur mine ; an"       92        13 
      ⋮

단어가 정규화되므로 문맥을 읽기가 쉽지 않을 수 있습니다. 원래 텍스트 데이터를 사용해 문맥을 보려면 'Source' 옵션을 사용하여 소스 텍스트를 지정합니다.

T = context(documentsNormalized,"life",'Source',sonnets)
T=23×3 table
                            Context                             Document    Word
    ________________________________________________________    ________    ____

    "um'st thy self in single life? Ah! if thou issueless s"        9        18 
    ": So should the lines of life that life repair, Which "       16        73 
    "d the lines of life that life repair, Which this, Time"       16        75 
    " a tomb Which hides your life, and shows not half your"       17        34 
    "ves this, and this gives life to thee.                "       18       128 
    "assy of love to thee, My life, being made of four, wit"       45        53 
    "eauty, though my lover's life: His beauty shall in the"       63       100 
    "n away, To live a second life on second head; Ere beau"       68        59 
    "t your love even with my life decay; Lest the wise wor"       71       118 
    " shall carry me away, My life hath in this line some i"       74        18 
    "st but lost the dregs of life, The prey of worms, my b"       74        83 
    "o my thoughts as food to life, Or as sweet-season'd sh"       75        10 
    "name from hence immortal life shall have, Though I, on"       81        42 
    ", When others would give life, and bring a tomb. There"       83       108 
    "a tomb. There lives more life in one of your fair eyes"       83       118 
    "hyself away, For term of life thou art assured mine; A"       92        13 
      ⋮

입력 인수

모두 축소

입력 문서로, tokenizedDocument 배열로 지정됩니다.

문맥에서 찾을 단어로, string형 스칼라, 문자형 벡터 또는 문자형 벡터를 포함하는 스칼라 셀형 배열로 지정됩니다.

데이터형: char | string | cell

문맥에서 찾을 n-gram으로, string형 배열 또는 문자형 벡터로 구성된 셀형 배열로 지정됩니다.

ngram의 크기는 1×N입니다. 여기서 N은 n-gram의 단어 개수입니다. ngram(j)의 값은 n-gram 중 j번째 단어입니다.

이 함수는 ngram의 후행 빈 문자열을 무시합니다.

데이터형: string | cell

문맥 길이로, 양의 정수로 지정됩니다.

이름-값 인수

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

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

예: 'Solver','avb'는 근사 변분 베이즈를 솔버로 사용하도록 지정합니다.

소스 텍스트로, 'Source'와 함께 string형 배열 또는 문자형 벡터로 구성된 셀형 배열이 쉼표로 구분되어 지정됩니다. 입력 문서가 전처리되었고 소스 텍스트를 가지고 있는 경우 이 옵션을 사용하면 더 읽기 쉽게 출력할 수 있습니다.

소스 텍스트는 documents와 크기가 동일해야 합니다.

대/소문자를 무시하는 옵션으로, 'IgnoreCase'와 함께 다음 중 하나가 쉼표로 구분되어 지정됩니다.

  • false – 해당 단어 또는 n-gram과 정확히 일치하는 단어를 검색합니다.

  • true – 대/소문자를 무시한 채 해당 단어 또는 n-gram과 일치하는 단어를 검색합니다.

출력 인수

모두 축소

문맥 테이블에는 다음과 같은 열이 있습니다.

Context문맥에서 쿼리된 단어 또는 n-gram을 포함하는 문자열
Document단어 또는 n-gram을 포함하는 문서의 숫자형 인덱스
Word문서 내 단어 또는 n-gram의 숫자형 인덱스

버전 내역

R2017b에 개발됨