LIST *property_set_create( PARSE *parse, FRAME *frame )
{
    LIST* properties = lol_get( frame->args, 0 );    
    LIST* sorted = 0;
    LIST* order_sensitive = 0;
    LIST* unique;
    LIST* tmp;
    LIST* val;
    string var[1];

#if 0
    /* Sort all properties which are not order sensitive */
    for(tmp = properties; tmp; tmp = tmp->next) {
        LIST* g = get_grist(tmp->string);
        LIST* att = call_rule("feature.attributes", frame, g, 0);
        if (list_in(att, "order-sensitive")) {
            order_sensitive = list_new( order_sensitive, tmp->string);
        } else {
            sorted = list_new( sorted, tmp->string);
        }
        list_free(att);
    }
    
    sorted = list_sort(sorted);
    sorted = list_append(sorted, order_sensitive);
    unique = list_unique(sorted);
#endif
    sorted = list_sort(properties);
    unique = list_unique(sorted);

    string_new(var);
    string_append(var, ".ps.");
    
    for(tmp = unique; tmp; tmp = tmp->next) {
        string_append(var, tmp->string);
        string_push_back(var, '-');
    }
    val = var_get(var->value);
    if (val == 0) 
    {          
        val = call_rule("new", frame, 
                        list_append(list_new(0, "property-set"), unique), 0);                
        
        var_set(newstr(var->value), list_copy(0, val), VAR_SET);
    }
    else
    {
        val = list_copy(0, val);
    }
    
    string_free(var);
    /* The 'unique' variable is freed in 'call_rule'. */
    list_free(sorted);

    return val;

}
Пример #2
0
void test_concat_append_add_union_intersection_difference(void)
{     
     List list1 = list_random(MAX_LIST_SIZE, ELEMENT_MAX_VALUE);
     list_sort_by_item(&list1);
     list_unique(&list1);
     printf("Original List 1 ::: ");
     list_print(&list1);

     List list2 = list_random(MAX_LIST_SIZE, ELEMENT_MAX_VALUE);
     list_sort_by_item(&list2);
     list_unique(&list2);
     printf("%sOriginal List 2 ::: ", brown);
     list_print(&list2);

     List concat = list_concat(&list1, &list2);
     printf("%sConcatenation List ::: ", cyan);
     list_print(&concat);

     List append = list_duplicate(&list1);
     list_append(&append, &list2);
     printf("%sList 1 appended to list 2 ::: ", magenta);
     list_print(&append);
     
     List add = list_duplicate(&list1);
     list_add(&add, &list2);
     printf("%sList 1 added to list 2 ::: ", green);
     list_print(&add);

     List union_list = list_union(&list1, &list2);	
     printf("%sList Union ::: ", blue);
     list_print(&union_list);

     List intersection_list = list_intersection(&list1, &list2);
     printf("%sList Intersection ::: ", red);
     list_print(&intersection_list);

     List difference_list = list_difference(&list1, &list2);
     printf("%sDifference List ::: ", cyan);
     list_print(&difference_list);

     uint union_size = list_union_size(&list1, &list2);
     printf("%sList Union Size = %d\n", brown, union_size);

     uint intersection_size = list_intersection_size(&list1, &list2);
     printf("%sList Intersection Size = %d\n", black, intersection_size);

     uint difference_size = list_difference_size(&list1, &list2);
     printf("%sList Difference Size = %d\n", black, difference_size);
     
     printf("%s",none);

}
Пример #3
0
void test_random_push_print(void)
{
     List list = list_random(MAX_LIST_SIZE, ELEMENT_MAX_VALUE);
     list_sort_by_item(&list);
     list_unique(&list);
     printf("Original List ::: ");
     list_print(&list);

     List push = list_random(MAX_LIST_SIZE, ELEMENT_MAX_VALUE);
     list_sort_by_item(&push);
     list_unique(&push);
     printf("%sList to be pushed ::: ", brown);
     list_print(&push);

     uint low = rand() % push.size;
     uint high = (rand() % (push.size - low)) + low;
     list_push_range(&list, &push, low, high);
     printf("%sList with %d-%d Items From List 2 Pushed ::: ", cyan, low, high);
     list_print(&list);
     printf("%s", none);

     list_sort_by_item(&list);
     list_unique(&list);
     printf("%sList Sorted By Item ::: ", magenta);
     list_print(&list);
     
     low = rand() % list.size;
     high = (rand() % (list.size - low)) + low;
     printf("%sRandom List range %d - %d ::: ", green, low, high);
     list_print_range(&list, low, high);
     printf("%s", none);
     
     List positions = list_random(list.size, list.size);
     list_sort_by_item(&positions);
     list_unique(&positions);
     
     printf("%sRandom positions ::: ", blue);
     list_print(&positions);
     printf("%sPrinting random positions ::: ", black);
     list_print_multi(&list, &positions);
     printf("%s", none);
}
Пример #4
0
void test_pop_delete(void)
{
     List list = list_random(MAX_LIST_SIZE, ELEMENT_MAX_VALUE);
     list_sort_by_item(&list);
     list_unique(&list);
     printf("Original List ::: ");
     list_print(&list);

     List duplicate = list_duplicate(&list);
     list_pop(&duplicate);
     printf("%sList 1 without last item ::: ", cyan);
     list_print(&duplicate);
   
     list_destroy(&duplicate);
     duplicate = list_duplicate(&list);
     uint random_value = rand() % duplicate.size;
     list_pop_multi(&duplicate, random_value);
     printf("%sList without last %d items ::: ", brown, random_value);
     list_print(&duplicate);
	      
     list_destroy(&duplicate);
     duplicate = list_duplicate(&list);
     uint random_end = rand() % duplicate.size;
     list_pop_until(&duplicate, random_end);
     printf("%sList until %d ::: ", magenta, random_end);
     list_print(&duplicate);

     list_destroy(&duplicate);
     duplicate = list_duplicate(&list);
     uint random_position = rand() % (duplicate.size);
     list_delete_position(&duplicate, random_position);
     printf("%sList wihout %d-d item ::: ", green, random_position);
     list_print(&duplicate);
     printf("%s", none);

     list_destroy(&duplicate);
     duplicate = list_duplicate(&list);
     Item random_item;
     random_position = rand() % (duplicate.size);
     random_item = duplicate.data[random_position];
     list_delete_item(&duplicate, random_item);
     printf("%sList without %d ::: ", red, random_item.item);
     list_print(&duplicate);
     printf("%s", none);
     
     list_destroy(&duplicate);
     duplicate = list_duplicate(&list);
     uint low = rand() % duplicate.size;
     uint high = (rand() % (duplicate.size - low)) + low;
     list_delete_range(&duplicate, low, high);
     printf("%sList without range %d - %d ::: ", blue, low, high);
     list_print(&duplicate);
     printf("%s", none);
}
Пример #5
0
/**
 * @brief Makes a query to the database
 *
 * @param ifindex Inverted file index
 * @param query Query list
 *
 * @return Query result
 */
List ifindex_query(ListDB *ifindex, List *query)
{
     List query_result;	
     list_init(&query_result);

     uint i;
     for (i = 0; i < query->size; i++) //retrieves each list in inverted
          list_append(&query_result, &ifindex->lists[query->data[i].item]);
     list_sort_by_item(&query_result);
     list_unique(&query_result);

     return query_result;
}
Пример #6
0
void test_jaccard_overlap_histogramsim(void)
{
     List list1 = list_random(MAX_LIST_SIZE, ELEMENT_MAX_VALUE);
     list_sort_by_item(&list1);
     list_unique(&list1);
     printf("Original List 1 ::: ");
     list_print(&list1);

     List list2 = list_random(MAX_LIST_SIZE, ELEMENT_MAX_VALUE);
     list_sort_by_item(&list2);
     list_unique(&list2);
     printf("%sOriginal List 2 ::: ", brown);
     list_print(&list2);

     double *weights = (double *) malloc(ELEMENT_MAX_VALUE * sizeof(double));
     uint i;
     printf("%sWeights = ",black);
     for (i = 0; i < ELEMENT_MAX_VALUE; i++){
          weights[i] = (double) (rand() % 10) / 10.0;
          printf(" [%d = %lf]", i, weights[i]);
     }
     printf("\n");

     double jaccard = list_jaccard(&list1, &list2);
     double overlap = list_overlap(&list1, &list2);
     double hist_inter = list_histogram_intersection(&list1, &list2);
     double weight_hist_inter = (double ) list_weighted_histogram_intersection(&list1, &list2, weights);
     double weight_sim = list_weighted_similarity(&list1, &list2, weights);
     uint inter_size = list_intersection_size(&list1, &list2);
     printf("%sJaccard = %lf\n"
            "%sOverlap = %lf\n"
            "%sHistogram Intersection = %lf\n"
            "%sWeighted Histogram Intersection = %lf\n"
            "%sWeighted Similarity = %lf\n"
            "%sInter size = %u%s\n",
            cyan, jaccard, magenta, overlap, green, hist_inter, blue, weight_hist_inter, red, weight_sim, cyan, inter_size, none);
}
Пример #7
0
void test_sort_unique_find_search(void)
{
     uint random_size;
    
     random_size = rand() % MAX_LIST_SIZE;
     List zeros = list_create(random_size);
     printf("Zero List ::: ");
     list_print(&zeros);

     List list = list_random(MAX_LIST_SIZE, ELEMENT_MAX_VALUE);
     printf("%sRandom List ::: ", cyan);
     list_print(&list);

     list_sort_by_item(&list);
     printf("%sList Resorted By Item ::: ", red);
     list_print(&list);
     
     printf("%sUnique List ::: ", magenta);
     list_unique(&list);
     list_print(&list);

     list_sort_by_frequency_back(&list);
     printf("%sList Sorted Backward By Frequency ::: ",green);
     list_print(&list);

     list_sort_by_frequency(&list);
     printf("%sList Resorted By Frequency ::: ", blue);
     list_print(&list);
     
     Item query = list.data[rand() % list.size];
     Item *found = list_find(&list, query);
     if (found != NULL)
          printf("%sFind function: %d found in position %d\n", brown, query.item, (int)(found - list.data));    
     else
          printf("%sFind function: %d not found", brown, query.item);
 
     list_sort_by_item_back(&list);
     printf("%sList Sorted Backwards By Item ::: ", black);
     list_print(&list);

     list_sort_by_item(&list);
     printf("%sList Resorted By Item ::: ", cyan);
     list_print(&list);

     query = list.data[rand() % list.size];
     found = list_binary_search(&list, query);
     printf("%sBinary search: %d found in position %d\n", none, query.item, (int)(found - list.data));    
}
Пример #8
0
LIST * property_set_create( FRAME * frame, int flags )
{
    LIST * properties = lol_get( frame->args, 0 );
    LIST * sorted = list_sort( properties );
    LIST * unique = list_unique( sorted );
    struct ps_map_entry * pos = ps_map_insert( &all_property_sets, unique );
    list_free( sorted );
    if ( pos->value )
    {
        list_free( unique );
        return list_new( object_copy( pos->value ) );
    }
    else
    {
        OBJECT * rulename = object_new( "new" );
        OBJECT * varname = object_new( "self.raw" );
        LIST * val = call_rule( rulename, frame,
            list_new( object_new( "property-set" ) ), 0 );
        LISTITER iter, end;
        object_free( rulename );
        pos->value = list_front( val );
        var_set( bindmodule( pos->value ), varname, unique, VAR_SET );
        object_free( varname );

        for ( iter = list_begin( unique ), end = list_end( unique ); iter != end; ++iter )
        {
            const char * str = object_str( list_item( iter ) );
            if ( str[ 0 ] != '<' || ! strchr( str, '>' ) )
            {
                string message[ 1 ];
                string_new( message );
                string_append( message, "Invalid property: '" );
                string_append( message, str );
                string_append( message, "'" );
                rulename = object_new( "errors.error" );
                call_rule( rulename, frame,
                    list_new( object_new( message->value ) ), 0 );
                /* unreachable */
                string_free( message );
                object_free( rulename );
            }
        }

        return val;
    }
}
Пример #9
0
void test_min_max(void)
{
     uint random_size;
    
     List list = list_random(MAX_LIST_SIZE, ELEMENT_MAX_VALUE);
     printf("%sRandom List ::: ", cyan);
     list_print(&list);

     Item *min_item = list_min_item(&list);
     Item *max_item = list_max_item(&list);
     printf("%sMin item = %d[%d] max item = %d [%d]\n", none, min_item->item, (int)(min_item - list.data), max_item->item, (int)(max_item - list.data));    

     list_sort_by_item(&list);
     list_unique(&list);
     printf("Sorted List ::: ");
     list_print(&list);
}
Пример #10
0
void test_less_more_frequent(void)
{
     List list = list_random(MAX_LIST_SIZE, ELEMENT_MAX_VALUE);
     list_sort_by_item(&list);
     list_unique(&list);
     list_sort_by_frequency_back(&list);
     printf("Original List ::: ");
     list_print(&list);

     List duplicate = list_duplicate(&list);
     list_delete_less_frequent(&duplicate, 5);
     printf("%sList without less frequent items ::: ", cyan);
     list_print(&duplicate);
   
     list_destroy(&duplicate);
     duplicate = list_duplicate(&list);
     list_delete_more_frequent(&duplicate, 8);	
     list_sort_by_frequency_back(&duplicate);
     printf("%sList without more frequent items ::: ", magenta);
     list_print(&duplicate);
     printf ("%s",none);
}
Пример #11
0
/**
 * @brief Appends one list to another and removes duplicated items
 *
 * @param list1 Base list
 * @param list2 List to be added
 */
void list_add(List *list1, List *list2)
{
     list_append(list1, list2);
     list_sort_by_item(list1);
     list_unique(list1);
}
main()
{
	/* Declarations Start */
	status_code SC;
	boolean boolval;
	FILE *fp;
	employee_type *emp_ptr,*ptr;
	employee_type *list1,*list2,*list3;
	employee_type *duplicate;
	empname_type *name_ptr,*ptr_name;
	char dumbo[2];
	char emp_name[NAME_LEN];
	char proj_name[NAME_LEN];
	char c;
	unsigned int Hrs;
	unsigned int emp_salary;
	char emp_address[ADD_LEN];
	unsigned long int phone;
	int option,contnue;
	int numRecords,maxNumHrs;
	/* Declarations End */
	/* Initialisations Start */
	emp_ptr=NULL;
	name_ptr=NULL;
	ptr_name=NULL;
	ptr=NULL;
	list1=NULL;
	list2=NULL;
	list3=NULL;
	duplicate=NULL;
	fp=NULL;
	/* Initialisations End */
	/* Start Reading Data from File */
    fp=fopen("record.txt","a");
    fclose(fp);
    fp=fopen("record.txt","r");
    while((c=getc(fp)) != EOF)
    {
		fseek(fp,-sizeof(char),1);
	    fscanf(fp,"%s %s %u %u %s %lu",emp_name,proj_name,&Hrs,&emp_salary,emp_address,&phone);
	    SC=insert(&emp_ptr,emp_name,proj_name,Hrs,emp_salary,emp_address,phone);
	}
	fclose(fp);
	fp=NULL;
	/* End Reading Data from File */
	do
	{
		/* Asking for Option */
		puts("ENTER the option as per the operation you want to do. ENTER :-\n");
		puts("1- insert/update\n2- delete\n3- getNumRecords\n4- isEmpty\n5- List_Unique\n6- getMaxNumHrs\n7- list_union\n8- list_intersection\n9- list_difference\n10- list_symmetric_difference\n");
		printf("Your Choice is:- ");
		scanf("%d",&option);
		printf("\n\n");
		switch (option)
		{
			/* INSERT/UPDATE */
			case 1: {
						    printf("***********INSERT**********\n\n");
						    /* Data Entering Start */
							printf("Enter Employee Name :-\t");
							gets(dumbo);
							gets(emp_name);
							remove_space_make_uppercase(emp_name);
							printf("Enter Employee's Project Name :-\t");
							gets(proj_name);
							remove_space_make_uppercase(proj_name);
							printf("Enter Number of Hours :-\t");
							scanf("%u",&Hrs);
							printf("Enter Employee's Salary :-\t");
							scanf("%u",&emp_salary);
							printf("Enter Employee's Address :-\t");
							gets(dumbo);
							gets(emp_address);
							remove_space_make_uppercase(emp_address);
							printf("Enter Employee's Phone Number :-\t");
							scanf("%lu",&phone);
							/* Data Entering End */
							/* Inserting/Updating Data */
							SC=insert(&emp_ptr,emp_name,proj_name,Hrs,emp_salary,emp_address,phone);
							if(SC==SUCCESS)
							{
								puts("\n**********Data inserted**********\n");	
							}
							else
							{
								puts("\n**********Data insertion failed**********\n");	
							}
					  		break;
				     }
			/* DELETE */
			case 2:  {
							printf("***********DELETE**********\n\n");
							/* Data Entering Start */
							printf("Enter Employee Name :-\t");
							gets(dumbo);
							gets(emp_name);
							remove_space_make_uppercase(emp_name);
							printf("Enter Employee's Project Name :-\t");
							gets(proj_name);
							remove_space_make_uppercase(proj_name);
							/* Data Entering End */
							/* Deleting Data */
							SC=delete_entry(&emp_ptr,emp_name,proj_name);
							if(SC==SUCCESS)
							{
								puts("\n**********Data deleted**********\n");	
							}
							else
							{
								puts("\n**********Data deletion failed**********\n");	
							}
							break;
					 } 
			/* getNumRecords */  
			case 3:  {
							printf("***********getNumRecords**********\n\n");
							numRecords=getNumRecords(emp_ptr);
							printf("\n\nNumber of ACTIVE record in the list is :-  %d",numRecords);
							break;
					 }
			/* isEmpty */
			case 4:  {
							printf("***********isEmpty**********\n\n");
							boolval=isEmpty(emp_ptr);
							if(boolval==NO)
							{
								puts("The list is NOT EMPTY");	
							}
							else
							{
								puts("The list is EMPTY");	
							}
							break;
					 }
			/* list_unique */
			case 5:  {
							printf("***********list_unique**********\n\n");
							/* Creating Duplicate Entries for Testing */
							duplicate=create_duplicate();
							list_unique(duplicate);
							printf("\n\n*****LIST MADE UNIQUE*****\n\n");
							print(duplicate);
							freeof_employee(&duplicate);
							break;
					 }
			/* getMaxNumHrs */
			case 6:  {
							printf("***********getMaxNumHrs**********\n\n");
							/* Data Entering Start */
							printf("Enter Project Name :-\t");
							gets(dumbo);
							gets(proj_name);
							remove_space_make_uppercase(proj_name);
							/* Data Entering End */
							maxNumHrs=getMaxNumHrs(emp_ptr,proj_name,&name_ptr);
							printf("\nMaximum hours spent in the given project is :-  %d\n\n",maxNumHrs);
							if(maxNumHrs!=0)
							{
								printf("Employee's spending maximum hours in this project are :-\n");
								ptr_name=name_ptr;
								while(ptr_name!=NULL)
								{
									puts(ptr_name->employee_name);
									ptr_name=ptr_name->next;	
								}
							}
							freeof_empname(&name_ptr);
							ptr_name=NULL;
							break;
					 }
			/* list_union */	
	   	    case 7:  {
							printf("***********list_union**********\n\n");
							/* Creating list1 and list2 for Testing */
							puts("*****Creating Testing Entries for list1*****");
							list1=create_checklist();
							puts("*****Creating Testing Entries for list2*****");
							list2=create_checklist();
							list3=list_union(list1,list2);
							printf("\n\n*****UNION of the given lists is as follows*****\n\n");
							print(list3);
							freeof_employee(&list1);
							freeof_employee(&list2);
							freeof_employee(&list3);
							break;
					 }
			/* list_intersection */
			case 8:  {
							printf("***********list_intersection**********\n\n");
							/* Creating list1 and list2 for Testing */
							puts("*****Creating Testing Entries for list1*****");
							list1=create_checklist();
							puts("*****Creating Testing Entries for list2*****");
							list2=create_checklist();
							list3=list_intersection(list1,list2);
							printf("\n\n*****INTERSECTION of the given lists is as follows*****\n\n");
							print(list3);
							freeof_employee(&list1);
							freeof_employee(&list2);
							freeof_employee(&list3);
							break;
					 }
			/* list_difference */
			case 9:  {
							printf("***********list_difference**********\n\n");
							/* Creating list1 and list2 for Testing */
							puts("*****Creating Testing Entries for list1*****");
							list1=create_checklist();
							puts("*****Creating Testing Entries for list2*****");
							list2=create_checklist();
							list3=list_difference(list1,list2);
							printf("\n\n*****DIFFERENCE of the given lists is as follows*****\n\n");
							print(list3);
							freeof_employee(&list1);
							freeof_employee(&list2);
							freeof_employee(&list3);
							break;
					 }
			/* list_symmetric_difference */
			case 10:  {
							printf("***********list_symmetric_difference**********\n\n");
							/* Creating list1 and list2 for Testing */
							puts("*****Creating Testing Entries for list1*****");
							list1=create_checklist();
							puts("*****Creating Testing Entries for list2*****");
							list2=create_checklist();
							list3=list_symmetric_difference(list1,list2);
							printf("\n\n*****SYMMETRIC DIFFERENCE of the given lists is as follows*****\n\n");
							print(list3);
							freeof_employee(&list1);
							freeof_employee(&list2);
							freeof_employee(&list3);
							break;
					 }
			/* Default */
			default: {
							break;
					 }
		}
		/* Asking for CHOICE to Continue */
		puts("\n\nIf you want to continue... ? Enter 1 if YES or 0 if NO\n");
		printf("Your Choice is:- ");
		scanf("%d",&contnue);
		printf("\n\n");
	}while(contnue==1);
	/* Start Writing Data from File */
    fp=fopen("record.txt","w");
    ptr=emp_ptr;
    while(ptr!=NULL)
    {
       fprintf(fp,"%s %s %u %u %s %lu",ptr->employee_name,ptr->project_name,ptr->numHrs,ptr->employee_salary,ptr->employee_address,ptr->phone_number);
       ptr=ptr->next;
    }
    fclose(fp);
    fp=NULL;
    /* End Writing Data from File */
	if(emp_ptr!=NULL)
	{
		print(emp_ptr);
		freeof_employee(&emp_ptr);
	}
	getch();
}