Main Content

docfun

문서의 단어에 함수 적용

설명

예제

newDocuments = docfun(func,documents)는 함수 핸들 func로 지정되는 함수를 호출하고 documents의 요소를 단어로 구성된 string형 벡터 형태로 전달합니다.

  • func가 정확히 한 개의 입력 인수를 받는 경우 func(string(documents(i)))의 출력값이 newDocuments(i)의 단어가 됩니다.

  • func가 두 개의 입력 인수를 받는 경우 func(string(documents(i)),details)의 출력값이 newDocuments(i)의 단어가 됩니다. 여기서 details에는 tokenDetails에 의해 출력된 해당 토큰 세부 정보가 들어 있습니다.

  • func가 문서의 단어 개수를 변경하는 경우 docfun은 그 문서에서 토큰 세부 정보를 제거합니다.

docfun은 함수 func에 대한 호출을 특정 순서로 수행하지 않습니다.

예제

newDocuments = docfun(func,documents1,...,documentsN)은 함수 핸들 func로 지정되는 함수를 호출한 후 documents1,…,documentsN의 요소를 단어로 구성된 string형 벡터 형태로 전달합니다. 여기서 N은 함수 func에 대한 입력값 개수입니다. func(string(documents1(i)),...,string(documentsN(i)))의 출력값이 newDocuments(i)의 단어가 됩니다.

documents1,…,documentsN 각각은 크기가 동일해야 합니다.

예제

모두 축소

reverse를 문서 배열의 각 단어에 적용합니다.

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

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

func = @reverse;
newDocuments = docfun(func,documents)
newDocuments = 
  2x1 tokenizedDocument:

    6 tokens: na elpmaxe fo a trohs ecnetnes
    4 tokens: a dnoces trohs ecnetnes

문자열 함수 plus를 사용하여, 한 문서 배열의 단어를 다른 문서 배열의 단어와 결합해 단어에 태그를 지정할 수 있습니다.

첫 번째 tokenizedDocument 배열을 만듭니다. 문장 부호를 지우고 텍스트를 소문자로 변환합니다.

str = [ ...
    "An example of a short sentence."
    "A second short sentence."];
str = erasePunctuation(str);
str = lower(str);
documents1 = tokenizedDocument(str)
documents1 = 
  2x1 tokenizedDocument:

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

두 번째 tokenizedDocument 배열을 만듭니다. 이 문서는 documents1에서 대응되는 문서와 동일한 개수의 단어를 가집니다. documents2의 단어는 대응되는 단어의 POS(part-of-speech, 품사) 태그입니다.

documents2 = tokenizedDocument([ ...
    "_det _noun _prep _det _adj _noun"
    "_det _adj _adj _noun"])
documents2 = 
  2x1 tokenizedDocument:

    6 tokens: _det _noun _prep _det _adj _noun
    4 tokens: _det _adj _adj _noun

func = @plus;
newDocuments = docfun(func,documents1,documents2)
newDocuments = 
  2x1 tokenizedDocument:

    6 tokens: an_det example_noun of_prep a_det short_adj sentence_noun
    4 tokens: a_det second_adj short_adj sentence_noun

출력값은 문서에 직접 plus를 호출하는 것과 동일하지 않습니다.

plus(documents1,documents2)
ans = 
  2x1 tokenizedDocument:

    12 tokens: an example of a short sentence _det _noun _prep _det _adj _noun
     8 tokens: a second short sentence _det _adj _adj _noun

입력 인수

모두 축소

N개의 string형 배열을 입력값으로 받고 string형 배열을 출력하는 함수 핸들. funcstring(documents1(i)),...,string(documentsN(i))를 입력값으로 받아야 합니다.

문서의 단어에 적용할 함수 핸들. 함수의 구문은 다음 중 하나여야 합니다.

  • newWords = func(words). 여기서 words는 단일 문서의 단어로 구성된 string형 배열입니다.

  • newWords = func(words,details). 여기서 words는 단일 문서의 단어로 구성된 string형 배열이고, detailstokenDetails에 의해 주어지는 해당 토큰 세부 정보의 테이블입니다.

  • newWords = func(words1,...,wordsN). words1,...,wordsN은 단어로 구성된 string형 배열입니다.

예: @reverse

데이터형: function_handle

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

출력 인수

모두 축소

출력 문서로, tokenizedDocument 배열로 반환됩니다.

버전 내역

R2017b에 개발됨