예제 #1
0
/**
 * This function adds a pattern number to the pattern list of a given
 * compound word tree node.
 */
void add_pattern_to_DLC_tree_node(struct DLC_tree_node* node,int pattern) {
struct list_int *previous;
if (node->patterns==NULL) {
  /* If the list is empty, we add the pattern */
  node->patterns=new_list_int(pattern);
  /* We update the length of the list */
  (node->number_of_patterns)++;
  return;
}
if (node->patterns->n==pattern)
  /* If the first element of the list is the same than 'pattern'
   * we have nothing to do */
  return;
if (node->patterns->n>pattern) {
  /* If we must insert 'pattern' at the beginning of the list */
  node->patterns=head_insert(pattern,node->patterns);
  /* We update the length of the list */
  (node->number_of_patterns)++;
  return;
}
/* General case */
previous=node->patterns;
int stop=0;
/* We parse the list until we have found the pattern or the place
 * to insert the pattern */
while (!stop && previous->next!=NULL) {
	/* If we find the pattern in the list, we have nothing to do */
	if (previous->next->n==pattern) return;
	else if (previous->next->n<pattern) previous=previous->next;
	else stop=1;
}
/* If must insert the pattern */
previous->next=head_insert(pattern,previous->next);
/* We update the length of the list */
(node->number_of_patterns)++;
return;
}
예제 #2
0
	void copy ( const node* source, node*& head, node*& tail )
	{
		if ( source != 0 )
		{
			head = 0;

			head_insert ( head , source-> data () );
			tail = head;

			while ( source->link () != 0 )
			{
				source = source-> link ();
				insert ( tail, source-> data () );
				tail = tail-> link ();
			}
		}
	}
예제 #3
0
/**
 * This function checks for each tag token like "{extended,extend.V:K}"
 * if it verifies some patterns. Its behaviour is very similar to the one
 * of the load_dic_for_locate function. However, as a side effect, this
 * function fills 'tag_token_list' with the list of tag token numbers.
 * This list is later used during Locate preprocessings.
 */
void check_patterns_for_tag_tokens(Alphabet* alphabet,int number_of_patterns,
                                   struct lemma_node* root,struct locate_parameters* parameters,Abstract_allocator prv_alloc) {
    struct string_hash* tokens=parameters->tokens;
    for (int i=0; i<tokens->size; i++) {
        if (tokens->value[i][0]=='{' && u_strcmp(tokens->value[i],"{S}")  && u_strcmp(tokens->value[i],"{STOP}")) {
            /* If the token is tag like "{today,.ADV}", we add its number to the tag token list */
            parameters->tag_token_list=head_insert(i,parameters->tag_token_list,prv_alloc);
            /* And we look for the patterns that can match it */
            struct dela_entry* entry=tokenize_tag_token(tokens->value[i]);
            if (entry==NULL) {
                /* This should never happen */
                fatal_error("Invalid tag token in function check_patterns_for_tag_tokens\n");
            }
            /* We add the inflected form to the list of forms associated to the lemma.
            * This will be used to replace patterns like "<be>" by the actual list of
            * forms that can be matched by it, for optimization reasons */
            add_inflected_form_for_lemma(tokens->value[i],entry->lemma,root);
            parameters->token_control[i]=(unsigned char)(get_control_byte(tokens->value[i],alphabet,NULL,parameters->tokenization_policy)|DIC_TOKEN_BIT_MASK);
            if (number_of_patterns) {
                /* We look for matching patterns only if there are some */
                struct list_pointer* list=get_matching_patterns(entry,parameters->pattern_tree_root);
                if (list!=NULL) {
                    if (parameters->matching_patterns[i]==NULL) {
                        /* We allocate the bit array if needed */
                        parameters->matching_patterns[i]=new_bit_array(number_of_patterns,ONE_BIT);
                    }
                    struct list_pointer* tmp=list;
                    while (tmp!=NULL) {
                        set_value(parameters->matching_patterns[i],((struct constraint_list*)(tmp->pointer))->pattern_number,1);
                        tmp=tmp->next;
                    }
                    free_list_pointer(list);
                }
            }
            /* At the opposite of DLC lines, a compound word tag like "{all around,.ADV}"
             * does not need to be put in the compound word tree, since the tag is already
             * characterized by its token number. */
            free_dela_entry(entry);
        }
    }
}
예제 #4
0
/**
 * This function explores a dictionary tree in order to insert an entry.
 * 'inflected' is the inflected form to insert, and 'pos' is the current position
 * in the string 'inflected'. 'node' is the current node in the dictionary tree.
 * 'infos' is used to access to constant parameters.
 */
static void add_entry_to_dictionary_tree(const unichar* inflected,int pos,struct dictionary_node* node,
                                  struct info* infos,int /*line*/, Abstract_allocator prv_alloc) {
for (;;) {
if (inflected[pos]=='\0') {
   /* If we have reached the end of 'inflected', then we are in the
    * node where the INF code must be inserted */
   int N=get_value_index(infos->INF_code,infos->INF_code_list);
   if (node->single_INF_code_list==NULL) {
      /* If there is no INF code in the node, then
       * we add one and we return */
      node->single_INF_code_list=new_list_int(N,prv_alloc);
      node->INF_code=N;
      return;
   }
   /* If there is an INF code list in the node ...*/
   if (is_in_list(N,node->single_INF_code_list)) {
      /* If the INF code has already been taken into account for this node
       * (case of duplicates), we do nothing */
      return;
   }
   /* Otherwise, we add it to the INF code list */
   node->single_INF_code_list=head_insert(N,node->single_INF_code_list,prv_alloc);
	/* And we update the global INF line for this node */
   node->INF_code=get_value_index_for_string_colon_string(infos->INF_code_list->value[node->INF_code],infos->INF_code,infos->INF_code_list);
   return;
}
/* If we are not at the end of 'inflected', then we look for
 * the correct outgoing transition and we follow it */
struct dictionary_node_transition* t=get_transition(inflected[pos],&node,prv_alloc);
if (t->node==NULL) {
   /* We create the node if necessary */
   t->node=new_dictionary_node(prv_alloc);
   (t->node->incoming)++;
}

node=t->node;
pos++;
}
}
예제 #5
0
static void DefLispObjects(struct net_object *netobj, struct net_object *unf_netobj)
{
 struct lisp_object *lisp;
 list curr = NULL;
 int i;
 markPTR m;
 
 
 
 init_list(&gListClasses);
 for ( lisp = netobj->lisps; lisp != NULL; lisp = lisp->next)
  switch(lisp->type)
  {
    case 'c':
   	{
   	 YACCobj_name = lisp->tag;
   	 LEXtoParsifyString = NewStringCat("~c ",lisp->text);
   	 EraseFinalCR(LEXtoParsifyString);
   	 
   	 yyparse();
	   
	 if(YACCparsedClass->type==SUBCLASS_TYPE) 
	   head_insert(&gListSubClasses, (generic_ptr) YACCparsedClass);
	 else
	   head_insert(&gListClasses, (generic_ptr) YACCparsedClass);
	     
	     
	 #if DEBUG_UNFOLD      	   
	   if(YACCparsedClass->type==SUBCLASS_TYPE){	     
	     printf("SubClass : %s\n", YACCparsedClass->name); 
	     printf("Elements : \n"); 
	     for(i=0; i < YACCparsedClass->num_el; i++)
	       printf("%s  ", (YACCparsedClass->elements)[i]->name);
	     printf("\n");
	   }
	   else
	   {	     
	     printf("Class %s\n", YACCparsedClass->name);
	     printf("SubClasses : \n");
	     curr = NULL;
	     while ( (curr = list_iterator(YACCparsedClass->sub_classes, curr)) != NULL ) 
	       printf("%s  ", ((ClassObjPTR)DATA(curr))->name);
	     printf("\n");
	   }
	 #endif
   	 
	 break;
   	}
    case 'm':
   	{
   	 break;
   	}	
    case 'f':
   	{
   	 break;
   	}
    default :
   	Error(UNKN_LISP_ERR, "DefLispObjects", lisp->tag);
  }
 
}
예제 #6
0
static list expandtransition(struct trans_object *trans_el, struct net_object *net, struct net_object *unf_net)
{
  struct trans_object *unf_trans;
  bool Found;
  struct lisp_object *lisp;
  struct arc_object *arc, *new_arc, *prev_arc;
  guard_exprPTR g;  
  arcPTR *parsedArcs;
  operandPTR op;
  list arcs, l=NULL, curr=NULL;
  int i, j, noarc, otd, vtd;
  multisetPTR p_MS;
  AssignmentPTR gamma;
  status state;
  char *new_var;
  
 init_list(&gListParsedArcs);
 init_list(&YACCParsedVarList);

 
 #if DEBUG_UNFOLD
   printf("Expand transition %s\n\n", trans_el->tag);
 #endif
 
  new_var = FreeVarName();

  for (arc = trans_el->arcs, noarc = 0; arc != NULL; arc = arc->next, noarc++);
                
  parsedArcs = (arcPTR *) Ecalloc( noarc , sizeof(arcPTR));
   
  init_list(&YACCParsedVarList);   

  i = 0; 
  for( arc = trans_el->arcs; arc != NULL; arc = arc->next){
      
   init_list(&l);
   
   if((find_key(gListDomain, (generic_ptr) (arc->place)->tag , CmpDomainName, &l))==OK) 
   {      
     YACCparsedDomain = ((DomainObjPTR) DATA(l));
     Found = FALSE;
     if ( arc->color != NULL ) {
       for ( lisp = net->lisps; lisp != NULL; lisp = lisp->next){       
         if(lisp->type=='f' && (strcmp(arc->color, lisp->tag)==0)) {
	   parsedArcs[i++]= ParseArc(lisp->text);
	   Found = TRUE;
	 }   
       }
       if(Found == FALSE){
        parsedArcs[i++]= ParseArc(arc->color);
	Found = TRUE;
       }
     }
     else if(Found == FALSE && arc->lisp != NULL)
       parsedArcs[i++]= ParseArc(arc->lisp->text);
     else
       parsedArcs[i++]= ParseNoColoredArc(arc, new_var);
   }
   else
     Error(UNDEF_DOM_ERR, "DefTransitions", (arc->place)->tag);
    
  }
   
 
  g = ParseGuard(trans_el, net);      
  create_assignment(&gamma, YACCParsedVarList); 
  
  
  otd = atoi(opt_list[OPT_ORIZ_TRANS_DISPLACEMENT].arg_val);
  vtd = atoi(opt_list[OPT_VERT_TRANS_DISPLACEMENT].arg_val);
  
  l = NULL;
  j = 0;
  init_list(&l);
  for(state = first_assignment(gamma) ; state != ERROR ; j++) {
    #if DEBUG_UNFOLD      
      printf("Assignment %s\n%",print_assignment(gamma));
    #endif
    if(eval_guard_expr(g, gamma) == TRUE){
      unf_trans = unfolding_transition(trans_el, j, gamma, &(unf_net->rpars));      
      unf_trans->center.x += j*otd;
      unf_trans->center.y += j*vtd;
      head_insert(&l, (generic_ptr) unf_trans);
    
      
      i = 0; 
      for( arc = trans_el->arcs; arc != NULL; arc = arc->next)
      {
        #if DEBUG_UNFOLD
          printf("Arc %s \n", PrintArcExpression(parsedArcs[i]));
	#endif        
	
	
	eval_arc(parsedArcs[i], gamma, &p_MS);	
        
		
	arcs = expand_arc(arc, p_MS, parsedArcs[i++]->domain->create_place, unf_net);
// 	destroy_multiset(p_MS);
	curr = NULL;
	while ( (curr = list_iterator(arcs, curr)) != NULL )
	{
	  new_arc = (struct arc_object *) DATA(curr);          
          if(unf_trans->arcs == NULL)
            unf_trans->arcs = new_arc;
          else
            prev_arc->next = new_arc;
          prev_arc = new_arc; 
         
	}
// 	destroy(&arcs, NULL);
      }
            
    } 
    state = next_assignment(gamma);
  }  
  
  return(l);
}
예제 #7
0
static void DefDomain(struct net_object *netobj, struct net_object *unf_netobj)
{
struct place_object *place;
char *great_domain, *class_name = UNCOLORED_CLASS_NAME;
list curr=NULL, l=NULL;
int i=1;
int cardinality;
ClassObjPTR c;
DomainObjPTR d;
markPTR m;


init_list(&gListDomain);
init_list(&gListMarking);


for( place = netobj->places; place != NULL; place = place->next)
 {
  YACCobj_name = place->tag;
  /* definizione dominio */
  if((great_domain = READ_DOMAIN(place)) != NULL) // se dominio colorato
  {
   LEXtoParsifyString = NewStringCat("~w ", great_domain); 
   EraseFinalCR(LEXtoParsifyString);

   yyparse();   
   
   #if DEBUG_UNFOLD
//    TEST PLACE DOMAIN         
     curr = NULL;
     printf("\n%s) ", YACCparsedDomain->place_name);
     while ( (curr = list_iterator(YACCparsedDomain->class_list, curr)) != NULL ){
       printf("%s ", ((ClassObjPTR) DATA(curr))->name);        
     }
     printf("\n");
   #endif
   
   cardinality =1;   
   curr = NULL;
   while ( (curr = list_iterator(YACCparsedDomain->class_list, curr)) != NULL )
     cardinality *=  ((ClassObjPTR) DATA(curr))->num_el;
      
   init_set(YACCparsedDomain->create_place, cardinality);
   append(&gListDomain, (generic_ptr) YACCparsedDomain);
   
   
   if(place->cmark!=NULL) {
          
     YACCobj_name = place->cmark->tag;
     LEXtoParsifyString = NewStringCat("~m ",place->cmark->text);
     EraseFinalCR(LEXtoParsifyString);    
     yyparse();
     YACCparsedMarking->place = place;
//      evalMarking(YACCparsedMarking, &p_MS);
     append(&gListMarking, (generic_ptr) YACCparsedMarking);
     
     
     #if DEBUG_UNFOLD
       printf("Marking: %s\n", PrintMarking(YACCparsedMarking)); 
//        printMultiset(p_MS);
     #endif
   
   }   
  }
  else { // dominio non colorato
    init_list(&l);    
    
    if((find_key(gListClasses, (generic_ptr) class_name, CmpClassName, &curr))==ERROR)
      Error(CLASS_DEF_ERR, "DefDomain", NULL);
    else
    { 
      head_insert(&l, DATA(curr));      
      YACCparsedDomain = NewDomain(place->tag, l, 1);     
      init_set(YACCparsedDomain->create_place, 1);
      append(&gListDomain, (generic_ptr) YACCparsedDomain);
    }
    #if DEBUG_UNFOLD
//  TEST PLACE DOMAIN         
    curr = NULL;
    printf("\n%s) ", YACCparsedDomain->place_name);
    while ( (curr = list_iterator(YACCparsedDomain->class_list, curr)) != NULL ){
      printf("%s ", ((ClassObjPTR) DATA(curr))->name);        
    }
    printf("\n");
    #endif   
        
    if(place->mpar!=NULL){
      
      YACCparsedMarking = NewMarking(place->mpar->tag, (generic_ptr) place->mpar);
      YACCparsedMarking->type = 1;
      
    }
    else{
      YACCobj_name = ""; 
      LEXtoParsifyString = EmptyString();
      
      sprintf(LEXtoParsifyString, "~m <%d S>",place->m0);       
      yyparse();  
      YACCparsedMarking->type = 0;
    } 
    YACCparsedMarking->place = place;                 
//     evalMarking(YACCparsedMarking, &p_MS);
    head_insert(&gListMarking, (generic_ptr) YACCparsedMarking);
            
  }  

     
 }
  


}
예제 #8
0
static void DefClasses(struct net_object *netobj, struct net_object *unf_netobj)
{
  
  list curr1 = NULL;
  list curr2 = NULL;  
  list FoundSubClass;
  list lSubClasses;
  ClassObjPTR c;
  ClassObjPTR SubClass;
  char *class_name = UNCOLORED_CLASS_NAME;
  int i, j;
      
  while ( (curr1 = list_iterator(gListClasses, curr1)) != NULL ) 
  {   
    c = (ClassObjPTR) DATA(curr1);
    switch(c->type)
    {
     case UNORD_CLASS_TYPE:
     case ORD_CLASS_TYPE :
    	{	  
	  c->elements = NULL;
	  lSubClasses = NULL;
	  c->num_el = 0;
	  c->min_idx = 0;
	  c->max_idx = 0;
	  i = 0;
	  while ( (curr2 = list_iterator(c->sub_classes, curr2)) != NULL ) 
	  {	   
	    char *subclassname;
	  
	    subclassname = ((ClassObjPTR) DATA(curr2))->name;
	    if((find_key(gListSubClasses, (generic_ptr) subclassname, CmpClassName, &FoundSubClass))==ERROR)
	      Error(SUBCLASS_DEF_ERR, "DefClasses", NULL);
	    else
	    {  	      	      
	      SubClass = (ClassObjPTR) DATA(FoundSubClass);
	      head_insert(&lSubClasses, SubClass);
	      c->elements = (Class_elementPTR *) Erealloc ( (generic_ptr) c->elements, 
	      						  (c->num_el+ SubClass->num_el) *  sizeof(Class_elementPTR));
	      	      
	      
              SubClass->min_idx = i;
	      SubClass->max_idx = i+SubClass->num_el;
	      
	      c->max_idx += SubClass->num_el;
	      c->num_el += SubClass->num_el;
	      
	      for(j= 0; j<SubClass->num_el; j++){
	        c->elements[i++] = SubClass->elements[j];
	        }
	      
	    }
	    
	  }
	  destroy(&(c->sub_classes), free);   /* Destroy List of Name of SubClasses */
	  c->sub_classes = lSubClasses;       /* Replace it with list of SubClasses*/
	  #if DEBUG_UNFOLD
	    printf("\nClass %s with %d elements:", c->name, c->num_el);
	    for(i = 0; i< c->num_el; i++)
  	      printf("%s ", (c->elements[i])->name ); 
            printf("\n");
	  #endif
	  
	  break;
	}     
     default : 
       Error(UNKN_CLASS_TYPE_ERR, "DefClasses", NULL); 
    }
  }  
  head_insert(&gListClasses, (generic_ptr) NewUncoloredClass(class_name)); /*Add Uncolored Class*/

}