SemanticImportString["string"]
Datasetオブジェクトを与えるために,文字列を意味的にインポートしようと試みる.
SemanticImportString["string",type]
文字列の全要素を,指定のタイプのものとして解釈しようと試みる.
SemanticImportString["string",{type1,type2,…}]
連続する列の要素を,指定のタイプのものとして解釈しようと試みる.
SemanticImportString["string",col1->type1,col2->type2,…]
名前付きの列にある要素を,指定のタイプのものとして解釈しようと試みる.
SemanticImportString["string",typespec,form]
結果を指定の形式で与える.
SemanticImportString
SemanticImportString["string"]
Datasetオブジェクトを与えるために,文字列を意味的にインポートしようと試みる.
SemanticImportString["string",type]
文字列の全要素を,指定のタイプのものとして解釈しようと試みる.
SemanticImportString["string",{type1,type2,…}]
連続する列の要素を,指定のタイプのものとして解釈しようと試みる.
SemanticImportString["string",col1->type1,col2->type2,…]
名前付きの列にある要素を,指定のタイプのものとして解釈しようと試みる.
SemanticImportString["string",typespec,form]
結果を指定の形式で与える.
詳細とオプション
- SemanticImportStringは,入力をファイルのコンテンツからではなく文字列から取る点を除き,SemanticImportと同じ機能性を持つ.
- SemanticImportStringは,次のオプションを取る.
-
CharacterEncoding "UTF-8" 応答本文における文字符号化 Delimiters Automatic 要素間に挿入する区切り記号で ExcludedLines {} 結果から除外する行 HeaderLines Automatic ヘッダとして扱う行番号 MissingDataRules Automatic データを「欠損」とみなす際の置換え規則
例題
すべて開く すべて閉じる例 (6)
SemanticImportString["Date City Sales
2014/1/1 Boston 198
2014/1/1 New York 220
2014/1/1 Paris 215
2014/1/1 London 225
2014/1/1 Shanghai 241
2014/1/1 Tokio 218
2014/1/2 Boston 189
2014/1/2 New York 232
2014/1/2 Paris 211
2014/1/2 London 228
2014/1/2 Shanghai 242
2014/1/2 Tokio 229
2014/1/3 Boston 196
2014/1/3 New York 235"]SemanticImportString["2014/1/1
2014/1/1
2014/1/1
2014/1/1
2014/1/1
2014/1/1
2014/1/2
2014/1/2
2014/1/2
2014/1/2
2014/1/2
2014/1/2
2014/1/3
2014/1/3", "Date"]SemanticImportString["Date City Sales
2014/1/1 Boston 198
2014/1/1 New York 220
2014/1/1 Paris 215
2014/1/1 London 225
2014/1/1 Shanghai 241
2014/1/1 Tokio 218
2014/1/2 Boston 189
2014/1/2 New York 232
2014/1/2 Paris 211
2014/1/2 London 228
2014/1/2 Shanghai 242
2014/1/2 Tokio 229
2014/1/3 Boston 196
2014/1/3 New York 235", {"Date", "City", "Integer"}]列の番号を使い,文字列のいくつかの列だけを指定された形式でインポートする:
SemanticImportString["Date City Sales
2014/1/1 Boston 198
2014/1/1 New York 220
2014/1/1 Paris 215
2014/1/1 London 225
2014/1/1 Shanghai 241
2014/1/1 Tokio 218
2014/1/2 Boston 189
2014/1/2 New York 232
2014/1/2 Paris 211
2014/1/2 London 228
2014/1/2 Shanghai 242
2014/1/2 Tokio 229
2014/1/3 Boston 196
2014/1/3 New York 235", <|1 -> "Date", 3 -> Automatic|>]列の名前を使い,文字列のいくつかの列だけを指定された形式でインポートする:
SemanticImportString["Date City Sales
2014/1/1 Boston 198
2014/1/1 New York 220
2014/1/1 Paris 215
2014/1/1 London 225
2014/1/1 Shanghai 241
2014/1/1 Tokio 218
2014/1/2 Boston 189
2014/1/2 New York 232
2014/1/2 Paris 211
2014/1/2 London 228
2014/1/2 Shanghai 242
2014/1/2 Tokio 229
2014/1/3 Boston 196
2014/1/3 New York 235", <|"Date" -> "Date", "Sales" -> Automatic|>]SemanticImportString["Date City Sales
2014/1/1 Boston 198
2014/1/1 New York 220
2014/1/1 Paris 215
2014/1/1 London 225
2014/1/1 Shanghai 241
2014/1/1 Tokio 218
2014/1/2 Boston 189
2014/1/2 New York 232
2014/1/2 Paris 211
2014/1/2 London 228
2014/1/2 Shanghai 242
2014/1/2 Tokio 229
2014/1/3 Boston 196
2014/1/3 New York 235", Automatic, "NamedRows"]スコープ (4)
SemanticImportString["1,2,3 1,2,3
1,2,3 1,2,3", Delimiters -> " "]SemanticImportString["1 2 3 4
5 6 7 8
1 2 3 4", HeaderLines -> 1]SemanticImportString["1 2 3
4 5 6
7 8 9
1 2 3
4 5 6
7 8 9", ExcludedLines -> {1, 5}]欠落値を特殊形式Missing["UnknownData"]の形式"Unknown"で返す:
SemanticImportString["1 2 Unknown
3 4 5
6 Unknown 8", MissingDataRules -> {"Unknown" -> Missing["UnknownData"]}]オプション (9)
Delimiters (2)
デリミタを指定することによって,値がどのように分けられるかが決まる:
SemanticImportString["1 2, 3 ; 4, 5 6", "String", "Columns", Delimiters -> ","]//InputFormSemanticImportString["1 2, 3 ; 4, 5 6", "String", "Columns", Delimiters -> ";"]//InputFormSemanticImportString["1 \"2, 3\" ; 4, 5 6", "String", "Columns", Delimiters -> ","]//InputFormExcludedLines (1)
HeaderLines (2)
SemanticImportString["1
2.
3.
4.
", Automatic, "NamedColumns"]ヘッダが検出されなかった場合,ヘッダは文字列中の指標(「column1」,「column2」等)になる:
SemanticImportString["France, 2m
Nigeria, 3m
Spain, 250cm
Canada, 290mm", Automatic, "NamedColumns"]SemanticImportString["1
2.
3.
4.
", Automatic, "NamedColumns", "HeaderLines" -> 0]SemanticImportString["1
2.
3.
4.
", Automatic, "NamedColumns", "HeaderLines" -> 2]MissingDataRules (4)
SemanticImportString["
1, 235, 411
no rank, 199, none
3, 207, 133
", {"Integer", "Integer", "Integer"}, "Columns", MissingDataRules -> {("no" ~~ ___) -> 0}]SemanticImportString["
1, USA
abc, France
3, Italy
", Automatic, "Columns", MissingDataRules -> {RegularExpression["a.*"] -> 0}]SemanticImportString["
1, USA
abc, France
3, Italy
", Automatic, "Columns", MissingDataRules -> {{RegularExpression["[^0-9]*"] -> 0}, Automatic}]SemanticImportString["
S. Africa
US
France
", Automatic, "Columns", MissingDataRules -> {"US" -> Missing["US caught before interpretation"]}, "HeaderLines" -> 0]アプリケーション (3)
数量のリストをDatasetオブジェクトとしてインポートする:
SemanticImportString["1 meters, 2 kilometers, 3 centimeters"]SemanticImportString["1 meters, 2 kilometers, 3 centimeters", Automatic, "Columns"]SemanticImportString["S. Africa, Japan, USA", Automatic, "Columns"]text = Import["ExampleData/countries-currency", "Text"];Short[text]入力ファイルに任意の文字列変換を適用する.この場合は,すべての文字を大文字にしている:
text2 = ToUpperCase[text];Short[text2]SemanticImportString[text2]SemanticImportString[text2, <|"PRICE" -> Automatic|>]考えられる問題 (4)
データの解釈は,そのコンテキストに依存する.これ以上の文脈が与えられなければ,"12,3"は日付として解釈される:
SemanticImportString["12,3", Automatic, "Rows"]有効な日付ではない値"45,4"が含まれる文脈では,"12,3"は2つの整数として解釈される:
SemanticImportString["12,3
45,4", Automatic, "Rows"]SemanticImportStringはSemanticInterpretationとは異なり,単純で素早い推測しか行わない.SemanticImportStringは州の名前を文字列としてインポートする:
SemanticImportString["Mississippi", Automatic, "Columns"]SemanticInterpretationは州の名前をEntityオブジェクトとしてインポートする:
SemanticInterpretation["Mississippi"]タイプの自動選択では,明示的にタイプを指定した場合よりも小さい解釈集合から選択する:
SemanticImportString["Mississippi", Automatic, "Columns"]SemanticImportString["Mississippi", "River", "Columns"]Automaticタイプは,自動的に選択された列数を指定する:
SemanticImportString["Nigeria,1
France,2", Automatic, "Rows", HeaderLines -> 0]{Automatic}タイプは,自動的に選択されたタイプの単一列を指定する:
SemanticImportString["Nigeria,1
France,2", {Automatic}, "Rows", HeaderLines -> 0]//InputFormタイプのリスト中のAutomaticは,対応する列に連続的に適用される:
SemanticImportString["Nigeria,1
France,2", {Automatic, Automatic}, "Rows", HeaderLines -> 0]関連するガイド
-
▪
- 自由形式入力と外部入力 ▪
- 式と文字列の間の変換 ▪
- テキストの操作 ▪
- 言語学データ
テキスト
Wolfram Research (2014), SemanticImportString, Wolfram言語関数, https://reference.wolfram.com/language/ref/SemanticImportString.html.
CMS
Wolfram Language. 2014. "SemanticImportString." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SemanticImportString.html.
APA
Wolfram Language. (2014). SemanticImportString. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SemanticImportString.html
BibTeX
@misc{reference.wolfram_2026_semanticimportstring, author="Wolfram Research", title="{SemanticImportString}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/SemanticImportString.html}", note=[Accessed: 09-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_semanticimportstring, organization={Wolfram Research}, title={SemanticImportString}, year={2014}, url={https://reference.wolfram.com/language/ref/SemanticImportString.html}, note=[Accessed: 09-November-2026]}