class_docstr: Implements the *PositionRank* algorithm described by
  [[florescuc17]](https://derwen.ai/docs/ptr/biblio/#florescuc17),
  deployed as a `spaCy` pipeline component.
  
  This class does not get called directly; instantiate its factory
  instead.
      
docstr: Get the *node weights* for initializing the use of the
  [*Personalized PageRank*](https://derwen.ai/docs/ptr/glossary/#personalized-pagerank)
  algorithm.
  
  From the cited reference:
  
  > Specifically, we propose to assign a higher probability to a word
  > found on the 2nd position as compared with a word found on the 50th
  > position in the same document. The weight of each candidate word is
  > equal to its inverse position in the document.  If the same word
  > appears multiple times in the target document, then we sum all its
  > position weights.
  
  > For example, a word v_i occurring in the following positions: 2nd,
  > 5th and 10th, has a weight p(v_i) = 1/2 + 1/5 + 1/10 = 4/5 = 0.8
  > The weights of words are normalized before they are used in the
  > position-biased PageRank.
  
      returns:
  Biased restart probabilities to use in the *PageRank* algorithm.
          
docstr_tok: ["Get","the","*","node","weights","*","for","initializing","the","use","of","the","[","*","Personalized","PageRank","*","]","(","https",":","\/\/derwen.ai\/docs\/ptr\/glossary\/","#","personalized-pagerank",")","algorithm",".","From","the","cited","reference",":",">","Specifically",",","we","propose","to","assign","a","higher","probability","to","a","word",">","found","on","the","2nd","position","as","compared","with","a","word","found","on","the","50th",">","position","in","the","same","document",".","The","weight","of","each","candidate","word","is",">","equal","to","its","inverse","position","in","the","document",".","If","the","same","word",">","appears","multiple","times","in","the","target","document",",","then","we","sum","all","its",">","position","weights",".",">","For","example",",","a","word","v_i","occurring","in","the","following","positions",":","2nd",",",">","5th","and","10th",",","has","a","weight","p","(","v_i",")","=","1\/2","+","1\/5","+","1\/10","=","4\/5","=","0.8",">","The","weights","of","words","are","normalized","before","they","are","used","in","the",">","position-biased","PageRank",".","returns",":","Biased","restart","probabilities","to","use","in","the","*","PageRank","*","algorithm","."]
code: def get_personalization(
      self,
  ) -> typing.Optional[typing.Dict[Lemma, float]]:
      """
      Get the *node weights* for initializing the use of the
      [*Personalized PageRank*](https://derwen.ai/docs/ptr/glossary/#personalized-pagerank)
      algorithm.
  
      From the cited reference:
  
      > Specifically, we propose to assign a higher probability to a word
      > found on the 2nd position as compared with a word found on the 50th
      > position in the same document. The weight of each candidate word is
      > equal to its inverse position in the document.  If the same word
      > appears multiple times in the target document, then we sum all its
      > position weights.
  
      > For example, a word v_i occurring in the following positions: 2nd,
      > 5th and 10th, has a weight p(v_i) = 1/2 + 1/5 + 1/10 = 4/5 = 0.8
      > The weights of words are normalized before they are used in the
      > position-biased PageRank.
  
          returns:
      Biased restart probabilities to use in the *PageRank* algorithm.
      """
      weighted_tokens: typing.List[typing.Tuple[str, float]] = [
          (tok, 1 / (i + 1))
          for i, tok in enumerate(
              token.lemma_
              for token in self.doc
              if token.pos_ in self.pos_kept
          )
      ]
  
      keyfunc = lambda x: x[0]
      applyfunc = lambda g: sum(w for text, w in g)
  
      accumulated_weighted_tokens: typing.List[
          typing.Tuple[str, float]
      ] = groupby_apply(
          weighted_tokens,
          keyfunc,
          applyfunc,
      )
  
      accumulated_weighted_tokens = sorted(
          accumulated_weighted_tokens, key=lambda x: x[1]
      )
  
      norm_weighted_tokens = {
          k: w / sum(w_ for _, w_ in accumulated_weighted_tokens)
          for k, w in accumulated_weighted_tokens
      }
  
      # while the authors assign higher probability to a "word",
      # our *lemma graph* vertices are (lemma, pos) tuples,
      # therefore we map each `Lemma` weight to all the *lemma
      # graph* vertices which contain it
  
      # TODO: # pylint: disable=W0511
      # => should this map to (lemma, pos) pairs instead?
  
      weighted_nodes: typing.Dict[Lemma, float] = {
          Lemma(token.lemma_, token.pos_): norm_weighted_tokens[
              token.lemma_
          ]
          for token in self.doc
          if token.pos_ in self.pos_kept
      }
  
      return weighted_nodes
  
file_path: pytextrank/pytextrank/positionrank.py
imports: import typing
  from spacy.tokens import Doc
  from .base import BaseTextRankFactory, BaseTextRank, Lemma
  from .util import groupby_apply
label_desc: Use image node_id 1 for calling the PositionRank obj's underlying member method code with example usage: obj.get_personalization() and returns: weighted_nodes