Secciones de la página

set. tol


Declaraciones


Constantes


Funciones


Time oriented language


Árbol de ficheros

Funciones

Text Set2TxtFormat()

Text Set2Txt()

Text Set2TxtKeyword()

Text Set2TxtCommaAmp()

Set SetFirstN()

Set SetFirstNByFun()

Serie Set2Ser()

Text Set2TxtTol()

Text Set2TxtSql()

Set SetInclude()

Set SetTxtBeginWith()

Set SetTxtCount()

Real SetTxtFindFirst()

Text SetReplaceTable()

Tol

Artículos del sitio

Presentación de Tol

Todos los programas

Simuladores visuales

Sitios que me gustan

Por categorías

Algoritmia

Búsqueda y ordenación

Computación fisiológica

Editorial y edición

Gráficos de datos

Herramientas y utilidades

Hipertexto

Informática forense

Lectura óptica de datos

Metaprogramación

No determinista

Ofimática

Recursión e iteración

Reglas y restricciones

Series y estadística









set.tol de Ink.Watercolor

Set functions.

Declaraciones

Constantes

Funciones

  • Text Set2TxtFormat(Anything val)
    Internal function, do not call it. Only for the use of Set2Txt() function.
  • Text Set2Txt(Set valSet, Text iniTxt, Text endTxt, Text sepTxt, Text sepLst, Text txtDet, Text datFmt, Text dteDet, Text dteFmt)
    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.
  • Text Set2TxtKeyword(Set valSet, Real minChr, Real a2zOrd)
    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.
  • Text Set2TxtCommaAmp(Set valSet)
    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.
  • Set SetFirstN(Set set, Real num)
    Returns a subset with the first num elements. If the set does not have num elements returns the set.
  • Set SetFirstNByFun(Set set, Real num, Code funSor)
    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.
  • Serie Set2Ser(Set dteVal, TimeSet serTms)
    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;
  • Text Set2TxtTol(Set valSet, Text datFmt)
    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 ]].
  • Text Set2TxtSql(Set valSet, Text datFmt)
    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´).
  • Set SetInclude(Set filSet)
    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.
  • Set SetTxtBeginWith(Set set, Text txt, Real cas)
    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.
  • Set SetTxtCount(Set set, Real noNull)
    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
  • Real SetTxtFindFirst(Set set, Text txt, Real cas)
    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.
  • Text SetReplaceTable(Text txt, Set set, Real pos)
    As ReplaceTable() but with only one loop and in strict order.

Constantes

Set SetSpanishMonth

//////////////////////////////////////////////////////////////////////////////
Set SetSpanishMonth = 
  [[ "Enero", "Febrero", "Marzo",      "Abril",   "Mayo",      "Junio",
     "Julio", "Agosto",  "Septiembre", "Octubre", "Noviembre", "Diciembre" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of spanish months names.", SetSpanishMonth);
//////////////////////////////////////////////////////////////////////////////

Set SetSpanishWeekday

//////////////////////////////////////////////////////////////////////////////
Set SetSpanishWeekday = 
  [[ "Lunes",   "Martes", "Miercoles", "Jueves",
     "Viernes", "Sabado", "Domingo" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of spanish weekdays names.", SetSpanishWeekday);
//////////////////////////////////////////////////////////////////////////////

Set SetEnglishMonth

//////////////////////////////////////////////////////////////////////////////
Set SetEnglishMonth = 
  [[ "January", "February", "March",     "April",   "May",      "June",
     "July",    "August",   "September", "October", "November", "December"  ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of english months names.", SetEnglishMonth);
//////////////////////////////////////////////////////////////////////////////

Set SetEnglishWeekday

//////////////////////////////////////////////////////////////////////////////
Set SetEnglishWeekday = 
  [[ "Monday", "Tuesday", "Wednesday", "Thursday",
     "Friday", "Saturday", "Sunday" ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of english weekdays names.", SetEnglishWeekday);
//////////////////////////////////////////////////////////////////////////////

Set SetPortugueseMonth

//////////////////////////////////////////////////////////////////////////////
Set SetPortugueseMonth = 
  [[ "Janeiro", "Fevereiro", "Março",    "Abril",   "Maio",     "Junho",
     "Julho",   "Agosto",    "Setembro", "Outubro", "Novembro", "Dezembro"  ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of portuguese months names.", SetPortugueseMonth);
//////////////////////////////////////////////////////////////////////////////

Set SetFrenchMonth

//////////////////////////////////////////////////////////////////////////////
Set SetFrenchMonth = 
  [[ "Janvier", "Février", "Mars",      "Avril",   "Mai",      "Juin",
     "Juillet", "Août",    "Septembre", "Octobre", "Novembre", "Décembre"  ]];
//////////////////////////////////////////////////////////////////////////////
PutDescription("Set of french months names.", SetFrenchMonth);
//////////////////////////////////////////////////////////////////////////////

Funciones

Text Set2TxtFormat()

//////////////////////////////////////////////////////////////////////////////
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()

//////////////////////////////////////////////////////////////////////////////
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()

//////////////////////////////////////////////////////////////////////////////
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), " "]],
       [["'",      " "]],
       [[". ",     " "]],
       [[":",      " "]],
       [[";",      " "]],
       [[",",      " "]],
       [["[",      " "]],
       [["]",      " "]],
       [["(",      " "]],
       [[")",      " "]],
       [["/",      " "]],
       [["¡",      " "]],
       [["!",      " "]],
       [["¿",      " "]],
       [["?",      " "]],
       [["&amp",   " "]],
       [[" 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()

//////////////////////////////////////////////////////////////////////////////
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 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 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()

//////////////////////////////////////////////////////////////////////////////
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()

//////////////////////////////////////////////////////////////////////////////
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()

//////////////////////////////////////////////////////////////////////////////
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 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 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 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()

//////////////////////////////////////////////////////////////////////////////
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 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);
//////////////////////////////////////////////////////////////////////////////

Time oriented language

//////////////////////////////////////////////////////////////////////////////
// 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), " "]],
       [["'",      " "]],
       [[". ",     " "]],
       [[":",      " "]],
       [[";",      " "]],
       [[",",      " "]],
       [["[",      " "]],
       [["]",      " "]],
       [["(",      " "]],
       [[")",      " "]],
       [["/",      " "]],
       [["¡",      " "]],
       [["!",      " "]],
       [["¿",      " "]],
       [["?",      " "]],
       [["&amp",   " "]],
       [[" 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, "", "", ", ", " &amp; ", "", "", "", "") };
//////////////////////////////////////////////////////////////////////////////
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 &amp; 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);
//////////////////////////////////////////////////////////////////////////////

Árbol de ficheros

Ink.Watercolor construye las páginas del sitio web inkwatercolor.com

  • make.tol proceso principal de generación de contenidos del sitio web
  • tol directorios de código fuente en lenguaje de programación Tol
    • cmm funciones comunes de textos, fechas, conjuntos, ficheros, etc.
      • txt.tol funciones de manejo de textos
      • set.tol funciones de manejo de conjuntos
      • tab.tol funciones de tablas como set of sets
      • ser.tol funciones de series temporales
      • fil.tol funciones de gestión de ficheros
      • zip.tol compresor de ficheros en línea de mandatos
      • apa.tol proceso de ficheros de log de Apache
      • dir.tol funciones de gestión de directorios
    • app funciones especificas de Ink.Watercolor
      • pdb.tol funciones de la base de datos de pinturas
      • pag.tol funciones para generar páginas web Html
      • sed.tol semillas, templates, de páginas web Html
      • ftp.tol funciones para generar mandatos para hacer Ftp
      • xml.tol funciones históricas para sitemaps en Xml
      • alc.tol alchemy para la transformación de imágenes
      • ink.tol funciones auxiliares de InkWatercolor
    • inc.tol inclusión de los ficheros Tol básicos y de aplicación
  • agenda directorio destinado a albergar los ficheros de agendas de posts
    • chpphodb01.txt ejemplo con las 4 primeras obras artísticas que se incluyeron
  • web directorio destinado a las paginas web generadas automáticamente
    • common directorio de recursos comunes a todas las galerías
      • css directorio para ficheros de estilo
        • common.css fichero de estilo para las paginas Html del sitio web
      • seed trozos de código Html para construir templates
        • strseed.htm estructura básica de página Html de inkwatercolor.com
        • pi1lowseed.htm estructura para albergar información sobre una obra
        • pi4cntseed.htm estructura para albergar 4 pinturas en una página
      • src directorio para ficheros javascript
    • chppho directorio para la galería principal de Inkwatercolor
      • index.html ejemplo de página Html generada automáticamente
    • download directorio para material extra para descargas
      • chppho0129.jpg ejemplo de imagen de obra artística para descargar
      • chppho0143.jpg ejemplo de imagen de obra artística para descargar
    • sitemap.xml mapa del sitio web generado en Xml de forma automática
  • history archivo de registro histórico del programa Ink.Watercolor
  • ink_watercolor.pdf documento resumen de funciones del programa de generación Html

2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio

Tol