Secciones de la página

pdb. tol


Declaraciones


Constantes


Funciones


Time oriented language


Árbol de ficheros

Funciones

Set PdbRead()

Set PdbFirstN()

Real PdbAppend()

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









pdb.tol de Antonio.Salmeron

Posts database functions.

Declaraciones

Constantes

  • Text PdbSep
    Post separator inside the agendas.

Funciones

  • Set PdbRead(Text inpDir)
    Reads and returns a post database.
  • Set PdbFirstN(Set inpSet, Real maxNum, Code funSel)
    Returns the maxNum recents posts selected using the function funSel.
  • Real PdbAppend(Text pstTxt)
    Guarda el contenido de un post en un fichero. Esta funcion solo se emplea cuando es necesario convertir una agenda grande en varias pequeñas. A los ficheros se les pone extension txt y no age, pero poder revisarlos antes de la siguiente carga.

Constantes

Text PdbSep

//////////////////////////////////////////////////////////////////////////////
Text PdbSep = Repeat("_",78);
//////////////////////////////////////////////////////////////////////////////
PutDescription("Post separator inside the agendas.", PdbSep);
//////////////////////////////////////////////////////////////////////////////

Funciones

Set PdbRead()

//////////////////////////////////////////////////////////////////////////////
Set PdbRead(Text inpDir)
//////////////////////////////////////////////////////////////////////////////
{
  Real err(Text msg){ Text WriteLn("\nERROR: "+msg+"\n"); FALSE }; // Function
  
  Text filSep = Char(7);

  Text WriteLn("Reading "+inpDir+"...");
  Text inpAll = DirReadFiles(inpDir, "age", filSep);

  Text inpTxt = Replace(inpAll, PdbSep+"\n",filSep);
  Set  inpSet = Tokenizer(inpTxt,filSep);

  Set  inpTab = EvalSet(inpSet, Set(Text inf)
  {
    // Read
    Set  pstCla = Txt2Set(TxtBetween2Tag(inf,"<Pst.Cla>", "\n<", TRUE),";");
    Text pstNam =         TxtBetween2Tag(inf,"<Pst.Nam>", "\n<", TRUE);
    Text pstTit =         TxtBetween2Tag(inf,"<Pst.Tit>", "\n<", TRUE);
    Date pstDte =    Eval(TxtBetween2Tag(inf,"<Pst.Dte>", "\n<", TRUE));
    Date pstUpd =    Eval(TxtBetween2Tag(inf,"<Pst.Upd>", "\n<", TRUE));
    Text pstTxt =         TxtBetween2Tag(inf,"<Pst.Txt>", "\n<", FALSE);
    Text pstLnk =         TxtBetween2Tag(inf,"<Pst.Lnk>", "\n<", FALSE);

    // Check classes
    Set  chkCla = EvalSet(pstCla, Real(Text claNam) // Category class
    { If(claNam <: CatAll, TRUE, err("Class: "+pstNam+" "+claNam)) });

    Real chkPer = // Check periods and dates
    {
      Text chkLst = pstCla[Card(pstCla)]; // The period must be the last
      Set  chkSet = Tokenizer(chkLst, "-");
      Text chkIni = chkSet[1];
      Text chkEnd = chkSet[2];
      Text chkYea = FormatReal(Year(pstDte),"%4.0lf");
      If(And(chkYea >= chkIni, chkYea <= chkEnd), TRUE,
         err(pstNam+"Period and date: "+chkIni+" ?<= "+chkYea+" ?<= "+chkEnd))
    };

    Real chkNam = // Check names and dates
    {
      Text yeaNam = Sub(TxtBetween2Tag(pstNam, ",", "]", TRUE),1,4);
      Text yeaDte = FormatReal(Year(pstDte),"%4.0lf");
      If(yeaNam == yeaDte, TRUE,
         err("Name and date: "+pstNam+" ? "+yeaDte))
    };

    // Store and returns a post object
    PdbSt(pstCla, pstNam, pstTit, pstDte, pstUpd, pstTxt, pstLnk)
  });
  Set inpSor = Sort(inpTab, Real(Set a, Set b) // Lasts first
               { Compare(b->pstDte,a->pstDte) });

  // Check duplicated names
  Real chkDup =
  {
    Set inpCla = Classify(inpTab, Real(Set a, Set b) // By name
                 { Compare(a->pstNam,b->pstNam) });
    Set inpDup = EvalSet(inpCla, Real(Set cla)
    {
      Real crd = Card(cla);
      Text nam = cla[1]->pstNam;
      If(EQ(crd,1), TRUE, err("Name: "+nam+" "+
                              FormatReal(crd,"%.0lf")+" times"))
    });
    Card(inpDup)
  };
  
  Text WriteLn("Readed "+FormatReal(Card(inpSor),"%.0lf")+" registers");

  inpSor
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Reads and returns a post database.",
PdbRead);
//////////////////////////////////////////////////////////////////////////////

Set PdbFirstN()

//////////////////////////////////////////////////////////////////////////////
Set PdbFirstN(Set  inpSet, // Post database
              Real maxNum, // Maximum numbers of posts to return
              Code funSel) // Post selection conditions
//////////////////////////////////////////////////////////////////////////////
{
  Set  selFst = Select(inpSet, funSel); // Select all that funSel()
  SetFirstN(selFst, maxNum)             // Fst maxNum or all if there are few
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns the maxNum recents posts selected using the function funSel.",
PdbFirstN);
//////////////////////////////////////////////////////////////////////////////

Real PdbAppend()

//////////////////////////////////////////////////////////////////////////////
Real PdbAppend(Text  pstTxt) // Post text
//////////////////////////////////////////////////////////////////////////////
{
  Text pstOut = pstTxt + PdbSep + "\n";

  Text Case(
   !TextFind(pstTxt, "<Pst.Nam> [Salmerón A."),
     AppendFile(CtrAge+"/06.externos.txt", pstOut),       // Otros autores

   TextFind(pstTxt, "<iframe"),
     AppendFile(CtrAge+"/05.iframe.txt", pstOut),         // Videos

   TextFind(pstTxt, "; Educación básica;"),
     AppendFile(CtrAge+"/04.niñas.txt", pstOut),          // Niñas educacion

   TextFind(pstTxt, "<Pst.Cla> Pintura y poesía;"),
     AppendFile(CtrAge+"/03.arte.txt", pstOut),           // Arte

   TextFind(pstTxt, "<Pst.Cla> Negocios;"),
     AppendFile(CtrAge+"/02.negocios.txt", pstOut),       // Negocios

   TextFind(pstTxt, "<Pst.Cla> Tecnología;"),
     AppendFile(CtrAge+"/01.tecnologia.txt", pstOut),     // Tecnologia

   TRUE,
     AppendFile(CtrAge+"/00.inclasificable.txt", pstOut)  // Error
  );
  
  TRUE
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Guarda el contenido de un post en un fichero.
Esta funcion solo se emplea cuando es necesario convertir una agenda grande
en varias pequeñas.
A los ficheros se les pone extension txt y no age, pero poder revisarlos
antes de la siguiente carga.",
PdbAppend);
//////////////////////////////////////////////////////////////////////////////

Time oriented language

//////////////////////////////////////////////////////////////////////////////
// FILE    : pdb.tol
// AUTHOR  : http://www.asolver.com
// PURPOSE : Posts database functions.
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
// CONSTANTS
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
Text PdbSep = Repeat("_",78);
//////////////////////////////////////////////////////////////////////////////
PutDescription("Post separator inside the agendas.", PdbSep);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
Set PdbRead(Text inpDir)
//////////////////////////////////////////////////////////////////////////////
{
  Real err(Text msg){ Text WriteLn("\nERROR: "+msg+"\n"); FALSE }; // Function
  
  Text filSep = Char(7);

  Text WriteLn("Reading "+inpDir+"...");
  Text inpAll = DirReadFiles(inpDir, "age", filSep);

  Text inpTxt = Replace(inpAll, PdbSep+"\n",filSep);
  Set  inpSet = Tokenizer(inpTxt,filSep);

  Set  inpTab = EvalSet(inpSet, Set(Text inf)
  {
    // Read
    Set  pstCla = Txt2Set(TxtBetween2Tag(inf,"<Pst.Cla>", "\n<", TRUE),";");
    Text pstNam =         TxtBetween2Tag(inf,"<Pst.Nam>", "\n<", TRUE);
    Text pstTit =         TxtBetween2Tag(inf,"<Pst.Tit>", "\n<", TRUE);
    Date pstDte =    Eval(TxtBetween2Tag(inf,"<Pst.Dte>", "\n<", TRUE));
    Date pstUpd =    Eval(TxtBetween2Tag(inf,"<Pst.Upd>", "\n<", TRUE));
    Text pstTxt =         TxtBetween2Tag(inf,"<Pst.Txt>", "\n<", FALSE);
    Text pstLnk =         TxtBetween2Tag(inf,"<Pst.Lnk>", "\n<", FALSE);

    // Check classes
    Set  chkCla = EvalSet(pstCla, Real(Text claNam) // Category class
    { If(claNam <: CatAll, TRUE, err("Class: "+pstNam+" "+claNam)) });

    Real chkPer = // Check periods and dates
    {
      Text chkLst = pstCla[Card(pstCla)]; // The period must be the last
      Set  chkSet = Tokenizer(chkLst, "-");
      Text chkIni = chkSet[1];
      Text chkEnd = chkSet[2];
      Text chkYea = FormatReal(Year(pstDte),"%4.0lf");
      If(And(chkYea >= chkIni, chkYea <= chkEnd), TRUE,
         err(pstNam+"Period and date: "+chkIni+" ?<= "+chkYea+" ?<= "+chkEnd))
    };

    Real chkNam = // Check names and dates
    {
      Text yeaNam = Sub(TxtBetween2Tag(pstNam, ",", "]", TRUE),1,4);
      Text yeaDte = FormatReal(Year(pstDte),"%4.0lf");
      If(yeaNam == yeaDte, TRUE,
         err("Name and date: "+pstNam+" ? "+yeaDte))
    };

    // Store and returns a post object
    PdbSt(pstCla, pstNam, pstTit, pstDte, pstUpd, pstTxt, pstLnk)
  });
  Set inpSor = Sort(inpTab, Real(Set a, Set b) // Lasts first
               { Compare(b->pstDte,a->pstDte) });

  // Check duplicated names
  Real chkDup =
  {
    Set inpCla = Classify(inpTab, Real(Set a, Set b) // By name
                 { Compare(a->pstNam,b->pstNam) });
    Set inpDup = EvalSet(inpCla, Real(Set cla)
    {
      Real crd = Card(cla);
      Text nam = cla[1]->pstNam;
      If(EQ(crd,1), TRUE, err("Name: "+nam+" "+
                              FormatReal(crd,"%.0lf")+" times"))
    });
    Card(inpDup)
  };
  
  Text WriteLn("Readed "+FormatReal(Card(inpSor),"%.0lf")+" registers");

  inpSor
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Reads and returns a post database.",
PdbRead);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Set PdbFirstN(Set  inpSet, // Post database
              Real maxNum, // Maximum numbers of posts to return
              Code funSel) // Post selection conditions
//////////////////////////////////////////////////////////////////////////////
{
  Set  selFst = Select(inpSet, funSel); // Select all that funSel()
  SetFirstN(selFst, maxNum)             // Fst maxNum or all if there are few
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns the maxNum recents posts selected using the function funSel.",
PdbFirstN);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Real PdbAppend(Text  pstTxt) // Post text
//////////////////////////////////////////////////////////////////////////////
{
  Text pstOut = pstTxt + PdbSep + "\n";

  Text Case(
   !TextFind(pstTxt, "<Pst.Nam> [Salmerón A."),
     AppendFile(CtrAge+"/06.externos.txt", pstOut),       // Otros autores

   TextFind(pstTxt, "<iframe"),
     AppendFile(CtrAge+"/05.iframe.txt", pstOut),         // Videos

   TextFind(pstTxt, "; Educación básica;"),
     AppendFile(CtrAge+"/04.niñas.txt", pstOut),          // Niñas educacion

   TextFind(pstTxt, "<Pst.Cla> Pintura y poesía;"),
     AppendFile(CtrAge+"/03.arte.txt", pstOut),           // Arte

   TextFind(pstTxt, "<Pst.Cla> Negocios;"),
     AppendFile(CtrAge+"/02.negocios.txt", pstOut),       // Negocios

   TextFind(pstTxt, "<Pst.Cla> Tecnología;"),
     AppendFile(CtrAge+"/01.tecnologia.txt", pstOut),     // Tecnologia

   TRUE,
     AppendFile(CtrAge+"/00.inclasificable.txt", pstOut)  // Error
  );
  
  TRUE
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Guarda el contenido de un post en un fichero.
Esta funcion solo se emplea cuando es necesario convertir una agenda grande
en varias pequeñas.
A los ficheros se les pone extension txt y no age, pero poder revisarlos
antes de la siguiente carga.",
PdbAppend);
//////////////////////////////////////////////////////////////////////////////

Árbol de ficheros

Antonio.Salmeron construye las páginas y documentos del sitio web antoniosalmeron.con

  • 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
      • dte.tol funciones de manejo de fechas en español
      • set.tol funciones de manejo de conjuntos
      • fil.tol funciones de gestión de ficheros
      • dir.tol funciones de gestión de directorios
      • tme.tol del macro-expansor simple de Tol en Html
      • htm.tol funciones básicas del lenguaje Html
      • ftp.tol funciones para generar mandatos para hacer Ftp
      • pdf.tol funciones para generar documentos en Pdf
      • xsm.tol para construir sitemaps en Xml
    • app funciones especificas de aplicacion para Antonio.Salmeron
      • pdb.tol funciones de manejo de los posts de una agenda
      • pht.tol funciones auxiliares para el Html de los post
    • 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
    • 03.arte.age ejemplo de 2 posts de contenido de poesía para publicar
  • web directorio destinado a las paginas web generadas automáticamente
    • css directorio para ficheros de estilo
      • common.css fichero de estilo para las paginas Html del sitio web
    • seed directorio para ficheros semilla de Html con Tol embebido
      • seed.htm semilla de pagina Html con Tol embebido para el sitio web
      • seed.cv.htm semilla Html con Tol embebido para generar curriculum vitae
    • articulos directorio para paginas de artículos generadas por este programa
    • categorias directorio para paginas de categorias generadas automáticamente
    • sitemap.xml mapa del sitio web generado en Xml de forma automática
  • doc directorio de documentación del programa Antonio.Salmeron
  • antonio_salmeron.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