段落内の数字を識別し、新しい表の列として抽出するにはどうすればよいでしょうか?異なる文に複数の数字が含まれるテキスト段落があり、それらの数字を抽出して新しい表の列に積み重ねたいと考えています。
文は次のようになります。
袋は保管場所にある移動式スケールで計量されます。各袋からサンプルを採取します。A: 10 kg、B: 20 kg、C: 30 kgの一次サンプルは、
40 kg および E: 50 kg を 105 ℃ で 24 時間乾燥させました。サンプルを繰り返し分割し、約 800 ~ 1000 グラムを残し、さらに粉砕して 100 メッシュのテストふるいに通しました。粉砕したサンプルを V ブレンダーで 20 分間混合し、100 ml の防水プラスチックボトルに移して密封しました。
さらに、異なる一次サンプルの数は 1 から 20 または 30 まで変化します。
誰かがスクリプトの正しい方向を指し示してくれると非常にありがたいです。Copilot の助けを借りてスクリプトを作成しようとしましたが、望んだ結果は得られませんでした。
本当にありがとう!
自動化とスクリプトRe: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればよいですか?これを行う方法の 1 つを次に示します。
names default to here(1);
paragraph="The bags are weighed on a mobile scale at storage location. Each 5. bag is spear sampled.
The primary sample of A: 10 kg, B: 20 kg, C: 30 kg, 40 kg and E: 50 kg was dried for 24 hours at 105 C.
The sample was subject to repeated splitting, leaving some 800-1000 grams which was further milled to
pass a 100-mesh test sieve. The crushed sample is blended in a V-blender for 20 minutes and transferred
to 100 ml waterproof plastic bottle and sealed.";
theNumbers = {};
i = 1;
While( Word( i, paragraph, " ." ) != "",
theWord = Word( i, paragraph, " ." );
If( Is Missing( Num( theWord ) ) == 0,
Insert Into( theNumbers, Num( theWord ) )
);
i++;
);<BR />Show( theNumbers );
RegEx() ソリューションも提供してくれる人がいるはずです。
Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればいいですか?これにはWordsを使用できますが、数値以外の文字のリストが必要です。その後、Concat Items()を使用して、取得したリストを文字列に戻すことができます。
Names Default To Here(1);
str = "The bags are weighed on a mobile scale at storage location. Each 5. bag is spear sampled. The primary sample of A: 10 kg, B: 20 kg, C: 30 kg, 40 kg and E: 50 kg was dried for 24 hours at 105 C. The sample was subject to repeated splitting, leaving some 800-1000 grams which was further milled to pass a 100-mesh test sieve. The crushed sample is blended in a V-blender for 20 minutes and transferred to 100 ml waterproof plastic bottle and sealed.";
matchchar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" || Get Punctuation Characters() || Get Whitespace Characters();
nums = Words(str, matchchar);
// {"5", "10", "20", "30", "40", "50", "24", "105", "800", "1000", "100", "20", "100"}
Concat Items(nums, ", "); // "5, 10, 20, 30, 40, 50, 24, 105, 800, 1000, 100, 20, 100"
より複雑なマッチングが必要な場合は、Regex() または Pat Match() がオプションですが、私の意見では、現在のドキュメントとドキュメントから見つかった例を使用して Pat Match() を学習する価値はあまりありません。Regex Match() にフラグを追加して、パターンの重複しない出現をすべて検索すると、このようなタスクをはるかに簡単に完了できるようになります。
Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればよいですか?あなたの提案を拡張してみましたが、うまくいきませんでした。残念ながら、私の調査結果は私を混乱させていますので、もう少し情報を得ることができればと思います。
以下のスニペットでは「10 kg」が見つかります。ここまでは順調です。
Names Default To Here( 1 );
text = "The bags are weighed on a mobile scale at storage location. Each 5. bag is spear sampled. <BR />The primary sample of A: 10 kg, B: 20 kg, C: 30 kg, 40 kg and E: 50 kg was dried for 24 hours at 105 C. <BR />The sample was subject to repeated splitting, leaving some 800-1000 grams which was further milled to <BR />pass a 100-mesh test sieve. The crushed sample is blended in a V-blender for 20 minutes and transferred <BR />to 100 ml waterproof plastic bottle and sealed.";<BR />
// Use a regular expression to find all the numbers, including decimals
matches = Regex( text, "\d+([.,]\d+)?\s*kg" );
Show( matches );
これをループにスクリプト化して、文字列内の「kg」に関連付けられたすべての重量を検索してみましょう。すべての個別の単語を検索し、それらをペアに組み合わせることができます。これらのペア内で、「10 kg」、「20 kg」、「30 kg」などのペアを見つけるのはスムーズに進むはずだと思いました。しかし、コードは頑固に一致するものを見つけてmatches={}リストに入れることを拒否しています。
regexPattern を If 関数内に移動し、Eval() で "combined" と "regexPattern" 変数をラップしてみました。
Names Default To Here( 1 );<BR />// the text
text = "The bags are weighed on a mobile scale at storage location. Each 5. bag is spear sampled. <BR />The primary sample of A: 10 kg, B: 20 kg, C: 30 kg, 40 kg and E: 50 kg was dried for 24 hours at 105 C. <BR />The sample was subject to repeated splitting, leaving some 800-1000 grams which was further milled to <BR />pass a 100-mesh test sieve. The crushed sample is blended in a V-blender for 20 minutes and transferred <BR />to 100 ml waterproof plastic bottle and sealed.";<BR />
// break text into words and print each of them. works as expected
words = Words( text );
For( i = 1, i <= N Items( words ), i++,
Print( words[i] )
);
// regex pattern variable
regexPattern = "\d+([.,]\d+)?\s*kg";
// empty list to store matches
matches = {};
// loop over all words in text to create and print pairs of words (we're looking for "10 kg", "20 kg" and so on). works fine
For( i = 1, i <= N Items( words ) - 1, i++,
combined = words[i] || " " || words[i + 1];
Print( "Checking: " || combined );
);
<BR /><BR /><BR />// THIS PART DOESN'T WORK
// loop once more over all words from text to create pairs of words and look for the regexPattern
For( i = 1, i <= N Items( words ) - 1, i++,
combined = words[i] || " " || words[i + 1];
// check if the current combined string matches the pattern (e.g., "10 kg")
If( Regex Match( combined, regexPattern ),
Insert Into( matches, combined );
Print( "Match found: " || combined );
,
// else
Print( "No match for: " || combined );
);
);私が見落としているものは何でしょうか?
Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればいいですか?すべてを確認したわけではありませんが、スクリプトをざっと見たところ、「.」はワイルドカードなので、エスケープする必要があります。
Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればいいですか?ありがとうございます。しかし、それが私が最初のスニペットで示したかったことです。例では、「数字 + kg」(つまり、「10 kg」) への最初の一致を正しく識別しています。一度機能するのであれば、トークン/単語のすべてのペアで機能するべきではないでしょうか?
Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればいいですか?ああ、そうそう、すみません。ここに投稿する前に起きてコーヒーを飲む必要があります。以前、このようなことに遭遇したことがあり、(前職のときに) ここに回答を投稿しました。
Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればいいですか?ハハハ、心配する必要はありません! フレンドリーな意見をいただけるのはいつでも嬉しいです:)
Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればいいですか?hogi のウィッシュリスト項目をサポートする良いケースです。
すべてのフラグに対する正規表現追加オプション
Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればよいですか?これまでのすべてのご意見に感謝します。現在テスト中です
Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればよいですか?あなたがしようとしているのが正規表現を実行することなのか、それとも実際にkg値へのすべての参照を見つける解決策を見つけようとしているのかはわかりません。後者の場合、以下のJSLは非常に効率的な解決策です。
Names Default To Here( 1 );// the text
text = "The bags are weighed on a mobile scale at storage location. Each 5. bag is spear sampled. The primary sample of A: 10 kg, B: 20 kg, C: 30 kg, 40 kg and E: 50 kg was dried for 24 hours at 105 C. The sample was subject to repeated splitting, leaving some 800-1000 grams which was further milled to pass a 100-mesh test sieve. The crushed sample is blended in a V-blender for 20 minutes and transferred to 100 ml waterproof plastic bottle and sealed.";
// break text into words and print each of them. works as expected
words = Words( text );
// regex pattern variable
regexPattern = "\d+([.,]\d+)?\s*kg";
// empty list to store matches
matches = {};
potential = loc(words,"kg");
If( length(potential) > 0,
for each( {kg}, potential,
if( isMissing(words[kg-1])==0,
insert into(matches, words[kg -1] || " kg")
)
)
);Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればよいですか?実のところ、両方です。ご協力とご辛抱に感謝します。私は「loc()」を使ったことがなかったので、いい勉強になりました。
コード ブロック全体をコピーして貼り付け、"Print( matches)" を追加すると、{"40 kg", "50 kg"} になります。これは、"[32, 36]" のみが見つかる "potential = Loc( words, "kg" );" と一致します。興味深いですね。
- なぜあなたのソリューションでは「10 kg」、「20 kg」、「30 kg」が見つからないのですか?
- 私の解決策では何も見つからないのはなぜですか?
Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればよいですか?それはコンマです。「kg」はそれを台無しにします。
Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればよいですか?Words() 関数は区切り文字としてスペースのみを使用しているため、カンマ (kg,) またはピリオド (kg.) を含む kg 単語は抽出された単語にそれらの文字を残します。これは、スペースとともにチェックする区切り文字としてカンマとピリオドを追加することで簡単に変更できます。
変化
words = Words( text );
に
words = Words( text," ,." );
Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればいいですか?このような場合は、while ループを 1 つ使用できます (これにより元の文字列が変更されるため、コピーを使用することをお勧めします)
Names Default To Here(1);
text = "The bags are weighed on a mobile scale at storage location. Each 5. bag is spear sampled. The primary sample of A: 10 kg, B: 20 kg, C: 30 kg, 40 kg and E: 50 kg was dried for 24 hours at 105 C. The sample was subject to repeated splitting, leaving some 800-1000 grams which was further milled to pass a 100-mesh test sieve. The crushed sample is blended in a V-blender for 20 minutes and transferred to 100 ml waterproof plastic bottle and sealed.";
res = {};
While(!Is Missing(match = Regex(text, "\d+.kg")),
Insert Into(res, match);
text = Substr(text, Contains(text, match) + Length(match));
);
show(res);
あるいは、仕組みがわかれば Pat Match も使えます (私は実際にそれをきちんとできたことはありません)
Names Default To Here(1);
text = "The bags are weighed on a mobile scale at storage location. Each 5. bag is spear sampled. The primary sample of A: 10 kg, B: 20 kg, C: 30 kg, 40 kg and E: 50 kg was dried for 24 hours at 105 C. The sample was subject to repeated splitting, leaving some 800-1000 grams which was further milled to pass a 100-mesh test sieve. The crushed sample is blended in a V-blender for 20 minutes and transferred to 100 ml waterproof plastic bottle and sealed.";
found_list = {};
Pat Match(
text,
Pat Any("., ") + Pat Regex("(\d+.kg)") >> match + Pat Any("., ") + Pat Test(
Insert Into(found_list, match);
0;
)
);
Show(found_list);Re: 段落内の数字を識別し、新しい表の列として抽出するにはどうすればいいですか?@CalibrationBear 、解決策は見つかりましたか?共有していただけますか? ありがとうございます:)