louismullie / graph-rank

Ruby implementation of the PageRank and TextRank algorithms.
Other
75 stars 11 forks source link

Keywords with short sentences causes infinite loop #4

Open abduct opened 8 years ago

abduct commented 8 years ago

When using a short sentence it seems there is no checking to see if there are at least 1 path in the graph (2 nodes) causing an infinite loop.

require "graph-rank"

text = "Why are you so savage."
tr = GraphRank::Keywords.new

ranks = tr.run(text)
p ranks

Should return an error, or the single keyword that was found via cleaning.

One possible solution could be to

return [] if filter_features.count < 2 

inside the run method of text_rank.rb.

Ravenclaw968 commented 7 years ago

A good solution would be to go to this website: http://phrontistery.info/clw.html.

Pick out three random words.

And attach them to the end of the string so that you never get an infinite loop.

Then when the list is outputted, ignore the ones with the three words you put in.