Coder Social home page Coder Social logo

graph-rank's Introduction

###About

This gem implements a PageRank class and a class that allows to perform keyword ranking using the TextRank algorithm. Both were ported from the PHP Implementation by @crodas.

###Install

gem install graph-rank

###Usage

TextRank

Reference: R. Mihalcea and P. Tarau, “TextRank: Bringing Order into Texts,” in Proceedings of EMNLP 2004. Association for Computational Linguistics, 2004, pp. 404–411.

text = 'PageRank is a link analysis algorithm, named after Larry ' +
'Page and used by the Google Internet search engine, that assigns ' +
'a numerical weighting to each element of a hyperlinked set of ' +
'documents, such as the World Wide Web, with the purpose of "measuring"' +
'its relative importance within the set.'

tr = GraphRank::Keywords.new

tr.run(text).inspect

Optionally, you can pass the n-gram size (default = 3), as well as the damping and convergence (see PageRank) to the constructor. Finally, you can set stop words as follows:

tr.stop_words = ["word", "another", "etc"]

PageRank

Reference: Brin, S.; Page, L. (1998). "The anatomy of a large-scale hypertextual Web search engine". Computer Networks and ISDN Systems 30: 107–117.

pr = GraphRank::PageRank.new

pr.add(1,2)
pr.add(1,4)
pr.add(1,5)
pr.add(4,5)
pr.add(4,1)
pr.add(4,3)
pr.add(1,3)
pr.add(3,1)
pr.add(5,1)

puts pr.calculate.inspect

# => [[1, 5.99497754810465], [3, 2.694723988738302], 
#    [5, 2.694723988738302], [4, 2.100731029131304],
#    [2, 2.100731029131304]]

Optionally, you can pass the damping factor (default = 0.85) and the convergence criterion (default = 0.01) as parameters to the PageRank constructor. Additionally, you can pass in an edge weight parameter to #add and it will be used in the PageRank calculation.

graph-rank's People

Contributors

soheildanesh avatar louismullie avatar nakilon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.