red_grape 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +25 -10
- data/README.txt +54 -5
- data/bin/redgrape +77 -0
- data/data/graph-example-2.xml +26380 -0
- data/lib/ext/array_ext.rb +41 -0
- data/lib/ext/object_ext.rb +16 -0
- data/lib/red_grape/edge.rb +4 -17
- data/lib/red_grape/{propertied_object.rb → element.rb} +26 -4
- data/lib/red_grape/graph.rb +75 -73
- data/lib/red_grape/path_group.rb +5 -9
- data/lib/red_grape/pipe/aggregate_pipe.rb +13 -0
- data/lib/red_grape/pipe/as_pipe.rb +3 -10
- data/lib/red_grape/pipe/back_pipe.rb +1 -8
- data/lib/red_grape/pipe/base.rb +51 -6
- data/lib/red_grape/pipe/cap_pipe.rb +16 -0
- data/lib/red_grape/pipe/context.rb +64 -3
- data/lib/red_grape/pipe/except_pipe.rb +15 -0
- data/lib/red_grape/pipe/fill_pipe.rb +19 -0
- data/lib/red_grape/pipe/filter_pipe.rb +1 -7
- data/lib/red_grape/pipe/group_count_pipe.rb +17 -0
- data/lib/red_grape/pipe/has_pipe.rb +24 -0
- data/lib/red_grape/pipe/if_then_else_pipe.rb +1 -7
- data/lib/red_grape/pipe/in_pipe.rb +12 -15
- data/lib/red_grape/pipe/in_v_pipe.rb +12 -0
- data/lib/red_grape/pipe/loop_pipe.rb +16 -25
- data/lib/red_grape/pipe/out_e_pipe.rb +25 -0
- data/lib/red_grape/pipe/out_pipe.rb +6 -15
- data/lib/red_grape/pipe/paths_pipe.rb +21 -9
- data/lib/red_grape/pipe/property_pipe.rb +2 -11
- data/lib/red_grape/pipe/retain_pipe.rb +16 -0
- data/lib/red_grape/pipe/transform_pipe.rb +3 -11
- data/lib/red_grape/property_description.rb +6 -0
- data/lib/red_grape/serializer/graphml_serializer.rb +73 -0
- data/lib/red_grape/vertex.rb +7 -20
- data/lib/red_grape.rb +15 -6
- data/test/{test_propertied_object.rb → test_element.rb} +5 -5
- data/test/test_graph.rb +10 -19
- data/test/test_on_the_nature_of_pipes.rb +13 -13
- data/test/test_pipe.rb +16 -0
- data/test/test_pipe_base.rb +17 -0
- data/test/test_traversal_patterns.rb +69 -0
- metadata +38 -22
- data/bin/red_grape +0 -3
- data/lib/red_grape/vertex_group.rb +0 -72
- data/test/test_red_grape.rb +0 -8
data/Manifest.txt
CHANGED
@@ -1,32 +1,47 @@
|
|
1
1
|
.autotest
|
2
|
-
History.txt
|
3
2
|
Manifest.txt
|
4
|
-
README.txt
|
5
3
|
Rakefile
|
6
|
-
|
4
|
+
README.txt
|
5
|
+
History.txt
|
6
|
+
bin/redgrape
|
7
7
|
data/graph-example-1.xml
|
8
|
-
|
8
|
+
data/graph-example-2.xml
|
9
|
+
lib/ext/array_ext.rb
|
10
|
+
lib/ext/object_ext.rb
|
11
|
+
lib/red_grape.rb
|
12
|
+
lib/red_grape/vertex.rb
|
9
13
|
lib/red_grape/edge.rb
|
14
|
+
lib/red_grape/element.rb
|
10
15
|
lib/red_grape/graph.rb
|
11
16
|
lib/red_grape/path_group.rb
|
12
|
-
lib/red_grape/pipe
|
17
|
+
lib/red_grape/pipe/aggregate_pipe.rb
|
13
18
|
lib/red_grape/pipe/as_pipe.rb
|
14
19
|
lib/red_grape/pipe/back_pipe.rb
|
15
20
|
lib/red_grape/pipe/base.rb
|
21
|
+
lib/red_grape/pipe/cap_pipe.rb
|
16
22
|
lib/red_grape/pipe/context.rb
|
23
|
+
lib/red_grape/pipe/except_pipe.rb
|
24
|
+
lib/red_grape/pipe/fill_pipe.rb
|
17
25
|
lib/red_grape/pipe/filter_pipe.rb
|
26
|
+
lib/red_grape/pipe/group_count_pipe.rb
|
27
|
+
lib/red_grape/pipe/has_pipe.rb
|
18
28
|
lib/red_grape/pipe/if_then_else_pipe.rb
|
19
29
|
lib/red_grape/pipe/in_pipe.rb
|
30
|
+
lib/red_grape/pipe/in_v_pipe.rb
|
20
31
|
lib/red_grape/pipe/loop_pipe.rb
|
32
|
+
lib/red_grape/pipe/out_e_pipe.rb
|
21
33
|
lib/red_grape/pipe/out_pipe.rb
|
22
34
|
lib/red_grape/pipe/paths_pipe.rb
|
23
35
|
lib/red_grape/pipe/property_pipe.rb
|
36
|
+
lib/red_grape/pipe/retain_pipe.rb
|
24
37
|
lib/red_grape/pipe/side_effect_pipe.rb
|
25
38
|
lib/red_grape/pipe/transform_pipe.rb
|
26
|
-
lib/red_grape/propertied_object.rb
|
27
39
|
lib/red_grape/property_description.rb
|
28
|
-
lib/red_grape/
|
29
|
-
|
30
|
-
|
40
|
+
lib/red_grape/serializer/graphml_serializer.rb
|
41
|
+
test/test_element.rb
|
42
|
+
test/test_graph.rb
|
31
43
|
test/test_on_the_nature_of_pipes.rb
|
32
|
-
test/
|
44
|
+
test/test_pipe.rb
|
45
|
+
test/test_pipe_base.rb
|
46
|
+
test/test_traversal_patterns.rb
|
47
|
+
test/test_vertex.rb
|
data/README.txt
CHANGED
@@ -4,15 +4,65 @@
|
|
4
4
|
|
5
5
|
## DESCRIPTION:
|
6
6
|
|
7
|
-
RedGrape is an in-memory graph database written in ruby.
|
7
|
+
RedGrape is an in-memory graph database written in ruby. I made this in order to learn how graph databases work so that please do not use this for serious purposes.
|
8
8
|
|
9
9
|
## FEATURES/PROBLEMS:
|
10
10
|
|
11
|
+
* REPL
|
11
12
|
* load GraphML
|
13
|
+
* construct a graph programmatically
|
14
|
+
* traverse nodes and edges
|
12
15
|
|
13
16
|
## SYNOPSIS:
|
14
17
|
|
15
|
-
|
18
|
+
g1 = RedGrape.load_graph 'data/graph-example-1.xml'
|
19
|
+
g1.v(1).out('knows').filter{it.age < 30}.name.transform{it.size}.take
|
20
|
+
# => [5]
|
21
|
+
|
22
|
+
g2 = RedGrape.load_graph 'data/graph-example-2.xml'
|
23
|
+
g2.v(89).as('x').outE.inV.loop('x'){loops < 3}.path.take
|
24
|
+
# => [[v[89], e[7006][89-followed_by->127], v[127], e[7786][127-sung_by->340], v[340]], [v[89],
|
25
|
+
|
26
|
+
## REPL:
|
27
|
+
|
28
|
+
$ bin/redgrape
|
29
|
+
T
|
30
|
+
ooooo
|
31
|
+
----- ooo -----
|
32
|
+
RED o GRAPE
|
33
|
+
-----------------
|
34
|
+
ruby :001 > g = RedGrape.create_tinker_graph
|
35
|
+
=> redgrape[vertices:6 edges:6]
|
36
|
+
ruby :002 > g.class
|
37
|
+
=> RedGrape::Graph
|
38
|
+
ruby :003 > g.V
|
39
|
+
=> [v[1], v[2], v[3], v[4], v[5], v[6]]
|
40
|
+
ruby :004 > g.V.name
|
41
|
+
=> ["marko", "vadas", "lop", "josh", "ripple", "peter"]
|
42
|
+
ruby :005 > g.E
|
43
|
+
=> [e[7][1-knows->2], e[8][1-knows->4], e[9][1-created->3], e[10][4-created->5], e[11][4-created->3], e[12][6-created->3]]
|
44
|
+
ruby :006 > v = g.v(1)
|
45
|
+
=> v[1]
|
46
|
+
ruby :007 > "#{v.name} is #{v.age} years old."
|
47
|
+
=> "marko is 29 years old."
|
48
|
+
ruby :008 > v.out
|
49
|
+
=> [v[2], v[4], v[3]]
|
50
|
+
ruby :009 > v.out('knows')
|
51
|
+
=> [v[2], v[4]]
|
52
|
+
ruby :010 > v.outE
|
53
|
+
=> [e[7][1-knows->2], e[8][1-knows->4], e[9][1-created->3]]
|
54
|
+
ruby :011 > v.outE('knows')
|
55
|
+
=> [e[7][1-knows->2], e[8][1-knows->4]]
|
56
|
+
ruby :012 > v.outE.weight
|
57
|
+
=> [0.5, 1.0, 0.4]
|
58
|
+
ruby :013 > v.outE.has('weight', :lt, 1).inV
|
59
|
+
=> [v[2], v[3]]
|
60
|
+
ruby :014 > v.outE.filter{it.weight < 1}.inV
|
61
|
+
=> [v[2], v[3]]
|
62
|
+
ruby :015 > v.out('knows').filter{it.age > 30}.out('created').name
|
63
|
+
=> ["ripple", "lop"]
|
64
|
+
|
65
|
+
In REPL, the `take' method which invokes all pipes is automatically called.
|
16
66
|
|
17
67
|
## REQUIREMENTS:
|
18
68
|
|
@@ -29,9 +79,8 @@ and generate the RDoc.
|
|
29
79
|
|
30
80
|
## REFERENCES:
|
31
81
|
|
32
|
-
* [
|
33
|
-
|
34
|
-
** [Pipes](https://github.com/tinkerpop/pipes/wiki/)
|
82
|
+
* [Gremlin](https://github.com/tinkerpop/gremlin/wiki)
|
83
|
+
* [Pipes](https://github.com/tinkerpop/pipes/wiki/)
|
35
84
|
|
36
85
|
## LICENSE:
|
37
86
|
|
data/bin/redgrape
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
require 'irb'
|
5
|
+
require 'irb/completion'
|
6
|
+
require 'optparse'
|
7
|
+
require 'red_grape'
|
8
|
+
|
9
|
+
RedGrape.set_auto_take
|
10
|
+
module RedGrape
|
11
|
+
module Help
|
12
|
+
module_function
|
13
|
+
|
14
|
+
def redgrape?(key=nil)
|
15
|
+
case key
|
16
|
+
when NilClass
|
17
|
+
puts help_message
|
18
|
+
:OK
|
19
|
+
when 'pipe', 'pipes', :pipe, :pieps
|
20
|
+
puts pipe_help_message
|
21
|
+
:OK
|
22
|
+
else
|
23
|
+
puts '?'
|
24
|
+
:NG
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def help_message
|
29
|
+
<<-EOS
|
30
|
+
Subcommands:
|
31
|
+
redgrape? :pipe : list all pipes.
|
32
|
+
EOS
|
33
|
+
#redgrape? '[pipe name]' : describe the given pipe.
|
34
|
+
end
|
35
|
+
|
36
|
+
def pipe_help_message
|
37
|
+
pipes = RedGrape::Pipe.constants.map(&:to_s).select{|p|
|
38
|
+
p =~ /.*Pipe$/}.map{|p| underscore p.sub(/Pipe$/, '')}
|
39
|
+
"Available pipes:\n #{pipes.sort.join ', '}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def underscore(str)
|
43
|
+
str.sub(/^[A-Z]/){|p| p.downcase}.gsub(/([a-z])([A-Z])/){"#{$1}_#{$2.downcase}"}
|
44
|
+
end
|
45
|
+
|
46
|
+
def camelcase(str)
|
47
|
+
str.sub(/^[a-z]/){|p| p.upcase}.gsub(/_([a-z])/){"#{$1.upcase}"}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def redgrape?(key=nil)
|
53
|
+
RedGrape::Help.redgrape? key
|
54
|
+
end
|
55
|
+
|
56
|
+
alias rg? redgrape?
|
57
|
+
|
58
|
+
COMMAND_LINE = "#{$0} #{ARGV.join(' ')}"
|
59
|
+
OPT = {}
|
60
|
+
opts = OptionParser.new
|
61
|
+
#opts.on('-a <abc>'){|v| OPT[:abc] = v}
|
62
|
+
#opts.on('-x', '--xyz <xyz>'){|v| OPT[:xyz] = v}
|
63
|
+
opts.on_tail('-v', '--version', 'Show version.'){puts(opts.ver); exit}
|
64
|
+
opts.on_tail('-h', '--help', 'Show this message.'){puts(opts.help); exit}
|
65
|
+
|
66
|
+
::Version = RedGrape::VERSION
|
67
|
+
opts.order! ARGV
|
68
|
+
CMD = ARGV.shift
|
69
|
+
|
70
|
+
puts %Q{ T
|
71
|
+
ooooo
|
72
|
+
------ ooo ------
|
73
|
+
RED o GRAPE
|
74
|
+
-------------------
|
75
|
+
}
|
76
|
+
|
77
|
+
IRB.start
|