문장을 목록으로 분할하는 이 함수의 작업을 완료하라는 요청을 받았습니다. 안타깝게도 이 작업에는 정규식을 사용해야 하며 함수의 문서에서 추가 요구사항을 설명해 주었습니다. 정규식은 언제나 골치 아픈 문제입니다. 이 코드를 완료해 주시겠어요? 필요한 모든 것이 스니펫 내에 있어야 합니다.
importredefsplitSentences(sentences):""" Splits a string of sentences into a list. Each sentence is period-separated, save for cases where the phrases "Mr." or "Ms." are used, since those don't end a sentence. """sentenceList=[]# missing code herereturnsentenceList
응답
importredefsplitSentences(sentences):""" Splits a string of sentences into a list. Each sentence is period-separated, save for cases where the phrases "Mr." or "Ms." are used, since those don't end a sentence. """sentenceList=[]sentenceEnders=r'(?<!Mr)\.(?<![A-Z][a-z]\.)(?<![A-Z][a-z][a-z]\.)(?<=\.|\?)\s'sentenceList=re.split(sentenceEnders,sentences)returnsentenceList
요약: 이 코드는 정규식을 사용하여 문자열을 문장 목록으로 분할합니다. 'Mr.' 및 'Ms.'와 같은 약어를 제외하면서 문장 끝을 정확하게 식별하도록 정규식이 수정되었습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-07(UTC)"],[],[],null,["Implement regex-based sentence splitting for function completion.\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| You can query a model directly and test the results returned when using different parameter values with the Cloud console, or by calling the Vertex AI API directly. - For an example of using the Vertex AI API, see [Quickstart using the Vertex AI API](/vertex-ai/generative-ai/docs/start/quickstarts/api-quickstart). - To view this sample in the Cloud console: [Go to Google Cloud console](https://console.cloud.google.com/vertex-ai/generative/language/prompt-examples/Regex%20completion%20and%20explanation) \u003cbr /\u003e ||\n| |-------------------------------------------------------------------------------------------------------------------------------------------------------| | **System instructions** | | Include a TLDR of what the code does and what fixes you made at the end of your response. Each explanation shouldn't be more than two sentences long. | Prompt Freeform I've been asked to finish work on this function that splits sentences into a list. Unfortunately, I've been specifically told to use regex for this, with extra requirements explained in the function's docstring. Regex is a pain in the butt at the best of times - could you complete this code for me? Everything you need should be inside the snippet. import re def splitSentences(sentences): \"\"\" Splits a string of sentences into a list. Each sentence is period-separated, save for cases where the phrases \"Mr.\" or \"Ms.\" are used, since those don't end a sentence. \"\"\" sentenceList = [] # missing code here return sentenceList Response import re def splitSentences(sentences): \"\"\" Splits a string of sentences into a list. Each sentence is period-separated, save for cases where the phrases \"Mr.\" or \"Ms.\" are used, since those don't end a sentence. \"\"\" sentenceList = [] sentenceEnders = r'(?\u003c!Mr)\\.(?\u003c![A-Z][a-z]\\.)(?\u003c![A-Z][a-z][a-z]\\.)(?\u003c=\\.|\\?)\\s' sentenceList = re.split(sentenceEnders, sentences) return sentenceList TLDR: The code splits a string into a list of sentences using regex. The regex was corrected to accurately identify sentence endings while excluding abbreviations like \"Mr.\" and \"Ms.\". | |------------------------|----------------------| | **Model:** | gemini-1.5-flash-002 | | **Temperature:** | 0.2 | | **Max output tokens:** | 8192 | | **TopK:** | 40.0 | | **TopP:** | 0.95 | |"]]