コード例 #1
0
ファイル: rcqpCommands.c プロジェクト: rforge/rcwb
/* 
 * ------------------------------------------------------------------------
 * 
 * "rcqpCmd_query(SEXP inMother, SEXP inChild, SEXP inQuery)" --
 * 
 *  
 * 
 * ------------------------------------------------------------------------
 */
SEXP rcqpCmd_query(SEXP inMother, SEXP inChild, SEXP inQuery)
{
	SEXP			result = R_NilValue;
	char			*child, *mother, *query, *c, *sc;
	
	if (!isString(inMother) || length(inMother) != 1) error("invalid corpus name");
	if (!isString(inChild) || length(inChild) != 1) error("invalid subcorpus name");
	if (!isString(inQuery) || length(inQuery) != 1) error("invalid query name");
	
	PROTECT(inMother);
	PROTECT(inChild);
	PROTECT(inQuery);

	mother = (char*)CHAR(STRING_ELT(inMother,0));
	child = (char*)CHAR(STRING_ELT(inChild,0));
	query = (char*)CHAR(STRING_ELT(inQuery,0));
	
	if (!split_subcorpus_spec(mother, &c, &sc)) {
		rcqp_error_code(cqi_errno);
	} else {
		char *cqp_query;
		int len = strlen(child) + strlen(query) + 10;
		
		cqp_query = (char *) cl_malloc(len);
		if (!check_subcorpus_name(child) || !cqi_activate_corpus(mother)) {
			rcqp_error_code(cqi_errno);
		} else {
			query_lock = floor(1e9 * cl_runif()) + 1; /* activate query lock mode with random key */
			
			if (rcqp_query_has_semicolon(query)) {
				sprintf(cqp_query, "%s = %s", child, query);
			} else {
				sprintf(cqp_query, "%s = %s;", child, query);
			}
			
			if (!cqp_parse_string(cqp_query)) {
				rcqp_error_code(CQI_CQP_ERROR_GENERAL); /* should be changed to detailed error messages */
			} else {
				char *			full_child;
				CorpusList *	childcl;
				
				full_child = combine_subcorpus_spec(c, child); /* c is the 'physical' part of the mother corpus */
				childcl = cqi_find_corpus(full_child);
				if ((childcl) == NULL) {
					rcqp_error_code(CQI_CQP_ERROR_GENERAL);
				} 
				free(full_child);
			}			
			query_lock = 0;           /* deactivate query lock mode */
		}
		free(cqp_query);
	}
	free(c);
	free(sc);
	
	UNPROTECT(3);
	
	return result;
}
コード例 #2
0
ファイル: cqpserver.c プロジェクト: cran/rcqp
void 
do_cqi_cqp_query(void)
{
  char *child, *mother, *query, *c, *sc;
  
  mother = cqi_read_string();
  child = cqi_read_string();
  query = cqi_read_string();
  if (server_debug) 
   Rprintf( "CQi: CQI_CQP_QUERY('%s', '%s', '%s')\n", mother, child, query);
  if (!split_subcorpus_spec(mother, &c, &sc)) {
    cqi_command(cqi_errno);
  }
  else {
    char *cqp_query;
    int len = strlen(child) + strlen(query) + 10;
    
    cqp_query = (char *) cl_malloc(len);
    if (!check_subcorpus_name(child) || !cqi_activate_corpus(mother)) {
      cqi_command(cqi_errno);
    }
    else {
      query_lock = floor(1e9 * cl_runif()) + 1; /* activate query lock mode with random key */

     Rprintf("CQPSERVER: query_lock = %d\n", query_lock);
      if (query_has_semicolon(query))
        sprintf(cqp_query, "%s = %s", child, query);
      else
        sprintf(cqp_query, "%s = %s;", child, query);
      if (!cqp_parse_string(cqp_query))
        cqi_command(CQI_CQP_ERROR_GENERAL); /* should be changed to detailed error messages */
      else {
        char *full_child;
        CorpusList *childcl;
        
        full_child = combine_subcorpus_spec(c, child); /* c is the 'physical' part of the mother corpus */
        childcl = cqi_find_corpus(full_child);
        if ((childcl) == NULL)
          cqi_command(CQI_CQP_ERROR_GENERAL);
        else {
          if (server_log) {
           Rprintf("'%s' ran the following query on %s\n", user, mother);
           Rprintf("\t%s\n", cqp_query);
           Rprintf("and got %d matches.\n", childcl->size);
          }
          cqi_command(CQI_STATUS_OK);

        }
        free(full_child);
      }

      query_lock = 0;           /* deactivate query lock mode */
    }
    free(cqp_query);
  }
  free(c);
  free(sc);
}