Text textrank extract - CyrilB1531/lodestar GitHub Wiki

Development build. This page describes main, not a released package. The latest published Lodestar.Text is 0.6.0 — read its documentation.

HomeTextKeyword extraction

TextRank.Extract

Extracts the ranked keywords of one document.

public IReadOnlyList<KeywordMatch> Extract(string text)

Parameterstext is the document.

ReturnsIReadOnlyList<KeywordMatch>, sorted by descending score, glued where their parts were adjacent in the source; a tie keeps the order gluing produced it in — summa's own sort is Python's, which is stable. Empty when the document has no co-occurrence at all — too short, or every token a stop word.

ExceptionsArgumentNullException when text is null. InvalidOperationException when the power iteration does not converge within TextRankOptions.MaxIterations.

Example — a clean run that reaches the last token of the document is dropped whole rather than reported as a partial phrase; adding a period changes what survives.

using Lodestar.Text.Keywords;

string doc = "Copper wires conduct electricity through metal circuits";
var textRank = new TextRank(new TextRankOptions { Words = 4 });

var withoutPeriod = textRank.Extract(doc);
var withPeriod = textRank.Extract(doc + ".");

int countWithoutPeriod = withoutPeriod.Count;  // => 2
int countWithPeriod = withPeriod.Count;        // => 3

Remarks — that difference is summa's own quirk, reproduced deliberately: its inner loop reports a continuation only when it is rejected, and a clean run that only stops because the document ran out is dropped rather than reported — see Copper wires conduct electricity through metal circuits above, where metal circuits never appears without the trailing period. A phrase carries the exact spelling found at its own position — never a document-wide most common form — and a spelling is consumed once it is glued into a phrase, so a repeated keyword contributes to at most one phrase per document.

TextRankOptions.Words overrides TextRankOptions.Ratio when set; with neither given, the default keeps the top 20% of ranked stems. The ranking itself is TextRank's dominant eigenvector, not whichever one an unchecked eigensolver returns first — see that page's Remarks.

Applies to — net10.0, netstandard2.0.

See alsoTextRank, TextRankOptions, KeywordMatch, Rake.Extract, the Python equivalence table.