Thread: Thesaurus in C

  1. #1
    Registered User
    Join Date
    Dec 2013
    Location
    Cebu City, Philippines
    Posts
    14

    Thesaurus in C

    I have a project on C Programming of a Thesaurus.
    We are required to use any of the ADT's and I am having a hard time trying to figure out which adt to use.

    Can anybody help?

    Thanks.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    care to explain what an ADT is, in this context?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User
    Join Date
    Dec 2013
    Location
    Cebu City, Philippines
    Posts
    14
    An Abstract Data Type.. Like Binary search tree ADT's, graph adt, tries, heap adt, etc..
    I would use these ADT's in creating my database for my Thesaurus program.
    But I'm not sure which adt to use.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I think a array of link lists might be a method of implementation.

    But, it might or might not be a perfect fit for the problem domain.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by stahta01 View Post
    I think a array of link lists might be a method of implementation.

    But, it might or might not be a perfect fit for the problem domain.

    Tim S.
    I think a graph might be better. An array of linked lists would require (well, not require, but for efficiency it would) any synonym to be in the array as well, so it's already becoming like a graph; synonymy, IMO, is graph-like.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Hodor View Post
    I think a graph might be better. An array of linked lists would require (well, not require, but for efficiency it would) any synonym to be in the array as well, so it's already becoming like a graph; synonymy, IMO, is graph-like.
    If every synonym relationship is NOT both ways; you are likely true.
    But, if they are both ways; I think a link list for each group of synonyms would be a valid method of implementation.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by stahta01 View Post
    If every synonym relationship is NOT both ways; you are likely true.
    But, if they are both ways; I think a link list for each group of synonyms would be a valid method of implementation.

    Tim S.
    The question remains, though, how would you find the search word? Search every array of linked lists? Excuse the bizarre notation I'm about to use... I'm sure you'll understand it though.

    [Mystery] --> Conundrum --> Puzzle --> Riddle --> Why

    Say the search word was "Riddle", would you have an array entry for that as well, which might have different words in it's list (which is fine) as well as some repeated? Just trying to make sure I'm understanding you correctly.

    [Riddle] --> Conundrum --> Puzzle --> Teaser

    // Hodor

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Definition -> 1st synonym -> 2nd synonym -> 3rd synonym

    Depending on what needed might need another ADT pointing to the Definition.

    To me, the solution needed depends on the real problem.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  9. #9
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by stahta01 View Post
    Definition -> 1st synonym -> 2nd synonym -> 3rd synonym

    Depending on what needed might need another ADT pointing to the Definition.

    To me, the solution needed depends on the real problem.
    But "1st synonym" would also have an array entry?

    Anyway, you have swayed me. I think that an array of linked lists would probably be acceptable given the context of this question. There's certainly no reason why it wouldn't work at least

  10. #10
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I think a array of link lists might be a method of implementation.
    O_o

    Thesaurus lives in memory: a "Trie" living over an ordered set of references to arrays containing ordered synonyms.

    Thesaurus lives on a disc: a "B+Tree" living over arrays containing ordered synonyms of all words in the node.

    Soma

    [Edit]
    [?]->[p]->[o]->[n]->[y](&Synonyms[Horse])
    ->[o]->[n]->[i]->[e]->[s](&Synonyms[Horse])
    ->[l]->[a]->[n](&Synonyms[Arrange], &Synonyms[Design])

    Synonyms[Arrange] = (VERB)[Arrange, Draft]
    Synonyms[Design] = (NOUN)[Procedure, Program]
    Synonyms[Horse] = (NOUN)[Filly, Horse, Mare, Pony]
    [/Edit]
    Last edited by phantomotap; 03-17-2014 at 07:46 PM.
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  11. #11
    Registered User
    Join Date
    Dec 2013
    Location
    Cebu City, Philippines
    Posts
    14
    Thank you for all your replies.

    I have started creating a program and used Graph ADT as I understood it.
    But I still have a problem in inserting. When I try to insert another set of words, the words that I have inserted before that seem to be gone from the list. I don't understand PLEASE HELP


    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    
    
    struct node
    {
    	char word [20];
    	struct node *below, *synonym, *nxt;
    };
    
    
    struct vertex
    {
    	struct node *next;
    };
    
    
    typedef struct vertex V;
    typedef struct node N;
    
    
    void display(N *node);
    int existingSyn(N *n, char s[20]);
    N *search(V *v, char w[20]);
    int checkNode(V *v, char w[20]);
    V *insert(V *v, char word [20], char syn [20]);
    N *create(char w [20]);
    
    
    
    
    N *create(char w [20])
    {
    	N *new;
    	new = (N*)malloc(sizeof(N));
    	new -> below = NULL;
    	new -> synonym = NULL;
    	new -> nxt = NULL;
    	strcpy(new->word, w);
    	return (new);
    }
    
    
    void main()
    {
    	int choice, flag;
    	char word [20], syn [20], searchKey[20];
    	int logIn;
    	V *v;
    	N ........;
    	v = NULL;
    	ss = NULL;
    	while(1)
    	{
    		clrscr();
    		printf("MENU\n1. Search\n2. Insert\n3. Exit \nCHOICE: ");
    		scanf("%d", &choice);
    		switch(choice)
    		{
    			case 1:
    				printf("\nWORD: ");
    				scanf("%s", searchKey);
    				flag = checkNode(v, searchKey);
    				if(flag == 0)
    				{
    					ss = search(v, searchKey);
    					printf("%s has the following synonyms: ", searchKey);
    					display(ss);
    					getch();
    					
    				}
    				else if(flag !=0)
    				{
    					printf("\nWORD NOT FOUND!");
    					getch();
    				}
    				break;
    				
    			case 2:
    			
    				printf("\nInput word: ");
    				scanf("%s", word);
    				getch();
    				printf("Synonym: ");
    				scanf("%s", syn);
    				getch();
    				v = insert(v, word, syn);
    				
    				getch();
    				break;
    				
    			case 3:
    				exit(0);
    				
    			default:
    				printf("\nINVALID INPUT. Press any key to try again...");
    				break;
    		}
    	}
    }
    
    
    V *insert(V *v, char word [20], char syn [20])
    {
    	int flag, existing;
    	N *new, *newsyn, *temp;
    	if (v==NULL)
    	{
    		new = create(word);
    		newsyn = create(syn);
    		v -> next = new;
    		new -> synonym = newsyn;
    		printf("\nINSERTED!\n");
    	}
    	else
    	{
    		flag = checkNode(v, word);
    		if (flag !=0)
    		{
    			temp = v -> next;
    			while(temp!=NULL)
    			{
    				temp = temp -> below;
    			}	
    			new = create(word);
    			newsyn = create(syn);
    			temp -> below = new;
    			new -> synonym = newsyn;
    			printf("\nINSERTED!\n");
    		}
    		else if(flag == 0)
    		{
    			new = search(v,word);
    			existing = existingSyn(new,syn);
    			if(existing !=0)
    			{
    				temp = new -> synonym;
    				while(temp->nxt!=NULL)
    				{
    					temp = temp -> nxt;
    				}
    				newsyn = create(syn);
    				temp -> nxt = newsyn;
    				printf("\nINSERTED!\n");
    			}
    			else if(existing == 1)
    			{
    				printf("\nSynonym already exist in %s's records.", word);
    				getch();
    			}
    		}
    	}
    	return (v);
    }
    
    
    int checkNode(V *v, char w[20])
    {
    	int flag;
    	N *temp;
    	temp = v -> next;
    	
    	while(temp !=NULL)
    	{
    		/*if(temp->word == w)
    		{
    			printf("\nCHECKEDD!");
    			return (1);
    			
    		}**/
    		if(strcmp(temp -> word,w) == 0)
    		{
    			printf("\nCHECKED!\n");
    			return (0);
    		}
    		temp = temp -> below;
    	}
    	flag = strcmp(temp -> word,w);
    	return (flag);
    
    
    }
    
    
    N *search(V *v, char w[20])
    {
    
    
    	N *temp;
    	temp = v -> next;
    	while(temp != NULL)
    	{
    		if(strcmp(temp->word,w)==0)
    		{
    			return (temp);
    		}
    		temp = temp -> below;
    	}
    	return (temp);
    }
    
    
    int existingSyn(N *n, char s[20])
    {
    	int flag;
    	N *temp;
    	temp = n -> synonym;
    	while(temp != NULL)
    	{
    		/*if(temp->word==s)
    		{
    			return (1);
    		}*/
    		if(strcmp(temp -> word,s)==0)
    		{
    			return (0);
    		}
    		temp = temp -> nxt;
    	}
    	flag = strcmp(temp -> word,s);
    	return (flag);
    }
    
    
    void display(N *node)
    {
    
    
    	N *temp;
    	temp = node -> synonym;
    	while(temp != NULL)
    	{
    		printf("\n%s", temp->word);
    		temp = temp -> nxt;
    	}
    }
    /*
    int Admin()
    {
    	char user [20];
    	int pw;
    	int flag = 0;
    	clrscr();
    	printf("\n--ADMIN--\n");
    	printf("USERNAME: ");
    	scanf("%s", user);
    	printf("\nPASSWORD: ");
    	scanf("%d", &pw);
    	getch();
    	if(strcmp(user,"admin")==0 && pw == 123)
    	{
    		flag = 1;
    	}
    	else
    	{
    		printf("\nInvalid log -in!!");
    	}
    	return (flag);
    }*/

  12. #12
    Registered User
    Join Date
    Dec 2013
    Location
    Cebu City, Philippines
    Posts
    14
    I also have another question:
    If you use file handling in C is it also possible to apply any of the ADT's?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Programming Thesaurus
    By Hexxx in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-23-2003, 04:55 AM
  2. thesaurus resource for programs?
    By brif in forum C++ Programming
    Replies: 4
    Last Post: 10-05-2002, 06:54 AM

Tags for this Thread