active-orient 0.79 → 0.80

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7aeeeec320281d1ed65f73145b3d3008890c3ab46c480b480157cd2cd08dbace
4
- data.tar.gz: 11d73a72a7510e5e6d8c93677504923141e78dd192ede941e4a042d4225f8dac
3
+ metadata.gz: 8b57e243fb22b2156f6a2e92aa5955cbafead6da0c5fd65be11ef2483b829f07
4
+ data.tar.gz: 5c67edc1f5c62713ab363720cf43a7f8371470a75c49df8869f4a91b6cd32494
5
5
  SHA512:
6
- metadata.gz: c88ddae001fbdfbeba888d579235eb84d579f5e61c53591e4ef5cd1802a47c41f9e40d929c6f294a6b11a44f777ea41eb5b8f598342c15d72a2654eb273fc0d2
7
- data.tar.gz: '0984f9cb17fe34c58047ad1e1144786f17bc5a760e2df883c4a9c8588eebd73cba7933b80d6c4a681c00927a791e986ca99303ae8fb9178c6705c652342b1842'
6
+ metadata.gz: 00d96784e43d226cd3b66acf2d02e6db57459f79fe70893a328d7fa60d3c5b54c27d76f0f082136ed3bfca267e59fd4337818894c98ec367092f4721f6654966
7
+ data.tar.gz: fbb32f47ab7dbfaa152dd5a0a2432b9c3039125e36255381e3874b8a04b148113a3b23dadf7e1ae22a09384b1144ad7f873aaf0413c8c9094142a921dcb64945
Binary file
data/Gemfile CHANGED
@@ -1,12 +1,8 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
- gem 'activesupport' # , "~>4.2"
4
- gem 'activemodel' #, "~>4.2"
5
- #gem 'activemodel-serializers-xml'
6
- gem 'rest-client' , :git => 'https://github.com/rest-client/rest-client.git'
7
- #gem 'nokogiri', '~> 1.6.6' #, :git => 'git://github.com/sparklemotion/nokogiri.git'
3
+ #gem 'rest-client' , :git => 'https://github.com/rest-client/rest-client.git'
8
4
  #gem 'orientdb' , :path => '/home/topo/orientdb-jruby' , :platforms => :jruby
9
- gem 'sdoc'
5
+ gem 'sdoc', git: 'https://github.com/zzak/sdoc'
10
6
  #gem 'orientdb' , :git => 'git://github.com/topofocus/orientdb-jruby.git', :branch => '2.1.2', :platforms => :jruby
11
7
  group :development, :test do
12
8
  gem "awesome_print"
data/README.md CHANGED
@@ -1,11 +1,18 @@
1
1
  # ActiveOrient
2
- Use OrientDB to persistently store dynamic Ruby-Objects and use database queries to manage even very large
3
- datasets. **OrientDB Version 3 is required**
2
+ Use OrientDB to persistently store Ruby-Objects and use database queries to manage even very large datasets.
3
+ **OrientDB Version 3 is required**, OrientDB 3.1 is supported
4
4
 
5
- For changes from Version OrientDB 2.2 -> [Wiki](../..//wiki/Changes-2.2--to------3.0)
5
+ ---
6
+ **Status**
7
+
8
+ * Preparing for a gem release in Dec. 2020
9
+
10
+ * Recent updates: concurrent database queries, multiple model-dirs, match-statements
11
+ * Finally working on the TestSuite
12
+ ---
6
13
  ### Quick Start
7
14
 
8
- You need a ruby 2.5/2.6 Installation and a working OrientDB-Instance (Version 3.0.17 or above).
15
+ You need a ruby 2.6 / 2.7 Installation and a working OrientDB-Instance (Version 3.0.17 or above).
9
16
 
10
17
  - clone the project,
11
18
  - run bundle install ; bundle update,
@@ -26,11 +33,11 @@ cd bin
26
33
  ### Philosophy
27
34
 
28
35
 
29
- OrientDB is basicly an Object-Database. It shares the concept of Inheritance with OO-Languages, like Ruby.
36
+ OrientDB is a Multi-Model-Database. It shares the concept of Inheritance with OO-Languages, like Ruby.
30
37
 
31
- Upon initialisation `ActiveOrient`reads the complete structure of the database, creates corresponding ruby-classes (including inheritance) and then loads user defined methods from the `Model Directory`. A separate schema definition is not neccessary.
38
+ Upon initialization `ActiveOrient` reads the complete structure of the database, creates corresponding ruby-classes (including inheritance) and then loads user defined methods from the `Model Directory`. A separate schema definition is not neccesary.
32
39
 
33
- `ActiveOrient`queries the OrientDB-Database, provides a cache to speed things up and provides handy methods to simplify the work with OrientDB. Like Active-Record it represents the "M" Part of the MCV-Design-Pattern. There is explicit Namespace support. Its philosophie resembles the [Hanami Project](https://github.com/hanami/hanami).
40
+ `ActiveOrient` queries the OrientDB-Database, provides a cache to speed things up and provides handy methods to simplify the work with OrientDB. Like Active-Record it represents the "M" Part of the MCV-Design-Pattern. There is explicit Namespace support. Its philosophie resembles the [Hanami Project](https://github.com/hanami/hanami).
34
41
 
35
42
 
36
43
 
@@ -39,7 +46,7 @@ Upon initialisation `ActiveOrient`reads the complete structure of the database,
39
46
  The CRUD-Process (create, read = query, update and remove) is performed as
40
47
  ```ruby
41
48
  # create the class
42
- ORD.create_class :m
49
+ V.create_class :m # V is the base »vertex» class. M is a vertex-class.
43
50
  # create a record
44
51
  M.create name: 'Hugo', age: 46, interests: [ 'swimming', 'biking', 'reading' ]
45
52
  # query the database
@@ -71,39 +78,34 @@ As for ActiveRecord-Tables, the Model-class itself provides methods to inspect a
71
78
 
72
79
  A »normal« Query is submitted via
73
80
  ```ruby
74
- M.get_records projection: { projection-parameter },
75
- distinct: { some parameters },
76
- where: { where-parameter },
77
- order: { sorting-parameters },
78
- group_by: { one grouping-parameter},
79
- unwind: ,
80
- skip: ,
81
- limit:
82
-
83
- # or
84
- query = OrientSupport::OrientQuery.new {paramter}
85
- M.query_database query
81
+ M.query.projection( projection-parameter)
82
+ .distinct( some parameters)
83
+ .where( where-parameter)
84
+ .order( sorting-parameters )
85
+ .group_by( one grouping-parameter )
86
+ (...)
87
+ .execute
86
88
 
87
89
  ```
88
90
 
89
- To update several records, a class-method »update_all« is defined.
91
+ To update several records, a class-method »update« is provided.
90
92
  ```ruby
91
- M.update_all connected: false # add a property »connected» to each record
92
- M.update_all set:{ connected: true }, where: "symbol containsText 'S'"
93
+ M.update connected: false # add a property »connected» to each record
94
+ M.update set:{ connected: true }, where: "symbol containsText 'S'"
93
95
  ```
94
96
 
95
97
  Graph-support:
96
98
 
97
99
  ```ruby
98
- ORD.create_vertex_class :the_vertex
99
- ORD.create_edge_class :the_edge
100
+ V.create_class :the_vertex
101
+ E.create_class :the_edge
100
102
  vertex_1 = TheVertex.create color: "blue"
101
103
  vertex_2 = TheVertex.create flower: "rose"
102
- TheEdge.create_edge attributes: {:birthday => Date.today }, from: vertex_1, to: vertex_2
104
+ vertex_1.assign via: TheEdge, vertex: vertex_2, attributes: {:birthday => Date.today }
103
105
  ```
104
106
  It connects the vertices and assigns the attributes to the edge.
105
107
 
106
- To query a graph, SQL-like-Queries and Match-statements can be used (see below).
108
+ To query a graph, SQL-like-Queries and Match-statements can be used (details in the [wiki](https://github.com/topofocus/active-orient/wiki)).
107
109
 
108
110
  #### Other Documents
109
111
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.79
1
+ 0.80
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.homepage = 'https://github.com/topofocus/active-orient'
10
10
  s.licenses = ['MIT']
11
11
  s.summary = 'Pure ruby client for OrientDB(V.3) based on ActiveModel'
12
- s.description = 'Persistent ORM for OrientDB(V.3), based on ActiveModel. Rails 5 compatible'
12
+ s.description = 'Persistent ORM for OrientDB(V.3), based on ActiveModel'
13
13
  s.platform = Gem::Platform::RUBY
14
14
  s.required_ruby_version = '>= 2.5'
15
15
  s.date = Time.now.strftime "%Y-%m-%d"
@@ -19,10 +19,11 @@ Gem::Specification.new do |s|
19
19
  s.bindir = "exe"
20
20
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
 
22
- s.add_development_dependency "bundler", "~> 1.8"
23
- s.add_development_dependency "rake", "~> 10.0"
22
+ s.add_development_dependency "bundler"
23
+ s.add_development_dependency "rake"
24
24
  s.add_dependency 'activesupport'#, "~> 4.2"
25
25
  s.add_dependency 'activemodel'#, "~> 4.2"
26
26
  s.add_dependency 'rest-client'
27
+ s.add_dependency 'pond'
27
28
 
28
29
  end
@@ -10,6 +10,7 @@ require 'bundler/setup'
10
10
  require 'yaml'
11
11
  require 'logger'
12
12
  require 'active-orient'
13
+ begin
13
14
  config_file = File.expand_path('../../config/connect.yml', __FILE__)
14
15
  connectyml = if File.exist?(config_file)
15
16
  YAML.load_file( config_file )[:orientdb]
@@ -17,12 +18,18 @@ connectyml = if File.exist?(config_file)
17
18
  puts "config/connect.yml not found "
18
19
  puts "using defaults"
19
20
  { server: 'localhost', port: 2480,
20
- database: { development: 'GratefulDeadConcerts',
21
+ database: { development: 'demodb',
21
22
  production: 'hcn_data',
22
23
  test: 'temp'},
23
24
  admin: { user: 'root', pass: 'root' } }
24
25
  end
25
-
26
+ rescue Psych::SyntaxError
27
+ puts "Please edit /config/connect.yml"
28
+ puts
29
+ puts "current settings:"
30
+ puts `cat ../config/connect.yml`
31
+ Kernel.exit
32
+ end
26
33
  e= ARGV.present? ? ARGV.last.downcase : 'development'
27
34
  env = if e =~ /^p/
28
35
  :production
@@ -37,8 +44,11 @@ begin
37
44
  password: connectyml[:admin][:pass].to_s,
38
45
  server: connectyml[:server].to_s
39
46
  ActiveOrient::Base.logger.level = Logger::INFO
40
- ActiveOrient::Model.keep_models_without_file = true
41
- ActiveOrient::OrientDB.new model_dir: 'lib/model'
47
+ ## example for namespace support, then set »keep_models_without_file« temporary to »false«
48
+ # module HH; end
49
+ # ActiveOrient::Init.define_namespace { HH }
50
+ ActiveOrient::Model.keep_models_without_file = true
51
+ ActiveOrient::OrientDB.new model_dir: '../lib/model' , preallocate: true
42
52
  rescue RestClient::Unauthorized
43
53
  puts "Cannot connect to the server. Wrong credentials"
44
54
  Kernel.exit
@@ -80,6 +90,8 @@ puts ActiveOrient::show_classes
80
90
 
81
91
  include OrientDB
82
92
 
83
- require 'irb'
93
+ require 'pry'
94
+ #require 'irb'
84
95
  ARGV.clear
85
- IRB.start(__FILE__)
96
+ #IRB.start(__FILE__)
97
+ Pry.start(__FILE__)
@@ -0,0 +1,60 @@
1
+ Changelog
2
+ =========
3
+ 2020/11/27 : file: /lib/database_utils.rb
4
+ method: system_classes, OrientDB 3.1 compatibility
5
+ Added 'OSecurityPolicy' class to system-classes array
6
+
7
+
8
+ 2020/11/30 : file: /lib/model/the_class.rb
9
+ method: require_model_file
10
+ The method now accepts an array of directories to be loaded
11
+
12
+ Thus hierarchical class-structures are initialised properly.
13
+ It appeared that on reopening a base-class in a hierarchical structure
14
+ the contents were not read when accessing the child-classes.
15
+
16
+ The change is backward compatible, the method accepts single directories as well.
17
+
18
+ 2020/12/01 Ruby 2.7 (3.0) Compatibiltiy
19
+ file: /lib/init.rb ** Hash-notation as method parameter
20
+ file: /lib/model/the_record.rb
21
+
22
+ 2020/12/13 file /lib/other.rb
23
+ method: Array#to_orient
24
+ If all members of the array respond to `rid?` and any of them is a reference
25
+ to a database-record, put it without quotes into the serialized string.
26
+ This enables: where: { contract: ['#194:0','208:0'] } => .in[ contract in [194:0, 208:0] ]
27
+
28
+ 2020/12/14 file /lib/other.rb
29
+ method: Array#orient_flatten
30
+ The method flattens the Array and removes nil-values. The array itself is modified
31
+
32
+ 2020/12/16 file /lib/model/vertex.rb
33
+ method: detect_edges
34
+ If no informations about edges are present, reload the vertex
35
+
36
+ file /example/books.rb
37
+ updated together with the spec-file
38
+
39
+ 2020/12/17 file /lib/support/orient.rb
40
+ class: OrientSupport::Hash
41
+ method: merge (alias << )
42
+ calls super (Hash#merge) and stores the result in the database, reloads the record
43
+
44
+ method: remove
45
+ performs the database-operation and reloads the record
46
+
47
+ 2020/12/21 file /lib/rest/create.rb
48
+ method: create_record
49
+ Included the option: »silence«. If set, if a duplicate index-error is fired, the
50
+ original record is loaded instead of creating a new one.
51
+
52
+ file /lib/model/vertex.rb
53
+ method: create
54
+ Vertex.create uses »create_record« with »silence:true« to create records.
55
+
56
+ file /lib/orientquery.rb
57
+ class: OrientSupport::OrientQuery
58
+ method: execute
59
+ If the execution of a query was not successfull, nil is returned
60
+
@@ -1,18 +1,18 @@
1
1
  ---
2
2
  :orientdb:
3
- :server: 172.28.50.25
4
- # localhost # 172.28.50.109 # localhost #mailout.halfgarten-capital.de
3
+ :server: 10.222.148.109
4
+ #:server: localhost
5
5
  :port: 2480
6
6
  :logger: stdout # 'file' or 'stdout'
7
7
  :database:
8
- :development: GratefulDeadConcerts
9
- :production: hcn_data
8
+ :development: devel
9
+ :production: produc
10
10
  :test: temp
11
11
  :admin:
12
- :user: hctw
13
- :pass: hc
12
+ :user: ***w
13
+ :pass: ***c
14
14
  :auth:
15
- :user: topo
16
- :pass: focus
15
+ :user: root
16
+ :pass: ****s
17
17
 
18
18
  # hfx: 101
@@ -19,112 +19,149 @@ However, any parameter given is transmitted as serach-criteria, ie.
19
19
  defines two search criteria.
20
20
 
21
21
  =end
22
+ require 'bundler/setup'
23
+ require 'yaml'
24
+ require 'logger'
25
+ require 'active-orient'
22
26
 
23
27
  class BooksExample
24
28
 
25
- def initialize rebuild: true
26
- if rebuild
27
- print "\n === REBUILD === \n"
28
- ## check wether the database tables exist. Then delete Database-Class and preallocated ruby-Object
29
- database_classes = [ :book, :keyword, :has_content ]
30
- puts "allocated-database-classes: #{ORD.database_classes.join(" , ")} "
31
- if database_classes.map{|c| ORD.database_classes.include?( c.to_s ) ? c : nil }.compact.size == 3
32
- print " deleting database tables \n"
33
- database_classes.each{ | c | d_class= c.to_s.classify.constantize # works if namespace=Object
34
- d_class.delete_class if d_class.present? }
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_vertex_class :book, :keyword
40
- ORD.create_edge_class :has_content
41
- print "\n === PROPERTY === \n"
42
- Keyword.create_property :item, type: :string, index: :unique
43
- Book.create_property :title, type: :string, index: :unique
44
- print "\n === Unique Edges === \n"
45
- HasContent.uniq_index
46
- end
47
- end
48
-
49
-
50
- def read_samples
51
- print "\n === READ SAMPLES === \n"
52
- ## Lambda fill databasea
53
- # Anaylse a sentence
54
- # Split into words and upsert them to Word-Class.
55
- # The Block is only performed, if a new Word is inserted.
56
- fill_database = ->(sentence, this_book ) do
57
-
58
- sentence.split(' ').map do | word |
59
- Keyword.upsert where: { item: word } do | new_keyword |
60
- HasContent.create from: this_book, to: new_keyword
61
- end
62
- end
63
-
64
- end
65
- ## Lambda end
66
- 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'
67
- this_book = Book.create title: 'first'
68
- fill_database[ words, this_book ]
69
-
70
- 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'
71
- this_book = Book.create title: 'second'
72
- fill_database[ words2, this_book ]
73
- puts "#{Keyword.count} keywords inserted into Database"
74
- end
75
-
76
- def display_books_with *desired_words
77
-
78
- ## Each serach criteria becomes a subquery
79
- ## This is integrated into the main_query using 'let'.
80
- ## Subquery: let ${a-y} = select expand(in('has_content')) from keyword where item = {search_word}
81
- ## combine with intercect: $z = Intercect( $a ... $y )
82
- ## Main Query is just
83
- ## select expand( $z ) followed by all let-statements and finalized by "intercect"
84
- #
85
- print("\n === display_books_with » #{ desired_words.join "," } « === \n")
86
- main_query = OrientSupport::OrientQuery.new projection: 'expand( $z )'
87
-
88
- intersects = Array.new
89
- desired_words.each_with_index do | word, i |
90
- symbol = ( i+97 ).chr # convert 1 -> 'a', 2 -> 'b' ...
91
- subquery = OrientSupport::OrientQuery.new from: Keyword, projection: "expand(in('has_content'))"
92
- subquery.where = { item: word }
93
- main_query.let << { symbol => subquery }
94
- intersects << "$#{symbol}"
95
- end
96
- main_query.let << "$z = Intersect(#{intersects.join(', ')}) "
97
- puts "generated Query:"
98
- puts main_query.compose
99
- result = Keyword.query_database main_query, set_from: false
100
- puts '-' * 23
101
- puts "found books: "
102
- puts result.map( &:title ).join("; ")
103
- if result.empty?
104
- puts " -- None -- "
105
- puts " try » ruby books.rb japan flaute « for a positive search in one of the two sentences"
106
- else
107
- puts '-_' * 23
108
- puts "that's it folks"
109
- end
110
- end
29
+ def initialize rebuild: true
30
+ if rebuild
31
+ print "\n === REBUILD === \n"
32
+ ## check wether the database tables exist. Then delete Database-Class and preallocated ruby-Object
33
+ di = database_instance = V.db
34
+ database_classes = [ :book, :keyword, :has_content ]
35
+ print " creating Book and Keyword as Vertex; HAS_CONTENT as Edge \n"
36
+ V.create_class :book, :keyword
37
+ E.create_class :has_content
38
+ print "\n === PROPERTY === \n"
39
+ Keyword.create_property :item, type: :string, index: :unique
40
+ Book.create_property :title, type: :string, index: :unique
41
+ print "\n === Unique Edges === \n"
42
+ HAS_CONTENT.uniq_index
43
+
44
+ Keyword.delete( all: true )
45
+ Book.delete :all => true
46
+ end
47
+ end
48
+
49
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
50
+ ################# read samples ##############
51
+ def read_samples
52
+ print "\n === READ SAMPLES === \n"
53
+ ## Lambda fill databasea
54
+ # Anaylse a sentence
55
+ # Split into words and upsert them to Word-Class.
56
+ # The Block is only performed, if a new Word is inserted.
57
+ fill_database = ->(sentence, this_book ) do
58
+
59
+ sentence.split(' ').map do | word |
60
+ this_book.assign vertex: Keyword.create( item: word ), via: HAS_CONTENT if Keyword.where( item: word ).empty?
61
+ end
62
+
63
+ end
64
+ ## Lambda end
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'
66
+ this_book = Book.create title: 'first'
67
+ fill_database[ words, this_book ]
68
+
69
+ 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
+ this_book = Book.create title: 'second'
71
+ fill_database[ words2, this_book ]
72
+ puts "#{Keyword.count} keywords inserted into Database"
73
+ end
74
+
75
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
76
+ ################# display books ##############
77
+ def display_books_with *desired_words
78
+ ## Each serach criteria becomes a subquery
79
+ ## This is integrated into the main_query using 'let'.
80
+ ## Subquery: let ${a-y} = select expand(in('has_content')) from keyword where item = {search_word}
81
+ ## combine with intercect: $z = Intercect( $a ... $y )
82
+ ## Main Query is just
83
+ ## select expand( $z ) followed by all let-statements and finalized by "intercect"
84
+ #
85
+
86
+ # lambda to create subqueries
87
+ word_query = -> (arg) do
88
+ q= Keyword.query where: arg
89
+ q.nodes :in, via: HAS_CONTENT
90
+ end
91
+
92
+ ## We just create "select expand($z)"
93
+ main_query = OrientSupport::OrientQuery.new
94
+ main_query.expand( '$z' )
95
+
96
+
97
+ print("\n === display_books_with » #{ desired_words.join "," } « === \n")
98
+
99
+ intersects = Array.new
100
+ ## Now, add subqueries to the main-query
101
+ desired_words.each_with_index do | word, i |
102
+ symbol = ( i+97 ).chr # convert 1 -> 'a', 2 -> 'b' ...
103
+ main_query.let symbol => word_query[ item: word ]
104
+ intersects << "$#{symbol}"
105
+ end
106
+ ## Finally add the intersects statement
107
+ main_query.let "$z = Intersect(#{intersects.join(', ')}) "
108
+ puts "generated Query:"
109
+ puts main_query.to_s
110
+ puts "\n\n\n"
111
+ result = main_query.execute
112
+ puts '-' * 23
113
+ puts "found books: "
114
+ puts result.map( &:title ).uniq.join("; ")
115
+ if result.empty?
116
+ puts " -- None -- "
117
+ puts " try » ruby books.rb japan flaute « for a positive search in one of the two sentences"
118
+ else
119
+ puts '-_' * 23
120
+ puts "that's it folks"
121
+ end
122
+ end
111
123
  end
112
124
 
113
- if $0 == __FILE__
125
+ if $0 == __FILE__
126
+ config_file = File.expand_path('../../config/connect.yml', __FILE__)
127
+ connectyml = if File.exist?(config_file)
128
+ YAML.load_file( config_file )[:orientdb]
129
+ else
130
+ puts "config/connect.yml not found "
131
+ puts "using defaults"
132
+ { server: 'localhost', port: 2480,
133
+ database: { development: 'temp' },
134
+ admin: { user: 'root', pass: 'root' } }
135
+ end
136
+
137
+ begin
138
+ ActiveOrient::Init.connect database: connectyml[:database][:development].to_s,
139
+ user: connectyml[:admin][:user].to_s,
140
+ password: connectyml[:admin][:pass].to_s,
141
+ server: connectyml[:server].to_s
142
+
143
+ ActiveOrient::Base.logger.level = Logger::INFO
144
+ ActiveOrient::Model.keep_models_without_file = true
145
+ ActiveOrient::OrientDB.new model_dir: 'lib/model'
146
+ rescue RestClient::Unauthorized
147
+ puts "Cannot connect to the server. Wrong credentials"
148
+ Kernel.exit
149
+ rescue Errno::ECONNREFUSED
150
+ puts "Database Server is not running on #{connectyml[:server]} "
151
+ Kernel.exit
152
+ end
114
153
 
115
- search_items = ARGV.empty? ? ['China', 'aus', 'Flaute'] : ARGV
116
- ARGV = [ 'd' ] # development-mode
117
- @configDatabase = 'BookTest'
118
154
 
119
- require '../config/boot'
155
+ search_items = ARGV.empty? ? ['China', 'aus', 'Flaute'] : ARGV
156
+ ARGV = [ 'd' ] # development-mode
120
157
 
121
- # search_items = ARGV.empty? ? ['China', 'aus', 'Flaute'] : ARGV
122
- b = BooksExample.new rebuild: true
158
+ # search_items = ARGV.empty? ? ['China', 'aus', 'Flaute'] : ARGV
159
+ b = BooksExample.new rebuild: true
123
160
 
124
- # ORD.create_vertex_class "Book", "Keyword"
125
- # ORD.create_edge_class 'has_content'
161
+ # ORD.create_vertex_class "Book", "Keyword"
162
+ # ORD.create_edge_class 'has_content'
126
163
 
127
- b.read_samples if Keyword.count.zero?
128
- b.display_books_with *search_items
164
+ b.read_samples if Keyword.count.zero?
165
+ b.display_books_with *search_items
129
166
 
130
167
  end