You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.8 KiB

4 years ago
4 years ago
4 years ago
  1. ## based on https://explosion.ai/blog/german-model
  2. '''
  3. Wolfgang Seeker
  4. Wolfgang is a computational linguist from Germany.
  5. He is fascinated with the complexity and variety of human language,
  6. and spent his PhD looking for ways to make NLP work well with any
  7. kind of language in the world.
  8. '''
  9. import spacy
  10. sentence1 = u'Ich bin ein Berliner'
  11. sentence2 = u'Menschen, die du mal als Vampire tituliertest, investieren gerne, wenn sie den CEO einsetzen: meinem besten Freund wurden da Flausen in den Kopf gesetzt.'
  12. sentence3 = u'Das demokratische Modell wird in Frage gestellt. Mir würde es die Sache erleichtern, wenn ich dort ein funktionierendes Modell etwas spezifizieren kann.'
  13. sentence4 = u'Telekom oder nicht? Wir glauben nicht ^^'
  14. sentence5 = u'Ich bin vom 1. April bis 6. April in Frankfurt. Falls du immer noch unter Druck arbeitest, nimm dies als reinen Belustigungsversuch. Würde mich freuen wenn es dann klappt. '
  15. nlp = spacy.load('de')
  16. doc = nlp(sentence1)
  17. #for word in doc:
  18. #print(word.orth_, word.pos_)
  19. print('(sb: subject, nk: noun kernel, pd: predicate)')
  20. for word in doc:
  21. print(word , word.tag_)
  22. print(word.pos_ , word)
  23. print(word.orth_ ,'<--', word.dep_,'--', word.head.orth_)
  24. '''
  25. # show universal pos tags
  26. print(' '.join('{word}/{tag}'.format(word=t.orth_, tag=t.pos_) for t in doc))
  27. # output: Ich/PRON bin/AUX ein/DET Berliner/NOUN ./PUNCT
  28. # show German specific pos tags (STTS)
  29. print(' '.join('{word}/{tag}'.format(word.orth_, tag.tag_) for t in doc))
  30. # output: Ich/PPER bin/VAFIN ein/ART Berliner/NN ./$.
  31. # show dependency arcs
  32. print('\n'.join('{child:<8} <{label:-^7} {head}'.format(child=t.orth_, label=t.dep_, head=t.head.orth_) for t in doc))
  33. # output: (sb: subject, nk: noun kernel, pd: predicate)
  34. # Ich <--sb--- bin
  35. # bin <-ROOT-- bin
  36. # ein <--nk--- Berliner
  37. # Berliner <--pd--- bin
  38. # . <-punct- bin
  39. '''