active-orient 0.6 → 0.42
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gemfile +4 -10
- data/Guardfile +4 -12
- data/README.md +198 -261
- data/VERSION +1 -1
- data/active-orient-0.4.gem +0 -0
- data/active-orient-0.41.gem +0 -0
- data/active-orient.gemspec +5 -6
- data/config/boot.rb +0 -84
- data/config/connect.yml +4 -8
- data/examples/books.rb +39 -86
- data/examples/streets.rb +84 -85
- data/lib/active-orient.rb +9 -57
- data/lib/base.rb +145 -172
- data/lib/base_properties.rb +44 -40
- data/lib/model.rb +468 -0
- data/lib/orient.rb +60 -114
- data/lib/query.rb +73 -71
- data/lib/rest.rb +1059 -0
- data/lib/support.rb +319 -386
- data/test.rb +4 -0
- data/usecase.md +91 -0
- metadata +20 -65
- data/bin/active-orient-console +0 -38
- data/config/config.yml +0 -10
- data/create_project +0 -19
- data/examples/test_commands.rb +0 -92
- data/examples/test_commands_2.rb +0 -54
- data/examples/test_commands_3.rb +0 -48
- data/examples/test_commands_4.rb +0 -28
- data/examples/time_graph.md +0 -162
- data/gratefuldeadconcerts.md +0 -94
- data/lib/class_utils.rb +0 -300
- data/lib/database_utils.rb +0 -106
- data/lib/init.rb +0 -45
- data/lib/java-api.rb +0 -437
- data/lib/jdbc.rb +0 -211
- data/lib/model/edge.rb +0 -55
- data/lib/model/model.rb +0 -91
- data/lib/model/the_class.rb +0 -500
- data/lib/model/the_record.rb +0 -322
- data/lib/model/vertex.rb +0 -136
- data/lib/orientdb_private.rb +0 -48
- data/lib/other.rb +0 -330
- data/lib/rest/change.rb +0 -137
- data/lib/rest/create.rb +0 -488
- data/lib/rest/delete.rb +0 -134
- data/lib/rest/operations.rb +0 -160
- data/lib/rest/read.rb +0 -150
- data/lib/rest/rest.rb +0 -112
- data/lib/rest_disabled.rb +0 -24
- data/linkmap.md +0 -75
- data/namespace.md +0 -111
- data/old_lib_functions/two_general_class.rb +0 -139
- data/rails.md +0 -125
- data/rails/activeorient.rb +0 -53
- data/rails/config.yml +0 -10
- data/rails/connect.yml +0 -17
- data/usecase_oo.md +0 -61
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.42
|
Binary file
|
Binary file
|
data/active-orient.gemspec
CHANGED
@@ -8,10 +8,10 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.email = ["topofocus@gmail.com"]
|
9
9
|
s.homepage = 'https://github.com/topofocus/active-orient'
|
10
10
|
s.licenses = ['MIT']
|
11
|
-
s.summary = 'Pure ruby client for OrientDB
|
12
|
-
s.description = 'Persistent ORM for OrientDB
|
11
|
+
s.summary = 'Pure ruby client for OrientDB based on ActiveModel'
|
12
|
+
s.description = 'Persistent ORM for OrientDB, based on ActiveModel'
|
13
13
|
s.platform = Gem::Platform::RUBY
|
14
|
-
s.required_ruby_version = '>= 2.2.
|
14
|
+
s.required_ruby_version = '>= 2.2.0'
|
15
15
|
s.date = Time.now.strftime "%Y-%m-%d"
|
16
16
|
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
17
17
|
s.require_paths = ["lib"]
|
@@ -21,8 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.add_development_dependency "bundler", "~> 1.8"
|
23
23
|
s.add_development_dependency "rake", "~> 10.0"
|
24
|
-
s.add_dependency 'activesupport'
|
25
|
-
s.add_dependency '
|
26
|
-
s.add_dependency 'rest-client'
|
24
|
+
s.add_dependency 'activesupport', "~> 4.2"
|
25
|
+
s.add_dependency 'rest-client' , "~> 1.8"
|
27
26
|
|
28
27
|
end
|
data/config/boot.rb
CHANGED
@@ -1,90 +1,6 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
require 'yaml'
|
3
|
-
if RUBY_VERSION == 'java'
|
4
|
-
require 'orientdb'
|
5
|
-
end
|
6
3
|
project_root = File.expand_path('../..', __FILE__)
|
7
4
|
require "#{project_root}/lib/active-orient.rb"
|
8
|
-
begin
|
9
|
-
connect_file = File.expand_path('../../config/connect.yml', __FILE__)
|
10
|
-
config_file = File.expand_path('../../config/config.yml', __FILE__)
|
11
|
-
connectyml = YAML.load_file( connect_file )[:orientdb][:admin] if connect_file.present?
|
12
|
-
configyml = YAML.load_file( config_file )[:active_orient] if config_file.present?
|
13
|
-
databaseyml = YAML.load_file( connect_file )[:orientdb][:database] if connect_file.present?
|
14
|
-
rescue Errno::ENOENT => e
|
15
|
-
ActiveOrient::Base.logger = Logger.new('/dev/stdout')
|
16
|
-
ActiveOrient::OrientDB.logger.error{ "config/connectyml not present" }
|
17
|
-
ActiveOrient::OrientDB.logger.error{ "Using defaults to connect database-server" }
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
e= ARGV.present? ? ARGV.last.downcase : 'development'
|
22
|
-
env = if e =~ /^p/
|
23
|
-
'production'
|
24
|
-
elsif e =~ /^t/
|
25
|
-
'test'
|
26
|
-
else
|
27
|
-
'development'
|
28
|
-
end
|
29
|
-
puts "Using #{env}-environment"
|
30
|
-
|
31
|
-
ActiveOrient::Model.model_dir = "#{project_root}/#{ configyml.present? ? configyml[:model_dir] : "model" }"
|
32
|
-
ActiveOrient::Model.keep_models_without_file = true
|
33
|
-
# lib/init.rb
|
34
|
-
ActiveOrient::Init.define_namespace yml: configyml, namespace: @namespace
|
35
|
-
|
36
|
-
|
37
|
-
log_file = if config_file.present?
|
38
|
-
dev = YAML.load_file( connect_file )[:orientdb][:logger]
|
39
|
-
if dev.blank? || dev== 'stdout'
|
40
|
-
'/dev/stdout'
|
41
|
-
else
|
42
|
-
project_root+'/log/'+env+'.log'
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
logger = Logger.new log_file
|
48
|
-
logger.level = case env
|
49
|
-
when 'production'
|
50
|
-
Logger::ERROR
|
51
|
-
when 'development'
|
52
|
-
Logger::WARN
|
53
|
-
else
|
54
|
-
Logger::INFO
|
55
|
-
end
|
56
|
-
logger.formatter = proc do |severity, datetime, progname, msg|
|
57
|
-
"#{datetime.strftime("%d.%m.(%X)")}#{"%5s" % severity}->#{progname}:..:#{msg}\n"
|
58
|
-
end
|
59
|
-
ActiveOrient::Base.logger = logger
|
60
|
-
ActiveOrient::OrientDB.logger = logger
|
61
|
-
|
62
|
-
if connectyml.present? and connectyml[:user].present? and connectyml[:pass].present?
|
63
|
-
ActiveOrient.default_server= { user: connectyml[:user], password: connectyml[:pass] ,
|
64
|
-
server: 'localhost', port: 2480 }
|
65
|
-
ActiveOrient.database = @configDatabase.presence || databaseyml[env.to_sym]
|
66
|
-
|
67
|
-
ORD = ActiveOrient::OrientDB.new preallocate: @do_not_preallocate.present? ? false : true
|
68
|
-
if RUBY_PLATFORM == 'java'
|
69
|
-
DB = ActiveOrient::API.new preallocate: false
|
70
|
-
else
|
71
|
-
DB = ORD
|
72
|
-
end
|
73
|
-
# ActiveOrient::Init.vertex_and_edge_class
|
74
|
-
|
75
|
-
ORD.create_classes 'E', 'V'
|
76
|
-
E.ref_name = 'E'
|
77
|
-
V.ref_name = 'V'
|
78
|
-
# require model files after initializing the database
|
79
|
-
require "#{project_root}/lib/model/edge.rb"
|
80
|
-
require "#{project_root}/lib/model/vertex.rb"
|
81
|
-
## attention: if the Egde- or Vertex-Base-Class is deleted (V.delte_class) the model-methods are gone.
|
82
|
-
## After recreating the BaseClass by ORD.create_class('V'), the model-classes have to be loaded manually (require does not work))
|
83
|
-
else
|
84
|
-
ActiveOrient::Base.logger = Logger.new('/dev/stdout')
|
85
|
-
ActiveOrient::OrientDB.logger.error{ "config/connectyml is misconfigurated" }
|
86
|
-
ActiveOrient::OrientDB.logger.error{ "Database Server is NOT available"}
|
87
|
-
end
|
88
|
-
|
89
5
|
|
90
6
|
|
data/config/connect.yml
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
---
|
2
2
|
:orientdb:
|
3
|
-
:server: localhost
|
3
|
+
:server: localhost
|
4
4
|
:port: 2480
|
5
|
-
:
|
6
|
-
:database:
|
7
|
-
:development: GratefulDeadConcerts
|
8
|
-
:production: hcn_data
|
9
|
-
:test: temp
|
5
|
+
:database: hc_database
|
10
6
|
:admin:
|
11
7
|
:user: hctw
|
12
|
-
:pass:
|
8
|
+
:pass: ++++
|
13
9
|
:auth:
|
14
10
|
:user: topo
|
15
|
-
:pass:
|
11
|
+
:pass: ++++
|
16
12
|
|
17
13
|
# hfx: 101
|
data/examples/books.rb
CHANGED
@@ -5,121 +5,74 @@ There are several Books. And there is a Table with Keywords. These are our Verte
|
|
5
5
|
|
6
6
|
The Keywords are associated to the books, this is realized via an Edge »has_content«
|
7
7
|
|
8
|
-
This Example demonstrates how
|
9
|
-
|
10
|
-
Book --> HasContent --> KeyWord
|
11
|
-
|
12
|
-
and to query it dynamically using OrientSupport::OrientQuery
|
13
|
-
|
14
|
-
REQUIREMENT: Configurate config/connectyml (admin/user+pass)
|
15
|
-
|
16
|
-
There are 3 default search items provided. They are used if no parameter is given.
|
17
|
-
However, any parameter given is transmitted as serach-criteria, ie.
|
18
|
-
ruby books.rb Juli August
|
19
|
-
defines two search criteria.
|
20
|
-
|
8
|
+
This Example demonstrates how to build a query by using OrientSupport::OrientQuery
|
21
9
|
=end
|
22
|
-
|
23
10
|
class BooksExample
|
24
11
|
|
25
|
-
def initialize
|
12
|
+
def initialize db, rebuild: true
|
26
13
|
if rebuild
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
else
|
36
|
-
puts " omitting deletion of database-classes "
|
37
|
-
end
|
38
|
-
print " creating Book and Keyword as Vertex; HasContent as Edge \n"
|
39
|
-
ORD.create_classes( { V: [:book, :keyword], E: :has_content })
|
40
|
-
print "\n === PROPERTY === \n"
|
41
|
-
Keyword.create_property :item, type: :string, index: :unique
|
42
|
-
Book.create_property :title, type: :string, index: :unique
|
43
|
-
print "\n === Unique Edges === \n"
|
44
|
-
HasContent.uniq_index
|
14
|
+
db.delete_class :book
|
15
|
+
db.delete_class :keyword
|
16
|
+
db.delete_class :has_content
|
17
|
+
db.create_vertex_class :book
|
18
|
+
db.create_vertex_class :keyword
|
19
|
+
db.create_edge_class :has_content
|
20
|
+
ActiveOrient::Model::Keyword.create_property( :item , type: :string, index: :unique )
|
21
|
+
ActiveOrient::Model::Book.create_property( :title, type: :string, index: :unique )
|
45
22
|
end
|
46
23
|
end
|
47
24
|
|
48
25
|
|
49
26
|
def read_samples
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
fill_database = ->(sentence, this_book ) do
|
56
|
-
|
57
|
-
sentence.split(' ').map do | word |
|
58
|
-
Keyword.upsert where: { item: word } do | new_keyword |
|
59
|
-
HasContent.create from: this_book, to: new_keyword
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
27
|
+
fill_database = ->(sentence, this_book ) do
|
28
|
+
sentence.split(' ').each do |x|
|
29
|
+
this_word = Keyword.update_or_create where: { item: x }
|
30
|
+
this_edge = HC.create_edge from: this_book, to: this_word if this_word.present?
|
31
|
+
end
|
63
32
|
end
|
64
|
-
|
65
|
-
words = 'Die Geschäfte in der Industrie im wichtigen US-Bundesstaat New York sind im August so schlecht gelaufen wie seit mehr als sechs Jahren nicht mehr Der entsprechende Empire-State-Index fiel überraschend von plus Punkten im Juli auf minus 14,92 Zähler Dies teilte die New Yorker Notenbank Fed heute mit. Bei Werten im positiven Bereich signalisiert das Barometer ein Wachstum Ökonomen hatten eigentlich mit einem Anstieg auf 5,0 Punkte gerechnet'
|
33
|
+
words = 'Die Geschäfte in der Industrie im wichtigen US-Bundesstaat New York sind im August so schlecht gelaufen wie seit mehr als sechs Jahren nicht mehr Der entsprechende Empire-State-Index fiel überraschend von plus Punkten im Juli auf minus 14,92 Zähler Dies teilte die New Yorker Notenbank Fed heut mit Bei Werten im positiven Bereich signalisiert das Barometer ein Wachstum Ökonomen hatten eigentlich mit einem Anstieg auf 5,0 Punkte gerechnet'
|
66
34
|
this_book = Book.create title: 'first'
|
67
35
|
fill_database[ words, this_book ]
|
68
36
|
|
69
37
|
words2 = 'Das Bruttoinlandsprodukt BIP in Japan ist im zweiten Quartal mit einer aufs Jahr hochgerechneten Rate von Prozent geschrumpft Zu Jahresbeginn war die nach den USA und China drittgrößte Volkswirtschaft der Welt noch um Prozent gewachsen Der Schwächeanfall wird auch als Rückschlag für Ministerpräsident Shinzo Abe gewertet der das Land mit einem Mix aus billigem Geld und Konjunkturprogramm aus der Flaute bringen will Allerdings wirkte sich die heutige Veröffentlichung auf die Märkten nur wenig aus da Ökonomen mit einem schwächeren zweiten Quartal gerechnet hatten'
|
70
38
|
this_book = Book.create title: 'second'
|
71
39
|
fill_database[ words2, this_book ]
|
72
|
-
puts "#{Keyword.count} keywords inserted into Database"
|
73
40
|
end
|
74
|
-
|
41
|
+
|
75
42
|
def display_books_with *desired_words
|
76
|
-
|
77
|
-
|
78
|
-
## This is integrated into the main_query using 'let'.
|
79
|
-
## Subquery: let ${a-y} = select expand(in('has_content')) from keyword where item = {search_word}
|
80
|
-
## combine with intercect: $z = Intercect( $a ... $y )
|
81
|
-
## Main Query is just
|
82
|
-
## select expand( $z ) followed by all let-statements and finalized by "intercect"
|
83
|
-
#
|
84
|
-
print("\n === display_books_with » #{ desired_words.join "," } « === \n")
|
85
|
-
main_query = OrientSupport::OrientQuery.new projection: 'expand( $z )'
|
43
|
+
query = OrientSupport::OrientQuery.new from: Keyword, projection: "expand(in('HasContent'))"
|
44
|
+
q = OrientSupport::OrientQuery.new projection: 'expand( $z )'
|
86
45
|
|
87
46
|
intersects = Array.new
|
88
47
|
desired_words.each_with_index do | word, i |
|
89
|
-
symbol = ( i+97 ).chr # convert 1 -> 'a'
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
intersects << "$#{symbol}"
|
48
|
+
symbol = ( i+97 ).chr # convert 1 -> 'a'
|
49
|
+
query.where = { item: word }
|
50
|
+
q.let << { symbol => query }
|
51
|
+
intersects << "$#{symbol}"
|
94
52
|
end
|
95
|
-
|
53
|
+
q.let << "$z = Intersect(#{intersects.join(', ')}) "
|
96
54
|
puts "generated Query:"
|
97
|
-
puts
|
98
|
-
result = Keyword.query_database
|
99
|
-
puts '-' * 23
|
55
|
+
puts q.to_s
|
56
|
+
result = Keyword.query_database q, set_from: false
|
100
57
|
puts "found books: "
|
101
|
-
puts result.map( &:title ).join("; ")
|
58
|
+
puts result.map( &:title ).join("; ")
|
102
59
|
puts " -- None -- " if result.empty?
|
103
|
-
puts '-_' * 23
|
104
|
-
puts "that's it folks"
|
105
60
|
end
|
106
61
|
end
|
107
62
|
|
108
63
|
if $0 == __FILE__
|
109
64
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
65
|
+
require '../config/boot'
|
66
|
+
|
67
|
+
ActiveOrient::OrientDB.default_server = { user: 'hctw', password: 'hc' }
|
68
|
+
ActiveOrient::OrientDB.logger.level = Logger::WARN
|
69
|
+
r = ActiveOrient::OrientDB.new database: 'BookTest'
|
70
|
+
b= BooksExample.new r, rebuild: true
|
71
|
+
|
72
|
+
Book = r.open_class :book
|
73
|
+
Keyword = r.open_class :keyword
|
74
|
+
HC = r.open_class :has_content
|
75
|
+
|
122
76
|
b.read_samples if Keyword.count.zero?
|
123
|
-
b.display_books_with
|
124
|
-
|
77
|
+
b.display_books_with 'Land', 'Quartal'
|
125
78
|
end
|
data/examples/streets.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
=begin
|
2
2
|
Streets Example
|
3
3
|
|
4
|
+
|
4
5
|
We load german cities from wikipedia and parse the document for cities and countries(states).
|
5
6
|
Further we load a collection of popular streetnames from a web-side called »strassen-in-deutschland«
|
6
7
|
|
@@ -14,117 +15,115 @@ At last we print the connected cities.
|
|
14
15
|
module DataImport
|
15
16
|
def read_german_street_names
|
16
17
|
doc = Nokogiri::HTML(open('http://www.strassen-in-deutschland.de/die-haeufigsten-strassennamen-in-deutschland.html'))
|
17
|
-
strassen = doc.css(
|
18
|
+
strassen = doc.css('#strassen-in-deutschland_main a' ) # identified via css-inspector in browser
|
18
19
|
# search for the css and include only links, then display the text-part
|
19
20
|
strassen.children.map( &:to_s )[3..-1] # omit the first three (strassen in deutschland, straßenverzeichnis, straßen)
|
20
21
|
end
|
21
22
|
|
22
|
-
def read_german_cities_from_wikipedia
|
23
|
-
# we extract <li> -elements and use the text until "("
|
23
|
+
def read_german_cities_from_wikipedia
|
24
|
+
# we extract <li> -elements and use the text until "("
|
24
25
|
#doc.xpath("//li").at(80)
|
25
|
-
# => #<Nokogiri::XML::Element:0x1ba551c name="li" children=[#<Nokogiri::XML::Element:0x1ba533c name="a" attributes=[#<Nokogiri::XML::Attr:0x1ba52d8 name="href" value="/wiki/Angerm%C3%BCnde">, #<Nokogiri::XML::Attr:0x1ba52c4 name="title" value="Angermünde">] children=[#<Nokogiri::XML::Text:0x1ba4c84 "Angermünde">]>, #<Nokogiri::XML::Text:0x1ba4ae0 " (Brandenburg)">]>
|
26
|
+
# => #<Nokogiri::XML::Element:0x1ba551c name="li" children=[#<Nokogiri::XML::Element:0x1ba533c name="a" attributes=[#<Nokogiri::XML::Attr:0x1ba52d8 name="href" value="/wiki/Angerm%C3%BCnde">, #<Nokogiri::XML::Attr:0x1ba52c4 name="title" value="Angermünde">] children=[#<Nokogiri::XML::Text:0x1ba4c84 "Angermünde">]>, #<Nokogiri::XML::Text:0x1ba4ae0 " (Brandenburg)">]>
|
26
27
|
|
27
28
|
doc = Nokogiri::HTML(open('https://en.wikipedia.org/wiki/List_of_cities_and_towns_in_Germany'))
|
28
|
-
print doc
|
29
29
|
doc.xpath("//li").map{|x| x.text[0 .. x.text.index('(')-2] if x.text.index('(').present? }.compact
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def read_german_cities_and_states_fom_wikipedia
|
33
33
|
doc =
|
34
|
-
|
35
|
-
doc.xpath("//li").map do |x|
|
36
|
-
if x.text.index('(').present?
|
37
|
-
|
34
|
+
Nokogiri::HTML(open('https://en.wikipedia.org/wiki/List_of_cities_and_towns_in_Germany'))
|
35
|
+
doc.xpath("//li").map do |x|
|
36
|
+
if x.text.index('(').present?
|
37
|
+
[ x.text[0 .. x.text.index('(')-2] , x.text[ x.text.index('(')+1 .. x.text.index(')')-1] ]
|
38
38
|
end
|
39
39
|
end.compact
|
40
|
-
end
|
40
|
+
end
|
41
41
|
|
42
42
|
end # module
|
43
43
|
|
44
|
-
class StreetExample
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
44
|
+
class StreetExample
|
45
|
+
|
46
|
+
include DataImport
|
47
|
+
def initialize db, rebuild: true
|
48
|
+
if rebuild
|
49
|
+
ActiveOrient::OrientDB.logger.progname = "StreetsExample#Initialize"
|
50
|
+
db.delete_class :state
|
51
|
+
db.delete_class :city
|
52
|
+
db.delete_class :street
|
53
|
+
db.delete_class :connects
|
54
|
+
db.create_vertex_class :state
|
55
|
+
db.create_vertex_class :city
|
56
|
+
db.create_vertex_class :street
|
57
|
+
db.create_edge_class :connects
|
58
|
+
ActiveOrient::Model::State.create_property( :name, type: :string, index: :unique )
|
59
|
+
ActiveOrient::Model::City.create_properties( { name: { type: :string },
|
60
|
+
state: { type: :link, :linked_class => 'State' } }
|
61
|
+
) do
|
62
|
+
{ citi_idx: :unique }
|
63
|
+
end
|
64
|
+
ActiveOrient::Model::Street.create_property :name , type: :string, index: :notunique
|
65
|
+
ActiveOrient::Model::Connects.create_property :distance, type: :integer, index: :notunique
|
66
|
+
ActiveOrient::OrientDB.logger.info { "Vertex- and Edge-Classes rebuilded" }
|
62
67
|
end
|
63
|
-
ActiveOrient::Model::Street.create_property :name , type: :string, index: :notunique
|
64
|
-
ActiveOrient::Model::CONNECTS.create_property :distance, type: :integer, index: :notunique
|
65
|
-
ActiveOrient::OrientDB.logger.progname = "StreetsExample#Initialize"
|
66
|
-
ActiveOrient::OrientDB.logger.info { "Vertex- and Edge-Classes rebuilded" }
|
67
68
|
end
|
68
|
-
end
|
69
69
|
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
71
|
+
def read_from_web
|
72
|
+
ActiveOrient::OrientDB.logger.progname = "StreetsExample#ReadFromWeb"
|
73
|
+
read_german_cities_and_states_fom_wikipedia.each do |city,state|
|
74
|
+
state = State.update_or_create( where: { name: state }).first
|
75
|
+
City.create name: city, state: state.link
|
76
|
+
end
|
77
|
+
ActiveOrient::OrientDB.logger.info { "#{City.count} Cities imported from Wikipedia " }
|
78
|
+
|
79
|
+
cities_rids = City.all.map &:link
|
80
|
+
read_german_street_names.each_with_index do |street, i|
|
81
|
+
street_record = Street.create name: street
|
82
|
+
count = i
|
83
|
+
cities = Array.new
|
84
|
+
while count < cities_rids.size && cities.size < 5 do
|
85
|
+
cities << cities_rids[count]
|
86
|
+
count = count + i
|
87
|
+
end
|
88
|
+
C.create_edge :from => street_record, :to => cities
|
87
89
|
end
|
88
|
-
C.
|
90
|
+
ActiveOrient::OrientDB.logger.info { "#{C.count} Edges between Streets and Cities created " }
|
89
91
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
puts "..................................."
|
105
|
-
puts streets.join("\n")
|
92
|
+
|
93
|
+
def display_streets_per_state
|
94
|
+
State.all.each do |state|
|
95
|
+
streets= Street.all.map do |street |
|
96
|
+
if street.connects.in.detect{|x| x.state == state }
|
97
|
+
street.name + " verbindet " + street.connects.in.map( &:name ).join('; ')
|
98
|
+
end
|
99
|
+
end.compact
|
100
|
+
unless streets.empty?
|
101
|
+
puts "..................................."
|
102
|
+
puts state.name
|
103
|
+
puts "..................................."
|
104
|
+
puts streets.join("\n")
|
105
|
+
end
|
106
106
|
end
|
107
107
|
end
|
108
|
-
|
109
|
-
end
|
108
|
+
end
|
110
109
|
|
111
110
|
if $0 == __FILE__
|
112
111
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
112
|
+
require '../config/boot'
|
113
|
+
require 'open-uri'
|
114
|
+
require 'nokogiri'
|
115
|
+
|
116
|
+
ActiveOrient::OrientDB.default_server= { user: 'hctw', password: 'hc' }
|
117
|
+
r = ActiveOrient::OrientDB.new database: 'StreetTest'
|
118
|
+
ActiveOrient::OrientDB.logger.level = Logger::INFO
|
119
|
+
s= StreetExample.new r, rebuild: true
|
120
|
+
|
121
|
+
City = r.open_class :city
|
122
|
+
State = r.open_class :state
|
123
|
+
Street = r.open_class :street
|
124
|
+
C = r.open_class :connects
|
125
|
+
|
126
|
+
s.read_from_web if City.count.zero?
|
127
|
+
s.display_streets_per_state
|
129
128
|
|
130
129
|
end
|