Skip to content

Instantly share code, notes, and snippets.

@ceteri
Last active January 22, 2022 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ceteri/e22a92e0a7f55b6d4121a323ce8108b4 to your computer and use it in GitHub Desktop.
Save ceteri/e22a92e0a7f55b6d4121a323ce8108b4 to your computer and use it in GitHub Desktop.
pytextrank#196 DE lang model
import spacy
import pytextrank
# example text
text = "Compatibility of systems of linear constraints over the set of natural numbers. Criteria of compatibility of a system of linear Diophantine equations, strict inequations, and nonstrict inequations are considered. Upper bounds for components of a minimal set of solutions and algorithms of construction of minimal generating sets of solutions for all types of systems are given. These criteria and the corresponding algorithms for constructing a minimal supporting set of solutions can be used in solving all the considered types systems and systems of mixed types."
# load a spaCy model, depending on language, scale, etc.
nlp = spacy.load("de_core_news_sm")
# add PyTextRank to the spaCy pipeline
nlp.add_pipe("textrank")
doc = nlp(text)
# examine the top-ranked phrases in the document
for phrase in doc._.phrases:
print(phrase.text)
print(phrase.rank, phrase.count)
print(phrase.chunks)
$ python3 p.py
over the set of natural numbers
0.1920289618649917 1
[over the set of natural numbers]
solving all the considered types systems and systems of mixed types
0.16821209557158007 1
[solving all the considered types systems and systems of mixed types]
Compatibility of systems of linear constraints over the set of natural numbers.
0.11734504452125584 1
[Compatibility of systems of linear constraints over the set of natural numbers.]
strict
0.051055242582527006 1
[strict]
Diophantine
0.03775375057612005 1
[Diophantine]
nonstrict inequations
0.0 1
[nonstrict inequations]
python3 -m venv venv-bug
source venv-bug/bin/activate
python3 -m pip install spacy pytextrank
python3 -m spacy download de_core_news_sm
python3 p.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment