UNPKG

qminer

Version:

A C++ based data analytics platform for processing large-scale real-time streams containing structured and unstructured data

948 lines (947 loc) 228 kB
<!doctype html> <html> <head> <meta name="generator" content="JSDoc 3"> <meta charset="utf-8"> <title>Source: qminerdoc.js</title> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css"> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css"> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css"> <link href="css/baseline.css" rel="stylesheet"> </head> <body onload="prettyPrint()"> <nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar"> <div id="jsdoc-navbar-container"> <div id="jsdoc-navbar-content"> <a href="index.html" class="jsdoc-navbar-package-name">Home</a> </div> </div> </nav> <div id="jsdoc-body-container"> <div id="jsdoc-content"> <div id="jsdoc-content-container"> <div id="jsdoc-banner" role="banner"> </div> <div id="jsdoc-main" role="main"> <header class="page-header"> <h1>Source: qminerdoc.js</h1> </header> <article> <pre class="prettyprint linenums"><code>/** * Copyright (c) 2015, Jozef Stefan Institute, Quintelligence d.o.o. and contributors * All rights reserved. * * This source code is licensed under the FreeBSD license found in the * LICENSE file in the root directory of this source tree. */ /** * QMiner module. * @module qm * @example * // import module * var qm &#x3D; require(&#x27;qminer&#x27;); */ /** * Creates a directory structure. * @param {string} [configPath&#x3D;&#x27;qm.conf&#x27;] - The path to configuration file. * @param {boolean} [overwrite&#x3D;false] - If you want to overwrite the configuration file. * @param {number} [portN&#x3D;8080] - The number of the port. Currently not used. * @param {number} [cacheSize&#x3D;1024] - Sets available memory for indexing (in MB). */ exports.config &#x3D; function(configPath, overwrite, portN, cacheSize) {} /** * Creates an empty base. * @param {string} [configPath&#x3D;&#x27;qm.conf&#x27;] - Configuration file path. * @param {string} [schemaPath&#x3D;&#x27;&#x27;] - Schema file path. * @param {boolean} [clear&#x3D;false] - Clear the existing db folder. * @returns {module:qm.Base} The newly created base. */ exports.create &#x3D; function (configPath, schemaPath, clear) { return Object.create(require(&#x27;qminer&#x27;).Base.prototype); } /** * Opens a base. * @param {string} [configPath&#x3D;&#x27;qm.conf&#x27;] - The configuration file path. * @param {boolean} [readOnly&#x3D;false] - Open in read-only mode. * @returns {module:qm.Base} The loaded base. */ exports.open &#x3D; function (configPath, readOnly) { return Object.create(require(&#x27;qminer&#x27;).Base.prototype); } /** * Set verbosity of QMiner internals. * @param {number} [level&#x3D;0] - verbosity level. Possible options: * &amp;lt;br&gt;1. &#x60;0&#x60; - No output, * &amp;lt;br&gt;2. &#x60;1&#x60; - Log output, * &amp;lt;br&gt;3. &#x60;2&#x60; - Log and debug output. */ exports.verbosity &#x3D; function (level) { } /** * Returns an JSON with two properties: &quot;byClass&quot; and &quot;total&quot;. The &quot;byClass&quot; value is a JSON where * each key is a class ID and each value is of the form { newFromCpp: number, newFromJs: number, destructorCalls: number} * and the value of &quot;total&quot; is of the same form (aggregated over &quot;byClass&quot;) */ exports.stats &#x3D; function () { } /** * @typedef {Object} QMinerFlags * The object containing the QMiner compile flags. * @property {string} buildTime - The module build time. * @property {boolean} win - True, if the module is compiled for Windows. * @property {boolean} linux - True, if the module is compiled for Linux. * @property {boolean} darwin - True, if the module is compiled for Darwin. * @property {boolean} x86 - True, if the module is compiled for x86 system. * @property {boolean} x64 - True, if the module is compiled for x64 system. * @property {boolean} omp - True, if the module is compiled for omp. * @property {boolean} debug - True, if the module is compiled for debug mode. * @property {boolean} gcc - True, if the module is compiled for gcc. * @property {boolean} clang - True, if the module is compiled for clang. * @property {boolean} blas - True, if the module is compiled with Blas. * @property {boolean} blas_intel - True, if the module is compiled with Intel Blas. * @property {boolean} blas_amd - True, if the module is compiled with AMD Blas. * @property {boolean} blas_openblas - True, if the module is compiled with OpenBLAS. * @property {boolean} lapacke - True, if the module is compiled with Lapacke. */ /** * Returns an object with all compile flags. Type {@link module:qm~QMinerFlags}. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // get the compile flags * var flags &#x3D; qm.flags; */ exports.flags &#x3D; { buildTime: &quot;&quot;, win: true, linux: true, darwin: true, x86: true, x64: true, omp: true, debug: true, gcc: true, clang: true, blas: true, blas_intel: true, blas_amd: true, blas_openblas: true, lapacke: true }; /** * Returns the module version. * @returns {string} The module version. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // get the module version * var version &#x3D; qm.version; */ exports.version &#x3D; &#x27;&#x27;; /** * @typedef {Object} BaseConstructorParam * Base constructor parameter used for {@link module:qm.Base}. * @property {string} [mode&#x3D;&#x27;openReadOnly&#x27;] - Base access mode. Can be one of the following: * &amp;lt;br&gt;1. &#x60;&#x27;create&#x27;&#x60; - Sets up the db folder, * &amp;lt;br&gt;2. &#x60;&#x27;createClean&#x27;&#x60; - Cleans db folder and then sets it up, * &amp;lt;br&gt;3. &#x60;&#x27;open&#x27;&#x60; - Opens the db with read/write permissions, * &amp;lt;br&gt;4. &#x60;&#x27;openReadOnly&#x27;&#x60; - Opens the db in read only mode. * @property {number} [indexCache&#x3D;1024] - The ammount of memory reserved for indexing (in MB). * @property {number} [storeCache&#x3D;1024] - The ammount of memory reserved for store cache (in MB). * @property {string} [schemaPath&#x3D;&#x27;&#x27;] - The path to schema definition file. * @property {Array&amp;lt;module:qm~SchemaDef&gt;} [schema&#x3D;[]] - Schema definition object array. * @property {string} [dbPath&#x3D;&#x27;./db/&#x27;] - The path to db directory. */ /** * @typedef {Object} SchemaDef * Store schema definition used in {@link module:qm~BaseConstructorParam}. * @property {string} name - The name of the store. Store name can be composed by from English letters, numbers, _ or $ characters. It can only begin with a character. * @property {Array&amp;lt;module:qm~SchemaFieldDef&gt;} fields - The array of field descriptors. * @property {Array&amp;lt;module:qm~SchemaJoinDef&gt;} [joins&#x3D;[]] - The array of join descriptors, used for linking records from different stores. * @property {Array&amp;lt;module:qm~SchemaKeyDef&gt;} [keys&#x3D;[]] - The array of key descriptors. Keys define how records are indexed, which is needed for search using the query language. * @property {module:qm~SchemaTimeWindowDef} [timeWindow] - Time window description. Stores can have a window, which is used by garbage collector to delete records once they fall out of the time window. Window can be defined by number of records or by time. * @example * var qm &#x3D; require(&#x27;qminer&#x27;); * // create a simple movies store, where each record contains only the movie title. * var base &#x3D; new qm.Base({ * mode: &#x27;createClean&#x27;, * schema: [{ * name: &quot;Movies&quot;, * fields: [{ name: &quot;title&quot;, type: &quot;string&quot; }] * }] * }); * base.close(); */ /** * @typedef {Object} SchemaFieldDef * Store schema field definition used in {@link module:qm~SchemaDef}. * @property {string} name - The name of the field. * @property {string} type - The type of the field. Possible options: * &amp;lt;br&gt;1. &#x60;&#x27;int&#x27;&#x60; - Signed 32-bit integer, * &amp;lt;br&gt;2. &#x60;&#x27;uint64&#x27;&#x60; - Unsigned 64-bit integer, * &amp;lt;br&gt;3. &#x60;&#x27;int_v&#x27;&#x60; - Array of signed 32-bit integers, * &amp;lt;br&gt;4. &#x60;&#x27;string&#x27;&#x60; - String, * &amp;lt;br&gt;5. &#x60;&#x27;string_v&#x27;&#x60; - Array of strings, * &amp;lt;br&gt;6. &#x60;&#x27;bool&#x27;&#x60; - Boolean, * &amp;lt;br&gt;7. &#x60;&#x27;float&#x27;&#x60; - Double precision flating point number, * &amp;lt;br&gt;8. &#x60;&#x27;float_pair&#x27;&#x60; - A pair of floats, useful for storing geo coordinates, * &amp;lt;br&gt;9. &#x60;&#x27;float_v&#x27;&#x60; - Array of floats, * &amp;lt;br&gt;10. &#x60;&#x27;datetime&#x27;&#x60; - Date and time format, stored in a form of miliseconds since 1600, * &amp;lt;br&gt;11. &#x60;&#x27;num_sp_v&#x27;&#x60; - Array of [&#x60;int&#x60;, &#x60;float&#x60;] pairs. See constructor array for {@link module:la.SparseVector}, * &amp;lt;br&gt;12. &#x60;&#x27;json&#x27;&#x60; - this field can be an arbitrary object and will be internally serialized into string using JSON notation, * &amp;lt;br&gt;13. &#x60;&#x27;blob&#x27;&#x60; - Binary buffer, used for storing binary data, * @property {boolean} [primary&#x3D;false] - Field which can be used to identify record. There can be only one primary field in a store. There can be at most one record for each value of the primary field. Currently following fields can be marked as primary: &#x60;int&#x60;, &#x60;uint64&#x60;, &#x60;string&#x60;, &#x60;float&#x60;, &#x60;datetime&#x60;. Primary fields of type &#x60;string&#x60; are also used for record querying using {@link module:qm.Store#recordByName}. * @property {boolean} [null&#x3D;false] - When set to true, null is a possible value for a field (allow missing values). * @property {string} [store&#x3D;&#x27;memory&#x27;] - Defines where to store the field. Possible options * &amp;lt;br&gt;1. &#x60;&#x27;memory&#x27;&#x60; - Stores the values in RAM. * &amp;lt;br&gt;2 &#x60;&#x27;cache&#x27;&#x60; - Stores the values on disk, with a layer of FIFO cache in RAM, storing the most recently used values. * @property {Object} [default] - Default value for field when not given for a new record. * @property {boolean} [codebook&#x3D;false] - Useful when many records have only few different values of this field. If set to true, then a separate table of all values is kept, and records only point to this table (replacing variable string field in record serialisation with fixed-length integer). Useful to decrease memory footprint, and faster to update. (STRING FIELD TYPE SPECIFIC). * @property {boolean} [shortstring&#x3D;false] - Useful for string shorter then 127 characters (STRING FIELD TYPE SPECIFIC). * @example * var qm &#x3D; require(&#x27;qminer&#x27;); * var base &#x3D; new qm.Base({ * mode: &#x27;createClean&#x27;, * schema: [ * { name: &#x27;NewsArticles&#x27;, * fields: [ * { name: &quot;ID&quot;, primary: true, type: &quot;string&quot;, shortstring: true }, * { name: &quot;Source&quot;, type: &quot;string&quot;, codebook: true }, * { name: &quot;DateTime&quot;, type: &quot;datetime&quot; }, * { name: &quot;Title&quot;, type: &quot;string&quot;, store: &quot;cache&quot; }, * { name: &quot;Tokens&quot;, type: &quot;string_v&quot;, store: &quot;cache&quot;, null: true }, * { name: &quot;Vector&quot;, type: &quot;num_sp_v&quot;, store: &quot;cache&quot;, null: true }] * } * ] * }); * // add a record: * // - we set the date using the ISO string representation * // - we set the string vector Tokens with an array of strings * // - we set the numeric sparse vector Vector with an array of two element arrays * // (index, value), see the sparse vector constructor {@link module:la.SparseVector} * base.store(&#x27;NewsArticles&#x27;).push({ * ID: &#x27;t12344&#x27;, * Source: &#x27;s1234&#x27;, * DateTime: &#x27;2015-01-01T00:05:00&#x27;, * Title: &#x27;the title&#x27;, * Tokens: [&#x27;token1&#x27;, &#x27;token2&#x27;], * Vector: [[0,1], [1,1]]}); * base.close(); */ /** * @typedef {Object} SchemaJoinDef * Store schema join definition used in {@link module:qm~SchemaDef}. * @property {string} name - The name of the join. * @property {string} type - Join types. Possible options: * &amp;lt;br&gt;1. &#x60;&#x27;field&#x27;&#x60; - Points to zero or one record and is implemented as an additional hidden field of type &#x60;uint64&#x60;, which can hold the ID of the record it links to. Accessing the records join returns a record. * &amp;lt;br&gt;2. &#x60;&#x27;index&#x27;&#x60; - Point to any number of records and is implemented using the inverted index, where for each record a list (vector) of linked records is kept. Accessing the records join returns a record set. * &amp;lt;b&gt;Important:&amp;lt;/b&gt; The records given to this join field must be in an array. * * @property {string} store - The store name from which the linked records are. * @example * var qm &#x3D; require(&#x27;qminer&#x27;); * // Create two stores: People which stores only names of persons and Movies, which stores only titles. * // Each person can direct zero or more movies, so we use an index join named &#x27;directed&#x27; and * // each movie has a single director, so we use a field join &#x27;director&#x27;. The joins are * // inverses of each other. The inverse join simplifies the linking, since only one join needs * // to be specified, and the other direction can be linked automatically (in the example * // below we specify only the &#x27;director&#x27; link and the &#x27;directed&#x27; join is updated automatically). * // * var base &#x3D; new qm.Base({ * mode: &#x27;createClean&#x27;, * schema: [ * { name: &#x27;People&#x27;, * fields: [{ name: &#x27;name&#x27;, type: &#x27;string&#x27;, primary: true }], * joins: [{ name: &#x27;directed&#x27;, &#x27;type&#x27;: &#x27;index&#x27;, &#x27;store&#x27;: &#x27;Movies&#x27;, &#x27;inverse&#x27;: &#x27;director&#x27; }] }, * { name: &#x27;Movies&#x27;, * fields: [{ name: &#x27;title&#x27;, type: &#x27;string&#x27;, primary: true }], * joins: [{ name: &#x27;director&#x27;, &#x27;type&#x27;: &#x27;field&#x27;, &#x27;store&#x27;: &#x27;People&#x27;, &#x27;inverse&#x27;: &#x27;directed&#x27; }] } * ] * }); * // Adds a movie, automatically adds &#x27;Jim Jarmusch&#x27; to People, sets the &#x27;director&#x27; join (field join) * // and automatically updates the index join &#x27;directed&#x27;, since it&#x27;s an inverse join of &#x27;director&#x27; * base.store(&#x27;Movies&#x27;).push({ title: &#x27;Broken Flowers&#x27;, director: { name: &#x27;Jim Jarmusch&#x27; } }); * * // Adds a movie, sets the &#x27;director&#x27; join, updates the index join of &#x27;Jim Jarmusch&#x27; * base.store(&#x27;Movies&#x27;).push({ title: &#x27;Coffee and Cigarettes&#x27;, director: { name: &#x27;Jim Jarmusch&#x27; } }); * // Adds movie, automatically adds &#x27;Lars von Trier&#x27; to People, sets the &#x27;director&#x27; join * // and &#x27;directed&#x27; inverse join (automatically) * base.store(&#x27;Movies&#x27;).push({ title: &#x27;Dogville&#x27;, director: { name: &#x27;Lars von Trier&#x27; } }); * * // Adds a person, sets the &#x27;directed&#x27; join with multiple movies (&#x27;directed&#x27; is of type &#x27;index&#x27;, movies must be given in an array) * base.store(&#x27;People&#x27;).push({ name: &#x27;Christopher Nolan&#x27;, directed: [{ title: &#x27;Inception&#x27; }, { title: &#x27;Interstellar&#x27; }] }); * * var movie &#x3D; base.store(&#x27;Movies&#x27;)[0]; // get the first movie (Broken Flowers) * // Each movie has a property corresponding to the join name: &#x27;director&#x27;. * // Accessing the property returns a {@link module:qm.Record} from the store People. * var person &#x3D; movie.director; // get the director * var personName &#x3D; person.name; // get person&#x27;s name (&#x27;Jim Jarmusch&#x27;) * * // Each person has a property corresponding to the join name: &#x27;directed&#x27;. * // Accessing the property returns a {@link module:qm.RecSet} from the store People. * var movies &#x3D; person.directed; // get all the movies the person directed. * movies.each(function (movie) { var title &#x3D; movie.title; }); * // Gets the following titles: * // &#x27;Broken Flowers&#x27; * // &#x27;Coffee and Cigarettes&#x27; * base.close(); */ /** * @typedef {Object} SchemaKeyDef * Store schema key definition used in {@link module:qm~SchemaDef}. * @property {string} field - The name of the field that will be indexed. * @property {string} type - Key type. Possible options: * &amp;lt;br&gt;1. &#x60;&#x27;value&#x27;&#x60; - Indexes records using an inverted index using full value of the field (no processing). * The key type supports &#x60;&#x27;string&#x27;&#x60;, &#x60;&#x27;string_v&#x27;&#x60; and &#x60;&#x27;datetime&#x27;&#x60; fields types. * &amp;lt;br&gt;2. &#x60;&#x27;text&#x27;&#x60; - Indexes string fields by using a tokenizer and text processing. Supported by &#x60;&#x27;string&#x27;&#x60; fields. * &amp;lt;br&gt;3. &#x60;&#x27;location&#x27;&#x60;- Indexes records as points on a sphere and enables nearest-neighbour queries. Supported by &#x60;&#x27;float_pair&#x27;&#x60; type fields. * @property {string} [name] - Allows using a different name for the key in search queries. This allows for multiple keys to be put against the same field. Default value is the name of the field. * @property {string} [vocabulary] - Defines the name of the vocabulary used to store the tokens or values. This can be used indicate to several keys to use the same vocabulary, to save on memory. Supported by &#x60;&#x27;value&#x27;&#x60; and &#x60;&#x27;text&#x27;&#x60; keys. * @property {string} [tokenize] - Defines the tokenizer that is used for tokenizing the values stored in indexed fields. Tokenizer uses same parameters as in bag-of-words feature extractor. Default is english stopword list and no stemmer. Supported by &#x60;&#x27;text&#x27;&#x60; keys. * @example * var qm &#x3D; require(&#x27;qminer&#x27;); * // Create a store People which stores only names of persons. * var base &#x3D; new qm.Base({ * mode: &#x27;createClean&#x27;, * schema: [ * { name: &#x27;People&#x27;, * fields: [{ name: &#x27;name&#x27;, type: &#x27;string&#x27;, primary: true }], * keys: [ * { field: &#x27;name&#x27;, type: &#x27;value&#x27;}, * { field: &#x27;name&#x27;, name: &#x27;nameText&#x27;, type: &#x27;text&#x27;} * ] * } * ] * }); * * base.store(&#x27;People&#x27;).push({name : &#x27;John Smith&#x27;}); * base.store(&#x27;People&#x27;).push({name : &#x27;Mary Smith&#x27;}); * // search based on indexed values * base.search({$from : &#x27;People&#x27;, name: &#x27;John Smith&#x27;}); // Return the record set containing &#x27;John Smith&#x27; * // search based on indexed values * base.search({$from : &#x27;People&#x27;, name: &#x27;Smith&#x27;}); // Returns the empty record set * // search based on text indexing * base.search({$from : &#x27;People&#x27;, nameText: &#x27;Smith&#x27;}); // Returns both records * base.close(); */ /** * @typedef {Object} SchemaTimeWindowDef * Stores can have a window, which is used by garbage collector to delete records once they * fall out of the time window. Window can be defined by number of records or by time. * Window defined by parameter window, its value being the number of records to be kept. Used in {@link module:qm~SchemaDef}. * &amp;lt;br&gt;&amp;lt;b&gt;Important:&amp;lt;/b&gt; {@link module:qm.Base#garbageCollect} must be called manually to remove records outside time window. * @property {number} duration - The size of the time window (in number of units). * @property {string} unit - Defines in which units the window size is specified. Possible options are &#x60;&#x27;second&#x27;&#x60;, &#x60;&#x27;minute&#x27;&#x60;, &#x60;&#x27;hour&#x27;&#x60;, &#x60;&#x27;day&#x27;&#x60;, &#x60;&#x27;week&#x27;&#x60; or &#x60;&#x27;month&#x27;&#x60;. * @property {string} [field] - Name of the datetime field, which defines the time of the record. In case it is not given, the insert time is used in its place. * @example &amp;lt;caption&gt;Define window by number of records&amp;lt;/caption&gt; * var qm &#x3D; require(&#x27;qminer&#x27;); * // create base * var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27; }); * // create store with window * base.createStore({ * &quot;name&quot;: &quot;TestStore&quot;, * &quot;fields&quot;: [ * { &quot;name&quot;: &quot;DateTime&quot;, &quot;type&quot;: &quot;datetime&quot; }, * { &quot;name&quot;: &quot;Measurement&quot;, &quot;type&quot;: &quot;float&quot; } * ], * window: 3, * }); * * // push 5 records into created store * for (var i &#x3D; 0; i &amp;lt; 5; i++) { * var rec &#x3D; { * &quot;DateTime&quot;: new Date().toISOString(), * &quot;Measurement&quot;: i * }; * base.store(&quot;TestStore&quot;).push(rec); * } * * // check number of records in store * base.store(&quot;TestStore&quot;).allRecords.length; // 5 * // clean base with garbage collector * base.garbageCollect(); * // check number of records in store * base.store(&quot;TestStore&quot;).allRecords.length; // 3 * base.close(); * * @example &amp;lt;caption&gt;Define window by time&amp;lt;/caption&gt; * var qm &#x3D; require(&#x27;qminer&#x27;); * // create base * var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27; }); * // create store with window * base.createStore({ * &quot;name&quot;: &quot;TestStore&quot;, * &quot;fields&quot;: [ * { &quot;name&quot;: &quot;DateTime&quot;, &quot;type&quot;: &quot;datetime&quot; }, * { &quot;name&quot;: &quot;Measurement&quot;, &quot;type&quot;: &quot;float&quot; } * ], * timeWindow: { * duration: 2, * unit: &quot;hour&quot;, * field: &quot;DateTime&quot; * } * }); * * // push 5 records into created store * for (var i &#x3D; 0; i &amp;lt; 5; i++) { * var rec &#x3D; { * &quot;DateTime&quot;: new Date(new Date().getTime() + i * 60 * 60 * 1001).toISOString(), * &quot;Measurement&quot;: i * }; * base.store(&quot;TestStore&quot;).push(rec); * } * * // check number of records in store * base.store(&quot;TestStore&quot;).allRecords.length; // 5 * // clean base with garbage collector * base.garbageCollect(); * // check number of records in store * base.store(&quot;TestStore&quot;).allRecords.length; // 2 * base.close(); */ /** * Base * @classdesc Represents the database and holds stores. * @class * @param {module:qm~BaseConstructorParam} paramObj - The base constructor parameter object. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // using a constructor, in open mode * var base &#x3D; new qm.Base({ mode: &#x27;open&#x27; }); * base.close(); */ exports.Base &#x3D; function (paramObj) { return Object.create(require(&#x27;qminer&#x27;).Base.prototype); }; /** * Closes the database. * @returns {null} No value is returned. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // using a constructor, in open mode * var base &#x3D; new qm.Base({ mode: &#x27;open&#x27; }); * // close the database * base.close(); */ exports.Base.prototype.close &#x3D; function () { return null; } /** * Checks if the base is closed. * @returns {Boolean} Returns &#x60;true&#x60;, if the base is closed. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // using a constructor, in open mode * var base &#x3D; new qm.Base({ mode: &#x27;open&#x27; }); * // check if the base is closed * var closed &#x3D; base.isClosed(); * // close the database * base.close(); */ exports.Base.prototype.isClosed &#x3D; function () { return true; } /** * Returns the store with the specified name. * @param {string} name - Store name. * @returns {module:qm.Store} The store. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // create a base with two stores * var base &#x3D; new qm.Base({ * mode: &quot;createClean&quot;, * schema: [ * { * name: &quot;KwikEMart&quot;, * fields: [ * { name: &quot;Worker&quot;, type: &quot;string&quot; }, * { name: &quot;Groceries&quot;, type: &quot;string_v&quot; } * ] * }, * { * name: &quot;NuclearPowerplant&quot;, * fields: [ * { name: &quot;Owner&quot;, type: &quot;string&quot; }, * { name: &quot;NumberOfAccidents&quot;, type: &quot;int&quot; }, * { name: &quot;Workers&quot;, type: &quot;string_v&quot; } * ] * }] * }); * // get the &quot;KwikEMart&quot; store * var store &#x3D; base.store(&quot;KwikEMart&quot;); // returns the store with the name &quot;KwikEMart&quot; * base.close(); */ exports.Base.prototype.store &#x3D; function (name) { return Object.create(require(&#x27;qminer&#x27;).Store.prototype); } /** * Checks if there is a store. * @param {string} name - Store name. * @returns {boolean} True, if there exists a store with the store &#x60;name&#x60;. Otherwise, false. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // create a base with two stores * var base &#x3D; new qm.Base({ * mode: &quot;createClean&quot;, * schema: [ * { * name: &quot;KwikEMart&quot;, * fields: [ * { name: &quot;Worker&quot;, type: &quot;string&quot; }, * { name: &quot;Groceries&quot;, type: &quot;string_v&quot; } * ] * }, * { * name: &quot;NuclearPowerplant&quot;, * fields: [ * { name: &quot;Owner&quot;, type: &quot;string&quot; }, * { name: &quot;NumberOfAccidents&quot;, type: &quot;int&quot; }, * { name: &quot;Workers&quot;, type: &quot;string_v&quot; } * ] * }] * }); * // get the &quot;KwikEMart&quot; store * var exists &#x3D; base.isStore(&quot;KwikEMart&quot;); // true * base.close(); */ exports.Base.prototype.isStore &#x3D; function (name) { return false; } /** * Returns a list of store descriptors. * @returns {Array.&amp;lt;object&gt;} An array of store descriptors. The store descriptor &#x60;storeDesc&#x60; contains the properties: * &amp;lt;br&gt;1. &#x60;storeDesc.storeId&#x60; - The store ID. Type &#x60;number&#x60;. * &amp;lt;br&gt;2. &#x60;storeDesc.storeName&#x60; - Store name. Type &#x60;string&#x60;. * &amp;lt;br&gt;3. &#x60;storeDesc.storeRecords&#x60; - Number of records in store. Type &#x60;number&#x60;. * &amp;lt;br&gt;4. &#x60;storeDesc.fields&#x60; - The store field schema. Type &amp;lt;code&gt;Array of &amp;lt;a href&#x3D;&quot;module-qm.html#~SchemaFieldDef&quot;&gt;module:qm.SchemaFieldDef&amp;lt;/a&gt;&amp;lt;/code&gt;. * &amp;lt;br&gt;5. &#x60;storeDesc.keys&#x60; - The store key schema. Type &amp;lt;code&gt;Array of &amp;lt;a href&#x3D;&quot;module-qm.html#~SchemaKeyDef&quot;&gt;module:qm.SchemaKeyDef&amp;lt;/a&gt;&amp;lt;/code&gt;. * &amp;lt;br&gt;6. &#x60;storeDesc.joins&#x60; - The store join schema. Type &amp;lt;code&gt;Array of &amp;lt;a href&#x3D;&quot;module-qm.html#~SchemaJoinDef&quot;&gt;module:qm.SchemaJoinDef&amp;lt;/a&gt;&amp;lt;/code&gt;. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // create a base with two stores * var base &#x3D; new qm.Base({ * mode: &quot;createClean&quot;, * schema: [ * { * name: &quot;KwikEMart&quot;, * fields: [ * { name: &quot;Worker&quot;, type: &quot;string&quot; }, * { name: &quot;Groceries&quot;, type: &quot;string_v&quot; } * ] * }, * { * name: &quot;NuclearPowerplant&quot;, * fields: [ * { name: &quot;Owner&quot;, type: &quot;string&quot; }, * { name: &quot;NumberOfAccidents&quot;, type: &quot;int&quot; }, * { name: &quot;Workers&quot;, type: &quot;string_v&quot; } * ] * }] * }); * // get the list of store descriptors * var exists &#x3D; base.getStoreList(); * base.close(); */ exports.Base.prototype.getStoreList &#x3D; function () { return [{storeId: 0, storeName:&#x27;&#x27;, storeRecords: 0, fields: [{}], keys: [{}], joins: [{}]}]; } /** * Creates a new store. * @param {Array.&amp;lt;module:qm~SchemaDef&gt;} storeDef - The definition of the store(s). * @param {number} [storeSizeInMB &#x3D; 1024] - The reserved size of the store(s). * @returns {(module:qm.Store | Array.&amp;lt;module:qm.Store&gt;)} - Returns a store or an array of stores (if the schema definition was an array). * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // create a new base with one store * var base &#x3D; new qm.Base({ * mode: &quot;createClean&quot;, * schema: [ * { * name: &quot;Superheroes&quot;, * fields: [ * { name: &quot;Name&quot;, type: &quot;string&quot; }, * { name: &quot;Superpowers&quot;, type: &quot;string_v&quot; }, * { name: &quot;YearsActive&quot;, type: &quot;int&quot; } * ] * }] * }); * // create a new store called &quot;Supervillains&quot; in the base * base.createStore({ * name: &quot;Supervillians&quot;, * fields: [ * { name: &quot;Name&quot;, type: &quot;string&quot; }, * { name: &quot;Superpowers&quot;, type: &quot;string_v&quot; }, * { name: &quot;YearsActive&quot;, type: &quot;int&quot; } * ] * }); * // create two new stores called &quot;Cities&quot; and &quot;Leagues&quot; * base.createStore([ * { * name: &quot;Cities&quot;, * fields: [ * { name: &quot;Name&quot;, type: &quot;string&quot;, primary: true }, * { name: &quot;Population&quot;, type: &quot;int&quot; } * ] * }, * { * name: &quot;Leagues&quot;, * fields: [ * { name: &quot;Name&quot;, type: &quot;string&quot; }, * { name: &quot;Members&quot;, type: &quot;string_v&quot; } * ] * } * ]); * base.close(); */ exports.Base.prototype.createStore &#x3D; function (storeDef, storeSizeInMB) { return storeDef instanceof Array ? [Object.create(require(&#x27;qminer&#x27;).Store.prototype)] : Object.create(require(&#x27;qminer&#x27;).Store.prototype) ;} /** * @typedef {object} QueryObject * The object used for querying records with {@link module:qm.Base#search}. * How to construct a query is found on the &amp;lt;a href&#x3D;&quot;https://github.com/qminer/qminer/wiki/Query-Language&quot;&gt;QMiner Wiki page&amp;lt;/a&gt;. */ /** * Makes a query search and returns a record set. * @param {module:qm~QueryObject} query - Query language JSON object. * @returns {module:qm.RecordSet} The record set that matches the search criterion. */ exports.Base.prototype.search &#x3D; function (query) { return Object.create(require(&#x27;qminer&#x27;).RecordSet.prototype); } /** * Calls qminer garbage collector to remove records outside time windows. For application example see {@link module:qm~SchemaTimeWindowDef}. * @param {number} [max_time&#x3D;-1] - Maximal number of time each store can spend on cleaning backlog in milisecons. If -1 then no limit is applied. */ exports.Base.prototype.garbageCollect &#x3D; function () { } /** * Base saves dirty data given some time window. * @param {number} [window&#x3D;500] - Length of available time window in miliseconds. * @returns {number} Number of records it flushed. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // create a base with two stores * var base &#x3D; new qm.Base({ * mode: &quot;createClean&quot;, * schema: [ * { * name: &quot;KwikEMart&quot;, * fields: [ * { name: &quot;Worker&quot;, type: &quot;string&quot; }, * { name: &quot;Groceries&quot;, type: &quot;string_v&quot; } * ] * }, * { * name: &quot;NuclearPowerplant&quot;, * fields: [ * { name: &quot;Owner&quot;, type: &quot;string&quot; }, * { name: &quot;NumberOfAccidents&quot;, type: &quot;int&quot; }, * { name: &quot;Workers&quot;, type: &quot;string_v&quot; } * ] * }] * }); * // call the garbage collector * base.partialFlush(); * base.close(); */ exports.Base.prototype.partialFlush &#x3D; function () { return 0; } /** * @typedef {object} PerformanceStat * The performance statistics used to describe {@link module:qm~PerformanceStatBase} and {@link module:qm~PerformanceStatStore}. * @property {number} alloc_count - \\ TODO: Add the description * @property {number} alloc_size - \\ TODO: Add the description * @property {number} alloc_unused_size - \\ TODO: Add the description * @property {number} avg_get_len - \\ TODO: Add the description * @property {number} avg_put_len - \\ TODO: Add the description * @property {number} avg_get_new_len - \\ TODO: Add the description * @property {number} dels - \\ TODO: Add the description * @property {number} gets - \\ TODO: Add the description * @property {number} puts - \\ TODO: Add the description * @property {number} puts_new - \\ TODO: Add the description * @property {number} released_count - \\ TODO: Add the description * @property {number} released_size - \\ TODO: Add the description * @property {number} size_changes - \\ TODO: Add the description */ /** * @typedef {object} PerformanceStatStore * The performance statistics of the store found in {@link module:qm~PerformanceStatBase}. * @property {string} name - Store name. * @property {module:qm~PerformanceStat} blob_storage_memory - \\ TODO: Add the description * @property {module:qm~PerformanceStat} blob_storage_cache - \\ TODO: Add the description */ /** * @typedef {object} PerformanceStatBase * The performance statistics that is returned by {@link module:qm.Base#getStats}. * @property {Array.&amp;lt;module:qm~PerformanceStatStore&gt;} stores - The performance statistics of the stores in base. \\ TODO: Check if this is right * @property {object} gix_stats - The statistics of the base. \\ TODO: Check if this is right * @property {number} gix_stats.avg_len - The average length. \\ TODO: Check if this is right * @property {number} gix_stats.cache_all - The number of cache. \\ TODO: Check if this is right * @property {number} gix_stats.cache_all_loaded_perc - \\ TODO: Add the description * @property {number} gix_stats.cache_dirty - \\ TODO: Add the description * @property {number} gix_stats.cache_dirty_loaded_perc - \\ TODO: Add the description * @property {number} gix_stats.mem_sed - \\ TODO: Add the description * @property {module:qm~PerformanceStat} gix_blob - \\ TODO: Add the description */ /** * Retrieves performance statistics for qminer. * @returns {module:qm~PerformanceStatBase} The performance statistics. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // create a base with two stores * var base &#x3D; new qm.Base({ * mode: &quot;createClean&quot;, * schema: [ * { * name: &quot;KwikEMart&quot;, * fields: [ * { name: &quot;Worker&quot;, type: &quot;string&quot; }, * { name: &quot;Groceries&quot;, type: &quot;string_v&quot; } * ] * }, * { * name: &quot;NuclearPowerplant&quot;, * fields: [ * { name: &quot;Owner&quot;, type: &quot;string&quot; }, * { name: &quot;NumberOfAccidents&quot;, type: &quot;int&quot; }, * { name: &quot;Workers&quot;, type: &quot;string_v&quot; } * ] * }] * }); * // call the garbage collector * base.getStats(); * base.close(); */ exports.Base.prototype.getStats &#x3D; function () { } /** * Gets the stream aggregate of the given name. * @param {string} saName - The name of the stream aggregate. * @returns {module:qm.StreamAggr} The stream aggregate whose name is &#x60;saName&#x60;. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // create a simple base containing one store * var base &#x3D; new qm.Base({ * mode: &quot;createClean&quot;, * schema: [{ * name: &quot;People&quot;, * fields: [ * { name: &quot;Name&quot;, type: &quot;string&quot; }, * { name: &quot;Gendre&quot;, type: &quot;string&quot; }, * ] * }, * { * name: &quot;Laser&quot;, * fields: [ * { name: &quot;Time&quot;, type: &quot;datetime&quot; }, * { name: &quot;WaveLength&quot;, type: &quot;float&quot; } * ] * }] * }); * * // create a new time series window buffer stream aggregator for &#x27;Laser&#x27; store (with the JSON object) * var wavelength &#x3D; { * name: &quot;WaveLengthLaser&quot;, * type: &quot;timeSeriesWinBuf&quot;, * store: &quot;Laser&quot;, * timestamp: &quot;Time&quot;, * value: &quot;WaveLength&quot;, * winsize: 10000 * } * var sa &#x3D; base.store(&quot;Laser&quot;).addStreamAggr(wavelength); * // get the stream aggregate with the name &#x27;Laser&#x27; * var streamAggr &#x3D; base.getStreamAggr(&#x27;WaveLengthLaser&#x27;); * base.close(); */ exports.Base.prototype.getStreamAggr &#x3D; function (saName) { return Object.create(require(&#x27;qminer&#x27;).StreamAggr.prototype); } /** * Gets an array of the stream aggregate names in the base. * @returns {Array.&amp;lt;string&gt;} The array containing the stream aggregate names. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // create a simple base containing one store * var base &#x3D; new qm.Base({ * mode: &quot;createClean&quot;, * schema: [{ * name: &quot;People&quot;, * fields: [ * { name: &quot;Name&quot;, type: &quot;string&quot; }, * { name: &quot;Gendre&quot;, type: &quot;string&quot; }, * ] * }, * { * name: &quot;Laser&quot;, * fields: [ * { name: &quot;Time&quot;, type: &quot;datetime&quot; }, * { name: &quot;WaveLength&quot;, type: &quot;float&quot; } * ] * }] * }); * * // create a new stream aggregator for &#x27;People&#x27; store, get the length of the record name (with the function object) * var aggr &#x3D; new qm.StreamAggr(base, new function () { * var length &#x3D; 0; * this.name &#x3D; &#x27;nameLength&#x27;, * this.onAdd &#x3D; function (rec) { * length &#x3D; rec.Name.length; * }; * this.saveJson &#x3D; function (limit) { * return { val: length }; * } * }, &quot;People&quot;); * * // create a new time series window buffer stream aggregator for &#x27;Laser&#x27; store (with the JSON object) * var wavelength &#x3D; { * name: &quot;WaveLengthLaser&quot;, * type: &quot;timeSeriesWinBuf&quot;, * store: &quot;Laser&quot;, * timestamp: &quot;Time&quot;, * value: &quot;WaveLength&quot;, * winsize: 10000 * } * var sa &#x3D; base.store(&quot;Laser&quot;).addStreamAggr(wavelength); * // get the stream aggregates names * var streamAggrNames &#x3D; base.getStreamAggrNames(); * base.close(); */ exports.Base.prototype.getStreamAggrNames &#x3D; function () { return [&quot;&quot;]; } /** * Retrieves performance statistics for stream aggregates. */ exports.Base.prototype.getStreamAggrStats &#x3D; function () { } /** * Stores are containers of records. &amp;lt;br&gt; * &amp;lt;b&gt;Factory pattern:&amp;lt;/b&gt; this class cannot be construced using the new keyword. This class is constructed when * calling a specific method or attribute, e.g. constructing the {@link module:qm.Base} using schema or with the * {@link module:qm.Base#createStore}. * @class * @example &amp;lt;caption&gt;Creating a store with createStore function&amp;lt;/caption&gt; * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // factory based construction using base.createStore * var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27; }); * base.createStore([{ * name: &quot;People&quot;, * fields: [ * { name: &quot;Name&quot;, type: &quot;string&quot;, primary: true }, * { name: &quot;Gender&quot;, type: &quot;string&quot;, shortstring: true }, * { name: &quot;Age&quot;, type: &quot;int&quot; } * ], * joins: [ * { name: &quot;ActedIn&quot;, type: &quot;index&quot;, store: &quot;Movies&quot;, inverse: &quot;Actor&quot; }, * { name: &quot;Directed&quot;, type: &quot;index&quot;, store: &quot;Movies&quot;, inverse: &quot;Director&quot; } * ], * keys: [ * { field: &quot;Name&quot;, type: &quot;text&quot; }, * { field: &quot;Gender&quot;, type: &quot;value&quot; } * ] * }, * { * name: &quot;Movies&quot;, * fields: [ * { name: &quot;Title&quot;, type: &quot;string&quot;, primary: true }, * { name: &quot;Plot&quot;, type: &quot;string&quot;, store: &quot;cache&quot; }, * { name: &quot;Year&quot;, type: &quot;int&quot; }, * { name: &quot;Rating&quot;, type: &quot;float&quot; }, * { name: &quot;Genres&quot;, type: &quot;string_v&quot;, codebook: true } * ], * joins: [ * { name: &quot;Actor&quot;, type: &quot;index&quot;, store: &quot;People&quot;, inverse: &quot;ActedIn&quot; }, * { name: &quot;Director&quot;, type: &quot;index&quot;, store: &quot;People&quot;, inverse: &quot;Directed&quot; } * ], * keys: [ * { field: &quot;Title&quot;, type: &quot;value&quot; }, * { field: &quot;Plot&quot;, type: &quot;text&quot;, vocabulary: &quot;voc_01&quot; }, * { field: &quot;Genres&quot;, type: &quot;value&quot; } * ] * }]); * base.close(); * @example &amp;lt;caption&gt;Creating store with schema in base constructor&amp;lt;/caption&gt; * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // using the base constructor * var base &#x3D; new qm.Base({ * mode: &quot;createClean&quot;, * schema: [{ * name: &quot;Class&quot;, * fields: [ * { name: &quot;Name&quot;, type: &quot;string&quot; }, * { name: &quot;StudyGroup&quot;, type: &quot;string&quot; } * ] * }] * }); * base.close(); */ exports.Store &#x3D; function (base, storeDef) { return Object.create(require(&#x27;qminer&#x27;).Store.prototype); }; /** * Returns a record from the store. * @param {string} recName - Record name. * @returns {(module:qm.Record | null)} Returns the record. If the record doesn&#x27;t exist, it returns &#x60;null&#x60;. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // create a base containing the store Class. Let the Name field be the primary field. * var base &#x3D; new qm.Base({ * mode: &quot;createClean&quot;, * schema: [{ * name: &quot;Class&quot;, * fields: [ * { name: &quot;Name&quot;, type: &quot;string&quot;, primary: true }, * { name: &quot;StudyGroup&quot;, type: &quot;string&quot; } * ] * }] * }); * // add some records to the store * base.store(&quot;Class&quot;).push({ Name: &quot;Dean&quot;, StudyGroup: &quot;A&quot; }); * base.store(&quot;Class&quot;).push({ Name: &quot;Chang&quot;, StudyGroup: &quot;D&quot; }); * base.store(&quot;Class&quot;).push({ Name: &quot;Magnitude&quot;, StudyGroup: &quot;C&quot; }); * base.store(&quot;Class&quot;).push({ Name: &quot;Leonard&quot;, StudyGroup: &quot;B&quot; }); * // get the record with the name &quot;Magnitude&quot; * var record &#x3D; base.store(&quot;Class&quot;).recordByName(&quot;Magnitude&quot;); * base.close(); */ exports.Store.prototype.recordByName &#x3D; function (recName) { return Object.create(require(&#x27;qminer&#x27;).Record.prototype); }; /** * Executes a function on each record in store. * @param {function} callback - Function to be executed. It takes two parameters: * &amp;lt;br&gt;1. &#x60;rec&#x60; - The current record. Type {@link module:qm.Record}. * &amp;lt;br&gt;2. &#x60;idx&#x60; - The index of the current record (&amp;lt;i&gt;optional&amp;lt;/i&gt;). Type &#x60;number&#x60;. * @returns {module:qm.Store} Self. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // create a base containing the store Class * var base &#x3D; new qm.Base({ * mode: &quot;createClean&quot;, * schema: [{ * name: &quot;Class&quot;, * fields: [ * { name: &quot;Name&quot;, type: &quot;string&quot; }, * { name: &quot;StudyGroup&quot;, type: &quot;string&quot; } * ] * }] * }); * // add some records to the store * base.store(&quot;Class&quot;).push({ Name: &quot;Abed&quot;, StudyGroup: &quot;A&quot; }); * base.store(&quot;Class&quot;).push({ Name: &quot;Annie&quot;, StudyGroup: &quot;B&quot; }); * base.store(&quot;Class&quot;).push({ Name: &quot;Britta&quot;, StudyGroup: &quot;C&quot; }); * base.store(&quot;Class&quot;).push({ Name: &quot;Jeff&quot;, StudyGroup: &quot;A&quot; }); * // change the StudyGroup of all records of store Class to A * base.store(&quot;Class&quot;).each(function (rec) { rec.StudyGroup &#x3D; &quot;A&quot;; }); // all records in Class are now in study group A * base.close(); */ exports.Store.prototype.each &#x3D; function (callback) { return Object.create(require(&#x27;qminer&#x27;).Store.prototype); } /** * Creates an array of function outputs created from the store records. * @param {function} callback - Function that generates the array. It takes two parameters: * &amp;lt;br&gt;1. &#x60;rec&#x60; - The current record. Type {@link module:qm.Record}. * &amp;lt;br&gt;2. &#x60;idx&#x60; - The index of the current record (&amp;lt;i&gt;optional&amp;lt;/i&gt;). Type &#x60;number&#x60;. * @returns {Array&amp;lt;Object&gt;} The array created by the callback function. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // create a base containing the store Class * var base &#x3D; new qm.Base({ * mode: &quot;createClean&quot;, * schema: [{ * name: &quot;Class&quot;, * fields: [ * { name: &quot;Name&quot;, type: &quot;string&quot; }, * { name: &quot;StudyGroup&quot;, type: &quot;string&quot; } * ] * }] * }); * // add some records to the store * base.store(&quot;Class&quot;).push({ Name: &quot;Shirley&quot;, StudyGroup: &quot;A&quot; }); * base.store(&quot;Class&quot;).push({ Name: &quot;Troy&quot;, StudyGroup: &quot;B&quot; }); * base.store(&quot;Class&quot;).push({ Name: &quot;Chang&quot;, StudyGroup: &quot;C&quot; }); * base.store(&quot;Class&quot;).push({ Name: &quot;Pierce&quot;, StudyGroup: &quot;A&quot; }); * // make an array of record names * var arr &#x3D; base.store(&quot;Class&quot;).map(function (rec) { return rec.Name; }); // returns an array [&quot;Shirley&quot;, &quot;Troy&quot;, &quot;Chang&quot;, &quot;Pierce&quot;] * base.close(); */ exports.Store.prototype.map &#x3D; function (callback) {} /** * Adds a record to the store. * @param {object} rec - The added record. The record must be a object corresponding to store schema created at store creation using {@link module:qm~SchemaDef}. * @param {boolean} [triggerEvents&#x3D;true] - If true, all stream aggregate callbacks &#x60;onAdd&#x60; will be called after the record is inserted. If false, no stream aggregate will be updated. * @returns {number} The ID of the added record. * @example * // import qm module * var qm &#x3D; require(&#x27;qminer&#x27;); * // create a new base containing two stores * var base &#x3D; new qm.Base({ * mode: &quot;createClean&quot;, * schema: [ * {