Привет У меня есть скрипт, который может удалить подзаголовки и абзацы, но я не могу удалить абзацы с неглавыми подзаголовками и словами.Удаление неанглийских заголовков и абзацев
Например, (Original Text):
=== Personal finance ===
Protection against unforeseen personal events, as well as events in the wider economies
Transference of family wealth across generations (bequests and inheritance)
=== Corporate finance ===
Corporate finance deals with the sources of funding and the capital structure of corporations and the actions that managers take to increase the value of the firm to the shareholders.
== External links ==
Business acronyms and abbreviations
Business acronyms
== Kūrybinės Industrijos ==
Kūrybinės industrijos apima sritį ekonominių veiksnių, susitelkusių ties žinių ir informacijos generavimu arba tyrimu.
(Результат) я получаю от моего кода:
Protection against unforeseen personal events, as well as events in the wider economies
Transference of family wealth across generations (bequests and inheritance)
Corporate finance deals with the sources of funding and the capital structure of corporations and the actions that managers take to increase the value of the firm to the shareholders.
Kūrybinės industrijos apima sritį ekonominių veiksnių, susitelkusių ties žinių ir informacijos generavimu arba tyrimu.
Это то, что я надеюсь достичь (Желаемый результат):
Protection against unforeseen personal events, as well as events in the wider economies
Transference of family wealth across generations (bequests and inheritance)
Corporate finance deals with the sources of funding and the capital structure of corporations and the actions that managers take to increase the value of the firm to the shareholders.
Сценарий выглядит следующим образом:
import re
from subprocess import call
f1 = open('asd.text', 'r') # read file that contains the orginal text
f2 = open('NoRef.text', 'w') # write to new file
section_title_re = re.compile("^=+\s+.*\s+=+$")
content = []
skip = False
for l in f1.read().splitlines():
line = l.strip()
if "== external links ==" in line.lower():
skip = True
continue
if section_title_re.match(line):
skip = False
continue
if skip:
continue
content.append(line)
content = '\n'.join(content) + '\n'
f2.write(content+"\n")
f2.close()
Проблема: Пока мой код способен удалить пункты с подзаголовком известных имен, таких как «Внешние ссылки».
Но удаляю ли эти подзаголовки и абзацы, которые не являются английскими?
спасибо.
Вы пытались выполнить поиск в Интернете для библиотек, которые обнаруживают языки? Беглый поиск привел к этому: https://pypi.python.org/pypi/langdetect? –
Если вы заранее знаете все возможные (английские) заголовки, которые вы можете встретить, просто проверьте, находится ли заголовок в вашем списке (лучше используйте 'set' на самом деле) и пропустите весь абзац, если это не так. – Julien
Привет, Жюльен. Я понятия не имею о всех возможных английских заголовках, таким образом, там, где моя проблема. – windboy