Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e3e0f0e
Showing
15 changed files
with
795 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
README.rdoc | ||
lib/**/*.rb | ||
bin/* | ||
features/**/*.feature | ||
LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## MAC OS | ||
.DS_Store | ||
|
||
## TEXTMATE | ||
*.tmproj | ||
tmtags | ||
|
||
## EMACS | ||
*~ | ||
\#* | ||
.\#* | ||
|
||
## VIM | ||
*.swp | ||
|
||
## PROJECT::GENERAL | ||
coverage | ||
rdoc | ||
pkg | ||
|
||
## PROJECT::SPECIFIC | ||
ext/*.bundle | ||
ext/*.o | ||
lib/*.bundle | ||
lib/*.o | ||
**/*/*.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2009 Daniel Cadenas | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
= rankable_graph | ||
|
||
A Ruby {PageRank}[http://en.wikipedia.org/wiki/PageRank] like implementation. | ||
|
||
== Description | ||
|
||
This gem is mostly writen in C with a pretty Ruby wrapper. | ||
It's intended to be used for big but not huge graphs, as | ||
those are better processed with a map-reduce distributed solution. | ||
|
||
== Usage | ||
|
||
rankable_graph = RankableGraph.new | ||
|
||
#First we draw our directed graph using the link method which receives as parameters two identifiers. | ||
#The only restriction for the identifiers is that they should be integers. | ||
rankable_graph.link(1234, 4312) | ||
rankable_graph.link(9876, 4312) | ||
rankable_graph.link(4312, 9876) | ||
rankable_graph.link(8888, 4312) | ||
|
||
probability_of_following_a_link = 0.85 # The bigger the number, less probability we have to teleport to some random link | ||
tolerance = 0.0001 # the smaller the number, the more exact the result will be but more CPU cycles will be needed | ||
|
||
rankable_graph.rank(probability_of_following_a_link, tolerance) do |identifier, rank| | ||
puts "Node #{identifier} rank is #{rank}" | ||
end | ||
|
||
Which outputs | ||
|
||
Node 1234 rank is 0.0375000014901161 | ||
Node 4312 rank is 0.479941636323929 | ||
Node 9876 rank is 0.445058345794678 | ||
Node 8888 rank is 0.0375000014901161 | ||
|
||
This ranks represent the probabilities that a certain node will be visited. | ||
For more examples please refer to the tests. | ||
|
||
== Requirements | ||
|
||
* Ruby 1.9 | ||
* {glib2}[http://library.gnome.org/devel/glib/2.22/] >= 2.22.2 | ||
|
||
== Note on Patches/Pull Requests | ||
|
||
* Fork the project. | ||
* Make your feature addition or bug fix. | ||
* Add tests for it. This is important so I don't break it in a | ||
future version unintentionally. | ||
* Commit, do not mess with rakefile, version, or history. | ||
(if you want to have your own version, that is fine but | ||
bump version in a commit by itself I can ignore when I pull) | ||
* Send me a pull request. Bonus points for topic branches. | ||
|
||
== Copyright | ||
|
||
Copyright (c) 2009 {Cubox}[http://cuboxsa.com]. See LICENSE for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'rubygems' | ||
require 'rake' | ||
|
||
begin | ||
require 'jeweler' | ||
Jeweler::Tasks.new do |gem| | ||
gem.name = "rankable_graph" | ||
gem.summary = %Q{A Ruby Pagerank implementation} | ||
gem.description = %Q{A Ruby Pagerank implementation} | ||
gem.email = "dev@cuboxsa.com" | ||
gem.homepage = "http://github.com/cubox/rankable_graph" | ||
gem.authors = ["Daniel Cadenas"] | ||
gem.add_development_dependency "rspec", ">= 1.2.9" | ||
gem.extensions = ["ext/extconf.rb"] | ||
gem.required_ruby_version = '>= 1.9' | ||
gem.requirements << 'glib2, v2.22.2 or greater' | ||
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings | ||
end | ||
rescue LoadError | ||
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler" | ||
end | ||
|
||
require 'spec/rake/spectask' | ||
Spec::Rake::SpecTask.new(:spec) do |spec| | ||
spec.libs << 'lib' << 'spec' | ||
spec.spec_files = FileList['spec/**/*_spec.rb'] | ||
end | ||
|
||
Spec::Rake::SpecTask.new(:rcov) do |spec| | ||
spec.libs << 'lib' << 'spec' | ||
spec.pattern = 'spec/**/*_spec.rb' | ||
spec.rcov = true | ||
end | ||
|
||
task :spec => :check_dependencies | ||
|
||
task :default => :spec | ||
|
||
require 'rake/rdoctask' | ||
Rake::RDocTask.new do |rdoc| | ||
version = File.exist?('VERSION') ? File.read('VERSION') : "" | ||
|
||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = "rankable_graph #{version}" | ||
rdoc.rdoc_files.include('README*') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#require 'rubygems' | ||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'ext')) | ||
|
||
require 'ext/rankable_graph' | ||
|
||
require "benchmark" | ||
include Benchmark | ||
|
||
n = 1000000 | ||
bmbm(12) do |test| | ||
r = RankableGraph.new | ||
srand(5) | ||
(0..(n-1)).map do |i| | ||
#each node has an average of 30 links | ||
rand(60).times do | ||
j = rand(n) | ||
#first three nodes are more linked to than the rest | ||
r.link(i, (j > 800000 ? rand(3) : j)) | ||
end | ||
end | ||
|
||
test.report("c:") do | ||
result = [] | ||
r.rank(0.85, 0.001){|key, val| result << [key, val]} | ||
puts "7 first values are #{result[0..6].map{|(k,v)| "[#{k}]=#{"%.4f" % (v * 100)}, "}}" | ||
end | ||
end | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
|
||
SHELL = /bin/sh | ||
|
||
#### Start of system configuration section. #### | ||
|
||
srcdir = . | ||
topdir = /usr/local/include/ruby19-1.9.1 | ||
hdrdir = /usr/local/include/ruby19-1.9.1 | ||
arch_hdrdir = /usr/local/include/ruby19-1.9.1/$(arch) | ||
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby | ||
prefix = $(DESTDIR)/usr/local | ||
exec_prefix = $(prefix) | ||
vendorhdrdir = $(rubyhdrdir)/vendor_ruby | ||
sitehdrdir = $(rubyhdrdir)/site_ruby | ||
rubyhdrdir = $(includedir)/$(RUBY_INSTALL_NAME)-$(ruby_version) | ||
vendordir = $(libdir)/$(RUBY_INSTALL_NAME)/vendor_ruby | ||
sitedir = $(libdir)/$(RUBY_INSTALL_NAME)/site_ruby | ||
mandir = $(datarootdir)/man | ||
localedir = $(datarootdir)/locale | ||
libdir = $(exec_prefix)/lib | ||
psdir = $(docdir) | ||
pdfdir = $(docdir) | ||
dvidir = $(docdir) | ||
htmldir = $(docdir) | ||
infodir = $(datarootdir)/info | ||
docdir = $(datarootdir)/doc/$(PACKAGE) | ||
oldincludedir = $(DESTDIR)/usr/include | ||
includedir = $(prefix)/include | ||
localstatedir = $(prefix)/var | ||
sharedstatedir = $(prefix)/com | ||
sysconfdir = $(prefix)/etc | ||
datadir = $(datarootdir) | ||
datarootdir = $(prefix)/share | ||
libexecdir = $(exec_prefix)/libexec | ||
sbindir = $(exec_prefix)/sbin | ||
bindir = $(exec_prefix)/bin | ||
rubylibdir = $(libdir)/$(ruby_install_name)/$(ruby_version) | ||
archdir = $(rubylibdir)/$(arch) | ||
sitelibdir = $(sitedir)/$(ruby_version) | ||
sitearchdir = $(sitelibdir)/$(sitearch) | ||
vendorlibdir = $(vendordir)/$(ruby_version) | ||
vendorarchdir = $(vendorlibdir)/$(sitearch) | ||
|
||
CC = gcc | ||
CXX = g++ | ||
LIBRUBY = $(LIBRUBY_SO) | ||
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a | ||
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME) | ||
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static | ||
OUTFLAG = -o | ||
COUTFLAG = -o | ||
|
||
RUBY_EXTCONF_H = | ||
cflags = $(optflags) $(debugflags) $(warnflags) | ||
optflags = -O2 | ||
debugflags = -g | ||
warnflags = -Wall -Wno-parentheses | ||
CFLAGS = -fno-common $(cflags) -fno-common -pipe -fno-common -I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include | ||
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir) | ||
DEFS = | ||
CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags) | ||
CXXFLAGS = $(CFLAGS) $(cxxflags) | ||
ldflags = -L. -L/usr/local/lib -L/opt/local/lib | ||
dldflags = | ||
archflag = | ||
DLDFLAGS = $(ldflags) $(dldflags) $(archflag) | ||
LDSHARED = cc -dynamic -bundle -undefined suppress -flat_namespace | ||
LDSHAREDXX = $(LDSHARED) | ||
AR = ar | ||
EXEEXT = | ||
|
||
RUBY_INSTALL_NAME = ruby19 | ||
RUBY_SO_NAME = ruby19 | ||
arch = i386-darwin10.2.0 | ||
sitearch = i386-darwin10.2.0 | ||
ruby_version = 1.9.1 | ||
ruby = /usr/local/bin/ruby19 | ||
RUBY = $(ruby) | ||
RM = rm -f | ||
RM_RF = $(RUBY) -run -e rm -- -rf | ||
RMDIRS = $(RUBY) -run -e rmdir -- -p | ||
MAKEDIRS = mkdir -p | ||
INSTALL = /usr/bin/install -c | ||
INSTALL_PROG = $(INSTALL) -m 0755 | ||
INSTALL_DATA = $(INSTALL) -m 644 | ||
COPY = cp | ||
|
||
#### End of system configuration section. #### | ||
|
||
preload = | ||
|
||
libpath = . $(libdir) | ||
LIBPATH = -L. -L$(libdir) | ||
DEFFILE = | ||
|
||
CLEANFILES = mkmf.log | ||
DISTCLEANFILES = | ||
DISTCLEANDIRS = | ||
|
||
extout = | ||
extout_prefix = | ||
target_prefix = | ||
LOCAL_LIBS = | ||
LIBS = $(LIBRUBYARG_SHARED) -lglib-2.0 -lintl -liconv -lpthread -ldl -lobjc | ||
SRCS = rankable_graph.c | ||
OBJS = rankable_graph.o | ||
TARGET = rankable_graph | ||
DLLIB = $(TARGET).bundle | ||
EXTSTATIC = | ||
STATIC_LIB = | ||
|
||
BINDIR = $(bindir) | ||
RUBYCOMMONDIR = $(sitedir)$(target_prefix) | ||
RUBYLIBDIR = $(sitelibdir)$(target_prefix) | ||
RUBYARCHDIR = $(sitearchdir)$(target_prefix) | ||
HDRDIR = $(rubyhdrdir)/ruby$(target_prefix) | ||
ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix) | ||
|
||
TARGET_SO = $(DLLIB) | ||
CLEANLIBS = $(TARGET).bundle | ||
CLEANOBJS = *.o *.bak | ||
|
||
all: $(DLLIB) | ||
static: $(STATIC_LIB) | ||
|
||
clean-rb-default:: | ||
clean-rb:: | ||
clean-so:: | ||
clean: clean-so clean-rb-default clean-rb | ||
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) | ||
|
||
distclean-rb-default:: | ||
distclean-rb:: | ||
distclean-so:: | ||
distclean: clean distclean-so distclean-rb-default distclean-rb | ||
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log | ||
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES) | ||
@-$(RMDIRS) $(DISTCLEANDIRS) | ||
|
||
realclean: distclean | ||
install: install-so install-rb | ||
|
||
install-so: $(RUBYARCHDIR) | ||
install-so: $(RUBYARCHDIR)/$(DLLIB) | ||
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB) | ||
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR) | ||
install-rb: pre-install-rb install-rb-default | ||
install-rb-default: pre-install-rb-default | ||
pre-install-rb: Makefile | ||
pre-install-rb-default: Makefile | ||
$(RUBYARCHDIR): | ||
$(MAKEDIRS) $@ | ||
|
||
site-install: site-install-so site-install-rb | ||
site-install-so: install-so | ||
site-install-rb: install-rb | ||
|
||
.SUFFIXES: .c .m .cc .cxx .cpp .C .o | ||
|
||
.cc.o: | ||
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< | ||
|
||
.cxx.o: | ||
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< | ||
|
||
.cpp.o: | ||
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< | ||
|
||
.C.o: | ||
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< | ||
|
||
.c.o: | ||
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $< | ||
|
||
$(DLLIB): $(OBJS) Makefile | ||
@-$(RM) $(@) | ||
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS) | ||
|
||
|
||
|
||
$(OBJS): $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'mkmf' | ||
|
||
unless pkg_config('glib-2.0') | ||
abort "glib2 not found" | ||
end | ||
|
||
create_makefile("rankable_graph") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package configuration for glib-2.0 | ||
cflags: -I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include | ||
ldflags: -L/opt/local/lib | ||
libs: -lglib-2.0 -lintl -liconv | ||
|
Oops, something went wrong.