Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 42 lines (36 sloc) 0.911 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
# for jruby with jung2
require 'rubygems'
require 'java'
require 'cgi'
require 'bundler'
Bundler.require
require 'jbundler'

java_import Java::edu.uci.ics.jung.algorithms.filters.VertexPredicateFilter
java_import Java::edu.uci.ics.jung.graph.DirectedSparseGraph
java_import Java::edu.uci.ics.jung.io.GraphMLWriter
java_import Java::org.apache.commons.collections15.Predicate

def url_to_id(url)
  if url.match(/.*\/([^\/]+)>$/)
    i = CGI.unescape($1)
    return i.gsub(/"/,'`').gsub(/&/,'and')
  else
    throw url
  end
end

G = DirectedSparseGraph.new

pred=Predicate.new
class << pred
  def evaluate(v)
    G.inDegree(v) > 5
  end
end

e = 0
while !(line=$stdin.gets).nil?
  line.chomp!
  s, p, o, dot = line.split(/ /)
  G.addEdge(e, url_to_id(s), url_to_id(o))
  e += 1
end
w = GraphMLWriter.new
filter = VertexPredicateFilter.new(pred)
w.save(filter.transform(G), java.io.FileWriter.new("out.graphml"))
Something went wrong with that request. Please try again.