Hallo Ich habe ein Skript, das Unterüberschriften und Absätze entfernen kann, aber ich bin nicht in der Lage, Absätze mit nicht englischen Unterüberschriften und Wörtern zu entfernen.Entfernen von nicht-englischen Unterüberschriften und Paragraphen
Zum Beispiel (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.
Das (Ergebnis) ich von meinem Code zu erhalten ist:
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.
Dies ist, was ich hoffe, erreicht (Gewünschtes Ergebnis):
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.
Das Skript ist wie folgt:
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()
Problem: Bisher mein Code ist in der Lage Absätze mit Hierher bekannten Namen wie „Externe Links“ zu entfernen.
Aber entferne ich die Unterüberschriften und Absätze, die nicht Englisch sind?
Vielen Dank.
Haben Sie versucht, nach Bibliotheken zu googeln, die Sprachen erkennen? Eine kursorische Suche brachte folgendes: https://pypi.python.org/pypi/langdetect? –
Wenn Sie im Voraus alle möglichen (englischen) Überschriften kennen, überprüfen Sie einfach, ob die Überschrift in Ihrer Liste steht (verwenden Sie lieber ein 'Set') und überspringen Sie den ganzen Absatz, wenn dies nicht der Fall ist. – Julien
Hallo Julien Ich habe keine Ahnung von all den möglichen englischen Überschriften, daher gibt es mein Problem. – windboy