Secciones de la página

Funciones de conjuntos set. tol

Funciones

Anything SetGetRand()

Real SetTxtFindFirst()

Serie Set2Ser()

Set Set2Keyword()

Set Set2Keyword()

Set SetFirstN()

Set SetFirstN()

Set SetFirstNByFun()

Set SetInclude()

Set SetLastN()

Set SetReverse()

Set SetShuffle()

Set SetSubCicle()

Set SetTxtBeginWith()

Set SetTxtCount()

Text Set2Txt()

Text Set2Txt()

Text Set2TxtCommaAmp()

Text Set2TxtFormat()

Text Set2TxtKeyword()

Text Set2TxtKeyword()

Text Set2TxtKeyword()

Text Set2TxtKeyword()

Text Set2TxtSql()

Text Set2TxtTol()

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









Funciones de conjuntos set.tol

Funciones para el manejo de conjuntos, que es la gramática Set del lenguaje de programación Tol.

Las funciones de esta página están ordenadas de forma alfabética por las diferentes gramáticas del lenguaje Tol ( Text, Set, Serie, Anything, Code, Date, Real,...) y, dentro de cada gramática, por el nombre de la función. Pueden encontrarse 2 o más funciones con idéntico nombre, pero con distintas maneras de programarse o con diferentes comentarios en diferentes idiomas, estas funciones aparecerán unas a continuación de las otras.

Anything SetGetRand() de Omr.Forms

//////////////////////////////////////////////////////////////////////////////
Anything SetGetRand(Set setInp)
//////////////////////////////////////////////////////////////////////////////
{
  Real setCrd = Card(setInp);
  If(LE(setCrd, 0), FALSE,
  {
    Real     rndPos = Min(setCrd, Max(1, Round(Rand(0, setCrd)+0.5)));
    Anything rndVal = setInp[rndPos];
    rndVal
  })  
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un elemento al azar del conjunto de entrada setInp. 
Si setInp es Empty retorna FALSE.",
SetGetRand);
//////////////////////////////////////////////////////////////////////////////

Real SetTxtFindFirst() de Ink.Watercolor

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

Serie Set2Ser() de Ink.Watercolor

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

Set Set2Keyword() de Antonio.Salmeron

//////////////////////////////////////////////////////////////////////////////
Set Set2Keyword(Set  valSet, // Set of texts
                Real minChr, // Minimum number of chars
                Real a2zOrd, // If true ordered az else by ocurrences
                Real maxKey) // Maximun number of keywords
//////////////////////////////////////////////////////////////////////////////
{
  Set cmmWrd =
  [[
     "ambos",
     "aunque",
     "avppm",
     "barcelona",
     "carlos",
     "cinco",
     "cuando",
     "cuatro",
     "con-q",
     "dentro",
     "desde",
     "donde",
     "entre",
     "están",
     "estas", "estos",
     "había",
     "junto",
     "luego",
     "madrid",
     "misma", "mismo",
     "mucho",
     "número",
     "otro", "otros",
     "página", "páginas",
     "partir", "permite",
     "primer", "primera",
     "propio",
     "puede", "pueden",
     "segunda", "segundo", "segundos", 
     "siguiente", "siguientes", 
     "sobre",
     "también",
     "tiene", "tienen",
     "través",
     "utilizando", "utilizar",
     "verse",
     "zulú"
  ]];

  // Convert all to text
  Text lstTxt = ToLower(Set2Txt(valSet,"", "", " ", " ", "", "", "", ""));
  
  Text htmNot = TxtOutHtmScr(lstTxt);

  Text lstCls = Compact(ReplaceTable(htmNot, // _ must NOT be changed
    [[ [[Char(34), " "]], [["'",      " "]],
       [["." ,     " "]], [[":",      " "]],
       [[";",      " "]], [[",",      " "]],
       [["[",      " "]], [["]",      " "]],
       [["(",      " "]], [[")",      " "]],
/*     [["<",      " "]], [[">",      " "]],    Sobra */
       [["«",      " "]], [["»",      " "]], // Titulos de libros
       [["¡",      " "]], [["!",      " "]],
       [["¿",      " "]], [["?",      " "]],
       [["/",      " "]], [["|",      " "]],
       [["&amp",   " "]],
       [["&nbsp;", " "]],
       [[" none ", " "]],
       [[" the ",  " "]],
       [[" and ",  " "]],
       [[" or ",   " "]],
       [[" & ",    " "]],
       [[" y ",    " "]],
       [[" o ",    " "]]
    ]]));

// Split in words
  Set  setTxt = Tokenizer(lstCls, " ");
  
// Select word with more than minChr characters that locks like words
  Set  setSel = Select(setTxt, Real(Text wrdTxt)
  {
    Real wrdLen = TextLength(wrdTxt);
    Text iniLet = Sub(wrdTxt, 1,      1);
    Text lstLet = Sub(wrdTxt, wrdLen, wrdLen);
    And(GT(wrdLen, minChr), iniLet >= "a", iniLet <= "z",
                            lstLet >= "a", lstLet <= "z")
  });

// Classify words
  Set  setCla = Classify(setSel, Real(Text a, Text b)
                        { Compare(ToLower(a),ToLower(b)) });

// Make a frecuencies table [ word, number of occurrencies ]
  Set  tabFrq = EvalSet(setCla, Set(Set cla)
                        { [[ cla[1], Card(cla) ]] });

// Sort (with most ocurrencies first)
  Set  srtFrq = Sort(tabFrq, Real(Set a, Set b)
                     { Compare(Real(b[2]), Real(a[2])) });

// Project by word column (the first column)
  Set  keySet = EvalSet(srtFrq, Text(Set a) { Text(a[1]) });

// Minus common words
  Set  keyMin = keySet - cmmWrd;

// Select the first maxKey or Card(keySet) or all if maxKey=0
  Set  keyFst = If(maxKey, SetFirstN(keyMin, maxKey), keyMin);

// Sort if is needed
  If(! a2zOrd, keyFst,
     Sort(keyFst, Real(Text a, Text b)
       { Compare(ToLower(a),ToLower(b)) })) // Order
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a set with all the elements of valSet converted in a
text format, ordered and without repetitions.
Remove all word with LE(TextLength(), minChr).
Returns the maxKey elements more occurrencies.",
Set2Keyword);
//////////////////////////////////////////////////////////////////////////////

Set Set2Keyword() de iForense

//////////////////////////////////////////////////////////////////////////////
Set Set2Keyword(Set  valSet, // Set of texts
                Real minChr, // Minimum number of chars
                Real a2zOrd, // If true ordered az else by ocurrences
                Real maxKey) // Maximun number of keywords
//////////////////////////////////////////////////////////////////////////////
{
  Set cmmWrd =
  [[
     "ambos",
     "desde",
     "dentro",
     "entre",
     "esta", "estas", "esto", "estos", 
     "junto",
     "mucho", "muchos",
     "otra", "otras", "otro", "otros",
     "parte",
     "porque",
     "puede", "pueden", "pudiendo",
     "siguiente", "siguientes",
     "sobre",
     "sumamente",
     "también",
     "tanto",
     "zulú"
  ]];

  // Convert all to text
  Text lstTxt = ToLower(Set2Txt(valSet,"", "", " ", " ", "", "", "", ""));
  
  Text htmNot = TxtOutHtmScr(lstTxt);

  Text lstCls = Compact(ReplaceTable(htmNot, // _ must NOT be changed
    [[ [[Char(34), " "]], [["'",      " "]],
       [["." ,     " "]], [[":",      " "]],
       [[";",      " "]], [[",",      " "]],
       [["[",      " "]], [["]",      " "]],
       [["(",      " "]], [[")",      " "]],
/*     [["<",      " "]], [[">",      " "]],    Sobra */
       [["«",      " "]], [["»",      " "]], // Titulos de libros
       [["¡",      " "]], [["!",      " "]],
       [["¿",      " "]], [["?",      " "]],
       [["/",      " "]], [["|",      " "]],
       [["&amp",   " "]],
       [["&nbsp;", " "]],
       [[" none ", " "]],
       [[" the ",  " "]],
       [[" and ",  " "]],
       [[" or ",   " "]],
       [[" & ",    " "]],
       [[" y ",    " "]],
       [[" o ",    " "]]
    ]]));

// Split in words
  Set  setTxt = Tokenizer(lstCls, " ");
  
// Select word with more than minChr characters that locks like words
  Set  setSel = Select(setTxt, Real(Text wrdTxt)
  {
    Real wrdLen = TextLength(wrdTxt);
    Text iniLet = Sub(wrdTxt, 1,      1);
    Text lstLet = Sub(wrdTxt, wrdLen, wrdLen);
    And(GT(wrdLen, minChr), iniLet >= "a", iniLet <= "z",
                            lstLet >= "a", lstLet <= "z")
  });

// Classify words
  Set  setCla = Classify(setSel, Real(Text a, Text b)
                        { Compare(ToLower(a),ToLower(b)) });

// Make a frecuencies table [ word, number of occurrencies ]
  Set  tabFrq = EvalSet(setCla, Set(Set cla)
                        { [[ cla[1], Card(cla) ]] });

// Sort (with most ocurrencies first)
  Set  srtFrq = Sort(tabFrq, Real(Set a, Set b)
                     { Compare(Real(b[2]), Real(a[2])) });

// Project by word column (the first column)
  Set  keySet = EvalSet(srtFrq, Text(Set a) { Text(a[1]) });

// Minus common words
  Set  keyMin = keySet - cmmWrd;

// Select the first maxKey or Card(keySet) or all if maxKey=0
  Set  keyFst = If(maxKey, SetFirstN(keyMin, maxKey), keyMin);

// Sort if is needed
  If(! a2zOrd, keyFst,
     Sort(keyFst, Real(Text a, Text b)
       { Compare(ToLower(a),ToLower(b)) })) // Order
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a set with all the elements of valSet converted in a
text format, ordered and without repetitions.
Remove all word with LE(TextLength(), minChr).
Returns the maxKey elements more occurrencies.",
Set2Keyword);
//////////////////////////////////////////////////////////////////////////////

Set SetFirstN() de iForense

//////////////////////////////////////////////////////////////////////////////
Set SetFirstN(Set  setInp, // Set de entrada
              Real numEle) // Numero de elementos a retornar
//////////////////////////////////////////////////////////////////////////////
{
  If(LE(numEle, 0), Empty,
     For(1, Min(Card(setInp), numEle), Anything(Real setPos)
         { setInp[setPos] }))
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un subconjunto de un conjunto con los primeros numEle elementos.
Si el conjunto tiene menos de numEle elementos los retorna todos.
Si numEle es 0 o negativo retorna el conjunto vacio.",
SetFirstN);
//////////////////////////////////////////////////////////////////////////////

Set SetFirstN() de Ink.Watercolor

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

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

Set SetInclude() de Ink.Watercolor

//////////////////////////////////////////////////////////////////////////////
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 SetLastN() de iForense

//////////////////////////////////////////////////////////////////////////////
Set SetLastN(Set  setInp, // Set de entrada
             Real numEle) // Numero de elementos a retornar
//////////////////////////////////////////////////////////////////////////////
{
  If(LE(numEle, 0), Empty,
     For(Max(1, 1+Card(setInp)-numEle), Card(setInp), Anything(Real setPos)
         { setInp[setPos] }))
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un subconjunto de un conjunto con los ultimos numEle elementos.
Si el conjunto tiene menos de numEle elementos los retorna todos.",
SetLastN);
//////////////////////////////////////////////////////////////////////////////

Set SetReverse() de Antonio.Salmeron

//////////////////////////////////////////////////////////////////////////////
Set SetReverse(Set  setInp) // Set de entrada
//////////////////////////////////////////////////////////////////////////////
{
  Real numEle = Card(setInp);
  If(LE(numEle, 0), Empty,
     For(1, numEle, Anything(Real setPos) { setInp[numEle+1-setPos] }))
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el conjunto de entrada con su orden invertido.",
SetReverse);
//////////////////////////////////////////////////////////////////////////////

Set SetShuffle() de ChRules.Iterative

//////////////////////////////////////////////////////////////////////////////
Set SetShuffle(Set anySet) // Set of Anything
//////////////////////////////////////////////////////////////////////////////
{
  Set tabSet = EvalSet(anySet, Set(Anything anyVal) // Para todo elemento
               { [[ Real Rand(0,1), anyVal ]] });   // Par [random, valor]
  
  Set tabSrt = Sort(tabSet, Real(Set a, Set b) // Ordenar por el aleatorio
               { Compare(a[1],b[1]) });

  EvalSet(tabSrt, Anything(Set parSet) { parSet[2] }) // Desordenados
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el conjunto de lo que sea desordenado, para ello:
- Para cada elemento del conjunto, sea lo que sea, Anything,
  construye una tabla de pares formados por un numero aleatorio y cada uno
  de los elementos.
- Ordena por el elemento aleatorio, por lo que sera un total desorden.
- Recorre la tabla desordenada retornando el conjunto de los valores
  originales.",
SetShuffle);
//////////////////////////////////////////////////////////////////////////////

Set SetSubCicle() de con-Q.tv

//////////////////////////////////////////////////////////////////////////////
Set SetSubCicle(Set  setInp, // Conjunto de elementos
                Real iniPos, // Posicion inicial 
                Real lenRet) // Numero de elementos a retornar
//////////////////////////////////////////////////////////////////////////////
{
  Real modCic(Real setPos, Real crdSet)
  {
    Real modPos = setPos % crdSet;
    If(LE(modPos, 0), crdSet, modPos)
  };
  
  Real crdSet = Card(setInp);
  
  For(0, lenRet-1, Anything(Real setPos)
  {
    Real posCic = modCic(iniPos + setPos, crdSet);
    setInp[posCic]
  })
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna un subconjunto de un conjunto con los primeros numEle elementos.
Si el conjunto tiene menos de numEle elementos los extrae por el principio.
Por ejemplo: SetSubCicle([a,b,c,d],3,8) -> [c,d,a,b,c,d,a,b]",
SetSubCicle);
//////////////////////////////////////////////////////////////////////////////

Set SetTxtBeginWith() de Ink.Watercolor

//////////////////////////////////////////////////////////////////////////////
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() de Ink.Watercolor

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

Text Set2Txt() de Ink.Watercolor

//////////////////////////////////////////////////////////////////////////////
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 Set2Txt() de Ediciones.aContracorriente

//////////////////////////////////////////////////////////////////////////////
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), F(valSet[1]),
    If(EQ(card,2), F(valSet[1])+sepLst+F(valSet[2]),
    {
      Set txtVal = For(2,card,Text(Real p)
      {
        If(EQ(p,card),sepLst,sepTxt) + F(valSet[p])
      });
      F(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 Set2TxtCommaAmp() de iForense

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

Text Set2TxtFormat() de Ink.Watercolor

//////////////////////////////////////////////////////////////////////////////
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 Set2TxtKeyword() de Ediciones.aContracorriente

//////////////////////////////////////////////////////////////////////////////
Text Set2TxtKeyword(Set  valSet, // Set of texts
                    Real minChr, // Minimum number of chars
                    Real a2zOrd, // If true ordered
                    Real maxKey) // Maximun number of keywords
//////////////////////////////////////////////////////////////////////////////
{
  Set cmmWrd =
  [[
     "_mca_", "_mar_",
     "actualmente",
     "ambos",
     "ante", "antes",
     "cuando", "cuándo",
     "desde",
     "dentro",
     "entre",
     "esta", "estas", "esto", "estos", 
     "gracias",
     "hemos",
     "iframes",
     "junto",
     "mientras",
     "mucho", "muchos", "mucha", "muchas",
     "navegador",
     "nosotros", 
     "nuestro", "nuestros", "nuestra", "nuestras", 
     "otra", "otras", "otro", "otros",
     "parte", "partes",
     "porque",
     "puede", "pueden", "pudiendo",
     "propia", "propias", "propio", "propios",
     "quien", "quién",
     "siguiente", "siguientes",
     "sobre",
     "soporta",
     "sumamente",
     "también",
     "tanto",
     "zulú"
  ]];

  // Convert all to text
  Text lstTxt = ToLower(Set2Txt(valSet,"", "", " ", " ", "", "", "", ""));
  
  Text htmNot = TxtOutHtmScr(lstTxt); // Sobra ya recibe texto puro

  Text lstCls = Compact(ReplaceTable(htmNot,
    [[ [[Char(34), " "]], [["'",      " "]],
       [["." ,     " "]], [[":",      " "]],
       [[";",      " "]], [[",",      " "]],
       [["[",      " "]], [["]",      " "]],
       [["(",      " "]], [[")",      " "]],
       [["<",      " "]], [[">",      " "]], // Sobra
       [["«",      " "]], [["»",      " "]], // Titulos de libros
       [["¡",      " "]], [["!",      " "]],
       [["¿",      " "]], [["?",      " "]],
       [["/",      " "]],
       [["&amp",   " "]],
       [["&nbsp;", " "]],
       [[" none ", " "]],
       [[" the ",  " "]],
       [[" and ",  " "]],
       [[" or ",   " "]],
       [[" & ",    " "]],
       [[" y ",    " "]],
       [[" o ",    " "]]
    ]]));

// Split in words
  Set  setTxt = Tokenizer(lstCls, " ");
  
// Select word with more than minChr characters  
  Set  setSel = Select(setTxt, Real(Text a) { GT(TextLength(a), minChr) });

// Classify words
  Set  setCla = Classify(setSel, Real(Text a, Text b)
                        { Compare(ToLower(a),ToLower(b)) });

// Make a frecuencies table [ word, number of occurrencies ]
  Set  tabFrq = EvalSet(setCla, Set(Set cla)
                        { [[ cla[1], Card(cla) ]] });

// Sort (with most ocurrencies first and more length first
  Set  srtFrq = Sort(tabFrq, Real(Set a, Set b)
  {
    Real fre = Compare(Real(b[2]), Real(a[2]));
    If(fre, fre,  Compare(TextLength(b[1]), TextLength(a[1])))
  });

// Project by word column (the first column)
  Set  keySet = EvalSet(srtFrq, Text(Set a) { Text(a[1]) });

// Minus common words
  Set  keyMin = keySet - cmmWrd;

// Select the first maxKey or Card(keySet) or all if maxKey=0
  Set  keyFst = If(maxKey, SetFirstN(keyMin, maxKey), keyMin);

// Sort if is needed
  Set  keySor = If(! a2zOrd, keyFst,
                   Sort(keyFst, Real(Text a, Text b)
                     { Compare(ToLower(a),ToLower(b)) })); // Order

// Convert to text
  Set2Txt(keySor, "", "", ", ", ", ", "", "", "", "")
};
//////////////////////////////////////////////////////////////////////////////
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).
Returns the maxKey elements more occurrencies.",
Set2TxtKeyword);
//////////////////////////////////////////////////////////////////////////////

Text Set2TxtKeyword() de Ink.Watercolor

//////////////////////////////////////////////////////////////////////////////
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 Set2TxtKeyword() de iForense

//////////////////////////////////////////////////////////////////////////////
Text Set2TxtKeyword(Set  valSet, // Set of texts
                    Real minChr, // Minimum number of chars
                    Real a2zOrd, // If true ordered az else by ocurrences
                    Real maxKey) // Maximun number of keywords
//////////////////////////////////////////////////////////////////////////////
{
  Set2Txt(Set2Keyword(valSet, minChr, a2zOrd, maxKey),
          "", "", ", ", ", ", "", "", "", "")
};
//////////////////////////////////////////////////////////////////////////////
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).
Returns the maxKey elements more occurrencies.",
Set2TxtKeyword);
//////////////////////////////////////////////////////////////////////////////

Text Set2TxtKeyword() de con-Q.tv

//////////////////////////////////////////////////////////////////////////////
Text Set2TxtKeyword(Set  valSet, // Set of texts
                    Real minChr, // Minimum number of chars
                    Real a2zOrd, // If true ordered
                    Real maxKey) // Maximun number of keywords
//////////////////////////////////////////////////////////////////////////////
{
  Set cmmWrd =
  [[
     "además",
     "ambos", "ambas",
     "aunque",
     "cualquier", "cualquiera",
     "cuando",
     "deberá", 
     "desde",
     "dentro",
     "entre",
     "esta", "estas", "esto", "estos", 
     "junto",
     "mismo", "mismos", "misma", "mismas",
     "mucho", "muchos", "mucha", "muchas",
     "ningún", "ninguna",
     "nosotros", "nosotras",
     "nuestro", "nuestros", "nuestra", "nuestras", 
     "otra", "otras", "otro", "otros",
     "parte",
     "porque",
     "puede", "pueden", "pudiendo",
     "quienes",
     "siempre",
     "siguiente", "siguientes",
     "sobre",
     "sumamente",
     "también",
     "tanto",
     "través",
     "zulú"
  ]];

  // Convert all to text
  Text lstTxt = ToLower(Set2Txt(valSet,"", "", " ", " ", "", "", "", ""));
  
  Text htmNot = TxtOutHtmScr(lstTxt);

  Text lstCls = Compact(ReplaceTable(htmNot,
    [[ [[Char(34), " "]], [["'",      " "]],
       [["." ,     " "]], [[":",      " "]],
       [[";",      " "]], [[",",      " "]],
       [["[",      " "]], [["]",      " "]],
       [["(",      " "]], [[")",      " "]],
/*     [["<",      " "]], [[">",      " "]],    Sobra */
       [["«",      " "]], [["»",      " "]], // Titulos de libros
       [["¡",      " "]], [["!",      " "]],
       [["¿",      " "]], [["?",      " "]],
       [["/",      " "]],
       [["&amp",   " "]],
       [["&nbsp;", " "]],
       [[" none ", " "]],
       [[" the ",  " "]],
       [[" and ",  " "]],
       [[" or ",   " "]],
       [[" & ",    " "]],
       [[" y ",    " "]],
       [[" o ",    " "]]
    ]]));

// Split in words
  Set  setTxt = Tokenizer(lstCls, " ");
  
// Select word with more than minChr characters  
  Set  setSel = Select(setTxt, Real(Text a) { GT(TextLength(a), minChr) });

// Classify words
  Set  setCla = Classify(setSel, Real(Text a, Text b)
                        { Compare(ToLower(a),ToLower(b)) });

// Make a frecuencies table [ word, number of occurrencies ]
  Set  tabFrq = EvalSet(setCla, Set(Set cla)
                        { [[ cla[1], Card(cla) ]] });

// Sort (with most ocurrencies first)
  Set  srtFrq = Sort(tabFrq, Real(Set a, Set b)
                     { Compare(Real(b[2]), Real(a[2])) });

// Project by word column (the first column)
  Set  keySet = EvalSet(srtFrq, Text(Set a) { Text(a[1]) });

// Minus common words
  Set  keyMin = keySet - cmmWrd;

// Select the first maxKey or Card(keySet) or all if maxKey=0
  Set  keyFst = If(maxKey, SetFirstN(keyMin, maxKey), keyMin);

// Sort if is needed
  Set  keySor = If(! a2zOrd, keyFst,
                   Sort(keyFst, Real(Text a, Text b)
                     { Compare(ToLower(a),ToLower(b)) })); // Order

// Convert to text
  Set2Txt(keySor, "", "", ", ", ", ", "", "", "", "")
};
//////////////////////////////////////////////////////////////////////////////
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).
Returns the maxKey elements more occurrencies.",
Set2TxtKeyword);
//////////////////////////////////////////////////////////////////////////////

Text Set2TxtSql() de Ink.Watercolor

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

Text Set2TxtTol() de Ink.Watercolor

//////////////////////////////////////////////////////////////////////////////
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 SetReplaceTable() de Ink.Watercolor

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

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

Tol