def lexrank(sentences, continuous=False, sim_threshold=<NUM_LIT:0.1>, alpha=<NUM_LIT>,<EOL>use_divrank=False, divrank_alpha=<NUM_LIT>):
<EOL>ranker_params = {'<STR_LIT>': <NUM_LIT:1000>}<EOL>if use_divrank:<EOL><INDENT>ranker = divrank_scipy<EOL>ranker_params['<STR_LIT>'] = divrank_alpha<EOL>ranker_params['<STR_LIT:d>'] = alpha<EOL><DEDENT>else:<EOL><INDENT>ranker = networkx.pagerank_scipy<EOL>ranker_params['<STR_LIT>'] = alpha<EOL><DEDENT>graph = networkx.DiGraph()<EOL>sent_tf_list = []<EOL>for sent in sentences:<EOL><INDENT>words = tools.word_segmenter_ja(sent)<EOL>tf = collections.Counter(words)<EOL>sent_tf_list.append(tf)<EOL><DEDENT>sent_vectorizer = DictVectorizer(sparse=True)<EOL>sent_vecs = sent_vectorizer.fit_transform(sent_tf_list)<EOL>sim_mat = <NUM_LIT:1> - pairwise_distances(sent_vecs, sent_vecs, metric='<STR_LIT>')<EOL>if continuous:<EOL><INDENT>linked_rows, linked_cols = numpy.where(sim_mat > <NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>linked_rows, linked_cols = numpy.where(sim_mat >= sim_threshold)<EOL><DEDENT>graph.add_nodes_from(list(range(sent_vecs.shape[<NUM_LIT:0>])))<EOL>for i, j in zip(linked_rows, linked_cols):<EOL><INDENT>if i == j:<EOL><INDENT>continue<EOL><DEDENT>weight = sim_mat[i,j] if continuous else <NUM_LIT:1.0><EOL>graph.add_edge(i, j, {'<STR_LIT>': weight})<EOL><DEDENT>scores = ranker(graph, **ranker_params)<EOL>return scores, sim_mat<EOL>
compute centrality score of sentences.

Args:
  sentences: [u'こんにちは．', u'私の名前は飯沼です．', ... ]
  continuous: if True, apply continuous LexRank. (see reference)
  sim_threshold: if continuous is False and smilarity is greater or
    equal to sim_threshold, link the sentences.
  alpha: the damping factor of PageRank and DivRank
  divrank: if True, apply DivRank instead of PageRank
  divrank_alpha: strength of self-link [0.0-1.0]
    (it's not the damping factor, see divrank.py)

Returns: tuple
  (
    {
      # sentence index -> score
      0: 0.003,
      1: 0.002,
      ...
    },
    similarity_matrix
  )

Reference:
  Günes Erkan and Dragomir R. Radev.
  LexRank: graph-based lexical centrality as salience in text
  summarization. (section 3)
  http://www.cs.cmu.edu/afs/cs/project/jair/pub/volume22/erkan04a-html/erkan04a.html