TextCases
テキストのコンテンツタイプのリスト »詳細とオプション
- TextCasesは,品詞のタグ付けや名前付き実体の認識等,いくつかの自然言語処理タスクに使われる.
- TextCases[text,…]の text は,文字列,File[…]で表されるテキストファイル,ContentObject式,あるいはこれらのテキストオブジェクトのリストでよい.
- TextCases[{text1,text2,…},…]は,各 textiの例を与える.
- 識別タイプ form には以下がある.
-
"type" 任意のテキストのコンテンツタイプ(例:"Noun","City") Entity[…,…] テキストのコンテンツタイプの特定の実体 form1|form2|… 任意の formiにマッチするフォーム Containing[outer,inner] タイプ inner を含むタイプ outer のフォーム Verbatim["string"] 厳密にマッチされる文字列 pattern マッチされる文字列パターン - 次は,特性 prop の可能な選択肢である.
-
"String" 識別されたテキスト文字列(デフォルト) "Position" text 中の文字列の始点と終点の位置 "Probability" 識別が正しいという推定の確率 "Interpretation" 識別された文字列の標準的な解釈 "Snippet" 識別された文字列周辺のスニペット "HighlightedSnippet" 識別された文字列がハイライトされた,テキストのスニペット f すべての特性を含む連想に f を適用する {prop1,prop2,…} 特性指定のリスト - 次は,使用可能なオプションである.
-
AcceptanceThreshold Automatic 識別を許容する最小確率 PerformanceGoal Automatic 特定の利点があるアルゴリズムを優先する TargetDevice "CPU" 実体検出にCPUまたはGPUの計算を使うべきかどうか VerifyInterpretation False 解釈可能性を確認するかどうか - TextCasesは機械学習を使う.含まれるメソッド,訓練集合,バイアスは使用するWolfram言語のバージョンによって変わることがあり,返される結果も異なることがある.
- TextCasesはリソースをダウンロードすることがある.ダウンロードされたリソースは,$LocalBaseのローカルなオブジェクトストアに保存され,LocalObjects[]でリストしたりResourceRemoveで削除したりできる.
例題
すべて開く すべて閉じる例 (6)
TextCases["NYC, Los Angeles, and Chicago are the largest cities in the United States of America in 2018.", "City"]TextCases["The quick brown fox jumps over the lazy dog.", "Noun"]TextCases["The shirt cost $50 in America, but only 5€ in Italy.", "CurrencyAmount" -> "Interpretation"]TextCases["NYC, Los Angeles, and Chicago are the largest cities in the United States of America in 2018.", {"City", "Country", "Date"}]TextCases["NYC, Los Angeles, and Chicago are the largest cities in the USA in 2018.", {"City", "Country", "Date"} -> {"String", "Interpretation", "Probability"}]TextCases["NYC, Los Angeles, and Chicago are the largest cities in the USA in 2018.", "Location" -> (#String -> #Interpretation&)]テキスト中の「New York City」についての言及箇所をすべて求める:
TextCases["I love New York - I ❤ NYC", Entity["City", {"NewYork", "NewYork", "UnitedStates"}]]スコープ (5)
ContentObjectとファイル (2)
ContentObject内の色の例を求める:
doc = TextSearch["ExampleData/Text", "dog"][1]TextCases[doc, "Color"]File内の数量を求める:
file = TextSearch["ExampleData/Text", "dog"][1, "Location"]TextCases[file, "Color"]代替と包含 (2)
Alternativesを使って複数のタイプをマッチさせる:
TextCases["John and Mary went to the store.", "Noun" | "Verb"]TextCases["John and Mary went to the store.", "Noun" | "ProperNoun" | "Verb"]TextCases["I have a fairly clear idea of what I will buy at the store. I want shoes, a computer, and a jacket. The computer will be the most expensive, and will cost over $1000.", Containing["Sentence", "CurrencyAmount"]]TextCases["On vacation, I first went to France, then I went to Belgium. The food was amazing in both countries.", Containing["Sentence", "Country"]]AlternativesとContainingを組み合せて高度に構造化されたクエリを作る:
TextCases["I have a fairly clear idea of what I will buy at the store. I want shoes, a computer, and a jacket. The computer will be the most expensive, and will cost over $1000. John will like my computer.", Containing["Sentence", "CurrencyAmount" | "ProperNoun"]]戻り型 (1)
TextCases["He spent $50 in Boston on the 11th July. For a shirt that costs 5€ in Rome!", "CurrencyAmount" -> {"String", "Position", "Interpretation"}]TextCases["He spent $50 in Boston on the 11th July. For a shirt that costs 5€ in Rome!", {"CurrencyAmount", "City", "Date"} -> {"String", "Position", "Interpretation"}]Associationで使用可能な全特性を示す:
TextCases["He spent $50 in Boston on the 11th July. For a shirt that costs 5€ in Rome!", "Date" -> Identity]TextCases["He spent $50 in Boston on the 11th July. For a shirt that costs 5€ in Rome!", {"CurrencyAmount", "City", "Date"} -> Identity]//DatasetTextCases["She took a plane from Toulouse in France to Montreal in Canada", "Location" -> (#String -> #Interpretation&)]オプション (3)
AcceptanceThreshold (1)
デフォルトで,検出された実体の推定確率は,すべて0.5より上である:
TextCases[ExampleData[{"Text", "JFKInaugural"}], {"Country", "Date", "Person"}]AcceptanceThresholdを高くして,ほぼ確実に正しい実体だけを得る:
TextCases[ExampleData[{"Text", "JFKInaugural"}], {"Country", "Date", "Person"}, "AcceptanceThreshold" -> 0.9]PerformanceGoal (1)
PerformanceGoal->"Speed"を使うと,確度は低くなるが,検出速度が上がる:
AbsoluteTiming@TextCases["My favourite cities are New York and Foix", "City"]AbsoluteTiming@TextCases["My favourite cities are New York and Foix", "City", PerformanceGoal -> "Speed"]VerifyInterpretation (1)
デフォルトで,実体の中には,正しくないあるいはまだ知識ベースに収録されていないという理由で解釈できないものがある.その場合は,解釈の代りに文字列が返される:
TextCases["We visited Toulouse and Foix in France.", {"City", "Country"} -> "Interpretation"]VerifyInterpretationを使って解釈できない実体を除外する:
TextCases["We visited Toulouse and Foix in Midi-Pyrénées in France.", {"City", "Country"} -> "Interpretation", VerifyInterpretation -> True]アプリケーション (6)
単語と文の分割 (2)
単語の分割は,電子メールアドレス,URL,Twitterのハンドル等の統語的要素を保存する:
TextCases["His email address is user@domain.com and Twitter handle is @username.", "Word"]TextCases["http://www.wolfram.com is a useful resource for Wolfram Language programmers.", "Word"]//TextElement"Word"と"Punctuation"の形式で,非空白文字がすべて取り出された:
TextCases["Washington D.C. is the capital of the United States. Mr. Anthony A. Williams was the mayor.", "Word" | "Punctuation"]//TextElementTextCases["Washington D.C. is the capital of the United States. Mr. Fox is the CEO of the company. She co-founded the company with Mrs. Smith.", "Sentence"]//TextElement品詞 (2)
TextCases["John and Mary went to the new store.", "Noun"]TextCases["John and Mary went to the new store.", "Verb"]TextCases["John and Mary went to the new store.", "Preposition"]alice = ExampleData[{"Text", "AliceInWonderland"}];partsOfSpeech = TextCases[alice, {"Noun", "Verb", "Adjective", "Adverb"}];Grid @Partition[KeyValueMap[Labeled[WordCloud[#2, ImageSize -> 200], #1]&, partsOfSpeech], 2]実体と解釈可能オブジェクト (2)
TextCases["On vacation, I first went to France, then I went to Belgium.", "Country"]解釈された文字列をEntityオブジェクトとして返す:
TextCases["On vacation, I first went to France, then I went to Belgium.", "Country" -> "Interpretation"]dollarstore = WikipediaData@First@WikipediaSearch["Variety Store"];currencies = TextCases[dollarstore, "CurrencyAmount" -> "Interpretation"]CurrencyConvert[currencies, "Yen"]特性と関係 (4)
TextCasesはTextPositionやTextPositionと同じタイプを扱い,与えられたタイプについて常にこれらの関数と同じ部分文字列を識別する:
TextContents["Boston, Worcester, and Springfield are the largest cities in Massachusetts.", "City"]TextCases["Boston, Worcester, and Springfield are the largest cities in Massachusetts.", "City"]TextPosition["Boston, Worcester, and Springfield are the largest cities in Massachusetts.", "City"]TextCasesはTextPositionの一般化である:
TextCases["Boston, Worcester, and Springfield are the largest cities in Massachusetts.", "City" -> "Position"]TextPosition["Boston, Worcester, and Springfield are the largest cities in Massachusetts.", {"City", "AdministrativeDivision"}]TextCases["Boston, Worcester, and Springfield are the largest cities in Massachusetts.", {"City", "AdministrativeDivision"} -> "Position"]TextCasesを使ってTextContentsの出力に似ているデータ集合を得ることができる:
Dataset@TextCases["Boston, Worcester, and Springfield are the largest cities in Massachusetts.", "City" -> Identity]Dataset@TextCases["Boston, Worcester, and Springfield are the largest cities in Massachusetts.", "City" -> Function[<|"City" -> Last[#Interpretation][[1]], "State" -> Last[#Interpretation][[2]], "Country" -> Last[#Interpretation][[3]], "Position" -> #Position, "HighlightedSnippet" -> #HighlightedSnippet|>]]TextSentencesはTextCases[…,"Sentence"]に等しい:
TextCases["Hi Michael J. Jordan. I am Michael I. Jordan.", "Sentence"]//TextElementTextSentences["Hi Michael J. Jordan. I am Michael I. Jordan."]//TextElementTextStructureは,テキストを同じ文に分割する:
TextStructure["Hi Michael J. Jordan. I am Michael I. Jordan.", "PartsOfSpeech"]TextWordsはTextCases[…,"Word"]に等しい:
TextCases["As a matter-of-fact, my mother-in-law is in N.Y.C.", "Word"]//TextElementTextWords["As a matter-of-fact, my mother-in-law is in N.Y.C."]//TextElementTextStructureはテキストをTextCases[…,"Word"|"Punctuation"]と同じ単語と句読点に分解する:
TextCases["As a matter-of-fact, my mother-in-law is in N.Y.C.", "Word" | "Punctuation"]//TextElementTextStructure["As a matter-of-fact, my mother-in-law is in New York.", "PartsOfSpeech"]おもしろい例題 (2)
都市や国のように多くの実体を地図上に示すことができる.TextCasesを使うとこれらの実体を一度に求めることができる.
text = WikipediaData["Rice"];Snippet[text, 4]locations = TextCases[text, "LocationEntity" -> "Interpretation", VerifyInterpretation -> True];RandomSample[locations, 10]GeoBubbleChart[Counts[locations]]ReverseSort@Counts[Cases[locations, Entity["GeographicRegion", _]]]ReverseSort@Counts[Cases[locations, Entity["Country", _]]]text = WikipediaData["World War"];Snippet[text, 4]日付を含むすべての文を求め,それぞれに対応するDateObjectの解釈を抽出する:
sentences = TextCases[text, "Date" -> {"HighlightedSnippet", "Interpretation"}, VerifyInterpretation -> True];RandomSample[sentences, 3]TimelinePlot[sentences[[All, 2]]]TimelinePlot[Association[Rule@@@sentences], Sequence[PlotRange -> {"1900", "1950"}, PlotLayout -> "Vertical", Background -> LightBlue]]テキスト
Wolfram Research (2015), TextCases, Wolfram言語関数, https://reference.wolfram.com/language/ref/TextCases.html (2019年に更新).
CMS
Wolfram Language. 2015. "TextCases." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2019. https://reference.wolfram.com/language/ref/TextCases.html.
APA
Wolfram Language. (2015). TextCases. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TextCases.html
BibTeX
@misc{reference.wolfram_2026_textcases, author="Wolfram Research", title="{TextCases}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/TextCases.html}", note=[Accessed: 11-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_textcases, organization={Wolfram Research}, title={TextCases}, year={2019}, url={https://reference.wolfram.com/language/ref/TextCases.html}, note=[Accessed: 11-November-2026]}