Python - как извлечь предложения, содержащие знак цитирования?

text = "Trondheim is a small city with a university and 140000 inhabitants. Its central bus systems has 42 bus lines, serving 590 stations, with 1900 (departures per) day in average. T h a t gives approximately 60000 scheduled bus station passings per day, which is somehow represented in the route data base. The starting point is to automate the function (Garry Weber, 2005) of a route information agent."
print re.findall(r"([^.]*?\(.+ [0-9]+\)[^.]*\.)",text)

Я использую приведенный выше код, чтобы извлечь предложение с цитатой в нем. Как видите, последнее предложение содержит цитату (Гарри Вебер, 2005).

Но я получил такой результат:

[' Its central bus systems has 42 bus lines, serving 590 stations, with 1900 (departures per) day in average. T h a t gives approximately 60000 scheduled bus station passings per day, which is somehow represented in the route data base. The starting point is to automate the function (Garry Weber, 2005) of a route information agent.']

В результате должно получиться предложение, содержащее только цитату, например:
Отправной точкой является автоматизация функции (Garry Weber, 2005) агента информации о маршруте.

Я предполагаю, что проблема вызвана текстом в круглых скобках, как вы можете видеть во второй строке, которую он содержит (отклонения на), любое решение для моего кода?


person gameon67    schedule 13.08.2017    source источник
comment
Вместо \(.+ вы можете использовать здесь \([^)]+.   -  person Sebastian Proske    schedule 13.08.2017
comment
О, мое спасибо, ты решила мою проблему   -  person gameon67    schedule 13.08.2017


Ответы (1)


Моя попытка. Живая демонстрация.

\b[^.]+\([^()]+\b(\d{2}|\d{4})\s*\)[^.]*\.

Он точно передает предложение и указывает год более конкретно, чем ваш.

person linden2015    schedule 13.08.2017