qminer
Version:
A C++ based data analytics platform for processing large-scale real-time streams containing structured and unstructured data
1,040 lines (1,038 loc) • 89.1 kB
HTML
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3">
<meta charset="utf-8">
<title>Class: RecordSet</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">QMiner JavaScript API v9.4.0</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-main" role="main">
<header class="page-header">
<div class="symbol-detail-labels"><span class="label label-kind">class</span> <span class="label label-static">static</span></div>
<h1><small><a href="module-qm.html">qm</a>.<wbr></small><span class="symbol-name">RecordSet</span></h1>
<p class="source-link">Source: <a href="qminerdoc.js.html#source-line-1706">qminerdoc.<wbr>js:1706</a></p>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
<div class="summary-callout">
<h2 class="summary-callout-heading">Properties</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.RecordSet.html#empty">empty</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#length">length</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.RecordSet.html#store">store</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#weighted">weighted</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
</div>
</div>
</div>
<div class="summary-callout">
<h2 class="summary-callout-heading">Methods</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.RecordSet.html#clone">clone()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#deleteRecords">deleteRecords(rs)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#each">each(callback)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#filter">filter(callback)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#filterByField">filterByField(fieldName, minVal, maxVal)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#filterByFq">filterByFq([minFq][, maxFq])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#filterById">filterById([minId][, maxId])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#getMatrix">getMatrix(fieldName)</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.RecordSet.html#getVector">getVector(fieldName)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#join">join(joinName[, sampleSize])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#map">map(callback)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#reverse">reverse()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#sample">sample(num)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#setDiff">setDiff(rs)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#setIntersect">setIntersect(rs)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#setUnion">setUnion(rs)</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.RecordSet.html#shuffle">shuffle([seed])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#sort">sort(callback)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#sortByField">sortByField(fieldName[, asc])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#sortByFq">sortByFq([asc])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#sortById">sortById([asc])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#split">split(callback)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#toJSON">toJSON()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.RecordSet.html#trunc">trunc(limit_num[, offset_num])</a></dt>
<dd>
</dd>
</dl>
</div>
</div>
</div>
</section>
<section>
<h2 id="RecordSet"><span class="symbol-name">RecordSet</span><span class="signature"><span class="signature-params">()</span></span></h2>
<p>Record Set is a set of records. <br>
<b>Factory pattern</b>: this class cannot be construced using the new keyword. This class is constructed
when calling a specific method or attribute, e.g. using <a href="module-qm.Store.html#allRecords">module:qm.Store#allRecords</a> to get all the records
in the store as a record set.
</p>
<dl class="dl-compact">
</dl>
</section>
<section>
<h2>Properties</h2>
<section>
<h3 id="empty"><span class="symbol-name">empty</span></h3>
<p>Checks if the record set is empty. If the record set is empty, then it returns true. Otherwise, it returns false. Type <code>boolean</code>.</p>
<dl class="dl-compact">
</dl>
<h3 id="length"><span class="symbol-name">length</span></h3>
<p>Returns the number of records in record set. Type <code>number</code>.</p>
<dl class="dl-compact">
</dl>
<h3 id="store"><span class="symbol-name">store</span></h3>
<p>Returns the store, where the records in the record set are stored. Type <a href="module-qm.Store.html">module:qm.Store</a>.</p>
<dl class="dl-compact">
</dl>
<h3 id="weighted"><span class="symbol-name">weighted</span></h3>
<p>Checks if the record set is weighted. If the record set is weighted, then it returns true. Otherwise, it returns false. Type <code>boolean</code>.</p>
<dl class="dl-compact">
</dl>
</section>
<h2>Methods</h2>
<section>
<h3 id="clone"><span class="symbol-name">clone</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-qm.RecordSet.html">module:qm.RecordSet</a></span></span></h3>
<p>Creates a new instance of the record set.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "Philosophers",
fields: [
{ name: "Name", type: "string" },
{ name: "Era", type: "string" }
]
}]
});
// put some records in the store
base.store("Philosophers").push({ Name: "Plato", Era: "Ancient philosophy" });
base.store("Philosophers").push({ Name: "Immanuel Kant", Era: "18th-century philosophy" });
base.store("Philosophers").push({ Name: "Emmanuel Levinas", Era: "20th-century philosophy" });
base.store("Philosophers").push({ Name: "Rene Descartes", Era: "17th-century philosophy" });
base.store("Philosophers").push({ Name: "Confucius", Era: "Ancient philosophy" });
// create a record set out of the records in store
var recordSet = base.store("Philosophers").allRecords;
// clone the record set of the "Philosophers" store
var philosophers = recordSet.clone();
base.close();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-qm.RecordSet.html">module:qm.RecordSet</a></code>B A copy of the record set.</p>
</dd>
</dl>
<h3 id="deleteRecords"><span class="symbol-name">deleteRecords</span><span class="signature"><span class="signature-params">(rs)</span> → <span class="signature-returns"> <a href="module-qm.RecordSet.html">module:qm.RecordSet</a></span></span></h3>
<p>Deletes the records, that are also in the second record set.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "BookWriters",
fields: [
{ name: "Name", type: "string" },
{ name: "Genre", type: "string" },
{ name: "Books", type: "string_v" }
]
}]
});
// set new records in the store
base.store("BookWriters").push({ Name: "Terry Pratchett", Genre: "Fantasy", Books: ["The Colour of Magic", "Going Postal", "Mort", "Guards! Guards!"] });
base.store("BookWriters").push({ Name: "Douglas Adams", Genre: "Sci-fi", Books: ["The Hitchhiker's Guide to the Galaxy", "So Long, and Thanks for All the Fish"] });
base.store("BookWriters").push({ Name: "Fyodor Dostoyevsky", Genre: "Drama", Books: ["Crime and Punishment", "Demons"] });
base.store("BookWriters").push({ Name: "J.R.R. Tolkien", Genre: "Fantasy", Books: ["The Hobbit", "The Two Towers", "The Silmarillion" ] });
base.store("BookWriters").push({ Name: "George R.R. Martin", Genre: "Fantasy", Books: ["A Game of Thrones", "A Feast of Crows"] });
base.store("BookWriters").push({ Name: "J. K. Rowling", Genre: "Fantasy", Books: ["Harry Potter and the Philosopher's Stone"] });
base.store("BookWriters").push({ Name: "Ivan Cankar", Genre: "Drama", Books: ["On the Hill", "The King of Betajnova", "The Serfs"] });
// create one record set containing all records of store
var recordSet = base.store("BookWriters").allRecords;
// create one record set containing the records with genre "Fantasy"
var fantasy = base.store("BookWriters").allRecords.filterByField("Genre", "Fantasy");
// delete the records in recordSet, that are also in fantasy
recordSet.deleteRecords(fantasy); // returns self, containing only three records: "Douglas Adams", "Fyodor Dostoyevsky" and "Ivan Cankar"
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>rs</p>
</td>
<td>
<p><a href="module-qm.RecordSet.html">module:qm.RecordSet</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The second record set.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-qm.RecordSet.html">module:qm.RecordSet</a></code>B Self. Contains only the records, that are not in <code>rs</code>.</p>
</dd>
</dl>
<h3 id="each"><span class="symbol-name">each</span><span class="signature"><span class="signature-params">(callback)</span> → <span class="signature-returns"> <a href="module-qm.RecordSet.html">module:qm.RecordSet</a></span></span></h3>
<p>Executes a function on each record in record set.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "People",
fields: [
{ name: "Name", type: "string" },
{ name: "Gender", type: "string" }
]
}]
});
// put some records in the store
base.store("People").push({ Name: "Eric Sugar", Gender: "Male" });
base.store("People").push({ Name: "Jane Tokyo", Gender: "Female" });
base.store("People").push({ Name: "Mister Tea", Gender: "Male" });
// create a record set out of the records of the store
var recordSet = base.store("People").allRecords;
// change the Name of all records into "Anonymous"
recordSet.each(function (rec) { rec.Name = "Anonymous"; }); // returns self, all record's Name are "Anonymous"
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>callback</p>
</td>
<td>
<p>function()</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Function to be executed. It takes two parameters:
<br>1. <code>rec</code> - The current record. Type <a href="module-qm.Record.html">module:qm.Record</a>. Warning: Do not use <code>rec</code> outside the scope of the callback. An internal optimization re-uses <code>rec</code> object between calls to <code>callback</code>.
<br>2. <code>idx</code> - The index of the current record (<i>optional</i>). Type <code>number</code>.
</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-qm.RecordSet.html">module:qm.RecordSet</a></code>B Self.</p>
</dd>
</dl>
<h3 id="filter"><span class="symbol-name">filter</span><span class="signature"><span class="signature-params">(callback)</span> → <span class="signature-returns"> <a href="module-qm.RecordSet.html">module:qm.RecordSet</a></span></span></h3>
<p>Keeps only the records that pass the callback function.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "ArcheryChampionship",
fields: [
{ name: "Name", type: "string" },
{ name: "ScorePerRound", type: "float_v" }
]
}]
});
// set new records in the store
base.store("ArcheryChampionship").push({ Name: "Robin Hood", ScorePerRound: [50, 48, 48] });
base.store("ArcheryChampionship").push({ Name: "Oliver Queen", ScorePerRound: [44, 46, 44] });
base.store("ArcheryChampionship").push({ Name: "Legolas", ScorePerRound: [50, 50, 48] });
// create a record set out of the records of the store
var recordSet = base.store("ArcheryChampionship").allRecords;
// filter the records: which archers have scored 48 points in the third round
recordSet.filter(function (rec) { return rec.ScorePerRound[2] == 48; }); // keeps only the records, where the score of the third round is equal 48
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>callback</p>
</td>
<td>
<p>function()</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The filter function. It takes one parameter:
<br>1. <code>rec</code> - The record in the record set. Type <a href="module-qm.Record.html">module:qm.Record</a>.
<br> Returns a <code>boolean</code> value.
</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-qm.RecordSet.html">module:qm.RecordSet</a></code>B Self. Contains only the records that pass the callback function.</p>
</dd>
</dl>
<h3 id="filterByField"><span class="symbol-name">filterByField</span><span class="signature"><span class="signature-params">(fieldName, minVal, maxVal)</span> → <span class="signature-returns"> <a href="module-qm.RecordSet.html">module:qm.RecordSet</a></span></span></h3>
<p>Keeps only the records with a specific value of some field.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "WeatherForcast",
fields: [
{ name: "Weather", type: "string" },
{ name: "Date", type: "datetime" },
{ name: "TemperatureDegrees", type: "int" },
]
}]
});
// put some records in the "WeatherForecast" store
base.store("WeatherForcast").push({ Weather: "Partly Cloudy", Date: "2015-05-27T11:00:00", TemperatureDegrees: 19 });
base.store("WeatherForcast").push({ Weather: "Partly Cloudy", Date: "2015-05-28T11:00:00", TemperatureDegrees: 22 });
base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-05-29T11:00:00", TemperatureDegrees: 25 });
base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-05-30T11:00:00", TemperatureDegrees: 25 });
base.store("WeatherForcast").push({ Weather: "Scattered Showers", Date: "2015-05-31T11:00:00", TemperatureDegrees: 24 });
base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-06-01T11:00:00", TemperatureDegrees: 27 });
// get the record set containing the records from the "WeatherForcast" store
var recordSet = base.store("WeatherForcast").allRecords;
// filter only the records, where the weather is Mostly Cloudy
recordSet.filterByField("Weather", "Mostly Cloudy"); // returns self, containing only the records, where the weather is "Mostly Cloudy"
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>fieldName</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The field by which the records will be filtered.</p>
</td>
</tr>
<tr>
<td>
<p>minVal</p>
</td>
<td>
<p>(string or number)</p>
</td>
<td>
<p> </p>
</td>
<td>
<p><br>1. If the field type is a <code>string</code>, the exact string to compare. Type <code>number</code>.
<br>2. If the field type is a <code>number</code>, the minimal value for comparison. Type <code>number</code>.
<br>3. TODO Time field
</p>
</td>
</tr>
<tr>
<td>
<p>maxVal</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Only in combination with <code>minVal</code> for non-string fields. The maximal value for comparison.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-qm.RecordSet.html">module:qm.RecordSet</a></code>B Self.
<br>1. If the <code>fieldName</code> field type is <code>number</code>, contains only the records with the <code>fieldName</code> value between <code>minVal</code> and <code>maxVal</code>.
<br>2. If the <code>fieldName</code> field type is <code>string</code>, contains only the records with <code>fieldName</code> equal to <code>minVal</code>.
</p>
</dd>
</dl>
<h3 id="filterByFq"><span class="symbol-name">filterByFq</span><span class="signature"><span class="signature-params">([minFq][, maxFq])</span> → <span class="signature-returns"> <a href="module-qm.RecordSet.html">module:qm.RecordSet</a></span></span></h3>
<p>Keeps only the records with weight between two values.</p>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>minFq</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>The minimum value.</p>
</td>
</tr>
<tr>
<td>
<p>maxFq</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>The maximum value.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-qm.RecordSet.html">module:qm.RecordSet</a></code>B Self.
<br>1. Contains only the records of the original with weights between <code>minFq</code> and <code>maxFq</code>, if parameters are given.
<br>2. Contains all the records of the original, if no parameter is given.
</p>
</dd>
</dl>
<h3 id="filterById"><span class="symbol-name">filterById</span><span class="signature"><span class="signature-params">([minId][, maxId])</span> → <span class="signature-returns"> <a href="module-qm.RecordSet.html">module:qm.RecordSet</a></span></span></h3>
<p>Keeps only records with ids between or equal two values.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm require
var qm = require('qminer');
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "FrankSinatraGreatestHits",
fields: [
{ name: "Title", type: "string" },
{ name: "Length", type: "int" }
]
}]
});
// put some records in the "FrankSinatraGreatesHits" store
base.store("FrankSinatraGreatestHits").push({ Title: "Strangers in the Night", Length: 145 });
base.store("FrankSinatraGreatestHits").push({ Title: "Summer Wind", Length: 173 });
base.store("FrankSinatraGreatestHits").push({ Title: "It Was a Very Good Year", Length: 265 });
base.store("FrankSinatraGreatestHits").push({ Title: "Somewhere in Your Heart", Length: 146 });
base.store("FrankSinatraGreatestHits").push({ Title: "Forget Domani", Length: 156 });
base.store("FrankSinatraGreatestHits").push({ Title: "Somethin' Stupid", Length: 155 });
base.store("FrankSinatraGreatestHits").push({ Title: "This Town", Length: 186 });
// get the records of the store as a record set
var recordSet = base.store("FrankSinatraGreatestHits").allRecords;
// from the record set keep the records with indeces between or equal 2 and 5
recordSet.filterById(2, 5);
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>minId</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>The minimum id.</p>
</td>
</tr>
<tr>
<td>
<p>maxId</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>The maximum id.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-qm.RecordSet.html">module:qm.RecordSet</a></code>B Self.
<br>1. Contains only the records of the original with IDs between <code>minId</code> and <code>maxId</code>, if parameters are given.
<br>2. Contains all the records of the original, if no parameter is given.
</p>
</dd>
</dl>
<h3 id="getMatrix"><span class="symbol-name">getMatrix</span><span class="signature"><span class="signature-params">(fieldName)</span> → <span class="signature-returns"> (<a href="module-la.Matrix.html">module:la.Matrix</a> or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>)</span></span></h3>
<p>Creates a vector containing the field values of records.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "ArcheryChampionship",
fields: [
{ name: "Name", type: "string" },
{ name: "ScorePerRound", type: "float_v" }
]
}]
});
// set new records in the store
base.store("ArcheryChampionship").push({ Name: "Robin Hood", ScorePerRound: [50, 48, 48] });
base.store("ArcheryChampionship").push({ Name: "Oliver Queen", ScorePerRound: [44, 46, 44] });
base.store("ArcheryChampionship").push({ Name: "Legolas", ScorePerRound: [50, 50, 48] });
// create a record set of the records in store
var recordSet = base.store("ArcheryChampionship").allRecords;
// create a matrix from the "ScorePerRound" field
// the i-th column of the matrix is the data of the i-th record in record set
// the matrix will look like
// 50 44 50
// 48 46 50
// 48 44 48
var matrix = recordSet.getMatrix("ScorePerRound");
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>fieldName</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The field from which to take the values. It's type must be numeric, e.g. <code>int</code>, <code>float</code>, <code>float_v</code>, <code>num_sp_v</code>...</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>(<a href="module-la.Matrix.html">module:la.Matrix</a> or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>)</code>B The matrix containing the field values of records.</p>
</dd>
</dl>
<h3 id="getVector"><span class="symbol-name">getVector</span><span class="signature"><span class="signature-params">(fieldName)</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Creates a vector containing the field values of records.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "TVSeries",
fields: [
{ name: "Title", type: "string", "primary": true },
{ name: "NumberOfEpisodes", type: "int" }
]
}]
});
// add some records in the store
base.store("TVSeries").push({ Title: "Archer", NumberOfEpisodes: 75 });
base.store("TVSeries").push({ Title: "The Simpsons", NumberOfEpisodes: 574 });
base.store("TVSeries").push({ Title: "New Girl", NumberOfEpisodes: 94 });
base.store("TVSeries").push({ Title: "Rick and Morty", NumberOfEpisodes: 11 });
base.store("TVSeries").push({ Title: "Game of Thrones", NumberOfEpisodes: 47 });
// create a record set of the records of store
var recordSet = base.store("TVSeries").allRecords;
// create a vector containing the number of episodes for each series
// the vector will look like [75, 574, 94, 11, 47]
var vector = recordSet.getVector("NumberOfEpisodes");
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>fieldName</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The field from which to take the values. It's type must be one-dimensional, e.g. <code>int</code>, <code>float</code>, <code>string</code>...</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B The vector containing the field values of records. The type it contains is dependant of the field type.</p>
</dd>
</dl>
<h3 id="join"><span class="symbol-name">join</span><span class="signature"><span class="signature-params">(joinName[, sampleSize])</span> → <span class="signature-returns"> <a href="module-qm.RecordSet.html">module:qm.RecordSet</a></span></span></h3>
<p>Creates a new record set out of the join attribute of records.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base containing two stores, with join attributes
var base = new qm.Base({
mode: "createClean",
schema: [
{
name: "Musicians",
fields: [
{ name: "Name", type: "string" },
{ name: "Instruments", type: "string_v" }
],
joins: [
{ name: "PlaysIn", type: "index", store: "Bands", inverse: "Members" }
]
},
{
name: "Bands",
fields: [
{ name: "Name", type: "string" },
{ name: "Genre", type: "string" }
],
joins: [
{ name: "Members", type: "index", store: "Musicians", inverse: "PlaysIn" }
]
}]
});
// add some new records to both stores
base.store("Musicians").push({ Name: "Robert Plant", Instruments: ["Vocals"], PlaysIn: [{Name: "Led Zeppelin", "Genre": "Rock" }] });
base.store("Musicians").push({ Name: "Jimmy Page", Instruments: ["Guitar"], PlaysIn: [{Name: "Led Zeppelin", "Genre": "Rock" }] });
base.store("Bands").push({ Name: "The White Stripes", Genre: "Rock" });
// create a record set containing the musicians, that are members of some bend
// returns a record set containing the records of "Robert Plant" and "Jimmy Page"
var ledZeppelin = base.store("Bands").allRecords.join("Members");
// create a record set containing the first musician, that is a member of some band
// returns a record set containing only one record, which is "Robert Plant" or "Jimmy Page"
var ledMember = base.store("Bands").allRecords.join("Members", 1);
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>joinName</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The name of the join attribute.</p>
</td>
</tr>
<tr>
<td>
<p>sampleSize</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>The number of records to be used for construction of the record set.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-qm.RecordSet.html">module:qm.RecordSet</a></code>B The record set containing the join records.</p>
</dd>
</dl>
<h3 id="map"><span class="symbol-name">map</span><span class="signature"><span class="signature-params">(callback)</span> → <span class="signature-returns"> Array of Object</span></span></h3>
<p>Creates an array of function outputs created from the records in record set.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "People",
fields: [
{ name: "Name", type: "string" },
{ name: "Gender", type: "string" }
]
}]
});
// put some records in the store
base.store("People").push({ Name: "Eric Sugar", Gender: "Male" });
base.store("People").push({ Name: "Jane Tokyo", Gender: "Female" });
base.store("People").push({ Name: "Mister Tea", Gender: "Male" });
// create a record set out of the records of the store
var recordSet = base.store("People").allRecords;
// make an array of record Names
var arr = recordSet.map(function (rec) { return rec.Name; }); // returns an array: ["Eric Sugar", "Jane Tokyo", "Mister Tea"]
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>callback</p>
</td>
<td>
<p>function()</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Function that generates the array. It takes two parameters:
<br>1. <code>rec</code> - The current record. Type <a href="module-qm.Record.html">module:qm.Record</a>. Warning: Do not use <code>rec</code> outside the scope of the callback. An internal optimization re-uses <code>rec</code> object between calls to <code>callback</code>.
<br>2. <code>idx</code> - The index of the current record (<i>optional</i>). Type <code>number</code>.
</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Array of Object</code>B The array created by the callback function.</p>
</dd>
</dl>
<h3 id="reverse"><span class="symbol-name">reverse</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-qm.RecordSet.html">module:qm.RecordSet</a></span></span></h3>
<p>It reverses the record order.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "WeatherForcast",
fields: [
{ name: "Weather", type: "string" },
{ name: "Date", type: "datetime" },
{ name: "TemperatureDegrees", type: "int" },
]
}]
});
// put some records in the "WeatherForecast" store
base.store("WeatherForcast").push({ Weather: "Partly Cloudy", Date: "2015-05-27T11:00:00", TemperatureDegrees: 19 });
base.store("WeatherForcast").push({ Weather: "Partly Cloudy", Date: "2015-05-28T11:00:00", TemperatureDegrees: 22 });
base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-05-29T11:00:00", TemperatureDegrees: 25 });
base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-05-30T11:00:00", TemperatureDegrees: 25 });
base.store("WeatherForcast").push({ Weather: "Scattered Showers", Date: "2015-05-31T11:00:00", TemperatureDegrees: 24 });
base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-06-01T11:00:00", TemperatureDegrees: 27 });
// get the record set containing the records from the "WeatherForcast" store
var recordSet = base.store("WeatherForcast").allRecords;
// reverse the record order in the record set
recordSet.reverse(); // returns self, the records in the record set are in the reverse order
base.close();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-qm.RecordSet.html">module:qm.RecordSet</a></code>B Self. Records are in reversed order.</p>
</dd>
</dl>
<h3 id="sample"><span class="symbol-name">sample</span><span class="signature"><span class="signature-params">(num)</span> → <span class="signature-returns"> <a href="module-qm.RecordSet.html">module:qm.RecordSet</a></span></span></h3>
<p>Creates a random sample of records of the record set.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base with one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "Movies",
fields: [
{ name: "Title", type: "string" },
{ name: &quo