문단에서 숫자를 식별하여 새 표의 열로 추출하려면 어떻게 해야 합니까?여러 문장에 숫자가 여러 개 포함된 텍스트 단락이 있는데, 해당 숫자를 추출하여 새 표의 열에 정리하고 싶습니다.
문장은 다음과 같습니다.
가방은 보관 장소에 있는 이동식 저울로 무게를 측정합니다. 각 5. 가방은 창으로 샘플링합니다. 1차 샘플 A: 10kg, B: 20kg, C: 30kg,
40kg과 E: 50kg을 105℃에서 24시간 동안 건조했습니다. 샘플은 반복적인 분할을 거쳐 약 800-1000g이 남았고, 이를 추가로 분쇄하여 100메시 시험체를 통과시켰습니다. 분쇄된 샘플은 V-블렌더에서 20분간 블렌딩한 후 100ml 방수 플라스틱 병에 옮겨 밀봉했습니다.
또한 다양한 1차 샘플의 수는 1개부터 20개 또는 30개까지 다양할 수 있습니다.
누군가가 스크립트로 올바른 방향을 가리켜 주시면 정말 감사하겠습니다. Copilot의 도움으로 작성하려고 했지만 원하는 결과를 얻지 못했습니다.
정말 고맙습니다!
자동화 및 스크립팅Re: 문단에서 숫자를 식별하여 새 표의 열로 추출하려면 어떻게 해야 합니까?이를 수행하는 한 가지 방법은 다음과 같습니다.
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: 문단에서 숫자를 식별하여 새 표의 열로 추출하려면 어떻게 해야 합니까?제안을 확장하려고 했지만, 작동하지 않았습니다. 불행히도, 제 발견 사항이 혼란스러워서, 더 많은 의견을 얻을 수 있기를 바랐습니다.
아래 스니펫은 "10kg"을 찾을 것입니다. 지금까지는 잘 되었습니다.
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={} 목록에 넣는 것을 완강히 거부합니다.
If 함수 내부에서 regexPattern을 옮겨보았고, Eval()에서 "regexPattern" 변수뿐만 아니라 "combined"도 래핑해봤습니다.
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: 문단에서 숫자를 식별하여 새 표의 열로 추출하려면 어떻게 해야 합니까?호기의 위시리스트 항목을 뒷받침하는 좋은 사례입니다.
모든 플래그에 대한 정규식 추가 옵션
Re: 문단에서 숫자를 식별하여 새 표의 열로 추출하려면 어떻게 해야 합니까?지금까지의 모든 의견에 감사드립니다. 지금 테스트 중입니다.
Re: 문단에서 숫자를 식별하여 새 표의 열로 추출하려면 어떻게 해야 합니까?당신이 하려는 것이 RegEx를 실행하는 것인지, 아니면 실제로 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"}이 됩니다. 이는 "potential = Loc(words, "kg");"에서 "[32, 36]"만 찾는 것과 일치합니다. 흥미롭네요.
- 왜 귀하의 솔루션에서 "10kg", "20kg", "30kg"을 찾을 수 없습니까?
- 내 솔루션이 아무것도 찾지 못하는 이유는 무엇입니까?
Re: 문단에서 숫자를 식별하여 새 표의 열로 추출하려면 어떻게 해야 합니까?쉼표 때문입니다. "kg"은 틀립니다.
Re: 문단에서 숫자를 식별하여 새 표의 열로 추출하려면 어떻게 해야 합니까?Words() 함수는 구분 기호로 공백만 사용하므로 쉼표(kg, ) 또는 마침표(kg. )가 있는 kg 단어는 추출된 단어에 해당 문자를 그대로 둡니다. 이는 쉼표와 마침표를 구분 기호로 추가하여 공백과 함께 확인하면 쉽게 변경할 수 있습니다.
변화
words = Words( text );
에게
words = Words( text," ,." );
Re: 문단에서 숫자를 식별하여 새 표의 열로 추출하려면 어떻게 해야 합니까?이와 같은 경우에는 while 루프를 하나 사용할 수 있습니다(이렇게 하면 원본 문자열이 수정되므로 복사본을 사용하는 것이 좋습니다)
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 , 해결책을 찾으셨나요? 공유해 주시겠어요? 감사합니다.:)