TextPosition[text,form]
text 中で form の例が出現する始点と終点のリストを与える.
TextPosition[text,{form1,form2,…}]
すべてのタイプ formiについての結果の連想を与える.
TextPosition[text,formspec,n]
求まった最初の n 個の例の位置を与える.
TextPosition
テキストのコンテンツタイプのリスト »TextPosition[text,form]
text 中で form の例が出現する始点と終点のリストを与える.
TextPosition[text,{form1,form2,…}]
すべてのタイプ formiについての結果の連想を与える.
TextPosition[text,formspec,n]
求まった最初の n 個の例の位置を与える.
詳細とオプション
- TextPosition[text,form]の text は,文字列,テキストファイル,ContentObject式,あるいはそれらのテキストオブジェクトのリストでよい.
- TextPosition[{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 解釈可能性をチェックするかどうか
例題
すべて開く すべて閉じる例 (6)
TextPosition["NYC, Los Angeles, and Chicago are the largest cities in the United States of America in 2018.", "City"]TextPosition["The quick brown fox jumps over the lazy dog.", "Noun"]TextPosition["The shirt cost $50 in America, but only 5€ in Italy.", "CurrencyAmount"]TextPosition["NYC, Los Angeles, and Chicago are the largest cities in the United States of America in 2018.", {"City", "Country", "Date"}]Function[text, Map[StringTake[text, #]&, TextPosition[text, {"City", "Country", "Date"}]]]["NYC, Los Angeles, and Chicago are the largest cities in the United States of America in 2018."]TextPosition["NYC, Los Angeles, and Chicago are the largest cities in the USA in 2018.", "Location"]Function[text, StringTake[text, TextPosition[text, "Location"]]]["NYC, Los Angeles, and Chicago are the largest cities in the USA in 2018."]テキスト中の「New York City」についてのすべての言及箇所を求める:
TextPosition["I love New York - I ❤ NYC", Entity["City", {"NewYork", "NewYork", "UnitedStates"}]]スコープ (4)
ContentObjectおよびファイル (2)
ContentObject中の色の例を求める:
doc = TextSearch["ExampleData/Text", "dog"][1]TextPosition[doc, "Color"]StringTake[doc["Plaintext"], TextPosition[doc, "Color"]]File中の数量を求める:
file = TextSearch["ExampleData/Text", "dog"][1, "Location"]TextPosition[file, "Color"]StringTake[Import[file, "Plaintext"], %]代替案と包含 (2)
Alternativesを使って複数のタイプをマッチする:
TextPosition["John and Mary went to the store.", "Noun" | "Verb"]TextPosition["John and Mary went to the store.", "Noun" | "ProperNoun" | "Verb"]TextPosition["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"]]TextPosition["On vacation, I first went to France, then I went to Belgium. The food was amazing in both countries.", Containing["Sentence", "Country"]]AlternativesとContainingを組み合せて高度に構造化されたクエリを作る:
TextPosition["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"]]オプション (3)
AcceptanceThreshold (1)
デフォルトで,検出された実体はすべて0.5より高い推定確率を持つ:
TextPosition[ExampleData[{"Text", "JFKInaugural"}], {"Country", "Date", "Person"}]Map[StringTake[ExampleData[{"Text", "JFKInaugural"}], #]&, TextPosition[ExampleData[{"Text", "JFKInaugural"}], {"Country", "Date", "Person"}]]AcceptanceThresholdを高く設定して,正確である可能性が高い実体だけを得る:
TextPosition[ExampleData[{"Text", "JFKInaugural"}], {"Country", "Date", "Person"}, "AcceptanceThreshold" -> 0.9]Map[StringTake[ExampleData[{"Text", "JFKInaugural"}], #]&, TextPosition[ExampleData[{"Text", "JFKInaugural"}], {"Country", "Date", "Person"}, "AcceptanceThreshold" -> 0.9]]PerformanceGoal (1)
PerformanceGoal->"Speed"を使うことで速く検出できるようになるが,確度は下がる:
AbsoluteTiming@TextPosition["My favourite cities are New York and Foix", "City"]AbsoluteTiming@TextPosition["My favourite cities are New York and Foix", "City", PerformanceGoal -> "Speed"]VerifyInterpretation (1)
デフォルトで,実体の中には,正しくないあるいは知識ベースにまだ含まれていないために解釈できないものがある.このような場合は,解釈の代りに文字列が返される:
TextPosition["We visited Toulouse and Foix in France.", "City"]AssociationMap[Interpreter["City"], StringTake["We visited Toulouse and Foix in France.", {{12, 19}, {25, 28}}]]VerifyInterpretationを使って解釈できない実体を除外する:
TextPosition["We visited Toulouse and Foix in Midi-Pyrénées in France.", "City", VerifyInterpretation -> True]アプリケーション (6)
単語および文の分割 (2)
単語の分割は,電子メールアドレス,URL,Twitterのハンドル名のような文法要素を保存する:
wordPositions = TextPosition["His email address is user@domain.com and Twitter handle is @username. http://www.wolfram.com is a useful resource for Wolfram Language programmers.", "Word"]TextElement@StringTake["His email address is user@domain.com and Twitter handle is @username. http://www.wolfram.com is a useful resource for Wolfram Language programmers.", wordPositions]"Word"または"Punctuation"の形式では,空白文字以外のすべての文字が拾われる:
tokenPositions = TextPosition["Washington D.C. is the capital of the United States. Mr. Anthony A. Williams was the mayor.", "Word" | "Punctuation"]TextElement@StringTake["Washington D.C. is the capital of the United States. Mr. Anthony A. Williams was the mayor.", tokenPositions]文の分割は,頭字語やその他の紛らわしい境界を知的に無視する:
text = "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.";
sentencePositions = TextPosition[text, "Sentence"]TextElement@StringTake[text, sentencePositions]品詞 (2)
TextPosition["John and Mary went to the new store.", "Noun"]TextPosition["John and Mary went to the new store.", "Verb"]TextPosition["John and Mary went to the new store.", "Preposition"]alice = ExampleData[{"Text", "AliceInWonderland"}];partsOfSpeech = TextPosition[alice, {"Noun", "Verb", "Adjective", "Adverb"}]Grid @Partition[KeyValueMap[Labeled[WordCloud[#2, ImageSize -> 200], #1]&, Map[StringTake[alice, #]&, partsOfSpeech]], 2]実体と解釈可能なオブジェクト (2)
text = "On vacation, I first went to France, then I went to Belgium.";
TextPosition[text, "Country"]StringTake[text, TextPosition[text, "Country"]]解釈された文字列をEntityオブジェクトとして返す:
AssociationMap[Interpreter["Country"], {"France", "Belgium"}]dollarstore = WikipediaData@First@WikipediaSearch["Variety Store"];currencies = TextPosition[dollarstore, "CurrencyAmount"]Interpreter["CurrencyAmount"][StringTake[dollarstore, currencies]]特性と関係 (1)
TextPositionはTextCasesやTextContentsと同じタイプを扱い,指定されたタイプについて常にこれらの関数と同じ部分文字列を識別する:
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"]関連するガイド
-
▪
- テキストコンテンツタイプ ▪
- テキスト解析 ▪
- 自然言語処理
テキスト
Wolfram Research (2015), TextPosition, Wolfram言語関数, https://reference.wolfram.com/language/ref/TextPosition.html (2019年に更新).
CMS
Wolfram Language. 2015. "TextPosition." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2019. https://reference.wolfram.com/language/ref/TextPosition.html.
APA
Wolfram Language. (2015). TextPosition. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TextPosition.html
BibTeX
@misc{reference.wolfram_2026_textposition, author="Wolfram Research", title="{TextPosition}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/TextPosition.html}", note=[Accessed: 01-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_textposition, organization={Wolfram Research}, title={TextPosition}, year={2019}, url={https://reference.wolfram.com/language/ref/TextPosition.html}, note=[Accessed: 01-November-2026]}