Set functions.
Constantes
Set SetSpanishMonthSet SetSpanishWeekdaySet SetEnglishMonthSet SetEnglishWeekdaySet SetPortugueseMonthSet SetFrenchMonthFunciones
Text Set2TxtFormat(Anything val)Text Set2Txt(Set valSet, Text iniTxt, Text endTxt, Text sepTxt, Text sepLst, Text txtDet, Text datFmt, Text dteDet, Text dteFmt)Text Set2TxtKeyword(Set valSet, Real minChr, Real a2zOrd)Text Set2TxtCommaAmp(Set valSet)Set SetFirstN(Set set, Real num)Set SetFirstNByFun(Set set, Real num, Code funSor)Serie Set2Ser(Set dteVal, TimeSet serTms)Text Set2TxtTol(Set valSet, Text datFmt)Text Set2TxtSql(Set valSet, Text datFmt)Set SetInclude(Set filSet)Set SetTxtBeginWith(Set set, Text txt, Real cas)Set SetTxtCount(Set set, Real noNull)Real SetTxtFindFirst(Set set, Text txt, Real cas)Text SetReplaceTable(Text txt, Set set, Real pos)//////////////////////////////////////////////////////////////////////////////
Set SetSpanishMonth =
[[ "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio",
"Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of spanish months names.", SetSpanishMonth);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetSpanishWeekday =
[[ "Lunes", "Martes", "Miercoles", "Jueves",
"Viernes", "Sabado", "Domingo" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of spanish weekdays names.", SetSpanishWeekday);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetEnglishMonth =
[[ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of english months names.", SetEnglishMonth);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetEnglishWeekday =
[[ "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of english weekdays names.", SetEnglishWeekday);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetPortugueseMonth =
[[ "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho",
"Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of portuguese months names.", SetPortugueseMonth);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetFrenchMonth =
[[ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin",
"Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of french months names.", SetFrenchMonth);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Set2TxtFormat(Anything val)
//////////////////////////////////////////////////////////////////////////////
{
Text gra = Grammar(val);
If(gra=="Text", txtDet+val+txtDet,
If(gra=="Real", If(datFmt=="", FormatReal(val),
FormatReal(val,datFmt)),
If(gra=="Date", dteDet+If(dteFmt=="", FormatDate(val),
FormatDate(val,dteFmt))+dteDet,
If(gra=="Set", Set2Txt(val, iniTxt, endTxt,
sepTxt, sepLst,
txtDet, datFmt, dteDet, dteFmt),
"Not valid grammar"))))
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Internal function, do not call it.
Only for the use of Set2Txt() function.",
Set2TxtFormat);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Set2Txt(Set valSet, // Set of elements
Text iniTxt, // Initial text for list
Text endTxt, // End text for list
Text sepTxt, // Element separators
Text sepLst, // 2 last elements separator
Text txtDet, // Delimiter for texts
Text datFmt, // Format for real numbers
Text dteDet, // Delimiter for dates
Text dteFmt) // Format for dates
//////////////////////////////////////////////////////////////////////////////
{
Real card = Card(valSet);
Text body =
If(EQ(card,0), "",
If(EQ(card,1), Set2TxtFormat(valSet[1]),
If(EQ(card,2), Set2TxtFormat(valSet[1])+sepLst+Set2TxtFormat(valSet[2]),
{
Set txtVal = For(2,card,Text(Real p)
{
If(EQ(p,card),sepLst,sepTxt) + Set2TxtFormat(valSet[p])
});
Set2TxtFormat(valSet[1]) + BinGroup("+",txtVal)
})));
iniTxt+body+endTxt
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a text like a list with all the elements of valSet converted in a
text format (elements types: Text, Real or Date).
Arguments:
- iniTxt initial text, for example: '(', '[[', '', etc.
- endTxt end text, for example ')', ']]', '', etc.
- sepTxt elements separator, for example '; ', ',', '', etc.
- sepLst two last elements separator, for example, ' & ', ' and ', etc.,
you can specify the same as sepTxt
- txtDet text delimiters, for exmple, quotes for TOL, single quote for
SQL, nothing, etc.
- datFmt real numbers format, for explame, '%.0lf' for integers, if none
then uses the default TOL real number format.
- dteDet date delimiters, for example, simgle quote for SQL.
- dteFmt date format, for example, '%c%Y%m%d', if none
then uses the default TOL dates format.
Only works with TOL types Text, Real or Date, when find a Set type then
works in a recursive way with the same arguments.",
Set2Txt);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Set2TxtKeyword(Set valSet, // Set of elements
Real minChr, // Minimum number of chars
Real a2zOrd) // If true ordered
//////////////////////////////////////////////////////////////////////////////
{
// Convert all to text
Text lstTxt = ToLower(Set2Txt(valSet,"", "", " ", " ", "", "", "", ""));
Text lstCls = Compact(ReplaceTable(TxtOutHtmScr(lstTxt),
[[ [[Char(34), " "]],
[["'", " "]],
[[". ", " "]],
[[":", " "]],
[[";", " "]],
[[",", " "]],
[["[", " "]],
[["]", " "]],
[["(", " "]],
[[")", " "]],
[["/", " "]],
[["¡", " "]],
[["!", " "]],
[["¿", " "]],
[["?", " "]],
[["&", " "]],
[[" none ", " "]],
[[" the ", " "]],
[[" and ", " "]],
[[" or ", " "]],
[[" & ", " "]],
[[" y ", " "]],
[[" o ", " "]]
]]));
Set setTxt = Tokenizer(lstCls, " "); // Obtain a new set
Set setUni = Unique(setTxt); // Without repetitions
Set setSel = Select(setUni, Real(Text a) { GT(TextLength(a), minChr) });
Set setSor = If(! a2zOrd, setSel,
Sort(setSel, Real(Text a, Text b)
{ Compare(ToLower(a),ToLower(b)) })); // Order
Set2Txt(setSor, "", "", ", ", ", ", "", "", "", "")
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a text list with all the elements of valSet converted in a
text format with commas like a keywords list, ordered and without repetitions.
Remove all word with LE(TextLength(), minChr).
For example Set2TxtKeyword([['cc, bb & dd',1,'dd ee',2,'ff',1,'aa']]) returns:
1.0, 2.0, aa, bb, cc, dd, ee, ff.",
Set2TxtKeyword);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Set2TxtCommaAmp(Set valSet) // Set of elements
//////////////////////////////////////////////////////////////////////////////
{ Set2Txt(valSet, "", "", ", ", " & ", "", "", "", "") };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Return a text list with all the elements of valSet converted in a
text format with commas and & in Html style.
For example Set2TxtCommaAmp([['a','b','c','d']]) returns:
a, b, c & d -> in html -> a, b, c & d.",
Set2TxtCommaAmp);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetFirstN(Set set, Real num)
//////////////////////////////////////////////////////////////////////////////
{ For(1, Min(Card(set), num), Anything(Real pos) { set[pos] }) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a subset with the first num elements.
If the set does not have num elements returns the set.",
SetFirstN);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetFirstNByFun(Set set, Real num, Code funSor)
//////////////////////////////////////////////////////////////////////////////
{ SetFirstN(Sort(set, funSor), num) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a subset with the first num elements of a set ordered by funSor.
If the set does not have num elements returns the set ordered by funSor.",
SetFirstNByFun);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Serie Set2Ser(Set dteVal, // Set table with dates and values
TimeSet serTms) // Time set
//////////////////////////////////////////////////////////////////////////////
{
If(EQ(Card(dteVal),0), CalInd(W,serTms), // Constant zero
{
// Order by date
Set tabSor = Sort(dteVal, Real(Set a, Set b) { Compare(a[1],b[1]) });
Date fstDte = tabSor[ 1][1];
Date lstDte = tabSor[Card(tabSor)][1];
Set pulSet = EvalSet(tabSor, Serie(Set row) // For all rows in dteVal
{
// Date dte = row[1]; // Date
// Real val = row[2]; // Value
Pulse(row[1],C)*row[2]
});
DatCh(SubSer(SetSum(pulSet), fstDte, lstDte),serTms,SumS)
})
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a serie in serTms time set using the dates and values of dteVal.
The First() and the Last() date of the serie are the minimun and the maximum
dates of the table dteVal.
The date in dteVal cauld be orderder or disordered.
If the table is Empty then return the a zero constant serie.
For the dates without value the value zero is assumed.
For the dates with several values all values are added.
The dates in dteVal table belong to C timeSet.
For example:
Serie ser008 = Set2Ser([[ [[y2004m01d03, 3]], // Only odd days
[[y2004m01d07, 3]],
[[y2004m01d07, 4]],
[[y2004m01d01, 1]],
[[y2004m01d05, 5]] ]], C);
returns the serie:
C; ser008;
2004/01/01; 1.000000;
2004/01/02; 0.000000;
2004/01/03; 3.000000;
2004/01/04; 0.000000;
2004/01/05; 5.000000;
2004/01/06; 0.000000;
2004/01/07; 7.000000;",
Set2Ser);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Set2TxtTol(Set valSet, // Set of elements
Text datFmt) // Format for real numbers
//////////////////////////////////////////////////////////////////////////////
{
Text iniBra = "[[ ";
Text endBra = " ]]";
Text tolLst = Set2Txt(valSet, iniBra, endBra, ", ", ", ",
Char(34), datFmt, "", "%cy%Ym%md%d");
Replace(tolLst, iniBra+endBra, "Empty")
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Return a text like a TOL list with all the elements of valSet converted in a
text format.
For example Set2TxtTol([['text',1.0,y2003m12d31]], '%.0lf') returns:
[[ 'text', 1, y2003m12d31 ]].",
Set2TxtTol);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Set2TxtSql(Set valSet, // Set of elements
Text datFmt) // Format for real numbers
//////////////////////////////////////////////////////////////////////////////
{
Set2Txt(valSet,
"(", ")", ", ", ", ", "'", datFmt, "'", "%c%Y/%m/%d")
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Return a text like a SQL list with all the elements of valSet converted in a
text format.
For example Set2TxtSql([['text',1.0,y2003m12d31]], '%.0lf') returns:
(´text´, 1, ´2003/12/31´).",
Set2TxtSql);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetInclude(Set filSet) // Set of TOL files paths
//////////////////////////////////////////////////////////////////////////////
{
// Select existing files
Set filSel = Select(filSet, Real(Text filPth) { FileExist(filPth) });
If(EQ(Card(filSel),0), Empty, // None
If(EQ(Card(filSel),1), Include(filSel[1]), // Only one file
{ // Include existing files
Set setInc = EvalSet(filSel, Set(Text filPth) { Include(filPth) });
BinGroup("<<", setInc) // Group to one level all definitions
}))
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a one level set with the result of the inclusion of a set of TOL
files.
The returning set looks like all the definitions will be declared in the same
(virtually single) TOL file.",
SetInclude);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetTxtBeginWith(Set set, // Set of texts
Text txt, // Text to find
Real cas) // If TRUE then case sensitive
//////////////////////////////////////////////////////////////////////////////
{
Text low = If(cas, txt, ToLower(txt));
Real car = Card(set);
Set cic = For(1, car, Real(Real pos)
{
Text beg = If(cas, set[pos], ToLower(set[pos]));
If(TextBeginWith(beg, low), pos, 0)
});
Select(cic, Real(Real pos) { GT(pos,0) })
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a set of set positions where the texts of the set begin with the
argument txt.
If none match then returns the empty set.
If the argument cas is true then work in a case sensitive way.",
SetTxtBeginWith);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetTxtCount(Set set, // Set of texts
Real noNull) // If true the empty texts are not counted
//////////////////////////////////////////////////////////////////////////////
{
// Selects text different than empty text
Set sel = If(noNull, Select(set, Real(Text txt) { txt!="" }), set);
Real emp = EQ(Card(sel),0); // True if there aren't texts
If(emp, Empty,
{
// Classify by text
Set cla = Classify(sel, Real(Text a, Text b) { Compare(a,b) });
EvalSet(cla, Set(Set ele)
{
Text ide = ele[1]; // The first ocurrence
Real num = Card(ele); // Number of ocurrences
[[ide, num]]
})
})
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a table with the differents texts insider a set a count of theirs
ocurrences.
If noNull is true the empty texts are not counted.
For example SetTxtCount([['aa','bb','aa','cc','','dd','bb']], TRUE) returns:
'aa', 2
'bb', 2
'cc', 1
'dd', 1
If there are not texts different than empty text retunrs Empty",
SetTxtCount);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Real SetTxtFindFirst(Set set, // Set of texts
Text txt, // Text to find
Real cas) // If TRUE then case sensitive
//////////////////////////////////////////////////////////////////////////////
{
Text low = If(cas, txt, ToLower(txt));
Real car = Card(set);
Set cic = For(1, car, Real(Real pos)
{
Text beg = If(cas, set[pos], ToLower(set[pos]));
If(beg==low, pos, 0)
});
Set sel = Select(cic, Real(Real pos) { GT(pos,0) });
If(EQ(Card(sel),0), 0, sel[1])
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns the position of the first text element of set equal to txt.
If none match then returns 0.
If the argument cas is true then work in a case sensitive way.",
SetTxtFindFirst);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text SetReplaceTable(Text txt,
Set set,
Real pos) // From set[pos] toset[Card(set)]
//////////////////////////////////////////////////////////////////////////////
{
If(GT(pos, Card(set)), txt, // end recursion
SetReplaceTable(Replace(txt, set[pos][1], set[pos][2]), set, pos+1))
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"As ReplaceTable() but with only one loop and in strict order.",
SetReplaceTable);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// FILE : set.tol
// AUTHOR : http://www.asolver.com
// PURPOSE : Set functions.
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// CONSTANTS
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetSpanishMonth =
[[ "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio",
"Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of spanish months names.", SetSpanishMonth);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetSpanishWeekday =
[[ "Lunes", "Martes", "Miercoles", "Jueves",
"Viernes", "Sabado", "Domingo" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of spanish weekdays names.", SetSpanishWeekday);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetEnglishMonth =
[[ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of english months names.", SetEnglishMonth);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetEnglishWeekday =
[[ "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of english weekdays names.", SetEnglishWeekday);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetPortugueseMonth =
[[ "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho",
"Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of portuguese months names.", SetPortugueseMonth);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetFrenchMonth =
[[ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin",
"Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of french months names.", SetFrenchMonth);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Set2TxtFormat(Anything val)
//////////////////////////////////////////////////////////////////////////////
{
Text gra = Grammar(val);
If(gra=="Text", txtDet+val+txtDet,
If(gra=="Real", If(datFmt=="", FormatReal(val),
FormatReal(val,datFmt)),
If(gra=="Date", dteDet+If(dteFmt=="", FormatDate(val),
FormatDate(val,dteFmt))+dteDet,
If(gra=="Set", Set2Txt(val, iniTxt, endTxt,
sepTxt, sepLst,
txtDet, datFmt, dteDet, dteFmt),
"Not valid grammar"))))
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Internal function, do not call it.
Only for the use of Set2Txt() function.",
Set2TxtFormat);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Set2Txt(Set valSet, // Set of elements
Text iniTxt, // Initial text for list
Text endTxt, // End text for list
Text sepTxt, // Element separators
Text sepLst, // 2 last elements separator
Text txtDet, // Delimiter for texts
Text datFmt, // Format for real numbers
Text dteDet, // Delimiter for dates
Text dteFmt) // Format for dates
//////////////////////////////////////////////////////////////////////////////
{
Real card = Card(valSet);
Text body =
If(EQ(card,0), "",
If(EQ(card,1), Set2TxtFormat(valSet[1]),
If(EQ(card,2), Set2TxtFormat(valSet[1])+sepLst+Set2TxtFormat(valSet[2]),
{
Set txtVal = For(2,card,Text(Real p)
{
If(EQ(p,card),sepLst,sepTxt) + Set2TxtFormat(valSet[p])
});
Set2TxtFormat(valSet[1]) + BinGroup("+",txtVal)
})));
iniTxt+body+endTxt
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a text like a list with all the elements of valSet converted in a
text format (elements types: Text, Real or Date).
Arguments:
- iniTxt initial text, for example: '(', '[[', '', etc.
- endTxt end text, for example ')', ']]', '', etc.
- sepTxt elements separator, for example '; ', ',', '', etc.
- sepLst two last elements separator, for example, ' & ', ' and ', etc.,
you can specify the same as sepTxt
- txtDet text delimiters, for exmple, quotes for TOL, single quote for
SQL, nothing, etc.
- datFmt real numbers format, for explame, '%.0lf' for integers, if none
then uses the default TOL real number format.
- dteDet date delimiters, for example, simgle quote for SQL.
- dteFmt date format, for example, '%c%Y%m%d', if none
then uses the default TOL dates format.
Only works with TOL types Text, Real or Date, when find a Set type then
works in a recursive way with the same arguments.",
Set2Txt);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Set2TxtKeyword(Set valSet, // Set of elements
Real minChr, // Minimum number of chars
Real a2zOrd) // If true ordered
//////////////////////////////////////////////////////////////////////////////
{
// Convert all to text
Text lstTxt = ToLower(Set2Txt(valSet,"", "", " ", " ", "", "", "", ""));
Text lstCls = Compact(ReplaceTable(TxtOutHtmScr(lstTxt),
[[ [[Char(34), " "]],
[["'", " "]],
[[". ", " "]],
[[":", " "]],
[[";", " "]],
[[",", " "]],
[["[", " "]],
[["]", " "]],
[["(", " "]],
[[")", " "]],
[["/", " "]],
[["¡", " "]],
[["!", " "]],
[["¿", " "]],
[["?", " "]],
[["&", " "]],
[[" none ", " "]],
[[" the ", " "]],
[[" and ", " "]],
[[" or ", " "]],
[[" & ", " "]],
[[" y ", " "]],
[[" o ", " "]]
]]));
Set setTxt = Tokenizer(lstCls, " "); // Obtain a new set
Set setUni = Unique(setTxt); // Without repetitions
Set setSel = Select(setUni, Real(Text a) { GT(TextLength(a), minChr) });
Set setSor = If(! a2zOrd, setSel,
Sort(setSel, Real(Text a, Text b)
{ Compare(ToLower(a),ToLower(b)) })); // Order
Set2Txt(setSor, "", "", ", ", ", ", "", "", "", "")
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a text list with all the elements of valSet converted in a
text format with commas like a keywords list, ordered and without repetitions.
Remove all word with LE(TextLength(), minChr).
For example Set2TxtKeyword([['cc, bb & dd',1,'dd ee',2,'ff',1,'aa']]) returns:
1.0, 2.0, aa, bb, cc, dd, ee, ff.",
Set2TxtKeyword);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Set2TxtCommaAmp(Set valSet) // Set of elements
//////////////////////////////////////////////////////////////////////////////
{ Set2Txt(valSet, "", "", ", ", " & ", "", "", "", "") };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Return a text list with all the elements of valSet converted in a
text format with commas and & in Html style.
For example Set2TxtCommaAmp([['a','b','c','d']]) returns:
a, b, c & d -> in html -> a, b, c & d.",
Set2TxtCommaAmp);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetFirstN(Set set, Real num)
//////////////////////////////////////////////////////////////////////////////
{ For(1, Min(Card(set), num), Anything(Real pos) { set[pos] }) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a subset with the first num elements.
If the set does not have num elements returns the set.",
SetFirstN);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetFirstNByFun(Set set, Real num, Code funSor)
//////////////////////////////////////////////////////////////////////////////
{ SetFirstN(Sort(set, funSor), num) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a subset with the first num elements of a set ordered by funSor.
If the set does not have num elements returns the set ordered by funSor.",
SetFirstNByFun);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Serie Set2Ser(Set dteVal, // Set table with dates and values
TimeSet serTms) // Time set
//////////////////////////////////////////////////////////////////////////////
{
If(EQ(Card(dteVal),0), CalInd(W,serTms), // Constant zero
{
// Order by date
Set tabSor = Sort(dteVal, Real(Set a, Set b) { Compare(a[1],b[1]) });
Date fstDte = tabSor[ 1][1];
Date lstDte = tabSor[Card(tabSor)][1];
Set pulSet = EvalSet(tabSor, Serie(Set row) // For all rows in dteVal
{
// Date dte = row[1]; // Date
// Real val = row[2]; // Value
Pulse(row[1],C)*row[2]
});
DatCh(SubSer(SetSum(pulSet), fstDte, lstDte),serTms,SumS)
})
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a serie in serTms time set using the dates and values of dteVal.
The First() and the Last() date of the serie are the minimun and the maximum
dates of the table dteVal.
The date in dteVal cauld be orderder or disordered.
If the table is Empty then return the a zero constant serie.
For the dates without value the value zero is assumed.
For the dates with several values all values are added.
The dates in dteVal table belong to C timeSet.
For example:
Serie ser008 = Set2Ser([[ [[y2004m01d03, 3]], // Only odd days
[[y2004m01d07, 3]],
[[y2004m01d07, 4]],
[[y2004m01d01, 1]],
[[y2004m01d05, 5]] ]], C);
returns the serie:
C; ser008;
2004/01/01; 1.000000;
2004/01/02; 0.000000;
2004/01/03; 3.000000;
2004/01/04; 0.000000;
2004/01/05; 5.000000;
2004/01/06; 0.000000;
2004/01/07; 7.000000;",
Set2Ser);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Set2TxtTol(Set valSet, // Set of elements
Text datFmt) // Format for real numbers
//////////////////////////////////////////////////////////////////////////////
{
Text iniBra = "[[ ";
Text endBra = " ]]";
Text tolLst = Set2Txt(valSet, iniBra, endBra, ", ", ", ",
Char(34), datFmt, "", "%cy%Ym%md%d");
Replace(tolLst, iniBra+endBra, "Empty")
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Return a text like a TOL list with all the elements of valSet converted in a
text format.
For example Set2TxtTol([['text',1.0,y2003m12d31]], '%.0lf') returns:
[[ 'text', 1, y2003m12d31 ]].",
Set2TxtTol);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Set2TxtSql(Set valSet, // Set of elements
Text datFmt) // Format for real numbers
//////////////////////////////////////////////////////////////////////////////
{
Set2Txt(valSet,
"(", ")", ", ", ", ", "'", datFmt, "'", "%c%Y/%m/%d")
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Return a text like a SQL list with all the elements of valSet converted in a
text format.
For example Set2TxtSql([['text',1.0,y2003m12d31]], '%.0lf') returns:
(´text´, 1, ´2003/12/31´).",
Set2TxtSql);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetInclude(Set filSet) // Set of TOL files paths
//////////////////////////////////////////////////////////////////////////////
{
// Select existing files
Set filSel = Select(filSet, Real(Text filPth) { FileExist(filPth) });
If(EQ(Card(filSel),0), Empty, // None
If(EQ(Card(filSel),1), Include(filSel[1]), // Only one file
{ // Include existing files
Set setInc = EvalSet(filSel, Set(Text filPth) { Include(filPth) });
BinGroup("<<", setInc) // Group to one level all definitions
}))
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a one level set with the result of the inclusion of a set of TOL
files.
The returning set looks like all the definitions will be declared in the same
(virtually single) TOL file.",
SetInclude);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetTxtBeginWith(Set set, // Set of texts
Text txt, // Text to find
Real cas) // If TRUE then case sensitive
//////////////////////////////////////////////////////////////////////////////
{
Text low = If(cas, txt, ToLower(txt));
Real car = Card(set);
Set cic = For(1, car, Real(Real pos)
{
Text beg = If(cas, set[pos], ToLower(set[pos]));
If(TextBeginWith(beg, low), pos, 0)
});
Select(cic, Real(Real pos) { GT(pos,0) })
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a set of set positions where the texts of the set begin with the
argument txt.
If none match then returns the empty set.
If the argument cas is true then work in a case sensitive way.",
SetTxtBeginWith);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetTxtCount(Set set, // Set of texts
Real noNull) // If true the empty texts are not counted
//////////////////////////////////////////////////////////////////////////////
{
// Selects text different than empty text
Set sel = If(noNull, Select(set, Real(Text txt) { txt!="" }), set);
Real emp = EQ(Card(sel),0); // True if there aren't texts
If(emp, Empty,
{
// Classify by text
Set cla = Classify(sel, Real(Text a, Text b) { Compare(a,b) });
EvalSet(cla, Set(Set ele)
{
Text ide = ele[1]; // The first ocurrence
Real num = Card(ele); // Number of ocurrences
[[ide, num]]
})
})
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a table with the differents texts insider a set a count of theirs
ocurrences.
If noNull is true the empty texts are not counted.
For example SetTxtCount([['aa','bb','aa','cc','','dd','bb']], TRUE) returns:
'aa', 2
'bb', 2
'cc', 1
'dd', 1
If there are not texts different than empty text retunrs Empty",
SetTxtCount);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Real SetTxtFindFirst(Set set, // Set of texts
Text txt, // Text to find
Real cas) // If TRUE then case sensitive
//////////////////////////////////////////////////////////////////////////////
{
Text low = If(cas, txt, ToLower(txt));
Real car = Card(set);
Set cic = For(1, car, Real(Real pos)
{
Text beg = If(cas, set[pos], ToLower(set[pos]));
If(beg==low, pos, 0)
});
Set sel = Select(cic, Real(Real pos) { GT(pos,0) });
If(EQ(Card(sel),0), 0, sel[1])
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns the position of the first text element of set equal to txt.
If none match then returns 0.
If the argument cas is true then work in a case sensitive way.",
SetTxtFindFirst);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text SetReplaceTable(Text txt,
Set set,
Real pos) // From set[pos] toset[Card(set)]
//////////////////////////////////////////////////////////////////////////////
{
If(GT(pos, Card(set)), txt, // end recursion
SetReplaceTable(Replace(txt, set[pos][1], set[pos][2]), set, pos+1))
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"As ReplaceTable() but with only one loop and in strict order.",
SetReplaceTable);
//////////////////////////////////////////////////////////////////////////////
Ink.Watercolor construye las páginas del sitio web inkwatercolor.com
2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio