Akron | b6efc73 | 2022-03-17 15:03:56 +0100 | [diff] [blame] | 1 | import spacy |
| 2 | import sys |
| 3 | from spacy.lang.de import German |
| 4 | |
| 5 | # slower and more accurate: ("de_dep_news_trf") |
| 6 | |
| 7 | model = sys.argv[1] |
| 8 | |
| 9 | if model == 'dep': |
| 10 | nlp = spacy.load("de_core_news_sm") |
| 11 | elif model == 'stat': |
| 12 | nlp = spacy.load("de_core_news_sm", exclude=["parser"]) |
| 13 | nlp.enable_pipe("senter") |
| 14 | elif model == 'sentencizer': |
| 15 | nlp = German() |
| 16 | nlp.add_pipe("sentencizer") |
| 17 | |
| 18 | # Create a Sentence Splitter based on dependency parsing. |
| 19 | |
| 20 | with open(sys.argv[2], 'r') as f: |
| 21 | contents = f.read() |
| 22 | |
Akron | da9c411 | 2022-03-19 17:51:05 +0100 | [diff] [blame] | 23 | nlp.max_length = len(contents) + 100 |
Akron | b6efc73 | 2022-03-17 15:03:56 +0100 | [diff] [blame] | 24 | |
Akron | da9c411 | 2022-03-19 17:51:05 +0100 | [diff] [blame] | 25 | doc = nlp(contents, disable = ['ner']) |
| 26 | |
Akron | b6efc73 | 2022-03-17 15:03:56 +0100 | [diff] [blame] | 27 | for sent in doc.sents: |
| 28 | print(sent.text) |
Akron | 049e526 | 2022-03-18 09:59:34 +0100 | [diff] [blame] | 29 | print(" </eos> ") |