-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgraphml.rb
More file actions
41 lines (36 loc) · 911 Bytes
/
graphml.rb
File metadata and controls
41 lines (36 loc) · 911 Bytes
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"))