text:
/*----------------------------------------------------------------------
  File    : ista.c
  Contents: finding frequent item sets by intersecting transactions
  Author  : Christian Borgelt
  History : 2009.10.26 file created
            2009.10.30 first version for closed item sets completed
            2009.11.05 default item sorting direction reversed
            2009.11.06 processing order of transactions optimized
            2009.11.07 item order and transaction order made options
            2009.11.18 pruning for higher minimum support added
            2010.06.25 support-based pruning added to intersection
            2010.07.14 output file made optional (for benchmarking)
            2010.08.19 item selection file added as optional input
            2010.08.22 adapted to modified modules tabread and tract
            2010.10.15 adapted to modified interface of module report
            2010.11.24 adapted to modified error reporting (tract)
            2010.12.11 adapted to a generic error reporting function
            2010.12.20 adapted to function tbg_ifrqs() (filter problem)
            2011.03.20 optional integer transaction weights added
            2011.07.08 adapted to modified function tbg_recode()
            2011.08.28 output of item set counters per size added
            2011.11.23 output/filtering of maximal item sets added
            2012.04.29 alternative filtering of maximal item sets added
            2012.06.13 bug resulting from exchange of n and k fixed
            2012.07.09 pruning of the prefix tree made optional (-p)
            2012.07.16 optional processing with patricia tree added
            2013.04.01 adapted to type changes in module tract
            2013.10.18 optional pattern spectrum collection added
            2013.11.12 item selection file changed to option -R#
            2014.05.12 option -F# added (support border for filtering)
            2014.08.24 adapted to modified item set reporter interface
            2014.08.28 functions ista_data() and ista_repo() added
            2014.10.24 changed from LGPL license to MIT license
------------------------------------------------------------------------
  Reference for the IsTa algorithm:
    C. Borgelt, X. Yang, R. Nogales-Cadenas,
    P. Carmona-Saez, and A. Pascual-Montano.
    Finding Closed Frequent Item Sets by Intersecting Transactions.
    Proc. 14th Int. Conf. on Extending Database Technology
    (EDBT 2011, Uppsala, Sweden), 367-376.
    ACM Press, New York, NY, USA 2011
  Reference for the basic idea:
    T. Mielik"ainen.
    Intersecting Data to Closed Sets with Constraints.
    Proc. Workshop Frequent Item Set Mining Implementations
    (FIMI 2003, Melbourne, FL).
    CEUR Workshop Proceedings 90, Aachen, Germany 2003
    http://www.ceur-ws.org/Vol-90/
----------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <limits.h>
#include <float.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#ifndef ISR_PATSPEC
#define ISR_PATSPEC
#endif
#ifdef  ISTA_MAIN
#ifndef PSP_REPORT
#define PSP_REPORT
#endif
#ifndef TA_READ
#define TA_READ
#endif
#endif
#include "ista.h"
#include "pfxtree.h"
#include "pattree.h"
#ifdef ISTA_MAIN
#include "error.h"
#endif
#ifdef STORAGE
#include "storage.h"
#endif

/*----------------------------------------------------------------------
  Preprocessor Definitions
----------------------------------------------------------------------*/
#define PRGNAME     "ista"
#define DESCRIPTION "find closed/maximal frequent item sets " \
                    "by intersecting transactions"
#define VERSION     "version 4.11 (2014.10.24)        " \
                    "(c) 2009-2014   Christian Borgelt"

/* --- error codes --- */
/* error codes   0 to  -4 defined in tract.h */
#define E_STDIN      (-5)       /* double assignment of stdin */
#define E_OPTION     (-6)       /* unknown option */
#define E_OPTARG     (-7)       /* missing option argument */
#define E_ARGCNT     (-8)       /* too few/many arguments */
#define E_TARGET     (-9)       /* invalid target type */
#define E_SIZE      (-10)       /* invalid item set size */
#define E_SUPPORT   (-11)       /* invalid item set support */
#define E_MEASURE   (-13)       /* invalid evaluation measure */
#define E_VARIANT   (-14)       /* invalid algorithm variant */
/* error codes -15 to -25 defined in tract.h */

#ifndef QUIET                   /* if not quiet version, */
#define MSG         fprintf     /* print messages */
#define XMSG        if (mode & ISTA_VERBOSE) fprintf
#else                           /* if quiet version, */
#define MSG(...)                /* suppress messages */
#define XMSG(...)
#endif

#define SEC_SINCE(t)  ((double)(clock()-(t)) /(double)CLOCKS_PER_SEC)

/*----------------------------------------------------------------------
  Type Definitions
----------------------------------------------------------------------*/
typedef struct {                /* --- ista execution data --- */
  int     mode;                 /* processing mode */
  PFXTREE *pxt;                 /* prefix tree for intersections */
  PATTREE *pat;                 /* patricia tree for intersections */
  SUPP    *frqs;                /* (remaining) item frequencies */
} ISTA;                         /* (ista execution data) */

/*----------------------------------------------------------------------
  Constants
----------------------------------------------------------------------*/
#if !defined QUIET && defined ISTA_MAIN
/* --- error messages --- */
static const char *errmsgs[] = {
  /* E_NONE      0 */  "no error",
  /* E_NOMEM    -1 */  "not enough memory",
  /* E_FOPEN    -2 */  "cannot open file %s",
  /* E_FREAD    -3 */  "read error on file %s",
  /* E_FWRITE   -4 */  "write error on file %s",
  /* E_STDIN    -5 */  "double assignment of standard input",
  /* E_OPTION   -6 */  "unknown option -%c",
  /* E_OPTARG   -7 */  "missing option argument",
  /* E_ARGCNT   -8 */  "wrong number of arguments",
  /* E_TARGET   -9 */  "invalid target type '%c'",
  /* E_SIZE    -10 */  "invalid item set size %"ITEM_FMT,
  /* E_SUPPORT -11 */  "invalid minimum support %g",
  /*           -12 */  NULL,
  /* E_MEASURE -13 */  "invalid evaluation measure '%c'",
  /* E_VARIANT -14 */  "invalid IsTa variant '%c'",
  /* E_NOITEMS -15 */  "no (frequent) items found",
  /*           -16 */  "unknown error"
};
#endif

/*----------------------------------------------------------------------
  Global Variables
----------------------------------------------------------------------*/
#ifdef ISTA_MAIN
#ifndef QUIET
static CCHAR    *prgname;       /* program name for error messages */
#endif
static TABREAD  *tread  = NULL; /* table/transaction reader */
static ITEMBASE *ibase  = NULL; /* item base */
static TABAG    *tabag  = NULL; /* transaction bag/multiset */
static ISREPORT *report = NULL; /* item set reporter */
static TABWRITE *twrite = NULL; /* table writer for pattern spectrum */
static double   *border = NULL; /* support border for filtering */
#endif

/*----------------------------------------------------------------------
  Intersecting Transactions
----------------------------------------------------------------------*/

int ista_data (TABAG *tabag, int target, SUPP smin, ITEM zmin,
               int eval, int algo, int mode, int sort)
{                               /* --- prepare data for IsTa */
  ITEM    m;                    /* number of items */
  TID     n;                    /* number of transactions */
  SUPP    w;                    /* total transaction weight */
  clock_t t;                    /* timer for measurements */

  assert(tabag);                /* check the function arguments */
  /* --- sort and recode items --- */
  t = clock();                  /* start timer, print log message */
  XMSG(stderr, "filtering, sorting and recoding items ... ");
  m = tbg_recode(tabag, smin, -1, -1, -sort);
  if (m <  0) return E_NOMEM;   /* recode items and transactions */
  if (m <= 0) return E_NOITEMS; /* and check the number of items */
  XMSG(stderr, "[%"ITEM_FMT" item(s)]", m);
  XMSG(stderr, " done [%.2fs].\n", SEC_SINCE(t));

  /* --- filter and sort transactions --- */
  t = clock();                  /* start timer, print log message */
  XMSG(stderr, "filtering and sorting transactions ... ");
  tbg_filter(tabag,zmin,NULL,0);/* remove items of short transactions */
  tbg_itsort(tabag, -1, 0);     /* sort items in transactions and */
  tbg_sortsz(tabag, -1, 0);     /* transactions lexicographically */
  /* The sorting direction is inverted here, because the transaction */
  /* identifiers are traversed backwards in both algorithm variants. */
  tbg_reduce(tabag, 0);         /* reduce transactions to unique ones */
  n = tbg_cnt(tabag);           /* get the number of transactions */
  w = tbg_wgt(tabag);           /* and the transaction weight */
  XMSG(stderr, "[%"TID_FMT, n); /* print number of transactions */
  if (w != (SUPP)n) { XMSG(stderr, "/%"SUPP_FMT, w); }
  XMSG(stderr, " transaction(s)] done [%.2fs].\n", SEC_SINCE(t));
  return 0;                     /* return 'ok' */
}  /* ista_data() */

/*--------------------------------------------------------------------*/

int ista_repo (ISREPORT *report, int target,
               int eval, double thresh, int algo, int mode)
{                               /* --- prepare reporter for Carpenter */
  int mrep;                     /* mode for item set reporter */

  assert(report);               /* check the function arguments */
  if      (target & ISR_RULES)   target = ISR_RULES;
  else if (target & ISR_GENERAS) target = ISR_GENERAS;
  else if (target & ISR_MAXIMAL) target = ISR_MAXIMAL;
  else if (target & ISR_CLOSED)  target = ISR_CLOSED;
  else                           target = ISR_ALL;
  if (eval == ISTA_LDRATIO)     /* set additional evaluation function */
    isr_seteval(report, isr_logrto, NULL, +1, thresh);
  mrep = ((target & ISR_MAXIMAL) && !(mode & ISTA_FILTER))
       ? ISR_MAXIMAL|ISR_MAXONLY : 0; /* build reporting mode */
  return (isr_settarg(report, target, mrep, -1)) ? E_NOMEM : 0;
}  /* ista_repo() */

/*--------------------------------------------------------------------*/

static int cleanup (ISTA *data)
{                               /* --- clean up on error */
  if (data->mode & ISTA_NOCLEAN) return E_NOMEM;
  if (data->pxt)  pxt_delete(data->pxt, 1);
  if (data->pat)  pat_delete(data->pat);
  if (data->frqs) free(data->frqs);
  return E_NOMEM;               /* free all allocated memory */
}  /* cleanup() */              /* return an error indicator */

/*--------------------------------------------------------------------*/

int ista (TABAG *tabag, int target, SUPP smin, int eval, double thresh,
          int algo, int mode, ISREPORT *report)
{                               /* --- intersecting transactions */
  int      r;                   /* result of function call, buffer */
  ITEM     m, k, z;             /* number of items, buffers */
  TID      n;                   /* number of transactions */
  SUPP     w;                   /* total transaction weight */
  TRACT    *tract;              /* to traverse the transactions */
  const ITEM *items;            /* to access the transaction items */
  const SUPP *ifs;              /* to access the item frequencies */
  size_t   zc, zm;              /* number of tree nodes */
  clock_t  t;                   /* timer for measurements */
  ISTA     a = { 0, NULL, NULL, NULL };  /* ista execution data */

  assert(tabag && report);      /* check the function arguments */
  a.mode = mode;                /* note the processing mode */

  /* --- find closed frequent item sets --- */
  t = clock();                  /* start timer, print log message */
  XMSG(stderr, "intersecting transactions ... ");
  ifs = tbg_ifrqs(tabag, 0);    /* get the item frequencies */
  if (!ifs)  return E_NOMEM;    /* in the transaction bag */
  m = tbg_itemcnt(tabag);       /* get the number of items */
  a.frqs = (SUPP*)malloc((size_t)m *sizeof(SUPP));
  if (!a.frqs) return E_NOMEM;  /* copy the item frequencies */
  memcpy(a.frqs, ifs,    (size_t)m *sizeof(SUPP));
  if (algo == ISTA_PATRICIA) {  /* if to use a patricia tree */
    a.pat = pat_create(m, -1);  /* create a patricia tree */
    if (!a.pat) return cleanup(&a); }
  else {                        /* if to use a prefix tree */
    a.pxt = pxt_create(m, -1, NULL);
    if (!a.pxt) return cleanup(&a);
  }                             /* create a prefix tree */
  n = tbg_cnt(tabag);           /* get the number of transactions */
  for (k = 0; --n >= 0; ) {     /* traverse the transactions */
    tract = tbg_tract(tabag, n);
    items = ta_items(tract); z = ta_size(tract); w = ta_wgt(tract);
    r = (a.pat) ? pat_isect(a.pat, items, z, w, smin, a.frqs)
                : pxt_isect(a.pxt, items, z, w, smin, a.frqs);
    if (r < 0) return cleanup(&a); /* intersect transaction and tree */
    while (*items >= 0)         /* count newly prunable items */
      if ((a.frqs[*items++] -= w) < smin) k++;
    if ((mode & ISTA_PRUNE)     /* if to prune prefix/patricia tree */
    &&  (smin >= 4) && (k > 0) && ((n & 0x0f) == 0x0f)) {
      r = (a.pat) ? pat_prunex(a.pat, smin, a.frqs)
                  : pxt_prunex(a.pxt, smin, a.frqs);
      if (r < 0) return cleanup(&a); /* if item sets could be pruned, */
      k = 0;                    /* prune the prefix/patricia tree and */
    }                           /* clear the prunable item counter */
    if (((n & 0xff) == 0)       /* print number of rem. transactions */
    ||  ((n < 0xff) && ((n & 0x0f) == 0)) || (n <= 0x0f))
      XMSG(stderr, "%12"TID_FMT"\b\b\b\b\b\b\b\b\b\b\b\b", n);
  }
  free(a.frqs); a.frqs = NULL;  /* delete the item frequency array */
  if (a.pat) { zc = pat_nodecnt(a.pat); zm = pat_nodemax(a.pat); }
  else       { zc = pxt_nodecnt(a.pxt); zm = pxt_nodemax(a.pxt); }
  XMSG(stderr, "[%"SIZE_FMT"/%"SIZE_FMT, zc, zm);
  XMSG(stderr, " node(s)] done [%.2fs].\n", SEC_SINCE(t));

  /* --- write closed/maximal frequent item sets --- */
  r = (target & ISR_MAXIMAL) ? 1 : 0;
  if (mode & ISTA_FILTER) r =-r;/* get the maximal item set mode */
  if ((mode & ISTA_PRUNE) && (r < 0)) { /* if to filter with repo. */
    t = clock();                /* start timer, print log message */
    XMSG(stderr, "pruning item set repository ... ");
    if (a.pat) { pat_prune(a.pat, smin);
                 zc = pat_nodecnt(a.pat); zm = pat_nodemax(a.pat); }
    else       { pxt_prune(a.pxt, smin);
                 zc = pxt_nodecnt(a.pxt); zm = pxt_nodemax(a.pxt); }
    XMSG(stderr, "[%"SIZE_FMT"/%"SIZE_FMT, zc, zm);
    XMSG(stderr, " node(s)] done [%.2fs].\n", SEC_SINCE(t));
  }                             /* prune the item set repository */
  t = clock();                  /* start timer, print log message */
  XMSG(stderr, "writing %s ... ", isr_name(report));
  k = (a.pat)                   /* report the found item sets */
    ? pat_report(a.pat, r, smin, report)
    : pxt_report(a.pxt, r, smin, report);
  if (k < 0) return cleanup(&a);/* check for a reporting error */
  XMSG(stderr, "[%"SIZE_FMT" set(s)]", isr_repcnt(report));
  XMSG(stderr, " done [%.2fs].\n", SEC_SINCE(t));
  cleanup(&a);                  /* clean up allocated memory */
  return 0;                     /* return 'ok' */
}  /* ista() */

/*----------------------------------------------------------------------
  Main Functions
----------------------------------------------------------------------*/
#ifdef ISTA_MAIN

static void help (void)
{                               /* --- print add. option information */
  #ifndef QUIET
  fprintf(stderr, "\n");        /* terminate startup message */
  printf("additional evaluation measures (option -e#)\n");
  printf("  x   no measure (default)\n");
  printf("  b   binary logarithm of support quotient\n");
  printf("\n");
  printf("information output format characters (option -v#)\n");
  printf("  %%%%  a percent sign\n");
  printf("  %%a  absolute item set support\n");
  printf("  %%s  relative item set support as a fraction\n");
  printf("  %%S  relative item set support as a percentage\n");
  printf("  %%e  additional evaluation measure\n");
  printf("  %%E  additional evaluation measure as a percentage\n");
  printf("All format characters can be preceded by the number\n");
  printf("of significant digits to be printed (at most 32 digits),\n");
  printf("even though this value is ignored for integer numbers.\n");
  #endif                        /* print help information */
  exit(0);                      /* abort the program */
}  /* help() */

/*--------------------------------------------------------------------*/

static ITEM getbdr (char *s, char **end, double **border)
{                               /* --- get the support border */
  ITEM   i, k;                  /* loop variables */
  double *b;                    /* support border */

  assert(s && end && border);   /* check the function arguments */
  for (i = k = 0; s[i]; i++)    /* traverse the string and */
    if (s[i] == ':') k++;       /* count the number separators */
  *border = b = (double*)malloc((size_t)++k *sizeof(double));
  if (!b) return -1;            /* allocate a support border */
  for (i = 0; i < k; i++) {     /* traverse the parameters */
    b[i] = strtod(s, end);      /* get the next parameter and */
    if (*end == s) break;       /* check for an empty parameter */
    s = *end; if (*s++ != ':') break;
  }                             /* check for a colon */
  if (++i < k)                  /* shrink support array if possible */
    *border = (double*)realloc(b, (size_t)i *sizeof(double));
  return i;                     /* return number of support values */
}  /* getbdr() */

/*--------------------------------------------------------------------*/

static int setbdr (ISREPORT *report, SUPP w, ITEM zmin,
                   double **border, ITEM n)
{                               /* --- set the support border */
  double s;                     /* to traverse the support values */

  assert(report                 /* check the function arguments */
  &&    (w > 0) && (zmin >= 0) && border && (*border || (n <= 0)));
  while (--n >= 0) {            /* traverse the support values */
    s = (*border)[n];           /* transform to absolute count */
    s = ceilsupp((s >= 0) ? 0.01 *s *(double)w *(1-DBL_EPSILON) : -s);
    if (isr_setbdr(report, n+zmin, (RSUPP)s) < 0) return -1;
  }                             /* set support in item set reporter */
  if (*border) { free(*border); *border = NULL; }
  return 0;                     /* return 'ok' */
}  /* setbdr() */

/*--------------------------------------------------------------------*/

#ifndef NDEBUG                  /* if debug version */
  #undef  CLEANUP               /* clean up memory and close files */
  #define CLEANUP \
  if (twrite) twr_delete(twrite, 1); \
  if (report) isr_delete(report, 0); \
  if (tabag)  tbg_delete(tabag,  0); \
  if (tread)  trd_delete(tread,  1); \
  if (ibase)  ib_delete (ibase);     \
  if (border) free(border);
#endif

GENERROR(error, exit)           /* generic error reporting function */

/*--------------------------------------------------------------------*/

int main (int argc, char *argv[])
{                               /* --- main function */
  int     i, k = 0;             /* loop variables, counters */
  char    *s;                   /* to traverse the options */
  CCHAR   **optarg = NULL;      /* option argument */
  CCHAR   *fn_inp  = NULL;      /* name of input  file */
  CCHAR   *fn_out  = NULL;      /* name of output file */
  CCHAR   *fn_sel  = NULL;      /* name of item selection file */
  CCHAR   *fn_psp  = NULL;      /* name of pattern spectrum file */
  CCHAR   *recseps = NULL;      /* record  separators */
  CCHAR   *fldseps = NULL;      /* field   separators */
  CCHAR   *blanks  = NULL;      /* blank   characters */
  CCHAR   *comment = NULL;      /* comment characters */
  CCHAR   *hdr     = "";        /* record header  for output */
  CCHAR   *sep     = " ";       /* item separator for output */
  CCHAR   *dflt    = " (%S)";   /* default format for check */
  CCHAR   *info    = dflt;      /* format for information output */
  int     target   = 'c';       /* target type (closed/maximal) */
  double  supp     = 10;        /* minimum support (in percent) */
  SUPP    smin     = 1;         /* minimum support of an item set */
  ITEM    zmin     = 1;         /* minimum size of an item set */
  ITEM    zmax     = ITEM_MAX;  /* maximum size of an item set */
  int     eval     = 'x';       /* additional evaluation measure */
  double  thresh   = 10;        /* threshold for evaluation measure */
  int     sort     = -2;        /* flag for item sorting and recoding */
  int     algo     = ISTA_PREFIX;  /* variant of IsTa algorithm */
  int     mode     = ISTA_DEFAULT; /* search mode (e.g. filtering) */
  int     mtar     = 0;         /* mode for transaction reading */
  int     scan     = 0;         /* flag for scanable item output */
  int     bdrcnt   = 0;         /* number of support values in border */
  int     stats    = 0;         /* flag for item set statistics */
  PATSPEC *psp;                 /* collected pattern spectrum */
  ITEM    m;                    /* number of items */
  TID     n;                    /* number of transactions */
  SUPP    w;                    /* total transaction weight */
  clock_t t;                    /* timer for measurements */

  #ifndef QUIET                 /* if not quiet version */
  prgname = argv[0];            /* get program name for error msgs. */

  /* --- print usage message --- */
  if (argc > 1) {               /* if arguments are given */
    fprintf(stderr, "%s - %s\n", argv[0], DESCRIPTION);
    fprintf(stderr, VERSION); } /* print a startup message */
  else {                        /* if no arguments given */
    printf("usage: %s [options] infile [outfile]\n", argv[0]);
    printf("%s\n", DESCRIPTION);
    printf("%s\n", VERSION);
    printf("-t#      target type                              "
                    "(default: %c)\n", target);
    printf("         (c: closed item sets, m: maximal item sets)\n");
    printf("-m#      minimum number of items per item set     "
                    "(default: %"ITEM_FMT")\n", zmin);
    printf("-n#      maximum number of items per item set     "
                    "(default: no limit)\n");
    printf("-s#      minimum support of an item set           "
                    "(default: %g%%)\n", supp);
    printf("         (positive: percentage, "
                     "negative: absolute number)\n");
    printf("-e#      additional evaluation measure            "
                    "(default: none)\n");
    printf("-d#      threshold for add. evaluation measure    "
                    "(default: %g%%)\n", thresh);
    printf("-q#      sort items w.r.t. their frequency        "
                    "(default: %d)\n", sort);
    printf("         (1: ascending, -1: descending, 0: do not sort,\n"
           "          2: ascending, -2: descending w.r.t. "
                    "transaction size sum)\n");
    printf("-i       use a patricia tree (or patricia trie)   ");
    printf(         "(default: prefix)\n");
    printf("         (may be faster for very few transactions "
                    "and very many items)\n");
    printf("-p       do not prune the prefix/patricia tree    "
                    "(default: prune)\n");
    printf("-z       filter maximal item sets with repository "
                    "(default: extra)\n");
    printf("         (needs less memory, but is usually slower)\n");
    printf("-F#:#..  support border for filtering item sets   "
                    "(default: none)\n");
    printf("         (list of minimum support values, "
                    "one per item set size,\n");
    printf("         starting at the minimum size, "
                    "as given with option -m#)\n");
    printf("-R#      read an item selection from a file\n");
    printf("-P#      write a pattern spectrum to a file\n");
    printf("-Z       print item set statistics "
                    "(number of item sets per size)\n");
    printf("-g       write output in scanable form "
                    "(quote certain characters)\n");
    printf("-h#      record header  for output                "
                    "(default: \"%s\")\n", hdr);
    printf("-k#      item separator for output                "
                    "(default: \"%s\")\n", sep);
    printf("-v#      output format for item set information   "
                    "(default: \"%s\")\n", info);
    printf("-w       integer transaction weight in last field "
                    "(default: only items)\n");
    printf("-r#      record/transaction separators            "
                    "(default: \"\\n\")\n");
    printf("-f#      field /item        separators            "
                    "(default: \" \\t,\")\n");
    printf("-b#      blank   characters                       "
                    "(default: \" \\t\\r\")\n");
    printf("-C#      comment characters                       "
                    "(default: \"#\")\n");
    printf("-!       print additional option information\n");
    printf("infile   file to read transactions from           "
                    "[required]\n");
    printf("outfile  file to write frequent item sets to      "
                    "[optional]\n");
    return 0;                   /* print a usage message */
  }                             /* and abort the program */
  #endif  /* #ifndef QUIET */
  /* free option characters: acjlouxyz [A-Z]\[CFPRZ] */

  /* --- evaluate arguments --- */
  for (i = 1; i < argc; i++) {  /* traverse arguments */
    s = argv[i];                /* get option argument */
    if (optarg) { *optarg = s; optarg = NULL; continue; }
    if ((*s == '-') && *++s) {  /* -- if argument is an option */
      while (*s) {              /* traverse options */
        switch (*s++) {         /* evaluate switches */
          case '!': help();                          break;
          case 't': target = (*s) ? *s++ : 'c';      break;
          case 'm': zmin   = (ITEM)strtol(s, &s, 0); break;
          case 'n': zmax   = (ITEM)strtol(s, &s, 0); break;
          case 's': supp   =       strtod(s, &s);    break;
          case 'e': eval   = (*s) ? *s++ : 0;        break;
          case 'd': thresh =       strtod(s, &s);    break;
          case 'q': sort   = (int) strtol(s, &s, 0); break;
          case 'i': algo   =  ISTA_PATRICIA;         break;
          case 'p': mode  &= ~ISTA_PRUNE;            break;
          case 'z': mode  |=  ISTA_FILTER;           break;
          case 'F': bdrcnt = getbdr(s, &s, &border); break;
          case 'R': optarg = &fn_sel;                break;
          case 'P': optarg = &fn_psp;                break;
          case 'Z': stats  = 1;                      break;
          case 'g': scan   = 1;                      break;
          case 'h': optarg = &hdr;                   break;
          case 'k': optarg = &sep;                   break;
          case 'v': optarg = &info;                  break;
          case 'w': mtar  |= TA_WEIGHT;              break;
          case 'r': optarg = &recseps;               break;
          case 'f': optarg = &fldseps;               break;
          case 'b': optarg = &blanks;                break;
          case 'C': optarg = &comment;               break;
          default : error(E_OPTION, *--s);           break;
        }                       /* set option variables */
        if (optarg && *s) { *optarg = s; optarg = NULL; break; }
      } }                       /* get option argument */
    else {                      /* -- if argument is no option */
      switch (k++) {            /* evaluate non-options */
        case  0: fn_inp = s;      break;
        case  1: fn_out = s;      break;
        default: error(E_ARGCNT); break;
      }                         /* note filenames */
    }
  }
  if (optarg)       error(E_OPTARG);     /* check option arguments */
  if (k      < 1)   error(E_ARGCNT);     /* and number of arguments */
  if (zmin   < 0)   error(E_SIZE, zmin); /* check the size limits */
  if (zmax   < 0)   error(E_SIZE, zmax); /* and the minimum support */
  if (supp   > 100) error(E_SUPPORT, supp);
  if (bdrcnt < 0)   error(E_NOMEM);
  switch (target) {             /* check and translate target type */
    case 'c': target = ISR_CLOSED;           break;
    case 'm': target = ISR_MAXIMAL;          break;
    default : error(E_TARGET, (char)target); break;
  }                             /* (get target type code) */
  switch (eval) {               /* check and translate measure */
    case 'x': eval = ISTA_NONE;              break;
    case 'b': eval = ISTA_LDRATIO;           break;
    default : error(E_MEASURE, (char)eval);  break;
  }                             /* (get evaluation measure code) */
  if (info == dflt)             /* adapt the default info. format */
    info = (supp < 0) ? " (%a)" : " (%S)";
  thresh *= 0.01;               /* scale the evaluation threshold */
  MSG(stderr, "\n");            /* terminate the startup message */

  /* --- read item selection --- */
  ibase = ib_create(0, 0);      /* create an item base */
  if (!ibase) error(E_NOMEM);   /* to manage the items */
  tread = trd_create();         /* create a transaction reader */
  if (!tread) error(E_NOMEM);   /* and configure the characters */
  trd_allchs(tread, recseps, fldseps, blanks, "", comment);
  if (fn_sel) {                 /* if item appearances are given */
    t = clock();                /* start timer, open input file */
    if (trd_open(tread, NULL, fn_sel) != 0)
      error(E_FOPEN, trd_name(tread));
    MSG(stderr, "reading %s ... ", trd_name(tread));
    m = ib_readsel(ibase,tread);/* read the given item selection */
    if (m < 0) error((int)-m, ib_errmsg(ibase, NULL, 0));
    trd_close(tread);           /* close the input file */
    MSG(stderr, "[%"ITEM_FMT" item(s)]", m);
    MSG(stderr, " done [%.2fs].\n", SEC_SINCE(t));
  }                             /* print a log message */

  /* --- read transaction database --- */
  tabag = tbg_create(ibase);    /* create a transaction bag */
  if (!tabag) error(E_NOMEM);   /* to store the transactions */
  t = clock();                  /* start timer, open input file */
  if (trd_open(tread, NULL, fn_inp) != 0)
    error(E_FOPEN, trd_name(tread));
  MSG(stderr, "reading %s ... ", trd_name(tread));
  k = tbg_read(tabag, tread, mtar);
  if (k < 0) error(-k, tbg_errmsg(tabag, NULL, 0));
  trd_delete(tread, 1);         /* read the transaction database, */
  tread = NULL;                 /* then delete the table reader */
  m = ib_cnt(ibase);            /* get the number of items, */
  n = tbg_cnt(tabag);           /* the number of transactions, */
  w = tbg_wgt(tabag);           /* the total transaction weight */
  MSG(stderr, "[%"ITEM_FMT" item(s), %"TID_FMT, m, n);
  if (w != (SUPP)n) { MSG(stderr, "/%"SUPP_FMT, w); }
  MSG(stderr, " transaction(s)] done [%.2fs].", SEC_SINCE(t));
  if ((m <= 0) || (n <= 0))     /* check for at least one item */
    error(E_NOITEMS);           /* and at least one transaction */
  MSG(stderr, "\n");            /* terminate the log message */
  supp = (supp >= 0) ? 0.01 *supp *(double)w *(1-DBL_EPSILON) : -supp;
  smin = (SUPP)ceilsupp(supp);  /* compute absolute support value */

  /* --- find closed frequent item sets --- */
  mode |= ISTA_VERBOSE|ISTA_NOCLEAN;
  k = ista_data(tabag, target, smin, zmin, eval, algo, mode, sort);
  if (k) error(k);              /* prepare data for IsTa */
  report = isr_create(ibase);   /* create an item set reporter */
  if (!report) error(E_NOMEM);  /* and configure it */
  isr_setsize(report,        zmin, zmax);
  isr_setsupp(report, (RSUPP)smin, RSUPP_MAX);
  if (setbdr(report, w, zmin, &border, bdrcnt) != 0)
    error(E_NOMEM);             /* set the support border */
  if (fn_psp && (isr_addpsp(report, NULL) < 0))
    error(E_NOMEM);             /* set a pattern spectrum if req. */
  if (isr_setfmt(report, scan, hdr, sep, NULL, info) != 0)
    error(E_NOMEM);             /* set the output format strings */
  k = isr_open(report, NULL, fn_out);
  if (k) error(k, isr_name(report)); /* open the item set file */
  if ((ista_repo(report, target, eval, thresh, algo, mode) < 0)
  ||  (isr_setup(report) < 0))  /* prepare reporter for IsTa and */
    error(E_NOMEM);             /* set up the item set reporter */
  k = ista(tabag, target, smin, eval, thresh, algo, mode, report);
  if (k) error(k);              /* find frequent item sets */
  if (stats)                    /* print item set statistics */
    isr_prstats(report, stdout, 0);
  if (isr_close(report) != 0)   /* close item set output file */
    error(E_FWRITE, isr_name(report));

  /* --- write pattern spectrum --- */
  if (fn_psp) {                 /* if to write a pattern spectrum */
    t = clock();                /* start timer, create table write */
    psp    = isr_getpsp(report);/* get the pattern spectrum */
    twrite = twr_create();      /* create a table writer and */
    if (!twrite) error(E_NOMEM);/* open the output file */
    if (twr_open(twrite, NULL, fn_psp) != 0)
      error(E_FOPEN,  twr_name(twrite));
    MSG(stderr, "writing %s ... ", twr_name(twrite));
    if (psp_report(psp, twrite, 1.0) != 0)
      error(E_FWRITE, twr_name(twrite));
    twr_delete(twrite, 1);      /* write the pattern spectrum */
    twrite = NULL;              /* and delete the table writer */
    MSG(stderr, "[%"SIZE_FMT" signature(s)]", psp_sigcnt(psp));
    MSG(stderr, " done [%.2fs].\n", SEC_SINCE(t));
  }                             /* write a log message */

  /* --- clean up --- */
  CLEANUP;                      /* clean up memory and close files */
  SHOWMEM;                      /* show (final) memory usage */
  return 0;                     /* return 'ok' */
}  /* main() */

#endif


text:
PACKAGE="headphones"
DNAME="Headphones"

# Others
INSTALL_DIR="/usr/local/${PACKAGE}"
SSS="/var/packages/${PACKAGE}/scripts/start-stop-status"
PYTHON_DIR="/usr/local/python"
PATH="${INSTALL_DIR}/bin:${INSTALL_DIR}/env/bin:${PYTHON_DIR}/bin:${PATH}"
USER="headphones"
GROUP="users"
VIRTUALENV="${PYTHON_DIR}/bin/virtualenv"
CFG_FILE="${INSTALL_DIR}/var/config.ini"
TMP_DIR="${SYNOPKG_PKGDEST}/../../@tmp"

preinst ()
{
    exit 0
}

postinst ()
{
    # Link
    ln -s ${SYNOPKG_PKGDEST} ${INSTALL_DIR}

    # Create a Python virtualenv
    ${VIRTUALENV} --system-site-packages ${INSTALL_DIR}/env > /dev/null

    # Create user
    adduser -h ${INSTALL_DIR}/var -g "${DNAME} User" -G ${GROUP} -s /bin/sh -S -D ${USER}

    # Correct the files ownership
    chown -R ${USER}:root ${SYNOPKG_PKGDEST}

    exit 0
}

preuninst ()
{
    # Stop the package
    ${SSS} stop > /dev/null

    # Remove the user (if not upgrading)
    if [ "${SYNOPKG_PKG_STATUS}" != "UPGRADE" ]; then
        delgroup ${USER} ${GROUP}
        deluser ${USER}
    fi

    exit 0
}

postuninst ()
{
    # Remove link
    rm -f ${INSTALL_DIR}

    exit 0
}

preupgrade ()
{
    # Stop the package
    ${SSS} stop > /dev/null

    # Save some stuff
    rm -fr ${TMP_DIR}/${PACKAGE}
    mkdir -p ${TMP_DIR}/${PACKAGE}
    mv ${INSTALL_DIR}/var ${TMP_DIR}/${PACKAGE}/

    exit 0
}

postupgrade ()
{
    # Restore some stuff
    rm -fr ${INSTALL_DIR}/var
    mv ${TMP_DIR}/${PACKAGE}/var ${INSTALL_DIR}/
    rm -fr ${TMP_DIR}/${PACKAGE}

    exit 0
}

redpajama_set_name: RedPajamaGithub


text:
module CustomReport
  class Settings < Hash
    def method_missing(name, *args)
      return self[name] if args.length == 0
      self[name] = args.first if args.length == 1
      super
    end
  end
end


text:
<?php
namespace Edge\GraphBundle\Entity;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;

class GraphTickRepository extends EntityRepository
{
    public function findLastTick()
    {
        return $this->findOneBy(array(), array('graphDatetime' => 'DESC'), 1);
    }

    public function findAllAsDataSeries($skipDuplicate = true)
    {
        $ticks = $this->findAll();
        $data = array();
        $prevFunding = 0;

        /** @var \Edge\GraphBundle\Entity\GraphTick $tick */
        foreach($ticks as $tick) {
            $funding = (int)$tick->getGraphFunding();

            if ($funding != $prevFunding || false == $skipDuplicate) {
                $data[] = array($tick->getGraphDatetime()->getTimestamp() * 1000, $funding);
                $prevFunding = $funding;
            }
        }

        return $data;
    }

    private function predictionQuery(\DateTime $dateTime, $period = 5)
    {
        // Get the growth for each day in the dataset
        /** @var EntityManager $em */
        $em = $this->getEntityManager();
        $query = $em->createQuery('SELECT MAX(gt.graphFunding) max_fund, '
        .'MAX (gt.graphFunding) - MIN(gt.graphFunding) growth, DATE(gt.graphDatetime) dateonly '
        .'FROM Edge\GraphBundle\Entity\GraphTick gt WHERE gt.graphDatetime < CURRENT_DATE() '
        .'GROUP BY dateonly ORDER BY dateonly DESC');
        $query->setMaxResults($period);
        $results = $query->getResult();

        return $results;
    }

    public function predictAmountOverTimeAsDataSeries(\DateTime $dateTime, $period)
    {
        $results = $this->predictionQuery($dateTime, $period);

        // Calculate the average growth per day
        $first = reset($results);
        $currentFund =  $first['max_fund'];
        $avg = $first['growth'];
        $pos = 1;

        // Calculate the average
        while($result = next($results)) {
            $avg += $result['growth'];
            $pos++;
        }
        $avg /= $pos;

        // Initialize the variables
        $now = new \DateTime();
        $daysLeft = (int) $now->diff( $dateTime )->format( '%a' );

        $funding = $currentFund;
        $date = $now;
        $interval = new \DateInterval('P1D');
        $ticks = array();

        // Calculate the values 'till perks end
        for($day=0; $day<=$daysLeft; $day++) {
            $funding += $avg;
            $date->add($interval);

            $ticks[] = array(
                $date->getTimestamp() * 1000, $funding
            );
        }

        return $ticks;

    }

    /**
     * Try to the predict the funding, by taking the average growth of
     * each day of the period, and multiplying it by the amount of days left
     * till the end of the perk.
     *
     * @param \DateTime $dateTime The date when the perk ends
     * @param int $period How many days back to analyze
     * @return GraphTick A GraphTick with the estimated funding, and the end date
     */
    public function predictAmountByDaysLeft(\DateTime $dateTime, $period)
    {
        $results = $this->predictionQuery($dateTime, $period);

        // Calculate the average growth per day
        $first = reset($results);
        $currentFund =  $first['max_fund'];
        $avg = $first['growth'];
        $pos = 1;

        while($result = next($results)) {
            $avg += $result['growth'];
            $pos++;
        }

        $avg /= $pos;

        $now = new \DateTime();
        $daysLeft = (int) $now->diff( $dateTime )->format( '%a' );

        $funding = ($avg * $daysLeft) + $currentFund;

        $graphTick = new GraphTick();
        $graphTick->setGraphFunding($funding);
        $graphTick->setGraphDatetime($dateTime);

        return $graphTick;
    }
}


text:
namespace MyGame.Example
{

using global::System;
using global::FlatBuffers;

public struct NestedStruct : IFlatbufferObject
{
  private Struct __p;
  public ByteBuffer ByteBuffer { get { return __p.bb; } }
  public void __init(int _i, ByteBuffer _bb) { __p = new Struct(_i, _bb); }
  public NestedStruct __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }

  public int A(int j) { return __p.bb.GetInt(__p.bb_pos + 0 + j * 4); }
  public void MutateA(int j, int a) { __p.bb.PutInt(__p.bb_pos + 0 + j * 4, a); }
  public MyGame.Example.TestEnum B { get { return (MyGame.Example.TestEnum)__p.bb.GetSbyte(__p.bb_pos + 8); } }
  public void MutateB(MyGame.Example.TestEnum b) { __p.bb.PutSbyte(__p.bb_pos + 8, (sbyte)b); }
  public MyGame.Example.TestEnum C(int j) { return (MyGame.Example.TestEnum)__p.bb.GetSbyte(__p.bb_pos + 9 + j * 1); }
  public void MutateC(int j, MyGame.Example.TestEnum c) { __p.bb.PutSbyte(__p.bb_pos + 9 + j * 1, (sbyte)c); }
  public long D(int j) { return __p.bb.GetLong(__p.bb_pos + 16 + j * 8); }
  public void MutateD(int j, long d) { __p.bb.PutLong(__p.bb_pos + 16 + j * 8, d); }

  public static Offset<MyGame.Example.NestedStruct> CreateNestedStruct(FlatBufferBuilder builder, int[] A, MyGame.Example.TestEnum B, MyGame.Example.TestEnum[] C, long[] D) {
    builder.Prep(8, 32);
    for (int _idx0 = 2; _idx0 > 0; _idx0--) {
      builder.PutLong(D[_idx0-1]);
    }
    builder.Pad(5);
    for (int _idx0 = 2; _idx0 > 0; _idx0--) {
      builder.PutSbyte((sbyte)C[_idx0-1]);
    }
    builder.PutSbyte((sbyte)B);
    for (int _idx0 = 2; _idx0 > 0; _idx0--) {
      builder.PutInt(A[_idx0-1]);
    }
    return new Offset<MyGame.Example.NestedStruct>(builder.Offset);
  }
};

}


text:
from __future__ import absolute_import, print_function, division
import numpy

from .. import jit, typeof, utils, types, numpy_support
from ..typing import npydecl
from ..typing.templates import AbstractTemplate, signature
from ..targets import npyimpl
from . import _internal, ufuncbuilder

class DUFuncKernel(npyimpl._Kernel):
    '''npyimpl._Kernel subclass responsible for lowering a DUFunc kernel
    (element-wise function) inside a broadcast loop (which is
    generated by npyimpl.numpy_ufunc_kernel()).
    '''
    dufunc = None

    def __init__(self, context, builder, outer_sig):
        super(DUFuncKernel, self).__init__(context, builder, outer_sig)
        self.inner_sig, self.cres = self.dufunc.find_ewise_function(
            outer_sig.args)

    def generate(self, *args):
        isig = self.inner_sig
        osig = self.outer_sig
        cast_args = [self.cast(val, inty, outty)
                     for val, inty, outty in zip(args, osig.args, isig.args)]
        if self.cres.objectmode:
            func_type = self.context.call_conv.get_function_type(
                types.pyobject, [types.pyobject] * len(isig.args))
        else:
            func_type = self.context.call_conv.get_function_type(
                isig.return_type, isig.args)
        module = self.builder.block.function.module
        entry_point = module.get_or_insert_function(
            func_type, name=self.cres.fndesc.llvm_func_name)
        entry_point.attributes.add("alwaysinline")
        _, res = self.context.call_conv.call_function(
            self.builder, entry_point, isig.return_type, isig.args, cast_args)
        return self.cast(res, isig.return_type, osig.return_type)

class DUFuncLowerer(object):
    '''Callable class responsible for lowering calls to a specific DUFunc.
    '''
    def __init__(self, _dufunc):
        # Specialize DUFuncKernel for the given dufunc.
        class DUFuncKernel_(DUFuncKernel):
            dufunc = _dufunc

        DUFuncKernel_.__name__ += _dufunc.ufunc.__name__
        self.kernel = DUFuncKernel_
        self.libs = []

    def __call__(self, context, builder, sig, args):
        explicit_output = len(args) > self.kernel.dufunc.ufunc.nin
        return npyimpl.numpy_ufunc_kernel(context, builder, sig, args,
                                          self.kernel,
                                          explicit_output=explicit_output)

class DUFunc(_internal._DUFunc):
    '''Dynamic universal funcion (DUFunc) intended to act like a normal
    Numpy ufunc, but capable of call-time (just-in-time) compilation
    of fast loops specialized to inputs.
    '''
    # NOTE: __base_kwargs must be kept in synch with the kwlist in
    # _internal.c:dufunc_init()
    __base_kwargs = set(('identity', '_keepalive', 'nin', 'nout'))

    def __init__(self, py_func, **kws):
        dispatcher = jit(target='npyufunc')(py_func)
        self.targetoptions = {}
        # Loop over a copy of the keys instead of the keys themselves,
        # since we're changing the dictionary while looping.
        kws_keys = tuple(kws.keys())
        for key in kws_keys:
            if key not in self.__base_kwargs:
                self.targetoptions[key] = kws.pop(key)
        kws['identity'] = ufuncbuilder._BaseUFuncBuilder.parse_identity(
            kws.pop('identity', None))
        super(DUFunc, self).__init__(dispatcher, **kws)
        self._install_type()
        self._lower_me = DUFuncLowerer(self)
        self._install_cg()

    @property
    def nin(self):
        return self.ufunc.nin

    @property
    def nout(self):
        return self.ufunc.nout

    @property
    def nargs(self):
        return self.ufunc.nargs

    @property
    def ntypes(self):
        return self.ufunc.ntypes

    @property
    def types(self):
        return self.ufunc.types

    @property
    def identity(self):
        return self.ufunc.identity

    def _compile_for_args(self, *args, **kws):
        nin = self.ufunc.nin
        args_len = len(args)
        assert (args_len == nin) or (args_len == nin + self.ufunc.nout)
        assert not kws
        argtys = []
        # To avoid a mismatch in how Numba types values as opposed to
        # Numpy, we need to first check for scalars.  For example, on
        # 64-bit systems, numba.typeof(3) => int32, but
        # numpy.array(3).dtype => int64.
        for arg in args[:nin]:
            if numpy_support.is_arrayscalar(arg):
                argtys.append(numpy_support.map_arrayscalar_type(arg))
            else:
                argty = typeof(arg)
                if isinstance(argty, types.Array):
                    argty = argty.dtype
                argtys.append(argty)
        return self._compile_for_argtys(tuple(argtys))

    def _compile_for_argtys(self, argtys):
        """Given a tuple of argument types (these should be the array
        dtypes, and not the array types themselves), compile the
        element-wise function for those inputs, generate a UFunc loop
        wrapper, and register the loop with the Numpy ufunc object for
        this DUFunc.
        """
        cres, argtys, return_type = ufuncbuilder._compile_element_wise_function(
            self._dispatcher, self.targetoptions, argtys)
        actual_sig = ufuncbuilder._finalize_ufunc_signature(
            cres, argtys, return_type)
        dtypenums, ptr, env = ufuncbuilder._build_element_wise_ufunc_wrapper(
            cres, actual_sig)
        self._add_loop(utils.longint(ptr), dtypenums)
        self._keepalive.append((ptr, cres.library, env))
        self._lower_me.libs.append(cres.library)

    def _install_type(self, typingctx=None):
        """Constructs and installs a typing class for a DUFunc object in the
        input typing context.  If no typing context is given, then
        _install_type() installs into the typing context of the
        dispatcher object (should be same default context used by
        jit() and njit()).
        """
        if typingctx is None:
            typingctx = self._dispatcher.targetdescr.typing_context
        _ty_cls = type('DUFuncTyping_' + self.ufunc.__name__,
                       (AbstractTemplate,),
                       dict(key=self, generic=self._type_me))
        typingctx.insert_user_function(self, _ty_cls)

    def find_ewise_function(self, ewise_types):
        """Given a tuple of element-wise argument types, find a matching
        signature in the dispatcher.

        Returns a 2-tuple containing the matching signature, and
        compilation result.  Will return two None's if no matching
        signature was found.
        """
        for sig, cres in self._dispatcher.overloads.items():
            if sig.args == ewise_types:
                return sig, cres
        return None, None

    def _type_me(self, argtys, kwtys):
        """Overloads (defines) AbstractTemplate.generic() for the typing class
        built by DUFunc._install_type().

        Returns the call-site signature after either validating the
        element-wise signature or compiling for it.
        """
        assert not kwtys
        ufunc = self.ufunc
        _handle_inputs_result = npydecl.Numpy_rules_ufunc._handle_inputs(
            ufunc, argtys, kwtys)
        base_types, explicit_outputs, ndims, layout = _handle_inputs_result
        explicit_output_count = len(explicit_outputs)
        if explicit_output_count > 0:
            ewise_types = tuple(base_types[:-len(explicit_outputs)])
        else:
            ewise_types = tuple(base_types)
        sig, cres = self.find_ewise_function(ewise_types)
        if sig is None:
            # Matching element-wise signature was not found; must
            # compile.
            self._compile_for_argtys(ewise_types)
            sig, cres = self.find_ewise_function(ewise_types)
            assert sig is not None
        if explicit_output_count > 0:
            outtys = list(explicit_outputs)
        elif ufunc.nout == 1:
            if ndims > 0:
                outtys = [types.Array(sig.return_type, ndims, layout)]
            else:
                outtys = [sig.return_type]
        else:
            raise NotImplementedError("typing gufuncs (nout > 1)")
        outtys.extend(argtys)
        return signature(*outtys)

    def _install_cg(self, targetctx=None):
        """Constructs and installs a typing class for a DUFunc object in the
        input typing context.  If no typing context is given, then
        _install_type() installs into the typing context of the
        dispatcher object (should be same default context used by
        jit() and njit()).
        """
        if targetctx is None:
            targetctx = self._dispatcher.targetdescr.target_context
        _any = types.Any
        _arr = types.Kind(types.Array)
        sig0 = _any(*((_any,) * self.ufunc.nin + (_arr,) * self.ufunc.nout))
        sig1 = _any(*((_any,) * self.ufunc.nin))
        targetctx.insert_func_defn([(self._lower_me, [
            (self, sig0),
            (self, sig1),
        ])])


text:
package com.integratingfactor.idp.lib.client.config;

import java.util.logging.Logger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
import org.springframework.util.StringUtils;

import com.integratingfactor.idp.lib.client.filter.IdpApiAuthFilter;
import com.integratingfactor.idp.lib.client.filter.IdpOpenIdConnectAuthenticationEntryPoint;
import com.integratingfactor.idp.lib.client.filter.IdpOpenIdConnectAuthenticationFilter;
import com.integratingfactor.idp.lib.client.rbac.IdpRbacService;
import com.integratingfactor.idp.lib.client.util.IdpOauthClient;
import com.integratingfactor.idp.lib.client.util.IdpOpenIdConnectClient;

@Configuration
@EnableWebSecurity
@PropertySource("classpath:idp_client.properties")
public class IdpClientSecurityConfig extends WebSecurityConfigurerAdapter {
    private static Logger LOG = Logger.getLogger(IdpClientSecurityConfig.class.getName());

    @Autowired
    IdpOpenIdConnectAuthenticationEntryPoint authenticationEntryPoint;

    @Autowired
    IdpOpenIdConnectAuthenticationFilter authenticationFilter;

    @Autowired
    IdpClientAuthProperties clientProperties;

    @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

    @Bean
    public IdpRbacService IdpRbacService() {
        LOG.info("Creating instance of IdpRbacService");
        return new IdpRbacService();
    }

    @Bean
    public IdpClientAuthProperties clientAuthProperties() {
        LOG.info("Creating instance of IdpClientAuthProperties");
        return new IdpClientAuthProperties();
    }

    @Bean
    public IdpApiAuthFilter idpApiAuthFilter() {
        LOG.info("Creating instance of IdpApiAuthFilter");
        return new IdpApiAuthFilter();
    }

    @Bean
    public IdpOauthClient idpOauthClient() {
        LOG.info("Creating instance of IdpOauthClient");
        return new IdpOauthClient();
    }

    @Bean
    public IdpOpenIdConnectClient idpOpenIdConnectClient() {
        LOG.info("Creating instance of IdpOpenIdConnectClient");
        return new IdpOpenIdConnectClient();
    }
    /**
     * register an external property place holder
     */
    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

    @Bean
    public IdpOpenIdConnectAuthenticationEntryPoint idpOpenIdConnectAuthenticationEntryPoint() {
        LOG.info("Creating instance of IdpOpenIdConnectAuthenticationEntryPoint");
        return new IdpOpenIdConnectAuthenticationEntryPoint();
    }

    @Bean
    public IdpOpenIdConnectAuthenticationFilter idpOpenIdConnectAuthenticationFilter() {
        LOG.info("Creating instance of IdpOpenIdConnectAuthenticationFilter");
        return new IdpOpenIdConnectAuthenticationFilter();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        String[] whiteListUrls;
        if (clientProperties.getMiscProp("idp.client.api.path") != null) {
            whiteListUrls = StringUtils.commaDelimitedListToStringArray(clientProperties.getAppClientPublicUrls() + ","
                    + clientProperties.getMiscProp("idp.client.api.path"));
        } else {
            whiteListUrls = StringUtils.commaDelimitedListToStringArray(clientProperties.getAppClientPublicUrls());
        }
        LOG.info("Registering authentication on all urls, except: " + whiteListUrls);
        http.authorizeRequests().antMatchers(whiteListUrls).permitAll().anyRequest().authenticated();
        http.csrf().ignoringAntMatchers(whiteListUrls);

        LOG.info("Registering custom AuthenticationEntryPoint: " + authenticationEntryPoint);
        http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint);

        LOG.info("Registering logout url: " + IdpOpenIdConnectClient.pathSuffixLogout);
        http.logout().logoutUrl(IdpOpenIdConnectClient.pathSuffixLogout);

        LOG.info("Registering logout success url: " + "/");
        http.logout().logoutSuccessUrl("/");

        LOG.info("Registering custom AuthenticationFilter: " + authenticationFilter);
        http.addFilterBefore(authenticationFilter, UsernamePasswordAuthenticationFilter.class);
    }

    /**
     * register Spring Security with existing application context
     *
     * @author gnulib
     *
     */
    public static class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {

    }
}


text:
package main

import "fmt"

type gallon float64

func (g gallon) quart() float64 {
	return float64(g * 4)
}

func main() {
	gal := gallon(5)
	fmt.Println(gal.quart())
}


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">

Username
<input type="month" name="my_field" value="2019-04">


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<TITLE>
org.jivesoftware.openfire.transport (Openfire 3.9.3 Javadoc)
</TITLE>

<META NAME="date" CONTENT="2014-05-06">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">

org.jivesoftware.openfire.transport

Classes

TransportHandler


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>
JaxbTypeFactory (Apache XML-RPC 3.1.3 API)
</TITLE>

<META NAME="date" CONTENT="2010-02-06">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">

      Overview
      Package
    Class
      Use
      Tree
      Deprecated
      Index
      Help

 PREV CLASS
 NEXT CLASS

  FRAMES
 NO FRAMES

  All Classes

  SUMMARY: NESTED | FIELD | CONSTR | METHOD

DETAIL: FIELD | CONSTR | METHOD

org.apache.xmlrpc.jaxb

Class JaxbTypeFactory

java.lang.Object
  org.apache.xmlrpc.common.TypeFactoryImpl
      org.apache.xmlrpc.jaxb.JaxbTypeFactory

All Implemented Interfaces:
TypeFactory

public class JaxbTypeFactory
extends TypeFactoryImpl

A type factory with support for JAXB objects.

Constructor Summary

JaxbTypeFactory(XmlRpcController pController,
                javax.xml.bind.JAXBContext pContext)

          Creates a new instance with the given controller and
 JAXB context.

Method Summary

 TypeParser
getParser(XmlRpcStreamConfig pConfig,
          org.apache.ws.commons.util.NamespaceContextImpl pContext,
          java.lang.String pURI,
          java.lang.String pLocalName)

          Creates a parser for a parameter or result object.

 TypeSerializer
getSerializer(XmlRpcStreamConfig pConfig,
              java.lang.Object pObject)

          Creates a serializer for the object pObject.

Methods inherited from class org.apache.xmlrpc.common.TypeFactoryImpl

getController

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

JaxbTypeFactory

public JaxbTypeFactory(XmlRpcController pController,
                       javax.xml.bind.JAXBContext pContext)

Creates a new instance with the given controller and
 JAXB context.

Parameters:
pController - The controller, which will invoke the factory.
pContext - The context being used to create marshallers
 and unmarshallers.

Method Detail

getParser

public TypeParser getParser(XmlRpcStreamConfig pConfig,
                            org.apache.ws.commons.util.NamespaceContextImpl pContext,
                            java.lang.String pURI,
                            java.lang.String pLocalName)

Description copied from interface: TypeFactory

Creates a parser for a parameter or result object.

Specified by:
getParser in interface TypeFactory
Overrides:
getParser in class TypeFactoryImpl

Parameters:
pConfig - The request configuration.
pContext - A namespace context, for looking up prefix mappings.
pURI - The namespace URI of the element containing the parameter or result.
pLocalName - The local name of the element containing the parameter or result.

Returns:
The created parser.

getSerializer

public TypeSerializer getSerializer(XmlRpcStreamConfig pConfig,
                                    java.lang.Object pObject)
                             throws org.xml.sax.SAXException

Description copied from interface: TypeFactory

Creates a serializer for the object pObject.

Specified by:
getSerializer in interface TypeFactory
Overrides:
getSerializer in class TypeFactoryImpl

Parameters:
pConfig - The request configuration.
pObject - The object being serialized.

Returns:
A serializer for pObject.

Throws:

org.xml.sax.SAXException - Creating the serializer failed.

      Overview
      Package
    Class
      Use
      Tree
      Deprecated
      Index
      Help

 PREV CLASS
 NEXT CLASS

  FRAMES
 NO FRAMES

  All Classes

  SUMMARY: NESTED | FIELD | CONSTR | METHOD

DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.


text:
@extends('templates.parent-menu')

@section('title')
	 Biblioteca de PDF'S
@stop

@section('title-baner')
   Biblioteca de PDF'S
@stop

@section('content-parent')

Grados

						<button type="button" class="btn lp-topic-active lp-btnTopic">Matemáticas</button>

						<button type="button" class="btn lp-btnTopic">Robótica</button>

						<button type="button" class="btn btn-info lp-btnTopic">Español</button>

						<button type="button" class="btn btn-info lp-btnTopic">Ciencias</button>

	<button type="button" class="btn btn-primary" id="activeBtn" style="display:none;">Primary</button>

@stop

@section('js-plus')

	{{ HTML::script('/packages/assets/js/parent/library_pdfs.js') }}

@stop


text:
package guitests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import seedu.address.model.AddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.testutil.TestUtil;

public class SampleDataTest extends AddressBookGuiTest {
    @Override
    protected AddressBook getInitialData() {
        // return null to force test app to load data from file only
        return null;
    }

    @Override
    protected String getDataFileLocation() {
        // return a non-existent file location to force test app to load sample data
        return TestUtil.getFilePathInSandboxFolder("SomeFileThatDoesNotExist1234567890.xml");
    }

    @Test
    public void addressBook_dataFileDoesNotExist_loadSampleData() throws Exception {
        Person[] expectedList = SampleDataUtil.getSamplePersons();
        assertTrue(personListPanel.isListMatching(expectedList));
    }
}


text:
from __future__ import print_function, absolute_import, division

import numpy as np
import astropy.units as u
from warnings import warn

from spectral_cube._moments import _moment_shp
from spectral_cube import SpectralCube
from spectral_cube.lower_dimensional_structures import Projection
from spectral_cube.cube_utils import iterator_strategy
from spectral_cube.wcs_utils import drop_axis

# from spectral_cube.np_compat import allbadtonan

'''
Functions for making moment error maps.

Borrows heavily from the functionality in _moments.py from spectral-cube.

Functions require, at minimum, a SpectralCube object and a scale value that
characterizes the noise.
'''

# convenience structures to keep track of the reversed index
# conventions between WCS and numpy
np2wcs = {2: 0, 1: 1, 0: 2}

def moment0_error(cube, scale, axis=0, how='auto'):
    '''
    Compute the zeroth moment error.

    Parameters
    ----------
    cube : SpectralCube
        Data cube.
    scale : SpectralCube or `~astropy.units.Quantity`
        The noise level in the data, either as a single value (with the same
        units as the cube) or a SpectralCube of noise values.
    axis : int
        Axis to compute moment over.
    how : {'auto', 'cube', 'slice'}, optional
        The computational method to use.

    Returns
    -------
    moment0 :  `~spectral_cube.lower_dimensional_structures.Projection`

    '''

    if how == "auto":
        how = iterator_strategy(cube, 0)

        if how == "ray":
            warn("Automatically selected 'ray' which isn't implemented. Using"
                 " 'slice' instead.")
            how = 'slice'

    if how == "cube":
        moment0_err = _cube0(cube, axis, scale)
    elif how == "slice":
        moment0_err = _slice0(cube, axis, scale)
    else:
        raise ValueError("how must be 'cube' or 'slice'.")

    # Multiply by spectral unit
    moment0_err *= cube.spectral_axis.unit

    meta = {'moment_order': 0,
            'moment_axis': axis,
            'moment_method': how}

    cube_meta = cube.meta.copy()
    meta.update(cube_meta)

    new_wcs = drop_axis(cube._wcs, np2wcs[axis])

    return Projection(moment0_err, copy=False, wcs=new_wcs, meta=meta,
                      header=cube._nowcs_header)

def moment1_error(cube, scale, axis=0, how='auto', moment0=None, moment1=None):
    '''
    Compute the first moment error.

    Parameters
    ----------
    cube : SpectralCube
        Data cube.
    scale : SpectralCube or `~astropy.units.Quantity`
        The noise level in the data, either as a single value (with the same
        units as the cube) or a SpectralCube of noise values.
    axis : int
        Axis to compute moment over.
    how : {'auto', 'cube', 'slice'}, optional
        The computational method to use.

    Returns
    -------
    moment1_err :  `~spectral_cube.lower_dimensional_structures.Projection`

    '''

    if how == "auto":
        how = iterator_strategy(cube, 0)

        if how == "ray":
            warn("Automatically selected 'ray' which isn't implemented. Using"
                 " 'slice' instead.")
            how = 'slice'

    # Compute moments if they aren't given.
    if moment0 is None:
        moment0 = cube.moment0(how=how, axis=axis)
    if moment1 is None:
        moment1 = cube.moment1(how=how, axis=axis)

    # Remove velocity offset from centroid to match cube._pix_cen
    # Requires converting to a Quantity
    moment1 = u.Quantity(moment1)
    moment1 -= cube.spectral_axis[0]

    if how == "cube":
        moment1_err = _cube1(cube, axis, scale, moment0, moment1)
    elif how == "slice":
        moment1_err = _slice1(cube, axis, scale, moment0, moment1)
    else:
        raise ValueError("how must be 'cube' or 'slice'.")

    meta = {'moment_order': 1,
            'moment_axis': axis,
            'moment_method': how}

    cube_meta = cube.meta.copy()
    meta.update(cube_meta)

    new_wcs = drop_axis(cube._wcs, np2wcs[axis])

    return Projection(moment1_err, copy=False, wcs=new_wcs, meta=meta,
                      header=cube._nowcs_header)

def moment2_error(cube, scale, axis=0, how='auto', moment0=None, moment1=None,
                  moment2=None, moment1_err=None):
    '''
    Compute the second moment error.

    Parameters
    ----------
    cube : SpectralCube
        Data cube.
    scale : SpectralCube or `~astropy.units.Quantity`
        The noise level in the data, either as a single value (with the same
        units as the cube) or a SpectralCube of noise values.
    axis : int
        Axis to compute moment over.
    how : {'auto', 'cube', 'slice'}, optional
        The computational method to use.

    Returns
    -------
    moment2_err :  `~spectral_cube.lower_dimensional_structures.Projection`

    '''

    if how == "auto":
        how = iterator_strategy(cube, 0)

        if how == "ray":
            warn("Automatically selected 'ray' which isn't implemented. Using"
                 " 'slice' instead.")
            how = 'slice'

    # Compute moments if they aren't given.
    if moment0 is None:
        moment0 = cube.moment0(how='cube', axis=axis)
    if moment1 is None:
        moment1 = cube.moment1(how='cube', axis=axis)

    # Remove velocity offset to match cube._pix_cen
    # Requires converting to a Quantity
    moment1 = u.Quantity(moment1)
    moment1 -= cube.spectral_axis[0]

    if moment2 is None:
        moment2 = cube.moment2(how='cube', axis=axis)
    if moment1_err is None:
        moment1_err = _cube1(cube, axis, scale, moment0=moment0,
                             moment1=moment1)

    if how == "cube":
        moment2_err = _cube2(cube, axis, scale, moment0, moment1, moment2,
                             moment1_err)
    elif how == "slice":
        moment2_err = _slice2(cube, axis, scale, moment0, moment1, moment2,
                              moment1_err)
    else:
        raise ValueError("how must be 'cube' or 'slice'.")

    meta = {'moment_order': 2,
            'moment_axis': axis,
            'moment_method': how}

    cube_meta = cube.meta.copy()
    meta.update(cube_meta)

    new_wcs = drop_axis(cube._wcs, np2wcs[axis])

    return Projection(moment2_err, copy=False, wcs=new_wcs, meta=meta,
                      header=cube._nowcs_header)

def _slice0(cube, axis, scale):
    """
    0th moment along an axis, calculated slicewise

    Parameters
    ----------
    cube : SpectralCube
    axis : int
    scale : float

    Returns
    -------
    moment0_error : array
    """
    if isinstance(scale, SpectralCube):
        # scale should then have the same shape as the cube.
        if cube.shape != scale.shape:
            raise IndexError("When scale is a SpectralCube, it must have the"
                             " same shape as the cube.")
        _scale_cube = True
    else:
        _scale_cube = False

    shp = _moment_shp(cube, axis)
    result = np.zeros(shp) * cube.unit ** 2

    view = [slice(None)] * 3
    valid = np.zeros(shp, dtype=np.bool)

    for i in range(cube.shape[axis]):
        view[axis] = i
        plane = cube._mask.include(data=cube._data, wcs=cube._wcs,
                                   view=tuple(view))
        valid |= plane

        if _scale_cube:
            noise_plane = np.nan_to_num(scale.filled_data[tuple(view)])
        else:
            noise_plane = scale

        result += plane * np.power(noise_plane, 2)

    out_result = np.sqrt(result) * cube._pix_size_slice(axis)
    out_result[~valid] = np.nan

    return out_result

def _slice1(cube, axis, scale, moment0, moment1):
    """
    1st moment along an axis, calculated slicewise

    Parameters
    ----------
    cube : SpectralCube
    axis : int
    scale : float or SpectralCube
    moment0 : 0th moment
    moment1 : 1st moment

    Returns
    -------
    moment1_error : array
    """

    if isinstance(scale, SpectralCube):
        # scale should then have the same shape as the cube.
        if cube.shape != scale.shape:
            raise IndexError("When scale is a SpectralCube, it must have the"
                             " same shape as the cube.")
        _scale_cube = True
    else:
        _scale_cube = False

    # I don't think there is a way to do this with one pass.
    # The first 2 moments always have to be pre-computed.

    # Divide moment0 by the pixel size in the given axis so it represents the
    # sum.
    spec_unit = cube.spectral_axis.unit
    axis_sum = u.Quantity(moment0 /
                          (cube._pix_size_slice(axis) * spec_unit))

    shp = _moment_shp(cube, axis)
    result = np.zeros(shp) * spec_unit ** 2

    view = [slice(None)] * 3
    pix_cen = u.Quantity(cube._pix_cen()[axis] * spec_unit)

    # term2 does not depend on the plane.
    term2 = moment1 / axis_sum

    for i in range(cube.shape[axis]):
        view[axis] = i

        term1 = pix_cen[tuple(view)] / axis_sum

        if _scale_cube:
            noise_plane = \
                np.nan_to_num(scale.filled_data[tuple(view)])
        else:
            noise_plane = scale

        result += np.power((term1 - term2) * noise_plane, 2)

    return np.sqrt(result)

def _slice2(cube, axis, scale, moment0, moment1, moment2,
            moment1_err):
    """
    2nd moment error along an axis, calculated slicewise

    Parameters
    ----------
    cube : SpectralCube
    axis : int
    scale : float or SpectralCube
    moment0 : 0th moment
    moment1 : 1st moment
    moment2 : 2nd moment
    moment1_err : 1st moment error

    Returns
    -------
    moment1_error : array
    """

    if isinstance(scale, SpectralCube):
        # scale should then have the same shape as the cube.
        if cube.shape != scale.shape:
            raise IndexError("When scale is a SpectralCube, it must have the"
                             " same shape as the cube.")
        _scale_cube = True
    else:
        _scale_cube = False

    # Divide moment0 by the pixel size in the given axis so it represents the
    # sum.
    spec_unit = cube.spectral_axis.unit
    axis_sum = u.Quantity(moment0 /
                          (cube._pix_size_slice(axis) * spec_unit))

    shp = _moment_shp(cube, axis)
    term1 = np.zeros(shp) * spec_unit ** 4
    term2 = np.zeros(shp) * spec_unit * cube.unit

    view = [slice(None)] * 3
    pix_cen = cube._pix_cen()[axis] * spec_unit

    # term12 does not depend on plane.
    term12 = moment2 / axis_sum

    for i in range(cube.shape[axis]):
        view[axis] = i
        plane = np.nan_to_num(cube.filled_data[tuple(view)])

        term11 = np.power((pix_cen[tuple(view)] - moment1), 2) / axis_sum

        if _scale_cube:
            noise_plane = \
                np.nan_to_num(scale.filled_data[tuple(view)])
        else:
            noise_plane = scale

        term1 += np.power((term11 - term12) * noise_plane, 2)

        term2 += np.nan_to_num(plane) * (pix_cen[tuple(view)] - moment1)

    term2 = 4 * np.power((moment1_err * term2) / (axis_sum), 2)

    return np.sqrt(term1 + term2)

def _cube0(cube, axis, scale):
    '''
    Moment 0 error computed cube-wise.
    '''

    if isinstance(scale, SpectralCube):
        # scale should then have the same shape as the cube.
        if cube.shape != scale.shape:
            raise IndexError("When scale is a SpectralCube, it must have the"
                             " same shape as the cube.")
        noise_plane = np.nan_to_num(scale.filled_data[:])
    else:
        noise_plane = scale

    error_arr = \
        np.sqrt(
            np.sum(cube._mask.include(data=cube._data, wcs=cube._wcs) *
                   noise_plane**2, axis=axis)) * cube._pix_size_slice(axis)

    return error_arr

def _cube1(cube, axis, scale, moment0, moment1):
    '''
    Moment 1 error computed cube-wise.
    '''

    if isinstance(scale, SpectralCube):
        # scale should then have the same shape as the cube.
        if cube.shape != scale.shape:
            raise IndexError("When scale is a SpectralCube, it must have the"
                             " same shape as the cube.")
        noise_plane = scale.filled_data[:]
    else:
        noise_plane = scale

    # I don't think there is a way to do this with one pass.
    # The first 2 moments always have to be pre-computed.

    # Divide moment0 by the pixel size in the given axis so it represents the
    # sum.
    spec_unit = cube.spectral_axis.unit
    axis_sum = u.Quantity(moment0 /
                          (cube._pix_size_slice(axis) * spec_unit))

    shp = _moment_shp(cube, axis)
    result = np.zeros(shp) * spec_unit

    pix_cen = cube._pix_cen()[axis] * spec_unit

    term1 = pix_cen / axis_sum
    term2 = moment1 / axis_sum

    result = np.sqrt(np.sum(np.power((term1 - term2) *
                                     np.nan_to_num(noise_plane), 2),
                            axis=axis))

    good_pix = np.isfinite(moment0) + np.isfinite(moment1)

    result[~good_pix] = np.NaN

    return result

def _cube2(cube, axis, scale, moment0, moment1, moment2,
           moment1_err):
    '''
    '''

    spec_unit = cube.spectral_axis.unit
    pix_cen = cube._pix_cen()[axis] * spec_unit

    if isinstance(scale, SpectralCube):
        # scale should then have the same shape as the cube.
        if cube.shape != scale.shape:
            raise IndexError("When scale is a SpectralCube, it must have the"
                             " same shape as the cube.")
        noise_plane = np.nan_to_num(scale.filled_data[:])
    else:
        noise_plane = scale

    # Divide moment0 by the pixel size in the given axis so it represents the
    # sum.
    axis_sum = u.Quantity(moment0 /
                          (cube._pix_size_slice(axis) * spec_unit))

    plane = np.nan_to_num(cube.filled_data[:])

    term11 = np.power((pix_cen - moment1), 2) / axis_sum
    term12 = moment2 / axis_sum

    term1 = np.sum(np.power((term11 - term12) * noise_plane, 2), axis=axis)

    term21 = u.Quantity(np.nan_to_num(plane) * (pix_cen - moment1))

    term2 = \
        4 * np.power((moment1_err * np.sum(term21, axis=axis)) / axis_sum, 2)

    result = np.sqrt(term1 + term2)

    good_pix = np.isfinite(moment0) + np.isfinite(moment1) + \
        np.isfinite(moment2)

    result[~good_pix] = np.NaN

    # result[result == 0] = np.NaN

    return result

def linewidth_sigma_err(cube, scale, how='auto', moment0=None, moment1=None,
                        moment2=None, moment1_err=None):
    '''
    Error on the line width.
    '''

    if how == "auto":
        how = iterator_strategy(cube, 0)

    if moment2 is None:
        moment2 = cube.moment2(how=how, axis=0)

    mom2_err = moment2_error(cube, scale, axis=0, how=how,
                             moment0=moment0,
                             moment1=moment1,
                             moment2=moment2,
                             moment1_err=moment1_err)

    return mom2_err / (2 * np.sqrt(moment2))

def linewidth_fwhm_err(cube, scale, how='auto', moment0=None, moment1=None,
                       moment2=None, moment1_err=None):
    '''
    Error on the FWHM line width.
    '''

    SIGMA2FWHM = 2. * np.sqrt(2. * np.log(2.))

    del_lwidth_sig = linewidth_sigma_err(cube, scale, how, moment0, moment1,
                                         moment2, moment1_err)

    return SIGMA2FWHM * del_lwidth_sig


text:
import { JokesResolvers } from "../types/index";

export const Jokes: JokesResolvers.Type = {
  ...JokesResolvers.defaultResolvers,

  byCategory: (parent, args, ctx) => {
    throw new Error("Resolver not implemented");
  },
  byId: (parent, args, ctx) => {
    throw new Error("Resolver not implemented");
  }
};


text:
R-travis
========

A script that faciliates testing R packages with Travis CI.
To test each commit and pull request:

- add the following
[`.travis.yml`](https://github.com/krlmlr/R-travis/blob/master/misc/.travis.yml)
file to the root of your R package on GitHub
- modify as necessary
- don't forget to add `.travis.yml` to `.Rbuildignore`
- [turn on travis](https://travis-ci.org/profile) for your project

```
language: c

env:
  global:
    - RTRAVISPATH=$HOME/r-travis
    - RTRAVISR="" # add custom R code to be executed before installing package
  matrix:
    - RTRAVISTYPE=quick
    - RTRAVISTYPE=full

# install dependencies
install:
  - curl -L https://raw.github.com/krlmlr/R-travis/master/r-travis -o $RTRAVISPATH
  - chmod +x $RTRAVISPATH
  - sudo -E $RTRAVISPATH/r-travis install

# run tests
script:
  - $RTRAVISPATH/r-travis test
```

Two test environments are run:

- A quick check against current R, without building vignettes or the manual
- A full check against stable *and* development versions of R


text:
Each `DevToolsClientImpl` object contains a list of event listeners.
These listeners are called when certain DevTools events occur,
and can run additional code in response to those events.
For example, a listener can listen for page navigation events
in order to keep track of navigation status, while another listener can
keep track of opening and closing of JavaScript dialog boxes, and so on.

(See [Chrome Connection](chrome_connection.md) for more information about
`DevToolsClientImpl` object.)

An event listener must be an object that implements the interface class
[`DevToolsEventListener`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_event_listener.h?q=DevToolsEventListener).
Each listener is called in the following situations:
* When the DevTools Client connects to Chrome.
  ([`ConnectIfNecessary`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_client_impl.cc?q=DevToolsClientImpl::ConnectIfNecessary)
  -> [`EnsureListenersNotifiedOfConnect`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_client_impl.cc?q=DevToolsClientImpl::EnsureListenersNotifiedOfConnect)
  -> [`DevToolsEventListener::OnConnected`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_event_listener.h?q=OnConnected))
* When an event is received from Chrome.
  ([`ProcessEvent`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_client_impl.cc?q=DevToolsClientImpl::ProcessEvent)
  -> [`EnsureListenersNotifiedOfEvent`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_client_impl.cc?q=DevToolsClientImpl::EnsureListenersNotifiedOfEvent)
  -> [`DevToolsEventListener::OnEvent`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_event_listener.h?q=OnEvent))
* When a command response is received from Chrome.
  ([`ProcessCommandResponse`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_client_impl.cc?q=DevToolsClientImpl::ProcessCommandResponse)
  -> [`EnsureListenersNotifiedOfCommandResponse`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_client_impl.cc?q=DevToolsClientImpl::EnsureListenersNotifiedOfCommandResponse)
  -> [`DevToolsEventListener::OnCommandSuccess`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_event_listener.h?q=OnCommandSuccess))

The DevTools Client has three lists to keep track of listeners that still need
to be notified of these three situations:
[`DevToolsClientImpl::unnotified_connect_listeners_`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_client_impl.h?q=DevToolsClientImpl::unnotified_connect_listeners_),
[`DevToolsClientImpl::unnotified_event_listeners_`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_client_impl.h?q=DevToolsClientImpl::unnotified_event_listeners_), and
[`DevToolsClientImpl::unnotified_cmd_response_listeners_`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_client_impl.h?q=DevToolsClientImpl::unnotified_cmd_response_listeners_).
These lists are necessary because while a listener processes one event,
it can trigger the generation of additional events.

The listeners are *not* notified of commands sent from ChromeDriver to DevTools.

## Listener Registration

Each instance of `DevToolsClientImpl` stores a list of listeners in field
[`DevToolsClientImpl::listeners_`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_client_impl.h?q=DevToolsClientImpl::listeners_).
Listeners can be added by calling
[`DevToolsClientImpl::AddListener`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/devtools_client_impl.cc?q=DevToolsClientImpl::AddListener).
* For the browser-wide DevTools client, this is done by
  [`CreateBrowserwideDevToolsClientAndConnect`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome_launcher.cc?q=CreateBrowserwideDevToolsClientAndConnect)
  shortly after Chrome starts.
* For other DevTools clients, this happens in
  [`ChromeImpl::UpdateWebViews`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/chrome_impl.cc?q=ChromeImpl::UpdateWebViews) and
  [`WebViewImpl` constructor](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/web_view_impl.cc?q=WebViewImpl::WebViewImpl).

Most listeners are added indirectly by `WebViewImpl` constructor.
The constructor instantiates several listener objects,
and the constructors for those listener objects are responsible for calling
`DevToolsClientImpl::AddListener` to add themselves.

## Details of Listeners

ChromeDriver has the following event listeners:
* [`CastTracker`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/cast_tracker.h?q=CastTracker)
* [`ConsoleLogger`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/console_logger.h?q=ConsoleLogger)
* [`DebuggerTracker`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/debugger_tracker.h?q=DebuggerTracker)
* [`DevToolsEventsLogger`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/devtools_events_logger.h?q=DevToolsEventsLogger)
* [`DomTracker`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/dom_tracker.h?q=DomTracker)
* [`DownloadDirectoryOverrideManager`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/download_directory_override_manager.h?q=DownloadDirectoryOverrideManager)
* [`FrameTracker`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/frame_tracker.h?q=FrameTracker)
* [`GeolocationOverrideManager`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/geolocation_override_manager.h?q=GeolocationOverrideManager)
* [`HeapSnapshotTaker`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/heap_snapshot_taker.h?q=HeapSnapshotTaker)
* [`JavaScriptDialogManager`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/javascript_dialog_manager.h?q=JavaScriptDialogManager)
* [`MobileEmulationOverrideManager`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/mobile_emulation_override_manager.h?q=MobileEmulationOverrideManager)
* [`NavigationTracker`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/navigation_tracker.h?q=NavigationTracker)
* [`NetworkConditionsOverrideManager`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/network_conditions_override_manager.h?q=NetworkConditionsOverrideManager)
* [`PerformanceLogger`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/performance_logger.h?q=PerformanceLogger)

The listener description below is still incomplete.
More will be added in the future.

### Navigation Tracker

The [`NavigationTracker`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/navigation_tracker.h?q=NavigationTracker)
implements the [wait for navigation to complete](https://www.w3.org/TR/webdriver/#dfn-waiting-for-the-navigation-to-complete)
algorithm defined by the WebDriver standard.
It is used when the
[page loading strategy](https://www.w3.org/TR/webdriver/#dfn-page-loading-strategy)
is [normal](https://www.w3.org/TR/webdriver/#dfn-normal-page-loading-strategy) (the default)
or [eager](https://www.w3.org/TR/webdriver/#dfn-eager-page-loading-strategy).
(When the page loading strategy is
[none](https://www.w3.org/TR/webdriver/#dfn-none-page-loading-strategy),
ChromeDriver uses [`NonBlockingNavigationTracker`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/non_blocking_navigation_tracker.h?q=NonBlockingNavigationTracker),
which is not a DevTools event listener.)

`NavigationTracker` keeps track of the loading state of the current
browsing context (either a window/tab or a frame).
The loading state is represented by
[`enum LoadingState`](https://source.chromium.org/chromium/chromium/src/+/master:chrome/test/chromedriver/chrome/page_load_strategy.h?q=LoadingState),
and can be one of three values: `kUnknown`, `kLoading`, and `kNotLoading`.
`NavigationTracker` moves the loading state between these values based on the
events it receives from Chrome DevTools.
Most ChromeDriver commands wait for the loading state to become `kNotLoading`
before returning.


text:
<?php
namespace Vivo\Indexer;

/**
 * Term
 * Represents a single query term - a word from text.  This is the unit of search.  It is
 * composed of two elements, the text of the word, as a string, and optionally the name of
 * the field that the text occurred in.
 */
class Term
{
    /**
     * Field name
     * @var string
     */
    protected $field;

    /**
     * Term value
     * @var string
     */
    protected $text;

    /**
     * Constructor
     * @param string $text
     * @param string|null $field
     */
    public function __construct($text, $field = null)
    {
        $this->setText($text);
        $this->setField($field);
    }

    /**
     * Sets the field name
     * @param string|null $field
     */
    public function setField($field = null)
    {
        $this->field = $field;
    }

    /**
     * Returns the field name
     * @return string
     */
    public function getField()
    {
        return $this->field;
    }

    /**
     * Sets the term text
     * @param string $text
     */
    public function setText($text)
    {
        $this->text = $text;
    }

    /**
     * Returns the term text
     * @return string
     */
    public function getText()
    {
        return $this->text;
    }
}


text:
package org.xmlcml.ami2.plugins.phylotree;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.xmlcml.ami2.AMIFixtures;
import org.xmlcml.ami2.plugins.phylotree.nexml.NexmlNEXML;
import org.xmlcml.ami2.plugins.phylotree.nexml.NexmlOtu;
import org.xmlcml.graphics.svg.SVGSVG;
import org.xmlcml.norma.editor.EditList;
import org.xmlcml.norma.editor.Extraction;
import org.xmlcml.norma.editor.SubstitutionEditor;
import org.xmlcml.norma.image.ocr.HOCRReader;
import org.xmlcml.xml.XMLUtil;

@Ignore("remove exception for development")
public class LongRunningTests {

	public static final Logger LOG = Logger.getLogger(LongRunningTests.class);
	static {
		LOG.setLevel(Level.DEBUG);
	}

	public final static String SUFFIX = ".pbm.png";
	@Test
	public void testImage2Nexml() throws IOException {
		File phyloDir = new File("src/test/resources/org/xmlcml/ami2/phylo/50images/");
		Assert.assertTrue("file exists "+phyloDir, phyloDir.exists() );
		Assert.assertTrue("file is dir "+phyloDir, phyloDir.isDirectory());
		List<File> images = new ArrayList<File>(FileUtils.listFiles(phyloDir, new String[]{"png"}, false));
		for (File image : images) {
			String name = image.getName();
			name = name.substring(0,  name.length() - SUFFIX.length());
			runPhyloEditing2Nexml(phyloDir, name);
		}
}

	private void runPhyloEditing2Nexml(File phyloDir, String name) throws IOException,
			FileNotFoundException {
		LOG.debug("============="+name+"=============");
//		CMDir cmDir = new CMDir(new File(AMIFixtures.TEST_PHYLO_DIR, name));
		File normaTemp = new File("target/phylo/"+name+"/");
		FileUtils.copyFile(new File(phyloDir, name+SUFFIX), new File(normaTemp, "image/"+name+SUFFIX));
//		cmDir.copyTo(normaTemp, true);
		String cmd = "--ph.phylo -q target/phylo/"+name+
				" -i image/"+name+".pbm.png"+
				" --log"+
				" --ph.specpattern ijsemSpeciesEditor.xml"+
				" --ph.hocr.html image/"+name+".hocr.html"+
				" --ph.hocr.svg image/"+name+".hocr.svg"+
				" --ph.nexml image/"+name+".nexml.xml"+
				"";
		PhyloTreePlugin phyloPlugin = new PhyloTreePlugin(cmd);
		PhyloTreeArgProcessor phyloTreeArgProcessor = (PhyloTreeArgProcessor)phyloPlugin.getArgProcessor();
		phyloPlugin.runAndOutput();
		NexmlNEXML nexml = phyloTreeArgProcessor.getNexml();

		SubstitutionEditor substitutionEditor = new SubstitutionEditor();
		substitutionEditor.addEditor(phyloTreeArgProcessor.getSpeciesPatternInputStream());
		List<NexmlOtu> otuList = nexml.getSingleOtusElement().getNexmlOtuList();
		nexml.getSingleOtusElement().addNamespaceDeclaration(PhyloConstants.CM_PHYLO_PREFIX, PhyloConstants.CM_PHYLO_NS);
		for (NexmlOtu otu : otuList) {
			String value = otu.getValue();
			String editedValue = substitutionEditor.createEditedValueAndRecord(value);
			List<Extraction> extractionList = substitutionEditor.getExtractionList();
			phyloTreeArgProcessor.annotateOtuWithEditRecord(otu, substitutionEditor.getEditRecord());
			phyloTreeArgProcessor.annotateOtuWithExtractions(otu, extractionList);
			LOG.trace(">otu>"+otu.toXML());
//			if (substitutionEditor.validate(extractionList)) {
			if (substitutionEditor.validate(editedValue)) {
				EditList editRecord = substitutionEditor.getEditRecord();
				otu.setEditRecord(editRecord.toString());
				LOG.debug("validated: "+value+" => "+editedValue+((editRecord == null || editRecord.size() == 0) ? "" :"; "+editRecord));
			} else {
				LOG.debug("failed validate: "+value);
			}
		}
		LOG.trace(nexml.toXML());
		normaTemp.mkdirs();
		XMLUtil.debug(nexml, new FileOutputStream(new File(normaTemp, name+".edited.nexml.xml")), 1);
	}

	@Test
	//	@Ignore("too many")
		public void testConvertLabelsAndTreeAndMerge() throws Exception {

			for (String root : MergeTipTest.ROOTS) {
				try {
					LOG.debug(root);
					File infile = new File(AMIFixtures.TEST_PHYLO_DIR, "15goodtree/"+root+MergeTipTest.PBM_PNG);
					org.apache.commons.io.FileUtils.copyFile(infile, new File(MergeTipTest.X15GOODTREE+root+MergeTipTest.PNG));
					PhyloTreeArgProcessor phyloTreeArgProcessor = new PhyloTreeArgProcessor();
					phyloTreeArgProcessor.setSpeciesPattern(MergeTipTest.IJSEM);
					phyloTreeArgProcessor.setOutputRoot(root);
					phyloTreeArgProcessor.setOutputDir(new File("target/phylo/combined/15goodtree/"));
					if (!phyloTreeArgProcessor.mergeOCRAndPixelTree(infile)) continue; // tesseract failure
					NexmlNEXML nexml = phyloTreeArgProcessor.getNexml();
					new File(MergeTipTest.X15GOODTREE).mkdirs();
					XMLUtil.debug(nexml, new FileOutputStream(MergeTipTest.X15GOODTREE+root+".nexml.xml"), 1);
					FileUtils.write(new File(MergeTipTest.X15GOODTREE+root+".nwk"), nexml.createNewick());
					XMLUtil.debug(nexml.createSVG(), new FileOutputStream(MergeTipTest.X15GOODTREE+root+".svg"), 1);
					HOCRReader hocrReader = phyloTreeArgProcessor.getOrCreateHOCRReader();
					SVGSVG.wrapAndWriteAsSVG(hocrReader.getOrCreateSVG(), new File(MergeTipTest.X15GOODTREE+root+".words.svg"));
				} catch (Exception e) {
					LOG.debug("error in conversion");
					e.printStackTrace();
				}

			}
		}
}


text: {{nav.title}}


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>B-Index</title>
<meta name="date" content="2016-12-12">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">

JavaScript is disabled on your browser.

Skip navigation links

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev Letter

Next Letter

Frames

No Frames

All Classes

A B C D E F G H I K L M N O P R S T U V W X Y Z

B

BackgroundTile - Class in org.plexian.grumy.tile

BackgroundTile() - Constructor for class org.plexian.grumy.tile.BackgroundTile

bind() - Method in class org.plexian.grumy.opengl.SpriteSheet

Bind the spritesheet to OpenGL.

bind() - Method in class org.plexian.grumy.opengl.Texture

Tell OpenGL to bind the texture, essencially allowing you to use the texture.

BLACK - Static variable in class org.plexian.grumy.opengl.RGBA

BLUE - Static variable in class org.plexian.grumy.opengl.RGBA

build() - Method in class org.plexian.grumy.world.Chunk

Build the chunk's tiles array.

A B C D E F G H I K L M N O P R S T U V W X Y Z

Skip navigation links

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev Letter

Next Letter

Frames

No Frames

All Classes