NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
dataaccess.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2018 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#include "dataaccess.hpp"
20#include "../utils/tools.hpp"
21#include "../../kernel.hpp"
22#include <vector>
23
24using namespace std;
25using namespace mu;
26
27
32{
33 //
34}
35
36
48{
49 size_t pos = string::npos;
50 bIsCluster = false;
51
52 // Get a pointer to the current kernel instance
54
55 // Do only something, if the instance is valid
56 if (instance)
57 {
58 // Examine the whole command line
59 for (size_t i = 0; i < sCommand.length(); i++)
60 {
61 // Is this a possible character start
62 // for a data object identifier?
63 if (pos == string::npos && (sCommand[i] == '_' || isalpha(sCommand[i])))
64 pos = i;
65
66 // Is a possible start character available
67 // and the current character is not part of a
68 // valid object identifier character set?
69 if (pos != string::npos && sCommand[i] != '_' && sCommand[i] != '~' && !isalnum(sCommand[i]))
70 {
71 // If the current character is an opening parenthesis
72 // or an opening brace, parse the identified data
73 // access, otherwise simply reset the possible starting
74 // character
75 if (sCommand[i] == '(')
76 {
77 // This is a usual table or a reference to "string()"
78 sDataObject = sCommand.subview(pos, i - pos).to_string();
79
80 // Ensure that the table exists
81 if (!instance->getMemoryManager().isTable(sDataObject) && sDataObject != "string")
82 {
83 sDataObject.clear();
84 pos = string::npos;
85 continue;
86 }
87
88 // Calculate the indices
89 ::getIndices(sCommand.subview(pos), idx, instance->getParser(), instance->getMemoryManager(), instance->getSettings());
90 break;
91 }
92 else if (sCommand[i] == '{')
93 {
94 // This is a cluster reference
95 sDataObject = sCommand.subview(pos, i - pos).to_string();
96
97 // Ensure that the cluster exists
98 if (!instance->getMemoryManager().isCluster(sDataObject))
99 {
100 sDataObject.clear();
101 pos = string::npos;
102 continue;
103 }
104
105 // Calculate the indices and switch the access
106 // to a cluster access
107 bIsCluster = true;
108 ::getIndices(sCommand.subview(pos), idx, instance->getParser(), instance->getMemoryManager(), instance->getSettings());
109 break;
110 }
111 else
112 pos = string::npos;
113 }
114 }
115 }
116
117}
118
119
127{
128 sDataObject = _accessParser.sDataObject;
129 idx = _accessParser.idx;
130 bIsCluster = _accessParser.bIsCluster;
131}
132
133
142{
144
145 if (idx.row.isOpenEnd())
146 {
147 if (bIsCluster)
148 idx.row.setRange(0, _data.getCluster(sDataObject).size()-1);
149 else
150 idx.row.setRange(0, _data.getLines(sDataObject)-1);
151 }
152
153 if (idx.col.isOpenEnd())
154 {
155 if (bIsCluster)
157 else
158 idx.col.setRange(0, _data.getCols(sDataObject)-1);
159 }
160}
161
162
171{
172 return sDataObject;
173}
174
175
184{
185 return idx.row.to_string() + ", " + idx.col.to_string();
186}
187
188
197{
198 return idx;
199}
200
201
210{
211 return bIsCluster;
212}
213
214
223{
225}
226
227
228static void resolveTablesAndClusters(string& sLine, Parser& _parser, MemoryManager& _data, const Settings& _option, int options);
229static const string handleCachedDataAccess(string& sLine, Parser& _parser, MemoryManager& _data, const Settings& _option);
230static void replaceEntityStringOccurence(string& sLine, const string& sEntityOccurence, const string& sEntityStringReplacement);
231static void replaceEntityOccurence(string& sLine, const string& sEntityOccurence, const string& sEntityName, const string& sEntityReplacement, const Indices& _idx, MemoryManager& _data, Parser& _parser, const Settings& _option, bool isCluster);
232static string createMafDataAccessString(const string& sAccessString, Parser& _parser);
233static string createEveryDefinition(const string& sLine, Parser& _parser);
234static string createMafVectorName(string sAccessString);
235static vector<mu::value_type> MafDataAccess(MemoryManager& _data, const string& sMafname, const string& sCache, const string& sMafAccess);
236static string getMafFromAccessString(const string& sAccessString);
237static string getMafAccessString(const string& sLine, const string& sEntity);
238static void handleMafDataAccess(string& sLine, const string& sMafAccess, Parser& _parser, MemoryManager& _data);
239static string getLastToken(const string& sLine);
240
241
243{
244 size_t pos = sCmd.find('=');
245
246 if (pos != std::string::npos
247 && pos > 0
248 && sCmd[pos - 1] != '!'
249 && sCmd[pos - 1] != '<'
250 && sCmd[pos - 1] != '>'
251 && sCmd[pos + 1] != '='
252 && sCmd[pos - 1] != '=')
253 return pos;
254
255 return std::string::npos;
256}
257
258
276string getDataElements(string& sLine, Parser& _parser, MemoryManager& _data, const Settings& _option, int options)
277{
278 // Evaluate possible cached equations
279 if ((_parser.HasCachedAccess() || _parser.GetCachedEquation().length()) && !_parser.IsCompiling())
280 return handleCachedDataAccess(sLine, _parser, _data, _option);
281
282 // Validate the number of parentheses
283 if (!validateParenthesisNumber(sLine))
285
286 string sCache; // Rueckgabe-string: Ggf. der linke Teil der Gleichung, falls es sich um eine Zuweisung handelt
287 string sLine_Temp; // temporaerer string, da wir die string-Referenz nicht unnoetig veraendern wollen
288 size_t eq_pos = string::npos; // int zum Zwischenspeichern der Position des "="
289
290
291 /* --> Jetzt folgt der ganze Spass fuer "cache(". Hier ist relativ viel aehnlich, allerdings gibt es
292 * noch den Fall, dass "cache(" links des "=" auftauchen darf, da es sich dabei um eine Zuweisung
293 * eines (oder mehrerer) Wert(e) an den Cache handelt. <--
294 */
295 if (_data.containsTablesOrClusters(sLine))
296 {
297 isClusterCandidate(sLine, sCache, false);
298
299 // Only try to find the position of the equality
300 // sign, if the line does not start with a minus. In
301 // these cases, it is most assured a parameter string
302 // full of equality signs.
303 if (sLine[sLine.find_first_not_of(' ')] != '-')
304 eq_pos = findAssignmentOperator(sLine);
305
306 // Try to handle the assignment operator shortcut
307 if (eq_pos != std::string::npos)
308 {
309 sCache = sLine.substr(0, eq_pos);
310 StripSpaces(sCache);
311
312 // Direct assignment shortcut
313 if (sCache.find('(') != std::string::npos
314 && sCache.substr(sCache.find('(')) == "()"
315 && sCache.find_first_of(" +-*/?:!%&|<>=") == std::string::npos)
316 {
317 std::string source = sLine.substr(eq_pos+1);
318 StripSpaces(source);
319
320 // Is the source also a complete table
321 if (source.find('(') != std::string::npos
322 && source.substr(source.find("(")) == "()"
323 && source.find_first_of(" +-*/?:!%&|<>=") == std::string::npos
324 && _data.isTable(source))
325 {
326 _data.copyTable(source, sCache);
327 sLine = _parser.CreateTempVectorVar(std::vector<mu::value_type>({_data.getLines(source.substr(0, source.find("("))),
328 _data.getCols(source.substr(0, source.find("(")))}));
329 return "";
330 }
331 }
332 }
333
334 if (eq_pos == string::npos // gar kein "="?
335 || !_data.containsTablesOrClusters(sCache)) // nur links von "cache("?
336 {
337 resolveTablesAndClusters(sLine, _parser, _data, _option, options);
338 sCache.clear();
339 }
340 else
341 {
342 /* --> Nein? Dann ist das eine Zuweisung. Wird komplizierter zu loesen. Außerdem kann dann rechts von
343 * "=" immer noch "cache(" auftreten. <--
344 * --> Suchen wir zuerst mal nach der Position des "=" und speichern diese in eq_pos <--
345 */
346 // --> Teilen wir nun sLine an "=": Der Teillinks in sCache, der Teil rechts in sLine_Temp <--
347
348 sCache = sLine.substr(0, eq_pos);
349 StripSpaces(sCache);
350
351 while (sCache[0] == '(')
352 sCache.erase(0, 1);
353
354 // --> Gibt's innerhalb von "cache()" nochmal einen Ausdruck "cache("? <--
355 if (_data.containsTablesOrClusters(sCache.substr(sCache.find_first_of("({") + 1)))
356 {
357 sLine_Temp = sCache.substr(sCache.find_first_of("({") + 1);
358 resolveTablesAndClusters(sLine_Temp, _parser, _data, _option, options);
359 sCache = sCache.substr(0, sCache.find_first_of("({") + 1) + sLine_Temp;
360 }
361
362 sLine_Temp = sLine.substr(eq_pos + 1);
363
364 // --> Gibt es rechts von "=" nochmals "cache("? <--
365 if (_data.containsTablesOrClusters(sLine_Temp))
366 {
367 /* --> Ja? Geht eigentlich trotzdem wie oben, mit Ausnahme, dass ueberall wo "sLine" aufgetreten ist,
368 * nun "sLine_Temp" auftritt <--
369 */
370 resolveTablesAndClusters(sLine_Temp, _parser, _data, _option, options);
371 }
372
373 // --> sLine_Temp an sLine zuweisen <--
374 sLine = sLine_Temp;
375 }
376 }
377
378 return sCache;
379}
380
381
394static void resolveTablesAndClusters(string& sLine, Parser& _parser, MemoryManager& _data, const Settings& _option, int options)
395{
396 // Try to find every cache and handle its contents
397 if (_data.containsTables(sLine))
398 {
399 for (auto iter = _data.getTableMap().begin(); iter != _data.getTableMap().end(); iter++)
400 {
401 if (sLine.find((iter->first) + "(") != string::npos)
402 replaceDataEntities(sLine, iter->first + "(", _data, _parser, _option, options);
403 }
404 }
405
406 // Try to find every cluster and handle its contents
407 if (_data.containsClusters(sLine))
408 {
409 for (auto iter = _data.getClusterMap().begin(); iter != _data.getClusterMap().end(); iter++)
410 {
411 if (sLine.find((iter->first) + "{") != string::npos)
412 replaceDataEntities(sLine, iter->first + "{", _data, _parser, _option, options);
413 }
414 }
415}
416
417
436void replaceDataEntities(string& sLine, const string& sEntity, MemoryManager& _data, Parser& _parser, const Settings& _option, int options)
437{
438 string sEntityOccurence = "";
439 string sEntityName = sEntity.substr(0, sEntity.length()-1);
440 unsigned int nPos = 0;
441 bool bWriteStrings = false;
442 bool bWriteFileName = false;
443 bool isCluster = sEntity.back() == '{';
444 vector<mu::value_type> vEntityContents;
445 string sEntityReplacement = "";
446 string sEntityStringReplacement = "";
448
449
450 // handle MAF methods. sEntity already has "(" at its back
451 while (!isCluster && (nPos = sLine.find(sEntity + ").", nPos)) != string::npos)
452 {
453 if (isInQuotes(sLine, nPos, true) || (nPos && !isDelimiter(sLine[nPos-1])))
454 {
455 nPos++;
456 continue;
457 }
458
459 handleMafDataAccess(sLine, getMafAccessString(sLine, sEntity), _parser, _data);
460 }
461
462 nPos = 0;
463
464 // handle logical table accesses
465 while (!isCluster && (nPos = sLine.find(sEntity + ")", nPos)) != string::npos)
466 {
467 if (isInQuotes(sLine, nPos, true) || (nPos && !isDelimiter(sLine[nPos-1])))
468 {
469 nPos++;
470 continue;
471 }
472
473 sLine.replace(nPos, sEntity.length()+1, (_data.getCols(sEntity.substr(0, sEntity.length()-1)) ? "true" : "false"));
474 }
475
476 if (sLine.find(sEntity) == string::npos)
477 return;
478
479 nPos = 0;
480 /* --> Diese Schleife ersetzt nacheinander alle Stellen, in denen sEntity auftritt, durch "Vektoren", die
481 * in einer anderen Funktion weiterverarbeitet werden koennen. <--
482 */
483 do
484 {
485 /* --> Zunaechst muessen wir herausfinden welche(s) Datenelement(e) wir aus der Datafile-Tabelle
486 * extrahieren sollen. Dies wird durch die Syntax data(i,j) bestimmt, wobei i der Zeilen- und
487 * j der Spaltenindex ist. i und j koennen mittels der Syntax "i_0:i_1" bzw. "j_0:j_1" einen
488 * Bereich bestimmen, allerdings (noch) keine Matrix. (Also entweder nur i oder j) <--
489 * --> Speichere zunaechst den Teil des Strings nach "data(" in si_pos[0] <--
490 */
491 sEntityOccurence = sLine.substr(sLine.find(sEntity, nPos));
492 nPos = sLine.find(sEntity, nPos);
493
494 if (nPos && (!isDelimiter(sLine[nPos-1]) || isInQuotes(sLine, nPos)))
495 {
496 nPos++;
497 continue;
498 }
499
500 // Get the current entity
501 sEntityOccurence = sEntityOccurence.substr(0, getMatchingParenthesis(sEntityOccurence) + 1);
502 vEntityContents.clear();
503 sEntityReplacement.clear();
504 sEntityStringReplacement.clear();
505
506 // Reading the indices happens in this function
507 Indices _idx;
508 getIndices(sEntityOccurence, _idx, _parser, _data, _option);
509
510 // check the indices, whether they are possible in the current context
511 if (!isValidIndexSet(_idx))
513
514 if (!isCluster && _idx.row.isOpenEnd() && _idx.col.isOpenEnd())
516
517 // evaluate the indices regarding the possible combinations:
518 // -1: no index
519 // -2: larges possible index
520 // -3: string access in the current dimension
521
522 if (!isCluster && _idx.col.isOpenEnd())
523 _idx.col.setRange(0, _data.getCols(sEntityName, false)-1);
524
525 if (!isCluster && _idx.row.isOpenEnd())
526 _idx.row.setRange(0, _data.getColElements(_idx.col.subidx(0, 1), sEntityName)-1);
527 else if (isCluster && _idx.row.isOpenEnd())
528 _idx.row.setRange(0, _data.getCluster(sEntityName).size()-1);
529
530 if (_idx.row.isString())
531 bWriteStrings = true;
532
533 if (_idx.col.isString())
534 bWriteFileName = true;
535
536 // Handle the filename and headline access different from the usual data access
537 if (!isCluster && bWriteFileName)
538 {
539 // Get the file name (or the cache table name)
540 sEntityStringReplacement = "\"" + _data.getDataFileName(sEntityName) + "\"";
541 }
542 else if (!isCluster && bWriteStrings)
543 {
544 vector<string> vStringContents;
545
546 // Get the headlines
547 for (size_t j = 0; j < _idx.col.size(); j++)
548 vStringContents.push_back("\"" + _data.getHeadLineElement(_idx.col[j], sEntityName) + "\"");
549
550 sEntityStringReplacement = _stringParser.createTempStringVectorVar(vStringContents);
551 }
552 else if (!isCluster)
553 {
554 // This is a usual data access
555 // create a vector containing the data
556#warning NOTE (numere#1#08/17/21): Might be the source of some bytecode issues
557 if (options & INSERT_STRINGS)
558 sEntityStringReplacement = _stringParser.createTempStringVectorVar(_data.getElementAsString(_idx.row, _idx.col, sEntityName));
559 else if (_data.getType(_idx.col, sEntityName) > TableColumn::STRINGLIKE)
560 sEntityStringReplacement = _stringParser.createTempStringVectorVar(_data.getElementMixed(_idx.row, _idx.col, sEntityName));
561 else
562 vEntityContents = _data.getElement(_idx.row, _idx.col, sEntityName);
563 }
564 else if (isCluster)
565 {
566 // Get a reference to the current cluster
567 NumeRe::Cluster& cluster = _data.getCluster(sEntityName);
568
569 // If the cluster contains only doubles,
570 // create a vector, otherwise insert the
571 // mixed vector representation
572 if (!cluster.size())
573 vEntityContents.push_back(NAN);
574 else if (cluster.isDouble())
575 {
576 // Create the vector using the indices
577 for (size_t i = 0; i < _idx.row.size(); i++)
578 vEntityContents.push_back(cluster.getDouble(_idx.row[i]));
579 }
580 else
581 {
582 if (_idx.row.size() == 1)
583 {
584 // Only a single element - needs no vector braces
586 vEntityContents.push_back(cluster.getDouble(_idx.row.front()));
587 else
588 sEntityStringReplacement = _stringParser.createTempStringVectorVar({cluster.getParserString(_idx.row.front())});
589 }
590 else
591 {
592 // Prepare a string vector
593 vector<string> vStringContents;
594
595 // Create the string vector representation
596 // using the calculated indices
597 for (size_t i = 0; i < _idx.row.size(); i++)
598 {
599 if (cluster.getType(_idx.row[i]) == NumeRe::ClusterItem::ITEMTYPE_DOUBLE)
600 vStringContents.push_back(toCmdString(cluster.getDouble(_idx.row[i])));
601 else
602 vStringContents.push_back(cluster.getParserString(_idx.row[i]));
603 }
604
605 sEntityStringReplacement = _stringParser.createTempStringVectorVar(vStringContents);
606 }
607 }
608 }
609
610 // replace the occurences
611 if (sEntityStringReplacement.length())
612 {
613 // Replace the strings (we don't need caching here)
614 _parser.DisableAccessCaching();
615 replaceEntityStringOccurence(sLine, sEntityOccurence, sEntityStringReplacement);
616 }
617 else
618 {
619 // Replace the numerical occurences
620 // Define the vector name
621 sEntityReplacement = replaceToVectorname(sEntityOccurence);
622
623 // Set the vector variable and its value for the parser
624 _parser.SetVectorVar(sEntityReplacement, vEntityContents);
625
626 // Cache the current access if needed
627 mu::CachedDataAccess _access = {sEntityName + (isCluster ? "{" + _idx.sCompiledAccessEquation + "}" : "(" + _idx.sCompiledAccessEquation + ")") , sEntityReplacement, sEntityName, isCluster ? mu::CachedDataAccess::IS_CLUSTER : mu::CachedDataAccess::NO_FLAG};
628 _parser.CacheCurrentAccess(_access);
629
630 // Replace the occurences
631 replaceEntityOccurence(sLine, sEntityOccurence, sEntityName, sEntityReplacement, _idx, _data, _parser, _option, isCluster);
632 }
633 }
634 while (sLine.find(sEntity, nPos) != string::npos);
635
636 return;
637}
638
639
652static const string handleCachedDataAccess(string& sLine, Parser& _parser, MemoryManager& _data, const Settings& _option)
653{
654 for (size_t i = 0; i < _parser.HasCachedAccess(); i++)
655 {
656 // Get the current cached data access
657 const mu::CachedDataAccess& _access = _parser.GetCachedAccess(i);
658
660 {
661 // handle cached MAF methods
662 _parser.SetVectorVar(_access.sVectorName, MafDataAccess(_data,
664 _access.sCacheName,
665 createMafDataAccessString(_access.sAccessEquation, _parser)));
666 continue;
667 }
668
669 // Create an index
670 Indices _idx;
671
672 bool isCluster = _access.flags & mu::CachedDataAccess::IS_CLUSTER;
673
674 // Read the indices
675 getIndices(_access.sAccessEquation, _idx, _parser, _data, _option);
676
677 // check the indices
678 if (!isValidIndexSet(_idx))
680
681 if (!isCluster && _idx.row.isOpenEnd() && _idx.col.isOpenEnd())
683
684 // Evaluate the indices
685 if (_idx.row.isOpenEnd())
686 _idx.row.setRange(0, isCluster ? _data.getCluster(_access.sCacheName).size()-1 : _data.getLines(_access.sCacheName, false)-1);
687
688 if (_idx.col.isOpenEnd())
689 _idx.col.setRange(0, isCluster ? 0 : _data.getCols(_access.sCacheName, false)-1);
690
691 // Get new data (Parser::GetVectorVar returns a pointer to the vector var) and update the stored elements in the internal representation
692 if (isCluster)
693 {
694 NumeRe::Cluster& clst = _data.getCluster(_access.sCacheName);
695
696 // Ensure that this cluster has only numerically
697 // interpretable values
698 if (!clst.isDouble())
699 {
700 _parser.DisableAccessCaching();
701 return getDataElements(sLine, _parser, _data, _option);
702 }
703
704 clst.insertDataInArray(_parser.GetVectorVar(_access.sVectorName), _idx.row);
705 }
706 else
707 {
708 // Ensure that the selected columns are actually numerically
709 // interpretable values
710 if (_data.getType(_idx.col, _access.sCacheName) >= TableColumn::STRINGLIKE)
711 {
712 _parser.DisableAccessCaching();
713 return getDataElements(sLine, _parser, _data, _option);
714 }
715
716 _data.copyElementsInto(_parser.GetVectorVar(_access.sVectorName), _idx.row, _idx.col, _access.sCacheName);
717 }
718
719 _parser.UpdateVectorVar(_access.sVectorName);
720 }
721
722 // Update the equation (probably there are cached elements, which could not be cached)
723 sLine = _parser.GetCachedEquation();
724 return _parser.GetCachedTarget();
725}
726
727
738static void replaceEntityStringOccurence(string& sLine, const string& sEntityOccurence, const string& sEntityStringReplacement)
739{
740 size_t nPos = 0;
741 while ((nPos = sLine.find(sEntityOccurence)) != string::npos)
742 {
743 sLine.replace(nPos, sEntityOccurence.length(), sEntityStringReplacement);
744 }
745}
746
747
765static void replaceEntityOccurence(string& sLine, const string& sEntityOccurence, const string& sEntityName, const string& sEntityReplacement, const Indices& _idx, MemoryManager& _data, Parser& _parser, const Settings& _option, bool isCluster)
766{
767 sLine = " " + sLine + " ";
768
769 size_t nPos = 0;
770
771 // As long as the entity occurs
772 while ((nPos = sLine.find(sEntityOccurence, nPos)) != string::npos)
773 {
774 // if the last character before the current occurence is
775 // alphanumeric, then ignore this occurence
776 if (nPos && (isalnum(sLine[nPos-1]) || sLine[nPos-1] == '_'))
777 {
778 nPos++;
779 continue;
780 }
781
782 // Get the last token
783 string sLeft = getLastToken(sLine.substr(0, nPos));
784
785 // Find the next character, which is no whitespace
786 size_t nNextNonWhiteSpace = sLine.find_first_not_of(" ", nPos + sEntityOccurence.length());
787
788 if (sLeft.length() < 3 || sLeft.back() != '(' || (sLine[nNextNonWhiteSpace] != ')' && sLine[nNextNonWhiteSpace] != ','))
789 {
790 // Simply replace it with the vector name
791 sLine.replace(nPos, sEntityOccurence.length(), sEntityReplacement);
792 continue;
793 }
794 else
795 {
796 // Calculate the statistical value and replace it with the result
797 // Although it seems to be duplicated code, these are only one-liners for each case
798 if (sLeft == "std(")
799 {
800 _parser.DisableAccessCaching();
801 sLine = sLine.substr(0, sLine.rfind("std(", sLine.find(sEntityOccurence)))
802 + toCmdString(isCluster ? _data.getCluster(sEntityName).std(_idx.row) : _data.std(sEntityName, _idx.row, _idx.col))
803 + sLine.substr(sLine.find(')', sLine.find(sEntityOccurence) + sEntityOccurence.length()) + 1);
804 }
805 else if (sLeft == "avg(")
806 {
807 _parser.DisableAccessCaching();
808 sLine = sLine.substr(0, sLine.rfind("avg(", sLine.find(sEntityOccurence)))
809 + toCmdString(isCluster ? _data.getCluster(sEntityName).avg(_idx.row) : _data.avg(sEntityName, _idx.row, _idx.col))
810 + sLine.substr(sLine.find(')', sLine.find(sEntityOccurence) + sEntityOccurence.length()) + 1);
811 }
812 else if (sLeft == "max(")
813 {
814 _parser.DisableAccessCaching();
815 sLine = sLine.substr(0, sLine.rfind("max(", sLine.find(sEntityOccurence)))
816 + toCmdString(isCluster ? _data.getCluster(sEntityName).max(_idx.row) : _data.max(sEntityName, _idx.row, _idx.col))
817 + sLine.substr(sLine.find(')', sLine.find(sEntityOccurence) + sEntityOccurence.length()) + 1);
818 }
819 else if (sLeft == "min(")
820 {
821 _parser.DisableAccessCaching();
822 sLine = sLine.substr(0, sLine.rfind("min(", sLine.find(sEntityOccurence)))
823 + toCmdString(isCluster ? _data.getCluster(sEntityName).min(_idx.row) : _data.min(sEntityName, _idx.row, _idx.col))
824 + sLine.substr(sLine.find(')', sLine.find(sEntityOccurence) + sEntityOccurence.length()) + 1);
825 }
826 else if (sLeft == "prd(")
827 {
828 _parser.DisableAccessCaching();
829 sLine = sLine.substr(0, sLine.rfind("prd(", sLine.find(sEntityOccurence)))
830 + toCmdString(isCluster ? _data.getCluster(sEntityName).prd(_idx.row) : _data.prd(sEntityName, _idx.row, _idx.col))
831 + sLine.substr(sLine.find(')', sLine.find(sEntityOccurence) + sEntityOccurence.length()) + 1);
832 }
833 else if (sLeft == "sum(")
834 {
835 _parser.DisableAccessCaching();
836 sLine = sLine.substr(0, sLine.rfind("sum(", sLine.find(sEntityOccurence)))
837 + toCmdString(isCluster ? _data.getCluster(sEntityName).sum(_idx.row) : _data.sum(sEntityName, _idx.row, _idx.col))
838 + sLine.substr(sLine.find(')', sLine.find(sEntityOccurence) + sEntityOccurence.length()) + 1);
839 }
840 else if (sLeft == "num(")
841 {
842 _parser.DisableAccessCaching();
843 sLine = sLine.substr(0, sLine.rfind("num(", sLine.find(sEntityOccurence)))
844 + toCmdString(isCluster ? _data.getCluster(sEntityName).num(_idx.row) : _data.num(sEntityName, _idx.row, _idx.col))
845 + sLine.substr(sLine.find(')', sLine.find(sEntityOccurence) + sEntityOccurence.length()) + 1);
846 }
847 else if (sLeft == "and(")
848 {
849 _parser.DisableAccessCaching();
850 sLine = sLine.substr(0, sLine.rfind("and(", sLine.find(sEntityOccurence)))
851 + toCmdString(isCluster ? _data.getCluster(sEntityName).and_func(_idx.row) : _data.and_func(sEntityName, _idx.row, _idx.col))
852 + sLine.substr(sLine.find(')', sLine.find(sEntityOccurence) + sEntityOccurence.length()) + 1);
853 }
854 else if (sLeft == "xor(")
855 {
856 _parser.DisableAccessCaching();
857 sLine = sLine.substr(0, sLine.rfind("xor(", sLine.find(sEntityOccurence)))
858 + toCmdString(isCluster ? _data.getCluster(sEntityName).xor_func(_idx.row) : _data.xor_func(sEntityName, _idx.row, _idx.col))
859 + sLine.substr(sLine.find(')', sLine.find(sEntityOccurence) + sEntityOccurence.length()) + 1);
860 }
861 else if (sLeft == "or(")
862 {
863 _parser.DisableAccessCaching();
864 sLine = sLine.substr(0, sLine.rfind("or(", sLine.find(sEntityOccurence)))
865 + toCmdString(isCluster ? _data.getCluster(sEntityName).or_func(_idx.row) : _data.or_func(sEntityName, _idx.row, _idx.col))
866 + sLine.substr(sLine.find(')', sLine.find(sEntityOccurence) + sEntityOccurence.length()) + 1);
867 }
868 else if (sLeft == "cnt(")
869 {
870 _parser.DisableAccessCaching();
871 sLine = sLine.substr(0, sLine.rfind("cnt(", sLine.find(sEntityOccurence)))
872 + toCmdString(isCluster ? _data.getCluster(sEntityName).cnt(_idx.row) : _data.cnt(sEntityName, _idx.row, _idx.col))
873 + sLine.substr(sLine.find(')', sLine.find(sEntityOccurence) + sEntityOccurence.length()) + 1);
874 }
875 else if (sLeft == "med(")
876 {
877 _parser.DisableAccessCaching();
878 sLine = sLine.substr(0, sLine.rfind("med(", sLine.find(sEntityOccurence)))
879 + toCmdString(isCluster ? _data.getCluster(sEntityName).med(_idx.row) : _data.med(sEntityName, _idx.row, _idx.col))
880 + sLine.substr(sLine.find(')', sLine.find(sEntityOccurence) + sEntityOccurence.length()) + 1);
881 }
882 else if (sLeft == "norm(")
883 {
884 _parser.DisableAccessCaching();
885 sLine = sLine.substr(0, sLine.rfind("norm(", sLine.find(sEntityOccurence)))
886 + toCmdString(isCluster ? _data.getCluster(sEntityName).norm(_idx.row) : _data.norm(sEntityName, _idx.row, _idx.col))
887 + sLine.substr(sLine.find(')', sLine.find(sEntityOccurence) + sEntityOccurence.length()) + 1);
888 }
889 else if (sLeft == "cmp(")
890 {
891 // cmp() is more difficult
892 _parser.DisableAccessCaching();
893 mu::value_type dRef = 0.0;
894 int nType = 0;
895 string sArg = "";
896 sLeft = sLine.substr(sLine.find(sLeft) + sLeft.length(), getMatchingParenthesis(sLine.substr(sLine.find(sLeft) + sLeft.length() - 1)) - 1);
897 sArg = getNextArgument(sLeft, true);
898 sArg = getNextArgument(sLeft, true);
899
900 if (_data.containsTablesOrClusters(sArg))
901 getDataElements(sArg, _parser, _data, _option);
902
903 _parser.SetExpr(sArg);
904 dRef = _parser.Eval();
905 sArg = getNextArgument(sLeft, true);
906
907 if (_data.containsTablesOrClusters(sArg))
908 getDataElements(sArg, _parser, _data, _option);
909
910 _parser.SetExpr(sArg);
911 nType = intCast(_parser.Eval());
912 sLine = sLine.replace(sLine.rfind("cmp(", sLine.find(sEntityOccurence)),
913 getMatchingParenthesis(sLine.substr(sLine.rfind("cmp(", sLine.find(sEntityOccurence)) + 3)) + 4,
914 toCmdString(isCluster ? _data.getCluster(sEntityName).cmp(_idx.row, dRef, nType) : _data.cmp(sEntityName, _idx.row, _idx.col, dRef, nType)));
915 }
916 else if (sLeft == "pct(")
917 {
918 // pct() is more difficult
919 _parser.DisableAccessCaching();
920 mu::value_type dPct = 0.5;
921 string sArg = "";
922 sLeft = sLine.substr(sLine.find(sLeft) + sLeft.length(), getMatchingParenthesis(sLine.substr(sLine.find(sLeft) + sLeft.length() - 1)) - 1);
923 sArg = getNextArgument(sLeft, true);
924 sArg = getNextArgument(sLeft, true);
925
926 if (_data.containsTablesOrClusters(sArg))
927 getDataElements(sArg, _parser, _data, _option);
928
929 _parser.SetExpr(sArg);
930 dPct = _parser.Eval();
931 sLine = sLine.replace(sLine.rfind("pct(", sLine.find(sEntityOccurence)),
932 getMatchingParenthesis(sLine.substr(sLine.rfind("pct(", sLine.find(sEntityOccurence)) + 3)) + 4,
933 toCmdString(isCluster ? _data.getCluster(sEntityName).pct(_idx.row, dPct) : _data.pct(sEntityName, _idx.row, _idx.col, dPct)));
934 }
935 else //Fallback
936 sLine.replace(nPos, sEntityOccurence.length(), sEntityReplacement);
937 }
938 }
939}
940
941
953static void handleMafDataAccess(string& sLine, const string& sMafAccess, Parser& _parser, MemoryManager& _data)
954{
955 size_t nPos = 0;
956 // Replace the access string with its corresponding vector name
957 string sMafVectorName = createMafVectorName(sMafAccess);
958
959 // Only store the value, if it is not a string literal (i.e. the name)
960 if (!NumeReKernel::getInstance()->getStringParser().isStringExpression(sMafVectorName))
961 {
962 // If the return value is not already a numerical vector
963 if (!_parser.ContainsVectorVars(sMafVectorName, false))
964 {
965 // Set the vector variable with its value for the parser
966 _parser.SetVectorVar(sMafVectorName,
967 MafDataAccess(_data,
968 getMafFromAccessString(sMafAccess),
969 sMafAccess.substr(0, sMafAccess.find('(')),
970 createMafDataAccessString(sMafAccess, _parser)));
971
972 // Create a cached access and store it
973 mu::CachedDataAccess _access = {sMafAccess,
974 sMafVectorName,
975 sMafAccess.substr(0, sMafAccess.find('(')),
977 _parser.CacheCurrentAccess(_access);
978 }
979 }
980 else
981 {
983
984 if (sMafVectorName.front() == '{')
985 sMafVectorName = _stringParser.createTempStringVectorVar(getAllArguments(sMafVectorName.substr(1, sMafVectorName.length()-2)));
986 else
987 sMafVectorName = _stringParser.createTempStringVectorVar({sMafVectorName});
988 }
989
990 // Replace every occurence
991 while ((nPos = sLine.find(sMafAccess, nPos)) != string::npos)
992 {
993 if (isInQuotes(sLine, nPos, true))
994 {
995 nPos++;
996 continue;
997 }
998
999 sLine.replace(nPos, sMafAccess.length(), sMafVectorName);
1000 }
1001}
1002
1003
1014static string createMafDataAccessString(const string& sAccessString, Parser& _parser)
1015{
1016 string sDataMaf;
1017
1018 if (sAccessString.find(".grid") != string::npos)
1019 sDataMaf += "grid";
1020
1021 if (sAccessString.find(".cols") != string::npos)
1022 sDataMaf += "cols";
1023
1024 if (sAccessString.find(".lines") != string::npos)
1025 sDataMaf += "lines";
1026
1027 if (sAccessString.find(".rows") != string::npos)
1028 sDataMaf += "lines";
1029
1030 if (sAccessString.find(".every(") != string::npos)
1031 sDataMaf += createEveryDefinition(sAccessString, _parser);
1032
1033 return sDataMaf;
1034}
1035
1036
1045static std::string getMafFromAccessString(const std::string& sAccessString)
1046{
1047 // Store these values statically
1048 static const int sMafListLength = 16;
1049 static std::string sMafList[sMafListLength] = {"std", "avg", "prd", "sum", "min", "max", "norm", "num", "cnt", "med", "and", "or", "xor", "size", "maxpos", "minpos"};
1050 size_t pos = 0;
1051
1052 for (int i = 0; i < sMafListLength; i++)
1053 {
1054 pos = sAccessString.find("." + sMafList[i]);
1055
1056 if (pos != std::string::npos
1057 && (pos + sMafList[i].length() + 1 >= sAccessString.length() || sAccessString[pos+sMafList[i].length()+1] == '.' || isDelimiter(sAccessString[pos+sMafList[i].length()+1])))
1058 return sMafList[i];
1059 }
1060
1061 // Special case: we only have TAB().rows or TAB().cols
1062 if ((pos = sAccessString.find(".rows")) != std::string::npos)
1063 {
1064 if (pos + 4 + 1 >= sAccessString.length()
1065 || sAccessString[pos+4+1] == '.'
1066 || isDelimiter(sAccessString[pos+4+1]))
1067 return "rows";
1068
1069 }
1070 else if ((pos = sAccessString.find(".cols")) != std::string::npos)
1071 {
1072 if (pos + 4 + 1 >= sAccessString.length()
1073 || sAccessString[pos+4+1] == '.'
1074 || isDelimiter(sAccessString[pos+4+1]))
1075 return "cols";
1076
1077 }
1078
1079 return "";
1080}
1081
1082
1092static string getMafAccessString(const string& sLine, const string& sEntity)
1093{
1094 size_t nPos = 0;
1095 static string sDelim = "+-*/^%&| ,=<>!()[]{}"; // delimiters (no "."!)
1096
1097 if ((nPos = sLine.find(sEntity + ").")) != string::npos)
1098 {
1099 // go through the string and try to find a MAF acces
1100 for (size_t i = nPos; i < sLine.length(); i++)
1101 {
1102 if (sLine[i] == '(' || sLine[i] == '[' || sLine[i] == '{')
1103 i += getMatchingParenthesis(sLine.substr(i)) + 1;
1104
1105 if (i >= sLine.length())
1106 return sLine.substr(nPos);
1107
1108 if (sDelim.find(sLine[i]) != string::npos)
1109 return sLine.substr(nPos, i - nPos);
1110
1111 if (i + 1 == sLine.length())
1112 return sLine.substr(nPos, i - nPos + 1);
1113 }
1114 }
1115
1116 // return nothing
1117 return "";
1118}
1119
1120
1132static vector<mu::value_type> MafDataAccess(MemoryManager& _data, const string& sMafname, const string& sCache, const string& sMafAccess)
1133{
1134 if (sMafname == "std")
1135 return _data.std(sCache, sMafAccess);
1136
1137 if (sMafname == "avg")
1138 return _data.avg(sCache, sMafAccess);
1139
1140 if (sMafname == "prd")
1141 return _data.prd(sCache, sMafAccess);
1142
1143 if (sMafname == "sum")
1144 return _data.sum(sCache, sMafAccess);
1145
1146 if (sMafname == "min")
1147 return _data.min(sCache, sMafAccess);
1148
1149 if (sMafname == "max")
1150 return _data.max(sCache, sMafAccess);
1151
1152 if (sMafname == "norm")
1153 return _data.norm(sCache, sMafAccess);
1154
1155 if (sMafname == "num")
1156 return _data.num(sCache, sMafAccess);
1157
1158 if (sMafname == "cnt")
1159 return _data.cnt(sCache, sMafAccess);
1160
1161 if (sMafname == "med")
1162 return _data.med(sCache, sMafAccess);
1163
1164 if (sMafname == "and")
1165 return _data.and_func(sCache, sMafAccess);
1166
1167 if (sMafname == "or")
1168 return _data.or_func(sCache, sMafAccess);
1169
1170 if (sMafname == "xor")
1171 return _data.xor_func(sCache, sMafAccess);
1172
1173 if (sMafname == "size")
1174 return _data.size(sCache, sMafAccess);
1175
1176 if (sMafname == "rows")
1177 return std::vector<mu::value_type>(1, _data.size(sCache, sMafAccess.find("grid") != std::string::npos ? "grid" : "").front());
1178
1179 if (sMafname == "cols")
1180 return std::vector<mu::value_type>(1, _data.size(sCache, sMafAccess.find("grid") != std::string::npos ? "grid" : "").back());
1181
1182 if (sMafname == "maxpos")
1183 return _data.maxpos(sCache, sMafAccess);
1184
1185 if (sMafname == "minpos")
1186 return _data.minpos(sCache, sMafAccess);
1187
1188 // return a vector with one NAN
1189 return vector<mu::value_type>(1, NAN);
1190}
1191
1192
1203static string createEveryDefinition(const string& sLine, Parser& _parser)
1204{
1205 string sExpr = sLine.substr(sLine.find(".every(") + 6);
1206 sExpr.erase(getMatchingParenthesis(sExpr)+1);
1207
1208 // Resolve possible remaining calls to data tables or clusters
1209 getDataElements(sExpr, _parser, NumeReKernel::getInstance()->getMemoryManager(), NumeReKernel::getInstance()->getSettings());
1210
1211 return "every=" + sExpr + " ";
1212}
1213
1214
1223static std::string tableMethod_aliasof(const std::string& sTableName, std::string sMethodArguments)
1224{
1225 // Might be necessary to resolve the contents of the reference
1226 getDataElements(sMethodArguments,
1227 NumeReKernel::getInstance()->getParser(),
1228 NumeReKernel::getInstance()->getMemoryManager(),
1229 NumeReKernel::getInstance()->getSettings());
1230
1231 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sMethodArguments))
1232 {
1233 std::string sDummy;
1235
1237 sMethodArguments = "\"\"";
1238 }
1239
1240 NumeReKernel::getInstance()->getMemoryManager().addReference(sTableName, sMethodArguments.substr(1, sMethodArguments.length()-2));
1241
1242 return sMethodArguments;
1243}
1244
1245
1254static std::string tableMethod_convert(const std::string& sTableName, std::string sMethodArguments)
1255{
1256 std::string sColumns = getNextArgument(sMethodArguments, true);
1257
1258 // Might be necessary to resolve the contents of columns and conversions
1259 getDataElements(sColumns,
1260 NumeReKernel::getInstance()->getParser(),
1261 NumeReKernel::getInstance()->getMemoryManager(),
1262 NumeReKernel::getInstance()->getSettings());
1263
1264 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sMethodArguments))
1265 {
1266 std::string sDummy;
1267 sMethodArguments += " -nq";
1269
1271 return "\"\"";
1272 }
1273
1274 int nResults = 0;
1278
1279 if (NumeReKernel::getInstance()->getMemoryManager().convertColumns(sTableName, VectorIndex(v, nResults, 0), sMethodArguments))
1280 return "\"" + sMethodArguments + "\"";
1281
1282 return "\"\"";
1283}
1284
1285
1294static std::string tableMethod_typeof(const std::string& sTableName, std::string sMethodArguments)
1295{
1296 // Might be necessary to resolve the contents of columns and conversions
1297 getDataElements(sMethodArguments,
1298 NumeReKernel::getInstance()->getParser(),
1299 NumeReKernel::getInstance()->getMemoryManager(),
1300 NumeReKernel::getInstance()->getSettings());
1301
1302 int nResults = 0;
1304 NumeReKernel::getInstance()->getParser().SetExpr(sMethodArguments);
1306
1307 std::string sRet;
1308
1309 for (int i = 0; i < nResults; i++)
1310 {
1311 if (sRet.length())
1312 sRet += ",";
1313
1315 sRet += "\"" + TableColumn::typeToString(type) + "\"";
1316 }
1317
1318 if (sRet.length())
1319 {
1320 if (sRet.find(',') != std::string::npos)
1321 return "{" + sRet + "}";
1322
1323 return sRet;
1324 }
1325
1326 return "\"\"";
1327}
1328
1329
1339static std::string tableMethod_categories(const std::string& sTableName, std::string sMethodArguments)
1340{
1341 // Might be necessary to resolve the contents of columns and conversions
1342 getDataElements(sMethodArguments,
1343 NumeReKernel::getInstance()->getParser(),
1344 NumeReKernel::getInstance()->getMemoryManager(),
1345 NumeReKernel::getInstance()->getSettings());
1346
1347 int nResults = 0;
1349 NumeReKernel::getInstance()->getParser().SetExpr(sMethodArguments);
1351
1352 ValueVector vCategories = NumeReKernel::getInstance()->getMemoryManager().getCategoryList(VectorIndex(v, nResults, 0), sTableName);
1353
1354 if (!vCategories.size())
1355 return "\"\"";
1356
1357 std::string sRet;
1358
1359 for (size_t i = 0; i < vCategories.size(); i+=2)
1360 {
1361 if (sRet.length())
1362 sRet += ",";
1363
1364 sRet += "\"" + vCategories[i] + "\"," + vCategories[i+1];
1365 }
1366
1367 return "{" + sRet + "}";
1368}
1369
1370
1380static std::string tableMethod_categorize(const std::string& sTableName, std::string sMethodArguments)
1381{
1382 std::string sColumns = getNextArgument(sMethodArguments, true);
1383 std::vector<std::string> vCategories;
1384
1385 // Might be necessary to resolve the contents of columns and conversions
1386 getDataElements(sColumns,
1387 NumeReKernel::getInstance()->getParser(),
1388 NumeReKernel::getInstance()->getMemoryManager(),
1389 NumeReKernel::getInstance()->getSettings());
1390
1391 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sMethodArguments))
1392 {
1393 std::string sDummy;
1394 sMethodArguments += " -nq";
1396
1398 return "\"\"";
1399
1401 }
1402
1403 int nResults = 0;
1407
1408 if (NumeReKernel::getInstance()->getMemoryManager().setCategories(sTableName, VectorIndex(v, nResults, 0), vCategories))
1409 {
1410 vCategories = NumeReKernel::getInstance()->getMemoryManager().getCategoryList(VectorIndex(v, nResults, 0), sTableName);
1411
1412 if (!vCategories.size())
1413 return "\"\"";
1414
1415 std::string sRet;
1416
1417 for (size_t i = 0; i < vCategories.size(); i+=2)
1418 {
1419 if (sRet.length())
1420 sRet += ",";
1421
1422 sRet += "\"" + vCategories[i] + "\"," + vCategories[i+1];
1423 }
1424
1425 return "{" + sRet + "}";
1426 }
1427
1428 return "\"\"";
1429}
1430
1431
1440static std::string tableMethod_findCols(const std::string& sTableName, std::string sMethodArguments)
1441{
1442 std::string sColumns = getNextArgument(sMethodArguments, true);
1443
1444 // Might be necessary to resolve the contents of columns and conversions
1445 getDataElements(sColumns,
1446 NumeReKernel::getInstance()->getParser(),
1447 NumeReKernel::getInstance()->getMemoryManager(),
1448 NumeReKernel::getInstance()->getSettings());
1449
1450 std::vector<std::string> vColNames;
1451
1452 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sColumns))
1453 {
1454 std::string sDummy;
1455 sColumns += " -nq";
1457
1459 return "nan";
1460
1462 }
1463
1464 std::vector<mu::value_type> vCols = NumeReKernel::getInstance()->getMemoryManager().findCols(sTableName, vColNames);
1465
1467}
1468
1469
1478static std::string tableMethod_counteq(const std::string& sTableName, std::string sMethodArguments)
1479{
1481 std::string sColumns = getNextArgument(sMethodArguments, true);
1482
1483 // Might be necessary to resolve the contents of columns and conversions
1484 getDataElements(sColumns,
1485 _kernel->getParser(),
1486 _kernel->getMemoryManager(),
1487 _kernel->getSettings());
1488
1489 int nResults = 0;
1490 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1491 _kernel->getParser().SetExpr(sColumns);
1492 mu::value_type* v = _kernel->getParser().Eval(nResults);
1493 VectorIndex vCols(v, nResults, 0);
1494
1495 std::vector<mu::value_type> vResults;
1496
1497 if (_kernel->getStringParser().isStringExpression(sMethodArguments))
1498 {
1499 std::string sDummy;
1500 sMethodArguments += " -nq";
1501 NumeRe::StringParser::StringParserRetVal res = _kernel->getStringParser().evalAndFormat(sMethodArguments, sDummy, true);
1502
1504 {
1505 _kernel->getParser().SetExpr(sMethodArguments);
1506 v = _kernel->getParser().Eval(nResults);
1507
1508 vResults = _kernel->getMemoryManager().countIfEqual(sTableName, vCols,
1509 std::vector<mu::value_type>(v, v+nResults),
1510 std::vector<std::string>());
1511 }
1512 else
1513 vResults = _kernel->getMemoryManager().countIfEqual(sTableName, vCols,
1514 std::vector<mu::value_type>(),
1515 _kernel->getAns().getInternalStringArray());
1516 }
1517 else
1518 {
1519 _kernel->getParser().SetExpr(sMethodArguments);
1520 v = _kernel->getParser().Eval(nResults);
1521
1522 vResults = _kernel->getMemoryManager().countIfEqual(sTableName, vCols,
1523 std::vector<mu::value_type>(v, v+nResults),
1524 std::vector<std::string>());
1525 }
1526
1527 return _kernel->getParser().CreateTempVectorVar(vResults);
1528}
1529
1530
1539static std::string tableMethod_index(const std::string& sTableName, std::string sMethodArguments)
1540{
1542 std::string sColumns = getNextArgument(sMethodArguments, true);
1543
1544 // Might be necessary to resolve the contents of columns and conversions
1545 getDataElements(sColumns,
1546 _kernel->getParser(),
1547 _kernel->getMemoryManager(),
1548 _kernel->getSettings());
1549
1550 int nResults = 0;
1551 _kernel->getParser().SetExpr(sColumns);
1552 mu::value_type* v = _kernel->getParser().Eval(nResults);
1553 size_t col = intCast(v[0])-1;
1554
1555 std::vector<mu::value_type> vResults;
1556
1557 if (_kernel->getStringParser().isStringExpression(sMethodArguments))
1558 {
1559 std::string sDummy;
1560 sMethodArguments += " -nq";
1561 NumeRe::StringParser::StringParserRetVal res = _kernel->getStringParser().evalAndFormat(sMethodArguments, sDummy, true);
1562
1564 {
1565 _kernel->getParser().SetExpr(sMethodArguments);
1566 v = _kernel->getParser().Eval(nResults);
1567
1568 vResults = _kernel->getMemoryManager().getIndex(sTableName, col,
1569 std::vector<mu::value_type>(v, v+nResults),
1570 std::vector<std::string>());
1571 }
1572 else
1573 vResults = _kernel->getMemoryManager().getIndex(sTableName, col,
1574 std::vector<mu::value_type>(),
1575 _kernel->getAns().getInternalStringArray());
1576 }
1577 else
1578 {
1579 _kernel->getParser().SetExpr(sMethodArguments);
1580 v = _kernel->getParser().Eval(nResults);
1581
1582 vResults = _kernel->getMemoryManager().getIndex(sTableName, col,
1583 std::vector<mu::value_type>(v, v+nResults),
1584 std::vector<std::string>());
1585 }
1586
1587 return _kernel->getParser().CreateTempVectorVar(vResults);
1588}
1589
1590
1599static std::string tableMethod_cov(const std::string& sTableName, std::string sMethodArguments)
1600{
1602 std::string sCols = getNextArgument(sMethodArguments, true);
1603 sCols += "," + getNextArgument(sMethodArguments, true);
1604
1605 // Might be necessary to resolve the contents of columns and conversions
1606 getDataElements(sCols,
1607 _kernel->getParser(),
1608 _kernel->getMemoryManager(),
1609 _kernel->getSettings());
1610
1611 int nResults = 0;
1612 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1613 _kernel->getParser().SetExpr(sCols);
1614 mu::value_type* v = _kernel->getParser().Eval(nResults);
1615
1616 if (nResults < 2)
1617 throw SyntaxError(SyntaxError::TOO_FEW_COLS, sTableName + "().cov()", ".cov(", ".cov(");
1618
1619 size_t col1 = intCast(v[0])-1;
1620 size_t col2 = intCast(v[1])-1;
1621
1622 std::vector<mu::value_type> vResults;
1625
1626 if (sMethodArguments.length())
1627 {
1628 getDataElements(sMethodArguments,
1629 _kernel->getParser(),
1630 _kernel->getMemoryManager(),
1631 _kernel->getSettings());
1632
1633 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1634 _kernel->getParser().SetExpr(getNextArgument(sMethodArguments, true));
1635 v = _kernel->getParser().Eval(nResults);
1636 vIndex1 = VectorIndex(v, nResults, 0);
1637
1638 if (sMethodArguments.length())
1639 {
1640 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1641 _kernel->getParser().SetExpr(getNextArgument(sMethodArguments, true));
1642 v = _kernel->getParser().Eval(nResults);
1643 vIndex2 = VectorIndex(v, nResults, 0);
1644 }
1645 }
1646
1647 vResults.push_back(_kernel->getMemoryManager().getCovariance(sTableName, col1, vIndex1, col2, vIndex2));
1648
1649 return _kernel->getParser().CreateTempVectorVar(vResults);
1650}
1651
1652
1661static std::string tableMethod_pcorr(const std::string& sTableName, std::string sMethodArguments)
1662{
1664 std::string sCols = getNextArgument(sMethodArguments, true);
1665 sCols += "," + getNextArgument(sMethodArguments, true);
1666
1667 // Might be necessary to resolve the contents of columns and conversions
1668 getDataElements(sCols,
1669 _kernel->getParser(),
1670 _kernel->getMemoryManager(),
1671 _kernel->getSettings());
1672
1673 int nResults = 0;
1674 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1675 _kernel->getParser().SetExpr(sCols);
1676 mu::value_type* v = _kernel->getParser().Eval(nResults);
1677
1678 if (nResults < 2)
1679 throw SyntaxError(SyntaxError::TOO_FEW_COLS, sTableName + "().pcorr()", ".pcorr(", ".pcorr(");
1680
1681 size_t col1 = intCast(v[0])-1;
1682 size_t col2 = intCast(v[1])-1;
1683
1684 std::vector<mu::value_type> vResults;
1687
1688 if (sMethodArguments.length())
1689 {
1690 getDataElements(sMethodArguments,
1691 _kernel->getParser(),
1692 _kernel->getMemoryManager(),
1693 _kernel->getSettings());
1694
1695 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1696 _kernel->getParser().SetExpr(getNextArgument(sMethodArguments, true));
1697 v = _kernel->getParser().Eval(nResults);
1698 vIndex1 = VectorIndex(v, nResults, 0);
1699
1700 if (sMethodArguments.length())
1701 {
1702 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1703 _kernel->getParser().SetExpr(getNextArgument(sMethodArguments, true));
1704 v = _kernel->getParser().Eval(nResults);
1705 vIndex2 = VectorIndex(v, nResults, 0);
1706 }
1707 }
1708
1709 vResults.push_back(_kernel->getMemoryManager().getPearsonCorr(sTableName, col1, vIndex1, col2, vIndex2));
1710
1711 return _kernel->getParser().CreateTempVectorVar(vResults);
1712}
1713
1714
1723static std::string tableMethod_scorr(const std::string& sTableName, std::string sMethodArguments)
1724{
1726 std::string sCols = getNextArgument(sMethodArguments, true);
1727 sCols += "," + getNextArgument(sMethodArguments, true);
1728
1729 // Might be necessary to resolve the contents of columns and conversions
1730 getDataElements(sCols,
1731 _kernel->getParser(),
1732 _kernel->getMemoryManager(),
1733 _kernel->getSettings());
1734
1735 int nResults = 0;
1736 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1737 _kernel->getParser().SetExpr(sCols);
1738 mu::value_type* v = _kernel->getParser().Eval(nResults);
1739
1740 if (nResults < 2)
1741 throw SyntaxError(SyntaxError::TOO_FEW_COLS, sTableName + "().scorr()", ".scorr(", ".scorr(");
1742
1743 size_t col1 = intCast(v[0])-1;
1744 size_t col2 = intCast(v[1])-1;
1745
1746 std::vector<mu::value_type> vResults;
1749
1750 if (sMethodArguments.length())
1751 {
1752 getDataElements(sMethodArguments,
1753 _kernel->getParser(),
1754 _kernel->getMemoryManager(),
1755 _kernel->getSettings());
1756
1757 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1758 _kernel->getParser().SetExpr(getNextArgument(sMethodArguments, true));
1759 v = _kernel->getParser().Eval(nResults);
1760 vIndex1 = VectorIndex(v, nResults, 0);
1761
1762 if (sMethodArguments.length())
1763 {
1764 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1765 _kernel->getParser().SetExpr(getNextArgument(sMethodArguments, true));
1766 v = _kernel->getParser().Eval(nResults);
1767 vIndex2 = VectorIndex(v, nResults, 0);
1768 }
1769 }
1770
1771 vResults.push_back(_kernel->getMemoryManager().getSpearmanCorr(sTableName, col1, vIndex1, col2, vIndex2));
1772
1773 return _kernel->getParser().CreateTempVectorVar(vResults);
1774}
1775
1776
1785static std::string tableMethod_zscore(const std::string& sTableName, std::string sMethodArguments)
1786{
1788 std::string sCols = getNextArgument(sMethodArguments, true);
1789
1790 // Might be necessary to resolve the contents of columns and conversions
1791 getDataElements(sCols,
1792 _kernel->getParser(),
1793 _kernel->getMemoryManager(),
1794 _kernel->getSettings());
1795
1796 int nResults = 0;
1797 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1798 _kernel->getParser().SetExpr(sCols);
1799 mu::value_type* v = _kernel->getParser().Eval(nResults);
1800 size_t col = intCast(v[0])-1;
1801
1802 std::vector<mu::value_type> vResults;
1804
1805 if (sMethodArguments.length())
1806 {
1807 getDataElements(sMethodArguments,
1808 _kernel->getParser(),
1809 _kernel->getMemoryManager(),
1810 _kernel->getSettings());
1811
1812 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1813 _kernel->getParser().SetExpr(getNextArgument(sMethodArguments, true));
1814 v = _kernel->getParser().Eval(nResults);
1815 vIndex = VectorIndex(v, nResults, 0);
1816 }
1817
1818 vResults = _kernel->getMemoryManager().getZScore(sTableName, col, vIndex);
1819
1820 return _kernel->getParser().CreateTempVectorVar(vResults);
1821}
1822
1823
1832static std::string tableMethod_anova(const std::string& sTableName, std::string sMethodArguments)
1833{
1835 std::string sCols = getNextArgument(sMethodArguments, true);
1836 sCols += "," + getNextArgument(sMethodArguments, true);
1837
1838 // Might be necessary to resolve the contents of columns and conversions
1839 getDataElements(sCols,
1840 _kernel->getParser(),
1841 _kernel->getMemoryManager(),
1842 _kernel->getSettings());
1843
1844 int nResults = 0;
1845 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1846 _kernel->getParser().SetExpr(sCols);
1847 mu::value_type* v = _kernel->getParser().Eval(nResults);
1848
1849 if (nResults < 2)
1850 throw SyntaxError(SyntaxError::TOO_FEW_COLS, sTableName + "().anovafor()", ".anovafor(", ".anovafor(");
1851
1852 size_t col1 = intCast(v[0])-1;
1853 size_t col2 = intCast(v[1])-1;
1854
1856 double significance = 0.05;
1857
1858 if (sMethodArguments.length())
1859 {
1860 getDataElements(sMethodArguments,
1861 _kernel->getParser(),
1862 _kernel->getMemoryManager(),
1863 _kernel->getSettings());
1864
1865 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1866 _kernel->getParser().SetExpr(getNextArgument(sMethodArguments, true));
1867 v = _kernel->getParser().Eval(nResults);
1868 significance = v[0].real();
1869
1870 if (sMethodArguments.length())
1871 {
1872 getDataElements(sMethodArguments,
1873 _kernel->getParser(),
1874 _kernel->getMemoryManager(),
1875 _kernel->getSettings());
1876
1877 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1878 _kernel->getParser().SetExpr(getNextArgument(sMethodArguments, true));
1879 v = _kernel->getParser().Eval(nResults);
1880 vIndex = VectorIndex(v, nResults, 0);
1881 }
1882 }
1883
1884 AnovaResult res = _kernel->getMemoryManager().getOneWayAnova(sTableName, col1, col2, vIndex, significance);
1885
1886 std::string sRet = "{";
1887
1888 sRet += "\"FisherRatio\"," + toString(res.m_FRatio) + ",";
1889 sRet += "\"FisherSignificanceVal\"," + toString(res.m_significanceVal) + ",";
1890 sRet += "\"SignificanceLevel\"," + toString(res.m_significance) + ",";
1891 sRet += "\"SignificantVariation\"," + toString(res.m_isSignificant) + ",";
1892 sRet += "\"Categories\"," + toString(res.m_numCategories) + "}";
1893
1894 return sRet;
1895}
1896
1897
1906static std::string tableMethod_binsof(const std::string& sTableName, std::string sMethodArguments)
1907{
1909 std::string sCols = getNextArgument(sMethodArguments, true);
1910
1911 if (sMethodArguments.length())
1912 sCols += "," + getNextArgument(sMethodArguments, true);
1913
1914 // Might be necessary to resolve the contents of columns and conversions
1915 getDataElements(sCols,
1916 _kernel->getParser(),
1917 _kernel->getMemoryManager(),
1918 _kernel->getSettings());
1919
1920 int nResults = 0;
1921 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1922 _kernel->getParser().SetExpr(sCols);
1923 mu::value_type* v = _kernel->getParser().Eval(nResults);
1924
1925 size_t col = intCast(v[0])-1;
1926 size_t nBins = 0;
1927
1928 if (nResults > 1)
1929 nBins = intCast(v[1]);
1930
1931 return _kernel->getParser().CreateTempVectorVar(_kernel->getMemoryManager().getBins(sTableName, col, nBins));
1932}
1933
1934
1943static std::string tableMethod_rank(const std::string& sTableName, std::string sMethodArguments)
1944{
1946 std::string sCols = getNextArgument(sMethodArguments, true);
1947
1948 // Might be necessary to resolve the contents of columns and conversions
1949 getDataElements(sCols,
1950 _kernel->getParser(),
1951 _kernel->getMemoryManager(),
1952 _kernel->getSettings());
1953
1954 int nResults = 0;
1955 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1956 _kernel->getParser().SetExpr(sCols);
1957 mu::value_type* v = _kernel->getParser().Eval(nResults);
1958 size_t col = intCast(v[0])-1;
1959
1960 std::vector<mu::value_type> vResults;
1963
1964 if (sMethodArguments.length())
1965 {
1966 sCols = getNextArgument(sMethodArguments, true);
1967
1968 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sCols))
1969 {
1970 std::string sDummy;
1971 sCols += " -nq";
1973
1975 return "nan";
1976
1977 std::string sStrat = NumeReKernel::getInstance()->getAns().getInternalStringArray().front();
1978
1979 if (sStrat == "f")
1980 _strat = Memory::RANK_FRACTIONAL;
1981 else if (sStrat == "d")
1982 _strat = Memory::RANK_DENSE;
1983 }
1984
1985 if (sMethodArguments.length())
1986 {
1987 getDataElements(sMethodArguments,
1988 _kernel->getParser(),
1989 _kernel->getMemoryManager(),
1990 _kernel->getSettings());
1991
1992 _kernel->getMemoryManager().updateDimensionVariables(sTableName);
1993 _kernel->getParser().SetExpr(getNextArgument(sMethodArguments, true));
1994 v = _kernel->getParser().Eval(nResults);
1995 vIndex = VectorIndex(v, nResults, 0);
1996 }
1997 }
1998
1999 vResults = _kernel->getMemoryManager().getRank(sTableName, col, vIndex, _strat);
2000
2001 return _kernel->getParser().CreateTempVectorVar(vResults);
2002}
2003
2004
2013static std::string tableMethod_annotate(const std::string& sTableName, std::string sMethodArguments)
2014{
2015 // Might be necessary to resolve the contents of columns and conversions
2016 getDataElements(sMethodArguments,
2017 NumeReKernel::getInstance()->getParser(),
2018 NumeReKernel::getInstance()->getMemoryManager(),
2019 NumeReKernel::getInstance()->getSettings());
2020
2021 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sMethodArguments))
2022 {
2023 std::string sDummy;
2024 sMethodArguments += " -nq";
2026
2028 return "\"\"";
2029 }
2030
2031 NumeReKernel::getInstance()->getMemoryManager().writeComment(sTableName, sMethodArguments);
2032 return "\"" + sMethodArguments + "\"";
2033}
2034
2035
2039typedef std::string (*TableMethod)(const std::string&, std::string);
2040
2041
2049static std::map<std::string, TableMethod> getInplaceTableMethods()
2050{
2051 std::map<std::string, TableMethod> mTableMethods;
2052
2053 mTableMethods["aliasof"] = tableMethod_aliasof;
2054 mTableMethods["convert"] = tableMethod_convert;
2055 mTableMethods["typeof"] = tableMethod_typeof;
2056 mTableMethods["describe"] = tableMethod_annotate;
2057 mTableMethods["categoriesof"] = tableMethod_categories;
2058 mTableMethods["categorize"] = tableMethod_categorize;
2059 mTableMethods["fndcols"] = tableMethod_findCols;
2060 mTableMethods["countif"] = tableMethod_counteq;
2061 mTableMethods["indexof"] = tableMethod_index;
2062 mTableMethods["covarof"] = tableMethod_cov;
2063 mTableMethods["pcorrof"] = tableMethod_pcorr;
2064 mTableMethods["scorrof"] = tableMethod_scorr;
2065 mTableMethods["rankof"] = tableMethod_rank;
2066 mTableMethods["zscoreof"] = tableMethod_zscore;
2067 mTableMethods["anovaof"] = tableMethod_anova;
2068 mTableMethods["binsof"] = tableMethod_binsof;
2069
2070 return mTableMethods;
2071}
2072
2073
2083static string createMafVectorName(string sAccessString)
2084{
2085 static std::map<std::string, TableMethod> mMethods = getInplaceTableMethods();
2086 std::string sTableName = sAccessString.substr(0, sAccessString.find("()."));
2087
2088 for (auto& method : mMethods)
2089 {
2090 if (sAccessString.compare(0, sTableName.length()+method.first.length()+4, sTableName+"()."+method.first+"(") == 0)
2091 {
2092 //std::string sMethodArguments = sAccessString.substr(sAccessString.find("." + method.first + "(") + 1 + method.first.length());
2093 std::string sMethodArguments = sAccessString.substr(sTableName.length()+method.first.length()+3);
2094 sMethodArguments.erase(getMatchingParenthesis(sMethodArguments)+1);
2095 sMethodArguments = sMethodArguments.substr(1, sMethodArguments.length()-2);
2096
2097 return method.second(sTableName, sMethodArguments);
2098 }
2099 }
2100
2101 if (sAccessString.find(".name") != std::string::npos)
2102 return "\"" + sAccessString.substr(0, sAccessString.find("().")+2) + "\"";
2103
2104 if (sAccessString.find(".description") != std::string::npos)
2105 return "\"" + NumeReKernel::getInstance()->getMemoryManager().getComment(sAccessString.substr(0, sAccessString.find("()."))) + "\"";
2106
2107 sAccessString.replace(sAccessString.find("()"), 2, "[");
2108 sAccessString = replaceToVectorname(sAccessString);
2109 return sAccessString + "]";
2110}
2111
2112
2122static string getLastToken(const string& sLine)
2123{
2124 string sToken = sLine;
2125 size_t pos;
2126 // Strip the spaces, because the string may end with "... FUNCTION( "
2127 StripSpaces(sToken);
2128
2129 if (sToken.back() == '(')
2130 {
2131 // Probably a function name here
2132 pos = sToken.find_last_of(" !%&|<>=?:.,/*-+^(){}#", sToken.length() - 2);
2133 if (pos == string::npos)
2134 return sToken;
2135 sToken.erase(0, pos + 1);
2136 return sToken;
2137 }
2138
2139 // Can be every thing else
2140 pos = sToken.find_last_of(" !%&|<>=?:.,/*-+^(){}#");
2141 if (pos == string::npos)
2142 return sToken;
2143 sToken.erase(0, pos + 1);
2144 return sToken;
2145}
2146
2147
2161Memory* extractRange(const std::string& sCmd, DataAccessParser& _accessParser, int nDesiredCols, bool bSort)
2162{
2163 // Validize the obtained index sets
2164 if (!isValidIndexSet(_accessParser.getIndices()))
2165 throw SyntaxError(SyntaxError::TABLE_DOESNT_EXIST, sCmd, _accessParser.getDataObject() + "(", _accessParser.getDataObject() + "()");
2166
2167 // Select the number of relevant columns
2168 if (nDesiredCols > 0 && _accessParser.getIndices().col.isOpenEnd())
2169 _accessParser.getIndices().col.setRange(0, _accessParser.getIndices().col.front() + nDesiredCols-1);
2170 else if (nDesiredCols == 2 && _accessParser.getIndices().col.numberOfNodes() == 2u)
2171 {
2172 // Check number of nodes and convert the columns to an explicit two-element vector,
2173 // if the user did not pass an open-end index set
2174 Indices& _idx = _accessParser.getIndices();
2175 _idx.col = VectorIndex(std::vector<int>({_idx.col.front(), _idx.col.last()}));
2176 }
2177
2178 // Evaluate the number of rows, if necessary
2179 _accessParser.evalIndices();
2180
2182
2183 if (!_mem)
2184 return nullptr;
2185
2186 _mem = _mem->extractRange(_accessParser.getIndices().row, _accessParser.getIndices().col);
2187
2188 if (bSort)
2189 _mem->sortElements(0, _mem->getLines()-1, 0, _mem->getCols()-1, "-c=1[2:]");
2190
2191 return _mem;
2192}
2193
2194
2206{
2207 // Search for tables and clusters
2208 DataAccessParser _accessParser(sExpression);
2209
2210 if (!_accessParser.getDataObject().length())
2212
2213 if (!isValidIndexSet(_accessParser.getIndices()))
2214 throw SyntaxError(SyntaxError::INVALID_INDEX, sExpression.to_string(), SyntaxError::invalid_position, _accessParser.getIndices().row.to_string() + ", " + _accessParser.getIndices().col.to_string());
2215
2216 return _accessParser;
2217}
2218
2219
2234Indices getIndicesForPlotAndFit(const string& sExpression, string& sDataTable, int& nColumns, bool& openEnd, bool& isCluster)
2235{
2236 Indices _idx;
2237 openEnd = false;
2238 isCluster = false;
2239 sDataTable = "data";
2240
2241 // Search for tables and clusters
2242 DataAccessParser _accessParser = getAccessParserForPlotAndFit(sExpression);
2243
2244 sDataTable = _accessParser.getDataObject();
2245 _idx = _accessParser.getIndices();
2246 isCluster = _accessParser.isCluster();
2247
2248 // Determine the number of passed columns and
2249 // whether the user left an open end in the column
2250 // index list
2251 if (_idx.col.numberOfNodes() > 2)
2252 nColumns = _idx.col.numberOfNodes();
2253 else
2254 {
2255 nColumns = _idx.col.numberOfNodes();
2256 openEnd = _idx.col.isOpenEnd();
2257
2258 if (isCluster)
2259 nColumns = 1;
2260 }
2261
2262 return _idx;
2263}
2264
2265
2275bool isNotEmptyExpression(const string& sExpr)
2276{
2277 if (!sExpr.length())
2278 return false;
2279 return sExpr.find_first_not_of(' ') != string::npos;
2280}
2281
2282
2296bool isClusterCandidate(string& sLine, string& sCluster, bool doCut)
2297{
2298 // Do nothing, if the current line does not contain
2299 // an assignment operator
2300 if (findAssignmentOperator(sLine) == string::npos || sLine[sLine.find_first_not_of(' ')] == '-')
2301 return false;
2302
2303 size_t nQuotes = 0;
2304
2305 // Go through the command line and try to detect
2306 // a opening brace following an alphanumeric character
2307 // or an underscore
2308 for (size_t i = 1; i < sLine.length(); i++)
2309 {
2310 // consider quotation marks
2311 if (sLine[i] == '"' && (!i || sLine[i-1] != '\\'))
2312 nQuotes++;
2313
2314 // Is this an opening brace following the alphanumeric
2315 // character? Then try to extract the corresponding cluster
2316 // name
2317 if (!(nQuotes % 2) && sLine[i] == '{' && (sLine[i-1] == '_' || isalnum(sLine[i-1])))
2318 {
2319 size_t start = 0;
2320
2321 // Find the starting position
2322 for (int j = i-1; j >= 0; j--)
2323 {
2324 if (!isalnum(sLine[j]) && sLine[j] != '_' && sLine[j] != '~')
2325 start = j+1;
2326 }
2327
2328 // Extract the cluster including its braces
2329 sCluster = sLine.substr(start, getMatchingParenthesis(sLine.substr(i))+(i-start)+1);
2330
2331 // If the command line shall be splitted, do that
2332 // here
2333 if (doCut)
2334 {
2335 sLine.erase(start, sCluster.length());
2336
2337 size_t nextCharPos = sLine.find_first_not_of(' ');
2338
2339 if (nextCharPos != string::npos && sLine[nextCharPos] == '=' && sLine[nextCharPos+1] != '=')
2340 sLine.erase(start, nextCharPos + 1);
2341 }
2342
2343 StripSpaces(sCluster);
2344
2345 // Get a reference to the datafile object
2347
2348 // Declare the extracted cluster, if it is not
2349 // known to the clustermanager
2350 if (!_data.isCluster(sCluster.substr(0, sCluster.find('{'))))
2351 _data.newCluster(sCluster);
2352
2353 return true;
2354 }
2355
2356 // These are characters, which do not belong to a cluster
2357 // identifier. Return false in this case.
2358 if (!(nQuotes % 2) && sLine[i] != '~' && sLine[i] != '_' && sLine[i] != '[' && sLine[i] != ']' && (sLine[i] == '(' || sLine[i] == '=' || ispunct(sLine[i])))
2359 return false;
2360 }
2361
2362 return false;
2363}
2364
2365
2378mu::value_type getDataFromObject(const std::string& sObject, long long int i, long long int j, bool isCluster)
2379{
2380 // Get a reference to the datafile object
2382
2383 // Fallback to ensure that valid indices are read
2384 if (i < 0 || j < 0)
2385 return NAN;
2386
2387 // return the data depending on the passed isCluster
2388 // boolean, the object name and its indices
2389 return isCluster ? _data.getCluster(sObject).getDouble(i) : _data.getElement(i, j, sObject);
2390}
2391
2392
2405std::vector<mu::value_type> getDataFromObject(const std::string& sObject, const VectorIndex& vRows, long long int j, bool isCluster)
2406{
2407 // Get a reference to the datafile object
2409
2410 // Fallback to ensure that valid indices are read
2411 if (vRows.front() == VectorIndex::INVALID || j < 0)
2412 return std::vector(1u, mu::value_type(NAN));
2413
2414 // return the data depending on the passed isCluster
2415 // boolean, the object name and its indices
2416 if (isCluster)
2417 {
2418 NumeRe::Cluster& clst = _data.getCluster(sObject);
2419 std::vector<mu::value_type> vRes;
2420
2421 for (int i = 0; i < vRows.size(); i++)
2422 {
2423 vRes.push_back(clst.getDouble(vRows[i]));
2424 }
2425
2426 return vRes;
2427 }
2428
2429 return _data.getElement(vRows, VectorIndex(j), sObject);
2430}
2431
2432
2443bool parser_CheckMultArgFunc(const string& sLeft, const string& sRight)
2444{
2445 // Get the last token form the left side (can be the name of a function, for example)
2446 string sFunc = getLastToken(sLeft);
2447
2448 // If it doesn't end with a parenthesis, it cannot be a function
2449 if (sFunc.back() != '(')
2450 return false;
2451
2452 bool bCMP = false;
2453
2454 // examine the first non-whitespace character of the right side:
2455 // - if it is a parenthesis, then simply break
2456 // - if it is a comma, then try to find the next parenthesis. If it exists, it can be a compare-like function signature
2457 for (unsigned int i = 0; i < sRight.length(); i++)
2458 {
2459 if (sRight[i] != ' ')
2460 {
2461 if (sRight[i] == ')')
2462 break;
2463 else if (sRight[i] == ',')
2464 {
2465 if (sRight.find(')', i + 1) != string::npos)
2466 bCMP = true;
2467 else
2468 return false;
2469 break;
2470 }
2471 }
2472 }
2473
2474 // Now compare sFunc with the possible multi-argument functions
2475 if (sFunc == "max(" && !bCMP)
2476 return true;
2477 else if (sFunc == "min(" && !bCMP)
2478 return true;
2479 else if (sFunc == "sum(" && !bCMP)
2480 return true;
2481 else if (sFunc == "avg(" && !bCMP)
2482 return true;
2483 else if (sFunc == "num(" && !bCMP)
2484 return true;
2485 else if (sFunc == "cnt(" && !bCMP)
2486 return true;
2487 else if (sFunc == "med(" && !bCMP)
2488 return true;
2489 else if (sFunc == "pct(" && bCMP)
2490 return true;
2491 else if (sFunc == "std(" && !bCMP)
2492 return true;
2493 else if (sFunc == "prd(" && !bCMP)
2494 return true;
2495 else if (sFunc == "and(" && !bCMP)
2496 return true;
2497 else if (sFunc == "or(" && !bCMP)
2498 return true;
2499 else if (sFunc == "xor(" && !bCMP)
2500 return true;
2501 else if (sFunc == "cmp(" && bCMP)
2502 return true;
2503 else if (sFunc == "norm(" && !bCMP)
2504 return true;
2505 else
2506 return false;
2507}
2508
2509
2519std::vector<size_t> getDataGridDimensions(const Indices& _idx, const std::string& sTableName)
2520{
2522 std::vector<size_t> sizes(2, 0);
2523
2524 if (_manager.isTable(sTableName))
2525 {
2526 sizes[0] = _manager.cnt(sTableName, _idx.row, _idx.col.subidx(0, 1)).real();
2527 sizes[1] = _manager.cnt(sTableName, _idx.row, _idx.col.subidx(1, 1)).real();
2528 }
2529
2530 return sizes;
2531}
2532
This class is defined to abstrahize the determination of the correct data object and the calculation ...
Definition: dataaccess.hpp:38
Indices & getIndices()
Returns a reference to the stored indices.
Definition: dataaccess.cpp:196
void evalIndices()
Evaluates open end indices using the identified data object size.
Definition: dataaccess.cpp:141
bool isCluster() const
Determines, whether the data access references a cluster.
Definition: dataaccess.cpp:209
std::string & getDataObject()
Returns a reference to the data object identifier.
Definition: dataaccess.cpp:170
std::vector< size_t > getDataGridDimensions() const
Covenience wrapper method for the global function.
Definition: dataaccess.cpp:222
DataAccessParser()
DataAccessParser default constructor.
Definition: dataaccess.cpp:31
std::string getIndexString()
This member function returns the index definitions as a human-readable string.
Definition: dataaccess.cpp:183
std::string sDataObject
Definition: dataaccess.hpp:40
This class represents a single table in memory, or a - so to say - single memory page to be handled b...
Definition: memory.hpp:68
int getLines(bool _bFull=false) const
This member function will return the number of lines, which are currently available in this table.
Definition: memory.cpp:258
int getCols(bool _bFull=false) const
This member function will return the number of columns, which are currently available in this table.
Definition: memory.cpp:241
std::vector< int > sortElements(int i1, int i2, int j1=0, int j2=0, const std::string &sSortingExpression="")
This member function is the interface function for the Sorter class. It will pre- evaluate the passed...
Definition: memory.cpp:1555
RankingStrategy
Definition: memory.hpp:79
@ RANK_DENSE
Definition: memory.hpp:80
@ RANK_COMPETETIVE
Definition: memory.hpp:81
@ RANK_FRACTIONAL
Definition: memory.hpp:82
Memory * extractRange(const VectorIndex &_vLine, const VectorIndex &_vCol) const
This member function extracts a range of this table and returns it as a new Memory instance.
Definition: memory.cpp:723
This class represents the central memory managing instance. It will handle all tables and clusters,...
TableColumn::ColumnType getType(const VectorIndex &_vCol, const std::string &_sTable) const
std::vector< mu::value_type > med(const std::string &sTable, std::string sDir) const
std::vector< mu::value_type > xor_func(const std::string &sTable, std::string sDir) const
std::vector< mu::value_type > avg(const std::string &sTable, std::string sDir) const
mu::value_type getElement(int _nLine, int _nCol, const std::string &_sTable) const
std::string getComment(const std::string &_sTable) const
std::vector< mu::value_type > findCols(const std::string &sTable, const std::vector< std::string > &vCols) const
ValueVector getElementAsString(const VectorIndex &_vLine, const VectorIndex &_vCol, const std::string &_sTable) const
std::vector< mu::value_type > countIfEqual(const std::string &sTable, const VectorIndex &_vCols, const std::vector< mu::value_type > &vValues, const std::vector< std::string > &vStringValues) const
std::vector< mu::value_type > min(const std::string &sTable, std::string sDir) const
std::vector< mu::value_type > norm(const std::string &sTable, std::string sDir) const
std::vector< mu::value_type > pct(const std::string &sTable, std::string sDir, mu::value_type dPct=0.5) const
void copyTable(const std::string &source, const std::string &target)
Copy one table to another one (and create the missing table automatically, if needed).
int getLines(StringView sTable, bool _bFull=false) const
const std::map< std::string, std::pair< size_t, size_t > > & getTableMap() const
std::vector< mu::value_type > cmp(const std::string &sTable, std::string sDir, mu::value_type dRef=0.0, int nType=0) const
std::vector< mu::value_type > getRank(const std::string &sTable, size_t col, const VectorIndex &_vIndex, Memory::RankingStrategy _strat) const
bool isTable(const std::string &sTable) const
This member function returns, whether the passed table name corresponds to a known table.
mu::value_type getSpearmanCorr(const std::string &sTable, size_t col1, const VectorIndex &_vIndex1, size_t col2, const VectorIndex &_vIndex2) const
std::vector< mu::value_type > getBins(const std::string &sTable, size_t col, size_t nBins) const
std::vector< mu::value_type > and_func(const std::string &sTable, std::string sDir) const
void copyElementsInto(std::vector< mu::value_type > *vTarget, const VectorIndex &_vLine, const VectorIndex &_vCol, const std::string &_sTable) const
std::vector< mu::value_type > cnt(const std::string &sTable, std::string sDir) const
void writeComment(const std::string &_sTable, const std::string &_comment)
void addReference(const std::string &sTable, const std::string &sReference)
std::vector< mu::value_type > num(const std::string &sTable, std::string sDir) const
mu::value_type getPearsonCorr(const std::string &sTable, size_t col1, const VectorIndex &_vIndex1, size_t col2, const VectorIndex &_vIndex2) const
ValueVector getElementMixed(const VectorIndex &_vLine, const VectorIndex &_vCol, const std::string &_sTable) const
std::string getHeadLineElement(int _i, const std::string &_sTable) const
std::vector< mu::value_type > max(const std::string &sTable, std::string sDir) const
bool containsTables(const std::string &sExpression)
This member function detects, whether a table is used in the current expression.
std::vector< mu::value_type > sum(const std::string &sTable, std::string sDir) const
mu::value_type getCovariance(const std::string &sTable, size_t col1, const VectorIndex &_vIndex1, size_t col2, const VectorIndex &_vIndex2) const
std::vector< mu::value_type > std(const std::string &sTable, std::string sDir) const
std::vector< mu::value_type > getZScore(const std::string &sTable, size_t col, const VectorIndex &_vIndex) const
std::vector< mu::value_type > or_func(const std::string &sTable, std::string sDir) const
ValueVector getCategoryList(const VectorIndex &_vCol, const std::string &_sTable) const
bool updateDimensionVariables(StringView sTableName)
This member function updates the dimension variables for the selected table to be used in expressions...
Memory * getTable(const std::string &sTable)
This member function returns a pointer to an existing Memory instance representing the selected table...
AnovaResult getOneWayAnova(const std::string &sTable, size_t colCategories, size_t colValues, const VectorIndex &_vIndex, double significance) const
bool containsTablesOrClusters(const std::string &sCmdLine)
This member function evaluates, whether the passed command line contains tables or clusters.
std::vector< mu::value_type > getIndex(const std::string &sTable, size_t nCol, const std::vector< mu::value_type > &vValues, const std::vector< std::string > &vStringValues) const
std::vector< mu::value_type > minpos(const std::string &sTable, std::string sDir) const
std::vector< mu::value_type > maxpos(const std::string &sTable, std::string sDir) const
std::vector< mu::value_type > size(const std::string &sTable, std::string sDir) const
int getCols(StringView sTable, bool _bFull=false) const
int getColElements(const VectorIndex &cols, const std::string &_sTable) const
Returns the maximal number of elements in the selected column range.
std::vector< mu::value_type > prd(const std::string &sTable, std::string sDir) const
This class represents a whole cluster. The single items are stored as pointers to the abstract cluste...
Definition: cluster.hpp:325
size_t size() const
This member function returns the size of the internal memory buffer as items.
Definition: cluster.cpp:356
std::string getParserString(size_t i) const
This member function returns the data of the i-th cluster item in memory as a parser string.
Definition: cluster.cpp:781
void push_back(ClusterItem *item)
This member function appends an arbitrary cluster item at the back of the internal cluster array buff...
Definition: cluster.cpp:274
mu::value_type med(const VectorIndex &_vLine)
This member function calculates the median value of the data in memory. Cluster items,...
Definition: cluster.cpp:1784
mu::value_type min(const VectorIndex &_vLine)
This member function calculates the minimal value of the data in memory. Cluster items,...
Definition: cluster.cpp:1306
std::vector< std::string > getInternalStringArray() const
This member function returns the data of all cluster items memory as a value vector.
Definition: cluster.cpp:848
mu::value_type cnt(const VectorIndex &_vLine)
This member function counts the number of valid cluster items in memory. Cluster items of any type ar...
Definition: cluster.cpp:1612
mu::value_type and_func(const VectorIndex &_vLine)
This member function applies an "AND" to the data in memory. Cluster items, which do not have the typ...
Definition: cluster.cpp:1506
mu::value_type num(const VectorIndex &_vLine)
This member function counts the number of valid cluster items in memory. Cluster items of any type ar...
Definition: cluster.cpp:1475
mu::value_type xor_func(const VectorIndex &_vLine)
This member function applies an "exclusive OR" to the data in memory. Cluster items,...
Definition: cluster.cpp:1572
mu::value_type avg(const VectorIndex &_vLine)
This member function calculates the average of the data in memory. Cluster items, which do not have t...
Definition: cluster.cpp:1198
void insertDataInArray(std::vector< mu::value_type > *vTarget, const VectorIndex &_vLine)
This member function inserts the data of all cluster items memory into the pointer passed to the func...
Definition: cluster.cpp:612
mu::value_type max(const VectorIndex &_vLine)
This member function calculates the maximal value of the data in memory. Cluster items,...
Definition: cluster.cpp:1234
mu::value_type getDouble(size_t i) const
This member function returns the data of the i-th cluster item in memory as a value.
Definition: cluster.cpp:541
mu::value_type std(const VectorIndex &_vLine)
This member function calculates the standard deviation of the data in memory. Cluster items,...
Definition: cluster.cpp:1160
mu::value_type pct(const VectorIndex &_vLine, mu::value_type dPct)
This member function calculates the p-th percentile of the data in memory. Cluster items,...
Definition: cluster.cpp:1851
mu::value_type or_func(const VectorIndex &_vLine)
This member function applies an "OR" to the data in memory. Cluster items, which do not have the type...
Definition: cluster.cpp:1542
mu::value_type norm(const VectorIndex &_vLine)
This member function calculates the euclidic vector norm of the data in memory. Cluster items,...
Definition: cluster.cpp:1639
mu::value_type cmp(const VectorIndex &_vLine, mu::value_type dRef, int _nType)
This member function compares the values in memory with the referenced value and returns indices or v...
Definition: cluster.cpp:1675
mu::value_type sum(const VectorIndex &_vLine)
This member function calculates the sum of the data in memory. Cluster items, which do not have the t...
Definition: cluster.cpp:1411
mu::value_type prd(const VectorIndex &_vLine)
This member function calculates the product of the data in memory. Cluster items, which do not have t...
Definition: cluster.cpp:1378
bool isDouble() const
This member function returns, whether the data in the cluster have only double as type.
Definition: cluster.cpp:451
unsigned short getType(size_t i) const
This member function returns the type of the i-th cluster item in the internal memory buffer.
Definition: cluster.cpp:524
bool containsClusters(const std::string &sCmdLine) const
This member function detects, whether any cluster is used in the current expression.
Definition: cluster.cpp:1989
Cluster & getCluster(StringView sCluster)
This member function returns a reference to the cluster indicated by the passed cluster identifier.
Definition: cluster.cpp:2077
Cluster & newCluster(const std::string &sCluster)
This member function creates a new cluster from the passed cluster identifier and returns a reference...
Definition: cluster.cpp:2139
bool isCluster(StringView sCluster) const
This member function returns true, if the passed cluster identifier can be found in the internal map.
Definition: cluster.cpp:2041
const std::map< std::string, Cluster > & getClusterMap() const
Definition: cluster.hpp:475
std::string getDataFileName(const std::string &sTable) const
This member function will return the file name of the selected table. Will default to the table name.
This class is the central string expression parser. It is designed as being a singleton with a persis...
virtual bool isStringExpression(const std::string &sExpression) override
Returns true, if the passed expression is an expression containing strings, string variables or strin...
StringParserRetVal evalAndFormat(std::string &sLine, std::string &sCache, bool bSilent=false, bool bCheckAssertions=false)
This public member function evaluates the passed string expression and formats the results for the co...
std::string createTempStringVectorVar(const std::vector< std::string > &vStringVector)
This member function is used to create a temporary string vector variable.
This class provides the interface to the core of NumeRe. It provides all functionalities,...
Definition: kernel.hpp:97
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
Definition: kernel.hpp:221
NumeRe::StringParser & getStringParser()
Definition: kernel.hpp:286
mu::Parser & getParser()
Definition: kernel.hpp:281
MemoryManager & getMemoryManager()
Definition: kernel.hpp:263
NumeRe::Cluster & getAns()
Definition: kernel.hpp:268
Settings & getSettings()
Definition: kernel.hpp:296
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663
std::string to_string() const
This member function returns a copy of the viewed section of the string (via std::string::substr)....
size_t find(const std::string &findstr, size_t pos=0) const
Wrapper member function for std::string::find()
size_t length() const
This member function simply returns the length of the viewed section.
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
StringView subview(size_t pos=0, size_t len=std::string::npos) const
This member function creates a new StringView class instance using the selected position and length a...
Common exception class for all exceptions thrown in NumeRe.
Definition: error.hpp:32
@ TABLE_DOESNT_EXIST
INSERT HERE.
Definition: error.hpp:211
@ UNMATCHED_PARENTHESIS
Definition: error.hpp:224
@ TOO_FEW_COLS
Definition: error.hpp:213
@ INVALID_INDEX
Definition: error.hpp:129
static size_t invalid_position
Definition: error.hpp:235
This class abstracts all the index logics, i.e. the logical differences between single indices and in...
Definition: structures.hpp:42
VectorIndex subidx(size_t pos, size_t nLen=std::string::npos) const
This member function returns a subset of the internal stored index just like the std::string::substr(...
Definition: structures.hpp:238
int last() const
This member function returns the last index value, which can be reached by the values stored internal...
Definition: structures.hpp:693
size_t size() const
This member function returns the size of the indices stored in this class.
Definition: structures.hpp:314
bool isOpenEnd() const
This member function determines, whether the internal index set has an open end.
Definition: structures.hpp:614
void setRange(int nMin, int nMax)
This member function can be used to force the indices stored internally to be in a defined interval....
Definition: structures.hpp:712
std::string to_string() const
This member function converts the vector indexes contents into a human-readable string representation...
Definition: structures.hpp:770
bool isString() const
This member function determines, whether the internal index set referres to the table headlines.
Definition: structures.hpp:627
int & front()
This member function returns a reference to the first index value stored internally.
Definition: structures.hpp:640
size_t numberOfNodes() const
This member function returns the number of nodes describing the index set, which is stored internally...
Definition: structures.hpp:340
void CacheCurrentAccess(const CachedDataAccess &_access)
Store the passed data access for this position internally.
void SetExpr(StringView a_sExpr)
Set the expression. Triggers first time calculation thus the creation of the bytecode and scanning of...
value_type Eval()
Single-value wrapper around the vectorized overload of this member function.
const CachedDataAccess & GetCachedAccess(size_t nthAccess)
Returns the cached data access for the passed position.
const std::string & GetCachedEquation() const
Returns the stored equation for this position.
const std::string & GetCachedTarget() const
Returns the stored target equation for this position.
std::vector< mu::value_type > * GetVectorVar(const std::string &sVarName)
This member function returns a pointer to the vector stored internally.
bool IsCompiling()
Returns true, if the parser is currently in compiling step.
string_type CreateTempVectorVar(const std::vector< mu::value_type > &vVar)
This member function copies the passed vector into the internal storage referencing it with a auto-ge...
void UpdateVectorVar(const std::string &sVarName)
This member function updates the corresponding variable of a vector with the previously newly assigne...
size_t HasCachedAccess()
Evaluate, whether there are any cached data accesses for this position.
void DisableAccessCaching()
Disable the data access caching for this position.
bool ContainsVectorVars(StringView sExpr, bool ignoreSingletons)
This member function checks, whether the passed expression contains a vector.
void SetVectorVar(const std::string &sVarName, const std::vector< mu::value_type > &vVar, bool bAddVectorType=false)
This member function copies the passed vector into the internal storage referencing it with the passe...
Mathematical expressions parser.
Definition: muParser.h:51
mu::value_type getDataFromObject(const std::string &sObject, long long int i, long long int j, bool isCluster)
This function returns the data from the selected object and switches automatically between tables and...
static std::map< std::string, TableMethod > getInplaceTableMethods()
Returns the declared list of table methods.
static std::string tableMethod_index(const std::string &sTableName, std::string sMethodArguments)
Realizes the "index()" table method.
static const string handleCachedDataAccess(string &sLine, Parser &_parser, MemoryManager &_data, const Settings &_option)
This function handles cached data access strings, which may be available in the parser.
Definition: dataaccess.cpp:652
static std::string tableMethod_pcorr(const std::string &sTableName, std::string sMethodArguments)
Realizes the "pcorr()" table method.
DataAccessParser getAccessParserForPlotAndFit(StringView sExpression)
This function will return the access parser instance for the current expression validate,...
static std::string tableMethod_categories(const std::string &sTableName, std::string sMethodArguments)
Realizes the "categories()" table method.
static std::string tableMethod_scorr(const std::string &sTableName, std::string sMethodArguments)
Realizes the "scorr()" table method.
static std::string tableMethod_convert(const std::string &sTableName, std::string sMethodArguments)
Realizes the "convert()" table method.
static std::string tableMethod_typeof(const std::string &sTableName, std::string sMethodArguments)
Realizes the "typeof()" table method.
static std::string tableMethod_anova(const std::string &sTableName, std::string sMethodArguments)
Realizes the "anova()" table method.
string getDataElements(string &sLine, Parser &_parser, MemoryManager &_data, const Settings &_option, int options)
Searches the passed string for calls to any table or cluster and replaces them with internal vectors ...
Definition: dataaccess.cpp:276
static void replaceEntityStringOccurence(string &sLine, const string &sEntityOccurence, const string &sEntityStringReplacement)
This function simply replaces every occurences of the entity with its replacement.
Definition: dataaccess.cpp:738
static string createMafVectorName(string sAccessString)
This function simply returns the vector name obtained from the MAF method string.
size_t findAssignmentOperator(StringView sCmd)
Definition: dataaccess.cpp:242
static string getMafAccessString(const string &sLine, const string &sEntity)
This function returns the first MAF access in the passed sLine string.
Indices getIndicesForPlotAndFit(const string &sExpression, string &sDataTable, int &nColumns, bool &openEnd, bool &isCluster)
This function will calculate the indices from the passed data expression and return them optimized fo...
static string createEveryDefinition(const string &sLine, Parser &_parser)
This function creates an every definition from the methods, which the Datafile class is able to parse...
static void handleMafDataAccess(string &sLine, const string &sMafAccess, Parser &_parser, MemoryManager &_data)
This function handles the MAF data access using methods.
Definition: dataaccess.cpp:953
static void resolveTablesAndClusters(string &sLine, Parser &_parser, MemoryManager &_data, const Settings &_option, int options)
Resolves every call to a cluster or a table.
Definition: dataaccess.cpp:394
static void replaceEntityOccurence(string &sLine, const string &sEntityOccurence, const string &sEntityName, const string &sEntityReplacement, const Indices &_idx, MemoryManager &_data, Parser &_parser, const Settings &_option, bool isCluster)
This function replaces every occurence of the entity with either the vector name for the parser or wi...
Definition: dataaccess.cpp:765
bool isNotEmptyExpression(const string &sExpr)
This function checks, whether the passed expression is non-empty (i.e. it contains more than white sp...
static std::string tableMethod_aliasof(const std::string &sTableName, std::string sMethodArguments)
Realizes the "aliasof()" table method.
std::string(* TableMethod)(const std::string &, std::string)
Typedef for a table method.
static std::string tableMethod_categorize(const std::string &sTableName, std::string sMethodArguments)
Realizes the "categorize()" table method.
static string getLastToken(const string &sLine)
This function returns the last token of the current string, e.g. a function name, etc.
Memory * extractRange(const std::string &sCmd, DataAccessParser &_accessParser, int nDesiredCols, bool bSort)
This function extracts a portion of a table and returns it to the calling function....
static std::string tableMethod_findCols(const std::string &sTableName, std::string sMethodArguments)
Realizes the "fndcols()" table method.
bool isClusterCandidate(string &sLine, string &sCluster, bool doCut)
This function checks, whether the passed command line contains the syntax for a cluster candidate,...
static std::string tableMethod_annotate(const std::string &sTableName, std::string sMethodArguments)
Realizes the "describe()" method.
static vector< mu::value_type > MafDataAccess(MemoryManager &_data, const string &sMafname, const string &sCache, const string &sMafAccess)
This function simply performs the MAF access and returns the vector of the results.
void replaceDataEntities(string &sLine, const string &sEntity, MemoryManager &_data, Parser &_parser, const Settings &_option, int options)
This function replaces all calls to a single data entity with an internal vector or its value,...
Definition: dataaccess.cpp:436
static std::string tableMethod_counteq(const std::string &sTableName, std::string sMethodArguments)
Realizes the "countif()" table method.
static string createMafDataAccessString(const string &sAccessString, Parser &_parser)
This function returns the modifier list obtained from the method string.
static std::string tableMethod_zscore(const std::string &sTableName, std::string sMethodArguments)
Realizes the "zscore()" table method.
static std::string tableMethod_rank(const std::string &sTableName, std::string sMethodArguments)
Realizes the "rankof()" table method.
static string getMafFromAccessString(const string &sAccessString)
This function returns the name of the MAF.
static std::string tableMethod_cov(const std::string &sTableName, std::string sMethodArguments)
Realizes the "cov()" table method.
std::vector< size_t > getDataGridDimensions(const Indices &_idx, const std::string &sTableName)
Returns the accessed data grid dimensions.
static std::string tableMethod_binsof(const std::string &sTableName, std::string sMethodArguments)
Realizes the "binsof()" table method.
bool parser_CheckMultArgFunc(const string &sLeft, const string &sRight)
This function checks, whether the argument located between sLeft and sRight is part of a multi-argume...
Indices getIndices(StringView sCmd, mu::Parser &_parser, MemoryManager &_data, const Settings &_option)
Wrapper for the new getIndices function interface.
Definition: indices.cpp:49
@ INSERT_STRINGS
Definition: dataaccess.hpp:61
bool isValidIndexSet(const Indices &_idx)
Definition: dataaccess.hpp:81
std::vector< std::string > ValueVector
This type defines a generic value vector.
Definition: memory.hpp:58
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
Definition: tools.cpp:414
Namespace for mathematical applications.
Definition: muParser.cpp:53
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
std::string toCmdString(double dNumber)
Converts a numerical value into a "full" precision string.
std::string getNextArgument(std::string &sArgList, bool bCut)
Definition: tools.cpp:2294
Contains the relevant results of the ANOVA F test.
Definition: memory.hpp:40
mu::value_type m_FRatio
Definition: memory.hpp:41
mu::value_type m_significance
Definition: memory.hpp:43
mu::value_type m_significanceVal
Definition: memory.hpp:42
bool m_isSignificant
Definition: memory.hpp:44
size_t m_numCategories
Definition: memory.hpp:45
This structure is central for managing the indices of a table or cluster read or write data access....
VectorIndex col
VectorIndex row
std::string sCompiledAccessEquation
static std::string typeToString(ColumnType type)
Converts the passed ColumnType value to a string representation.
Describes an already evaluated data access, which can be reconstructed from the current parser state.
std::string sAccessEquation
long long int intCast(const std::complex< double > &)
Casts the real part of the complex number to an integer and avoids rounding errors.
Definition: tools.cpp:1824
std::string toString(int)
Converts an integer to a string without the Settings bloat.
string replaceToVectorname(const string &sExpression)
This function replaces a data access expression (i.e. the contents of the object argument parentheses...
Definition: tools.cpp:3108
bool isInQuotes(StringView sExpr, unsigned int nPos, bool bIgnoreVarParser)
Checks, whether the position in the passed expression is part of a string literal.
Definition: tools.cpp:1672
bool validateParenthesisNumber(const string &sCmd)
This function is used to validate the number of parentheses, i.e. whether there's a closing parenthes...
Definition: tools.cpp:3512
EndlessVector< StringView > getAllArguments(StringView sArgList)
Splits up the complete argument list and returns them as an EndlessVector.
Definition: tools.cpp:2346
bool isDelimiter(char c)
This function determines, if the passed character is a delimiter character.
Definition: tools.cpp:1852