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 +4 -4
- data/.graphs.txt.swp +0 -0
- data/Gemfile +2 -6
- data/README.md +29 -27
- data/VERSION +1 -1
- data/active-orient.gemspec +4 -3
- data/bin/active-orient-console +18 -6
- data/changelog.md +60 -0
- data/config/connect.yml +8 -8
- data/examples/books.rb +134 -97
- data/graphs.txt +70 -0
- data/lib/active-orient.rb +2 -0
- data/lib/base.rb +38 -17
- data/lib/base_properties.rb +15 -14
- data/lib/class_utils.rb +11 -50
- data/lib/database_utils.rb +23 -22
- data/lib/init.rb +4 -3
- data/lib/model/custom.rb +7 -4
- data/lib/model/e.rb +6 -0
- data/lib/model/edge.rb +74 -30
- data/lib/model/the_class.rb +181 -131
- data/lib/model/the_record.rb +115 -68
- data/lib/model/vertex.rb +261 -126
- data/lib/other.rb +93 -41
- data/lib/rest/change.rb +23 -20
- data/lib/rest/create.rb +71 -63
- data/lib/rest/delete.rb +80 -64
- data/lib/rest/operations.rb +79 -68
- data/lib/rest/read.rb +42 -24
- data/lib/rest/rest.rb +38 -30
- data/lib/support/conversions.rb +42 -0
- data/lib/support/default_formatter.rb +7 -0
- data/lib/support/errors.rb +41 -0
- data/lib/support/orient.rb +167 -58
- data/lib/support/orientquery.rb +526 -348
- data/lib/support/query.rb +92 -0
- metadata +34 -18
- data/examples/test_commands.rb +0 -97
- data/examples/test_commands_2.rb +0 -59
- data/examples/test_commands_3.rb +0 -55
- data/examples/test_commands_4.rb +0 -33
- data/examples/time_graph.md +0 -162
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b57e243fb22b2156f6a2e92aa5955cbafead6da0c5fd65be11ef2483b829f07
|
4
|
+
data.tar.gz: 5c67edc1f5c62713ab363720cf43a7f8371470a75c49df8869f4a91b6cd32494
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00d96784e43d226cd3b66acf2d02e6db57459f79fe70893a328d7fa60d3c5b54c27d76f0f082136ed3bfca267e59fd4337818894c98ec367092f4721f6654966
|
7
|
+
data.tar.gz: fbb32f47ab7dbfaa152dd5a0a2432b9c3039125e36255381e3874b8a04b148113a3b23dadf7e1ae22a09384b1144ad7f873aaf0413c8c9094142a921dcb64945
|
data/.graphs.txt.swp
ADDED
Binary file
|
data/Gemfile
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
gemspec
|
3
|
-
gem '
|
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
|
3
|
-
|
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
|
-
|
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.
|
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
|
36
|
+
OrientDB is a Multi-Model-Database. It shares the concept of Inheritance with OO-Languages, like Ruby.
|
30
37
|
|
31
|
-
Upon
|
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
|
-
|
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.
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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 »
|
91
|
+
To update several records, a class-method »update« is provided.
|
90
92
|
```ruby
|
91
|
-
M.
|
92
|
-
M.
|
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
|
-
|
99
|
-
|
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
|
-
|
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 (
|
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.
|
1
|
+
0.80
|
data/active-orient.gemspec
CHANGED
@@ -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
|
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"
|
23
|
-
s.add_development_dependency "rake"
|
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
|
data/bin/active-orient-console
CHANGED
@@ -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: '
|
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
|
-
|
41
|
-
|
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 '
|
93
|
+
require 'pry'
|
94
|
+
#require 'irb'
|
84
95
|
ARGV.clear
|
85
|
-
IRB.start(__FILE__)
|
96
|
+
#IRB.start(__FILE__)
|
97
|
+
Pry.start(__FILE__)
|
data/changelog.md
ADDED
@@ -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
|
+
|
data/config/connect.yml
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
---
|
2
2
|
:orientdb:
|
3
|
-
:server:
|
4
|
-
|
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:
|
9
|
-
:production:
|
8
|
+
:development: devel
|
9
|
+
:production: produc
|
10
10
|
:test: temp
|
11
11
|
:admin:
|
12
|
-
:user:
|
13
|
-
:pass:
|
12
|
+
:user: ***w
|
13
|
+
:pass: ***c
|
14
14
|
:auth:
|
15
|
-
:user:
|
16
|
-
:pass:
|
15
|
+
:user: root
|
16
|
+
:pass: ****s
|
17
17
|
|
18
18
|
# hfx: 101
|
data/examples/books.rb
CHANGED
@@ -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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
155
|
+
search_items = ARGV.empty? ? ['China', 'aus', 'Flaute'] : ARGV
|
156
|
+
ARGV = [ 'd' ] # development-mode
|
120
157
|
|
121
|
-
|
122
|
-
|
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
|
-
|
128
|
-
|
164
|
+
b.read_samples if Keyword.count.zero?
|
165
|
+
b.display_books_with *search_items
|
129
166
|
|
130
167
|
end
|