Как извлечь первый абзац с помощью Regex в python - PullRequest
1 голос
/ 20 июня 2020

Мне нужно извлечь первый абзац ниже.

corpus = "CHRISTINE MOORMAN and REBECCA J. SLOTEGRAAF*

 Current interdisciplinary research suggests that organizational capabil-
 ities have a direct, unconditional impact on firm performance. The authors
 extend this literature by developing a framework that proposes a contin-
 gency approach to the value of organizational capabilities. This frame-
 work highlights the effect of information in the external environment in
 stimulating firms to deploy their technology and marketing capabilities to
 influence the level and speed of relevant product development activities.
 

 The Contingency Value of Complementary Capabilities in Product Development."

Мне удалось выбрать заглавные буквы из корпуса в качестве начальной, но не удалось установить конечную точку.

my Шаблон регулярного выражения для поиска в верхнем регистре:

r'+[A-Z]\W\s'

Приведенный выше текст был взят из файла PDF, поэтому я был бы очень признателен, если бы я смог найти общий шаблон для получения аналогичного текста из других файлов.

Найдите образец изображения в формате PDF: https://ibb.co/FW9V0nk

preferred_output = ['Current interdisciplinary research suggests that organizational capabil-ities have a direct, unconditional impact on firm performance. The authors extend this literature by developing a framework that proposes a contin-gency approach to the value of organizational capabilities. This frame-work highlights the effect of information in the external environment in stimulating firms to deploy their technology and marketing capabilities to
influence the level and speed of relevant product development activities.']

1 Ответ

2 голосов
/ 21 июня 2020

вот ваше общее регулярное выражение (это для вашей текущей строки style , и предполагается, что другие строки имеют тот же стиль. В противном случае вы можете немного изменить шаблон:

import regex as re
x = [re.search(r'\n\n((.*\n)*?\n)', corpus).group(1).replace('\n', '')]
print(x)
  • \n\n найти первый абзац
  • (.*\n) проверяет строку, начинающуюся с новой строки (первая строка абзаца).
  • *?\n соответствует строке до следующей пустой строки. (повторяйте предыдущее регулярное выражение до конца абзаца)
  • () вокруг, что гарантирует, что все строки попадают в одну группу захвата.
    [' Current interdisciplinary research suggests that organizational capabil- ities have a direct, unconditional impact on firm performance. The authors extend this literature by developing a framework that proposes a contin- gency approach to the value of organizational capabilities. This frame- work highlights the effect of information in the external environment in stimulating firms to deploy their technology and marketing capabilities to influence the level and speed of relevant product development activities. ']
    
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...