コード例 #1
0
ファイル: preparation.c プロジェクト: asajadi/UniLinkParser
void build_deletable(Sentence sent, int has_conjunction) {
/* Initialize the array deletable[i][j] to indicate if the words           */
/* i+1...j-1 could be non existant in one of the multiple linkages.  This  */
/* array is used in conjunction_prune and power_prune.  Regions of length  */
/* 0 are always deletable.  A region of length two with a conjunction at   */
/* one end is always deletable.  Another observation is that for the       */
/* comma to form the right end of a deletable region, it must be the case  */
/* that there is a conjunction to the right of the comma.  Also, when      */
/* considering deletable regions with a comma on their left sides, there   */
/* must be a conjunction inside the region to be deleted. Finally, the     */
/* words "either", "neither", "both", "not" and "not only" are all         */
/* deletable.                                                              */
   
    int i,j,k;

    free_deletable(sent);
    assert(sent->length < MAX_SENTENCE, "sent->length too big");

    sent->deletable = (char **) xalloc((sent->length+1)*sizeof(char *));
    sent->deletable++;  /* we need to be able to access the [-1] position in this array */

    for (i = -1; i<sent->length; i++) {
	sent->deletable[i] = (char *) xalloc(sent->length+1);  
	/* the +1 is to allow us to have the info for the last word
	   read the comment above */
	for (j=0; j<= sent->length; j++) {
	    if (j == i+1) {
		sent->deletable[i][j] = TRUE;
	    } else if (null_links) {
		sent->deletable[i][j] = TRUE;
	    } else if (!has_conjunction) {
		sent->deletable[i][j] = FALSE;
	    } else if ((j>i+2)&&(sent->is_conjunction[i+1] || 
				 sent->is_conjunction[j-1] ||
                                (strcmp(",",sent->word[i+1].string)==0 && 
				 conj_in_range(sent, i+2,j-1)) ||
 	                        (strcmp(",",sent->word[j-1].string)==0 && 
				 conj_in_range(sent, j,sent->length-1)))){
		sent->deletable[i][j] = TRUE;
	    } else if (j > i) {
		for (k=i+1; k<j; k++) {
		    if ((strcmp("either", sent->word[k].string) == 0) ||
			(strcmp("neither", sent->word[k].string) == 0) ||
			(strcmp("both", sent->word[k].string) == 0) ||
			(strcmp("not", sent->word[k].string) == 0)) continue;
		    if ((strcmp("only", sent->word[k].string)==0) && (k > i+1) &&
                                   (strcmp("not", sent->word[k-1].string)==0)) continue;
		    break;
		}
		sent->deletable[i][j] = (k==j);
	    } else {
		sent->deletable[i][j] = FALSE;
	    }
	}
    }
}
コード例 #2
0
ファイル: api.c プロジェクト: mclumd/Alfred
void sentence_delete(Sentence sent) {

  /*free_andlists(sent); */
    free_sentence_disjuncts(sent);      
    free_sentence_expressions(sent);
    string_set_delete(sent->string_set);
    free_parse_set(sent);
    free_post_processing(sent);
    post_process_close_sentence(sent->dict->postprocessor);
    free_lookup_list();
    free_deletable(sent);
    free_effective_dist(sent);
    xfree(sent->is_conjunction, sizeof(char)*sent->length);
    xfree((char *) sent, sizeof(struct Sentence_s));
}