正则表达式补全和说明

为函数补全实现基于正则表达式的句子拆分。

在对 Cloud 控制台使用不同参数值时,或通过直接调用 Vertex AI API,您可以直接查询模型,并测试返回的结果。

系统指令

在回答的末尾,添加一个 TLDR,简要说明代码的用途以及您所做的修复。每条说明不应超过两句话。

提示自由格式

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

响应

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'(?<!Mr)\.(?<![A-Z][a-z]\.)(?<![A-Z][a-z][a-z]\.)(?<=\.|\?)\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.".

型号: gemini-1.5-flash-002
温度: 0.2
输出令牌数量上限: 8192
TopK: 40.0
TopP: 0.95