Alt-CWB-CL-ambs

 view release on metacpan or  search on metacpan

CL.xs  view on Meta::CPAN

      return CDA_ENYI;
    if (strEQ(name, "CDA_EOTHER"))
      return CDA_EOTHER;
    if (strEQ(name, "CDA_EPATTERN"))
      return CDA_EPATTERN;
    if (strEQ(name, "CDA_EPOSORNG"))
      return CDA_EPOSORNG;
    if (strEQ(name, "CDA_EREMOTE"))
      return CDA_EREMOTE;
    if (strEQ(name, "CDA_ESTRUC"))
      return CDA_ESTRUC;
    if (strEQ(name, "CDA_OK"))
      return CDA_OK;
    break;
  case 'I':
    if (strEQ(name, "IGNORE_CASE")) /* regexp flags */
      return IGNORE_CASE;
    if (strEQ(name, "IGNORE_DIAC")) 
      return IGNORE_DIAC;
    if (strEQ(name, "IGNORE_REGEX"))
      return IGNORE_REGEX;
    break;
  case 'S':
    if (strEQ(name, "STRUC_INSIDE")) /* s-attribute region boundaries */
      return STRUC_INSIDE;
    if (strEQ(name, "STRUC_LBOUND")) 
      return STRUC_LBOUND;
    if (strEQ(name, "STRUC_RBOUND")) 
      return STRUC_RBOUND;    
  default:
    errno = EINVAL;
    return 0;
  }
}

/*
  ********* XS segment (preamble) **********
*/ 

MODULE = CWB::CL        PACKAGE = CWB::CL       

PROTOTYPES: ENABLE

const char *
cwb_cl_error_message(error_code)
    int error_code

const char *
error_message() 
  PREINIT:
    int error_code;
  CODE:
    /* return string with last CL error encountered in last method call ("" if last call was successful) */
    error_code = (last_cl_error != CDA_OK) ? last_cl_error : cderrno; /* after simple function invocation, use CL library error status */
    if (error_code == CDA_OK) {
      RETVAL = "";
    }
    else {
      RETVAL = cwb_cl_error_message(error_code); /* returns pointer to string constant */
    }
  OUTPUT:
    RETVAL

void
set_strict_mode(on_off)
    int on_off
  CODE:
    strict_mode = on_off;

int
get_strict_mode()
  CODE:
    RETVAL = strict_mode;
  OUTPUT:
    RETVAL

double
constant(name)
    char *  name

Corpus *
cl_new_corpus(registry_dir, registry_name)
    char *  registry_dir
    char *  registry_name
  INIT:
    last_cl_error = CDA_OK;

int
cl_delete_corpus(corpus)
    Corpus *    corpus

char *
cl_standard_registry()
  INIT:
    last_cl_error = CDA_OK;

void
cl_set_debug_level(level)
    int   level
  INIT:
    last_cl_error = CDA_OK;

void
cl_set_memory_limit(megabytes)
    int   megabytes
  INIT:
    last_cl_error = CDA_OK;

char *
cl_make_set(s, split="")
    char *  s
    char *  split
  PREINIT:
    char *set;
    int split_mode;
  PPCODE:
    last_cl_error = CDA_OK;
    if (split == NULL || (split[0] != '\0' && split[0] != 's'))
      croak("Usage:  $feature_set = CWB::CL::make_set($string [, 'split' | 's']);");
    split_mode = (split[0] == 's');
    set = cl_make_set(s, split_mode);
    if (set != NULL) {
      XPUSHs(sv_2mortal(newSVpv(set, 0)));  /* create Perl string (let Perl compute length) */
      free(set);  /* <set> was allocated by cl_make_set, so free it again */
    }   
    else {
      last_cl_error = cderrno;
      if (strict_mode)
        croak_on_error(last_cl_error);
      XSRETURN_UNDEF;  /* else return undefined value */
    }

char *
cl_set_intersection(s1, s2)
    char *  s1
    char *  s2
  PREINIT:
    static char result[CL_DYN_STRING_SIZE];  /* static buffer for results string */
    int ok;
  PPCODE:
    last_cl_error = CDA_OK;
    ok = cl_set_intersection(result, s1, s2);
    if (ok) {
      XPUSHs(sv_2mortal(newSVpv(result, 0)));  /* create Perl string (let Perl compute length) */
    }
    else {
      last_cl_error = cderrno;
      if (strict_mode)
        croak_on_error(last_cl_error);
      XSRETURN_UNDEF;  /* return undefined value */
    }

int
cl_set_size(s)
    char *  s
  PREINIT:
    int size;
  CODE:
    last_cl_error = CDA_OK;
    size = cl_set_size(s);
    if (size >= 0) {
      RETVAL = size;
    }
    else {
      last_cl_error = cderrno;
      if (strict_mode)
        croak_on_error(last_cl_error);
      XSRETURN_UNDEF;  /* return undefined value */
    }
  OUTPUT:
    RETVAL

Attribute *
cl_new_attribute(corpus, attribute_name, type)
    Corpus *    corpus
    char *  attribute_name
    int   type
  INIT:
    last_cl_error = CDA_OK;

int
cl_delete_attribute(attribute)
    Attribute *   attribute
  INIT:
    last_cl_error = CDA_OK;

int
cl_max_cpos(attribute)
    PosAttrib   attribute
  INIT:
    last_cl_error = CDA_OK;

int
cl_max_id(attribute)
    PosAttrib   attribute
  INIT:
    last_cl_error = CDA_OK;

void
cl_id2str(attribute, ...)
    PosAttrib   attribute
  PREINIT:
    int i, id, size;
    char *s;
    SV *id_arg;
  PPCODE:
    last_cl_error = CDA_OK;
    size = items - 1;
    if (size > 0) {
      EXTEND(sp, size);
      for (i = 0; i < size; i++) {
        id_arg = ST(i+1);
        if (!SvOK(id_arg)) {
          last_cl_error = CWB_CL_INVALID_ARG;
          PUSHs(sv_newmortal()); /* undef ID arguments return undef */
        }
        else {
          id = (int) SvIV(id_arg);
          s = cl_id2str(attribute, id);
          if (s) {
            PUSHs(sv_2mortal(newSVpv(s, 0)));
          }
          else {
            last_cl_error = cderrno;
            PUSHs(sv_newmortal()); /* all errors are turned into undefs */
          }
        }
      }
      if (strict_mode && last_cl_error != CDA_OK)
        croak_on_error(last_cl_error);

CL.xs  view on Meta::CPAN

    PosAttrib   attribute
    char *  pattern
    int   canonicalize
  PREINIT:
    int number_of_matches = 0;
    int *idlist;
    int i;
  PPCODE:
    last_cl_error = CDA_OK;
    idlist = cl_regex2id(attribute, pattern, canonicalize, &number_of_matches);
    if (idlist != NULL) {
      EXTEND(sp, number_of_matches); /* push IDs on result stack */
      for (i=0; i < number_of_matches; i++)
        PUSHs(sv_2mortal(newSViv(idlist[i])));
      free(idlist);
    }
    else {
      if (strict_mode && cderrno != CDA_OK)
        croak_on_error(cderrno);
    }
    /* else return empty list */ 

int
cl_idlist2freq(attribute, ...)
    PosAttrib   attribute
  PREINIT:
    int i, size, errors;
    int *list;
  CODE:
    last_cl_error = CDA_OK;
    size = items - 1;
    if (size > 0) {
      Newx(list, size, int); /* convert argument list to list of integer IDs */
      if (!list)
        croak("Can't allocate temporary array for %d integers", size);
      errors = 0;
      for (i = 0; i < size; i++) {
        if (SvOK(ST(i+1)))
          list[i] = (int) SvIV(ST(i+1));
        else
          errors++;
      }
      if (errors) {
        RETVAL = -1;
        last_cl_error = CWB_CL_INVALID_ARG;
      }
      else {
        RETVAL = cl_idlist2freq(attribute, list, size);
        if (RETVAL < 0)
          last_cl_error = cderrno;
      }
      Safefree(list);
      if (strict_mode && last_cl_error != CDA_OK)
        croak_on_error(last_cl_error);
      if (RETVAL < 0)
        XSRETURN_UNDEF;
    }
    else {
      RETVAL = 0;
    }
  OUTPUT:
    RETVAL

void
cl_idlist2cpos(attribute, ...)
    PosAttrib   attribute
  PREINIT:
    int i, id, idlist_size, size, errors;
    int *idlist, *list;
  PPCODE:
    last_cl_error = CDA_OK;
    idlist_size = items - 1;
    if (idlist_size > 0) {
      Newx(idlist, idlist_size, int); /* convert argument list to list of integer IDs */
      if (!idlist)
        croak("Can't allocate temporary array of size %d in idlist2cpos() method\n", idlist_size);
      for (i = 0; i < idlist_size; i++) {
        if (SvOK(ST(i+1)))
          idlist[i] = (int) SvIV(ST(i+1));
        else {
          last_cl_error = CWB_CL_INVALID_ARG;
          break;
        }
      }
      if (last_cl_error != CDA_OK) {
        Safefree(idlist);
        if (strict_mode)
          croak_on_error(last_cl_error);
        /* else return empty list to indicate error condition (valid IDs would never return empty list) */
      }
      else {
        if (idlist_size > 1)
          list = cl_idlist2cpos(attribute, idlist, idlist_size, /* sorted */ 1, &size);
        else
          list = cl_id2cpos(attribute, idlist[0], &size); /* should be more efficient for single ID */
        Safefree(idlist);
        if (list) {
          EXTEND(sp, size);
          for (i=0; i < size; i++)
            PUSHs(sv_2mortal(newSViv(list[i])));
          free(list);
        }
        else {
          last_cl_error = cderrno;
          if (strict_mode)
            croak_on_error(last_cl_error);
          /* else return empty list to indicate error condition */
        }
      }
    }
    /* else return empty list */


int
cl_struc_values(attribute)
    Attribute *   attribute
  INIT:
    last_cl_error = CDA_OK;

int
cl_max_struc(attribute)



( run in 0.914 second using v1.01-cache-2.11-cpan-98e64b0badf )