예제 #1
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));
}
예제 #2
0
void build_effective_dist(Sentence sent, int has_conjunction) {
  /*
    The "effective distance" between two words is the actual distance minus
    the largest deletable region strictly between the two words.  If the
    effective distance between two words is greater than a connector's max
    link length, then that connector cannot be satisfied by linking these
    two words.

    [Note: The effective distance is not monotically increasing as you move
    away from a word.]

    This function creates effective_dist[][].  It assumes that deleteble[][]
    has already been computed.

    Dynamic programming is used to compute this.  The order used is smallest
    region to largest.

    Just as deletable[i][j] is constructed for j=N_words (which is one
    off the end of the sentence) we do that for effective_dist[][].
  */

    int i, j, diff;

    free_effective_dist(sent);
    sent->effective_dist = (char **) xalloc((sent->length)*sizeof(char *));

    for (i=0; i<sent->length; i++) {
	sent->effective_dist[i] = (char *) xalloc(sent->length+1);
    }
    for (i=0; i<sent->length; i++) {  
	/* Fill in the silly part */
	for (j=0; j<=i; j++) {
	    sent->effective_dist[i][j] = j-i;
	}
    }

    /* what is the rationale for ignoring the effective_dist 
       if null links are allowed? */
    if (null_links) {  
	for (i=0; i<sent->length; i++) {  
	    for (j=0; j<=sent->length; j++) {
		sent->effective_dist[i][j] = j-i;
	    }
	}
    } 
    else {
	for (diff = 1; diff < sent->length; diff++) {
	    for (i=0; i+diff <= sent->length; i++) {
		j = i+diff;
		if (sent->deletable[i][j]) {  /* note that deletable[x][x+1] is TRUE */
		    sent->effective_dist[i][j] = 1;		    
		} else {
		    sent->effective_dist[i][j] = 1 + MIN(sent->effective_dist[i][j-1],sent->effective_dist[i+1][j]);
		}
	    }
	}

	/* now when you link to a conjunction, your effective length is 1 */

	for (i=0; i<sent->length; i++) {  
	    for (j=i+1; j<sent->length; j++) {
		if (sent->is_conjunction[i] || 
		    sent->is_conjunction[j]) sent->effective_dist[i][j] = 1;
	    }
	}
    }

    /* sent->effective_dist[i][i] should be 0 */

    /*      
    for (j=0; j<=sent->length; j++) {
      printf("%4d", j);
    }
    printf("\n");
    for (i=0; i<sent->length; i++) {  
      for (j=0; j<=sent->length; j++) {
	printf("%4d", sent->effective_dist[i][j]);
      }
      printf("\n");
    }
    */
}