メインコンテンツ

splitSentences

テキストから文への分割

説明

newStr = splitSentences(str) は、str を文の配列に分割します。

newDocuments = splitSentences(document) は、単一の tokenizedDocument オブジェクトを文の tokenizedDocument 配列に分割します。

すべて折りたたむ

例のファイル sonnets.txt からテキストを読み取り、文に分割します。

filename = "sonnets.txt";
str = extractFileText(filename);
sentences = splitSentences(str);

最初のいくつかの文を表示します。

sentences(1:10)
ans = 10×1 string
    "THE SONNETS"
    "by William Shakespeare"
    "I"
    "From fairest creatures we desire increase,↵That thereby beauty's rose might never die,↵But as the riper should by time decease,↵His tender heir might bear his memory:↵But thou, contracted to thine own bright eyes,↵Feed'st thy light's flame with self-substantial fuel,↵Making a famine where abundance lies,↵Thy self thy foe, to thy sweet self too cruel:↵Thou that art now the world's fresh ornament,↵And only herald to the gaudy spring,↵Within thine own bud buriest thy content,↵And tender churl mak'st waste in niggarding:↵Pity the world, or else this glutton be,↵To eat the world's due, by the grave and thee."
    "II"
    "When forty winters shall besiege thy brow,↵And dig deep trenches in thy beauty's field,↵Thy youth's proud livery so gazed on now,↵Will be a tatter'd weed of small worth held:↵Then being asked, where all thy beauty lies,↵Where all the treasure of thy lusty days;↵To say, within thine own deep sunken eyes,↵Were an all-eating shame, and thriftless praise."
    "How much more praise deserv'd thy beauty's use,↵If thou couldst answer 'This fair child of mine↵Shall sum my count, and make my old excuse,'↵Proving his beauty by succession thine!"
    "This were to be new made when thou art old,↵And see thy blood warm when thou feel'st it cold."
    "III"
    "Look in thy glass and tell the face thou viewest↵Now is the time that face should form another;↵Whose fresh repair if now thou not renewest,↵Thou dost beguile the world, unbless some mother."

入力引数

すべて折りたたむ

入力テキスト。string スカラー、文字ベクトル、または文字ベクトルを含むスカラー cell 配列として指定します。

データ型: string | char | cell

入力文書。スカラー tokenizedDocument オブジェクトとして指定します。

出力引数

すべて折りたたむ

出力テキスト。string 配列、または文字ベクトルの cell 配列として返されます。

str が string の場合、newStr は string になります。それ以外の場合、newStr は文字ベクトルの cell 配列になります。

データ型: string | cell

出力文書。tokenizedDocument 配列として返されます。

アルゴリズム

句点の後に顔文字または絵文字が現れる場合、この関数は顔文字や絵文字の後で文を分割します。

バージョン履歴

R2018a で導入