Class: DB::Classifier
Constant Summary collapse
- COLL_WAYS =
"ways"
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
-
#bulk_insert(*args) ⇒ Object
Abstract method.
-
#classify_all(feature_name) ⇒ Object
Load all features into feature_name collection.
-
#classify_subtype(main_feature, sub_feature) ⇒ Object
Load all features into feature_name collection with subfeature filtering.
-
#connect ⇒ Object
Connecting to database.
-
#initialize(database_name, bulk_limit, host, port) ⇒ Classifier
constructor
Constructor.
-
#insert(*args) ⇒ Object
Abstract method.
Methods included from AbstractInterface
Constructor Details
#initialize(database_name, bulk_limit, host, port) ⇒ Classifier
Constructor.
Attributes
-
database_name
database name -
collection_name
collection name -
bulk_limit
Array limit for bulk insert. -
host
host name (default: localhost) -
port
port number (default: 27017)
26 27 28 29 30 31 32 33 |
# File 'lib/db/classifier.rb', line 26 def initialize(database_name, bulk_limit, host, port) @host = host @port = port @dbname = database_name @bulk_limit = bulk_limit @data_array = Array.new connect() end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
14 15 16 |
# File 'lib/db/classifier.rb', line 14 def connection @connection end |
Instance Method Details
#bulk_insert(*args) ⇒ Object
Abstract method
Insert many data at once.
Attributes
-
data
Array of Hashes
100 101 102 |
# File 'lib/db/classifier.rb', line 100 def bulk_insert(*args) end |
#classify_all(feature_name) ⇒ Object
Load all features into feature_name collection.
Attributes
-
feature_name
OSM Map Feature Name
54 55 56 57 58 59 60 61 62 |
# File 'lib/db/classifier.rb', line 54 def classify_all(feature_name) feature_con = DB::Mongohandler.new(@dbname, feature_name, @bulk_limit, @host, @port) feature_con.use_connection(@connection) @collection.find("tags." << feature_name => {"$exists" => true}).each do |doc| feature_con.bulk_insert(doc) end return feature_con.collection.size end |
#classify_subtype(main_feature, sub_feature) ⇒ Object
Load all features into feature_name collection with subfeature filtering.
Attributes
-
feature_name
OSM Map Feature name -
sub_feature
OSM Map Sub feature name
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/db/classifier.rb', line 71 def classify_subtype(main_feature, sub_feature) # First argument identifies Main Feature, the rest sub-features feature_con = DB::Mongohandler.new(@dbname, main_feature, @bulk_limit, @host, @port) feature_con.use_connection(@connection) @collection.find({"tags." << main_feature => sub_feature}).each do |doc| feature_con.bulk_insert(doc) end return feature_con.collection.size end |
#connect ⇒ Object
Connecting to database
Connecting to database with given:
Attributes
-
host
Host name -
port
Port number -
pool_size
optional
44 45 46 47 |
# File 'lib/db/classifier.rb', line 44 def connect @connection = Mongo::Connection.new(@host, @port, :pool_size => 5) @collection = (@connection[@dbname])[COLL_WAYS] end |
#insert(*args) ⇒ Object
Abstract method
Insert data:
Attributes
-
data
Hash or Array
89 90 91 |
# File 'lib/db/classifier.rb', line 89 def insert(*args) end |