Предотвращение разбивки номеров абзацев на предложения - PullRequest
0 голосов
/ 22 ноября 2018

Я использую spaCy для сегментации предложений по текстам, которые используют нумерацию абзацев, например:

text = '3. English law takes a dim view of stealing stuff from the shops. Some may argue that this is a pity.'

Я пытаюсь заставить сегментатор предложений spaCy не разбивать 3. на предложениеего собственного.

В настоящий момент следующий код возвращает три отдельных предложения:

nlp = spacy.load("en_core_web_sm")

text = """3. English law takes a dim view of stealing stuff from the shops. Some may argue that this is a pity."""
doc = nlp(text)
for sent in doc.sents:
    print("****", sent.text)

Это возвращает:

**** 3.
**** English law takes a dim view of stealing stuff from the shops.
**** Some may argue that this is a pity.

Я пытался остановить это отПередача пользовательского правила в конвейер перед парсером:

if token.text == r'\d\.':
    doc[token.i+1].is_sent_start = False

Это, похоже, не имеет никакого эффекта.Кто-нибудь сталкивался с этой проблемой раньше?

1 Ответ

0 голосов
/ 22 ноября 2018

Как-то так?

text = ["""3. English law takes a dim view of stealing stuff from the shops. Some may argue that this is a pity. Are you upto something?""", 
        """4. It's hilarious and I think this can be more of a political moment. Don't you think so? Will Robots replace humans?"""]
for i in text:
    doc = nlp(i)
    span = doc[0:5]
    span.merge()
    for sent in doc.sents:
        print("****", sent.text)
    print("\n")

Вывод:

**** 3. English law takes a dim view of stealing stuff from the shops.
**** Some may argue that this is a pity.
**** Are you upto something?


**** 4. It's hilarious and I think this can be more of a political moment.
**** Don't you think so?
**** Will Robots replace humans?

Ссылка: span.merge ()

...