Beispiel #1
0
/**
 *  dict_display_word_info() - display the information about the given word.
 */
void dict_display_word_info(Dictionary dict, const char * s)
{
	Dict_node *dn, *dn_head;
	Disjunct * d1, * d2;
	int len;
	dn_head = dictionary_lookup_list(dict, s);
	if (dn_head == NULL)
	{
		printf("	\"%s\" matches nothing in the dictionary.\n", s);
		return;
	}
	printf("Matches:\n");
	for (dn = dn_head; dn != NULL; dn = dn->right)
	{
		len = 0;
		d1 = build_disjuncts_for_dict_node(dn);
		for(d2 = d1 ; d2 != NULL; d2 = d2->next)
		{
			len++;
		}
		free_disjuncts(d1);
		printf("    ");
		left_print_string(stdout, dn->string,
			"                         ");
		printf(" %5d  disjuncts ", len);
		if (dn->file != NULL)
		{
			printf("<%s>", dn->file->file);
		}
		printf("\n");
	}
	free_lookup_list(dn_head);
	return;
}
Beispiel #2
0
int word_has_connector(Dict_node * dn, char * cs, int direction) {

  /* This function takes a dict_node (corresponding to an entry in a given dictionary), a
     string (representing a connector), and a direction (0 = right-pointing, 1 = left-pointing);
     it returns 1 if the dictionary expression for the word includes the connector, 0 otherwise.
     This can be used to see if a word is in a certain category (checking for a category 
     connector in a table), or to see if a word has a connector in a normal dictionary. The
     connector check uses a "smart-match", the same kind used by the parser. */

    Connector * c2=NULL;
    Disjunct * d, *d0;
    if(dn == NULL) return -1;
    d0 = d = build_disjuncts_for_dict_node(dn);
    if(d == NULL) return 0;
    for(; d!=NULL; d=d->next) { 
      if(direction==0) c2 = d->right;
      if(direction==1) c2 = d->left;
      for(; c2!=NULL; c2=c2->next) {
	if(easy_match(c2->string, cs)==1) {
	    free_disjuncts(d0);
	    return 1;
	}
      }
    }
    free_disjuncts(d0);
    return 0;
}
Beispiel #3
0
int position_words(Dictionary dict, Alink * alink, int currentword, int direction, double leftend, double rightend) {
  /* direction: left = 0, right = 1 */
    Disjunct * d, * d0;
    Connector * c;
    Dict_node * dn;
    wchar_t * s;
    wchar_t * ds;
    int numcon, i, n, w, ok;
    int linkage_found = 1;
    Link link;
    wchar_t * ws;
    Alink * al;
    double position;
    double range;
    double newleftend, newrightend;
    /* Right now it goes through and choose the disjunct twice - once for the right and once for the left. This seems
       unnecessary... */

    ds = tword[currentword].gstring; 

    if(localv == 2) wprintf_s(L"  Tracing word '%s', word %d, direction %d\n", ds, currentword, direction); 

    /* With a conjunction: you could submit a string from one of the andlist element words here as ds, instead of the
       conjunction itself - "currentword" would still be the conjunction, though. (But what about the XL and XR connectors?) */

    dn = dictionary_lookup(dict, ds);

    /* Should we go through the dict_nodes here, or is it okay to just take the first one? */
    d0 = d = build_disjuncts_for_dict_node(dn);
    for(; d!=NULL; d=d->next) { 
      ok = evaluate_disjunct(d, alink, currentword);
      if(ok==1) break;
    }

    if(d == NULL) {
      if(localv == 2) wprintf_s(L"No disjunct found for word '%s'\n", ds);
      free_disjuncts(d0);
      return 0;
    }

    /* We've found a disjunct to use for the current word. Now we go through all the connectors on the disjunct;
       for each one, we look through the links to find a link of the right type with the current word on one end; 
       then we position the word on the other end and repeat this process recursively */

    range=rightend-leftend;
    if(direction==0) c = d->left;
    if(direction==1) c = d->right;
    numcon = 5; 

    /* A better way:
    numcon = 0;      
    if(direction == 0) {
      for(; c!=NULL; c=c->next) numcon++;
    }
    */
    n=1;
    ok = 1;
    while(c!=NULL) {  /* for(n=1; n<=numcon; n++) { */
      s = c->string;
      if(localv == 2) wprintf_s(L"    String from disjunct for '%s': %s\n", ds, s);  
      for(al = alink; al!=NULL; al=al->next) {
	if(al->ignore == 1) continue;
	if(direction==0 && al->rightsub == currentword) {  /* Does the link have the current word on the right end? */
	  if (wcscmp(s, L"XR")==0) continue;
	  if (easy_match (s, al->connector) == 1 && word_position[al->leftsub]==-1.0) {
	    ws=al->left;
	    position = rightend - (range * ((numcon+1.0 - n) / (numcon+1.0)));
	    word_position[al->leftsub] = position;
	    if(localv == 2) wprintf_s(L"  Word '%s' has position %6.6f\n", ws, position); 
	    newleftend = ( position + (rightend - (range * ((numcon+1.0 - (n-1.0)) / (numcon+1.0)))) ) / 2.0;
	    newrightend = ( position + (rightend - (range * ((numcon+1.0 - (n+1.0)) / (numcon+1.0)))) ) / 2.0;
	    /* wprintf_s("Newleftend = %6.6f, newrightend = %6.6f\n", newleftend, newrightend); */
	    linkage_found = position_words(dict, alink, al->leftsub, 0, newleftend, position);
	    if(linkage_found==0) ok = 0;
	    linkage_found = position_words(dict, alink, al->leftsub, 1, position, newrightend);
	    if(linkage_found==0) ok = 0;
	    n++;
	  }
	}
	if(direction==1 && al->leftsub == currentword) {
	  if (wcscmp(s, L"XL")==0) continue;
	  if (easy_match (s, al->connector) == 1 && word_position[al->rightsub]==-1.0) {
	    ws = al->right;
	    position = leftend + (range * ((numcon+1.0 - n) / (numcon+1.0)));
	    word_position[al->rightsub] = position;
	    if(localv == 2) wprintf_s(L"  Word '%s' has position %6.6f\n", ws, position); 
	    newrightend = ( position + (leftend + (range * ((numcon+1.0 - (n-1.0)) / (numcon+1.0)))) ) / 2.0;
	    newleftend = ( position + (leftend + (range * ((numcon+1.0 - (n+1.0)) / (numcon+1.0)))) ) / 2.0;
	    /* wprintf_s("Newleftend = %6.6f, newrightend = %6.6f\n", newleftend, newrightend); */
 	    linkage_found = position_words(dict, alink, al->rightsub, 0, newleftend, position);
	    if(linkage_found==0) ok = 0;
 	    linkage_found = position_words(dict, alink, al->rightsub, 1, position, newrightend);
	    if(linkage_found==0) ok = 0;
	    n++;
	  }
	}
      }
      c = c->next;
    }
    free_disjuncts(d0);
    if(ok==1) return 1;
    else return 0;
}