Added a comment note to the regular expression that it is a POSIX version of the one used in tools/*.js where it is a PCRE type of regex
Updated db model

Renamed 'phones' to 'devices', separated the keywords and weights from each other, add 'keyword' property to the weights collection
Changed the way the user-agents and the mongodb connection is handled

First big change is that the user_agents.txt file is first read and an array of all user agents is build up. Then this array is passed once to db.collection(...).insert() function which makes it much faster compared to the previous state. Mongodb connection has been updated to the MongoClient class API
Removed unused/duplicated code that updated the keywords collection - this was not needed because the keywords are updated in process_user_agents_datafile.js
property 'aka: []' added to the devices collection
Added a check when training set length = 0

In that case the function returns a pointer to unitialized training set
The main function exits when the training set is empty