i want to create a program that translates a sentance in english to another language

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jerger
    New Member
    • May 2007
    • 77

    #46
    man it wont do it now unless you type it in order... im frustrated lol. meh!

    thats what i was trying to do but did the .open part wrong so this is a good start i just need to find a magic spot to place that.... but it seems it will

    do first two words in order, or at least the second word if first (but not in reverse with both words, just the second word first then nothing), or it just outputs nothing if i put open/close in wrong spots lol

    Comment

    • DeMan
      Top Contributor
      • Nov 2006
      • 1799

      #47
      try it just inside this loop:
      [code=cpp]
      ifstream myFile; //Don't need to initalise here now
      while (tempword != ".")
      {
      myFile.open("fi lename");
      /* Do All the other Processing */



      myFile.close();
      }
      [/code]

      (I'm not sure that the condition in that while will work as expected either, but we'll worry about that later)

      Comment

      • jerger
        New Member
        • May 2007
        • 77

        #48
        update when i use the code i said that works, if i go

        ab
        apple

        it outputs ab and apple

        if i say apple it outputs nothing
        if you input apple ab, it outputs apple lol

        maybe its getting stuck if not starting the text from the first word? maybe that is whats hanging up... that the textfile only works if done in order....

        Comment

        • jerger
          New Member
          • May 2007
          • 77

          #49
          i think we might be subrtacting to early? maybe thats why it freezes or skips a word? im not sure


          or maybe the getline, isn't matching the tempword? maybe i should have the getline stop at the = sign, if it matches tempword, print it and if it doesnt, keep searching for the correct line?

          maybe i cant use equal like love = hlub... maybe i need if temp = line, then getline from 2nd file 0.o

          im exhausted lol

          Comment

          • DeMan
            Top Contributor
            • Nov 2006
            • 1799

            #50
            It probably freezes because( tempString!="." ) is always true.....
            to compare the actual values, we can either revert back to our facourite
            [code=cpp]
            if(strncmp(".", tempString, 1)!=0)
            {
            }
            [/code]
            OR
            we can try copmparing a single character
            [code=cpp]
            if(tempString.a t(0)!='.')
            {
            }
            [/code]

            The not processing elements out of order is more like a file handling thing......whic h the open/close combination 3 posts ago should have helped....

            Comment

            • jerger
              New Member
              • May 2007
              • 77

              #51
              where would i place this, in the first while, in the internal while, after both?

              Comment

              • DeMan
                Top Contributor
                • Nov 2006
                • 1799

                #52
                Use it instead of the line you have :
                [code=cpp]
                while(tempStrin g!=".")
                {
                }
                [/code]

                Comment

                • patrickdepinguin
                  New Member
                  • May 2007
                  • 6

                  #53
                  Just my 2 cents, but using a simple text file to handle this problem is very inefficient. Furthermore, such a dictionary problem has undoubtedly been solved before and if you want a good result (and don't necessarily want to do it yourself) you can look on the internet for an appropriate solution which is free to use.

                  A more efficient way to store the dictionary would be to use some kind of tree structure (simple tree, btree, balanced tree, ...) which will make the search for a certain word much faster. Currently (I didn't read the whole thread but I suppose this is what you do) you need to read the text file line by line until you find a match.

                  With trees, you would have a program which runs once and which will generate the tree (based on your original dictionary, simple text file). This tree will contain the same information but in a much more efficient way.
                  Then the actual lookup program will look in the trees instead of the textfile.

                  If you want to read some more on trees, look here:
                  http://en.wikipedia.or g/wiki/Tree_data_struc ture

                  Thomas

                  Comment

                  • jerger
                    New Member
                    • May 2007
                    • 77

                    #54
                    hmm... cool!

                    however i had no luck finding such a template. when i searched dictionary for like 2 hours all i found were like programming and c++ dictionaries meaning definitions and how to guides for beginners and general information... nothing about actual dictionary programs. any ideas where to search?

                    Comment

                    • patrickdepinguin
                      New Member
                      • May 2007
                      • 6

                      #55
                      Originally posted by jerger
                      hmm... cool!

                      however i had no luck finding such a template. when i searched dictionary for like 2 hours all i found were like programming and c++ dictionaries meaning definitions and how to guides for beginners and general information... nothing about actual dictionary programs. any ideas where to search?
                      This one doesn't use trees, but nevertheless seems of use:
                      http://www.boost.org/libs/iostreams/doc/tutorial/dictionary_filt ers.html
                      It is from a library called boost, the source code should be downloadable.

                      I didn't find a complete tree solution immediately, but you can find examples on searching in trees separately. You can then uses these in your own script.

                      Comment

                      • weaknessforcats
                        Recognized Expert Expert
                        • Mar 2007
                        • 9214

                        #56
                        Back on Post #14 I suggested you use a multimap. That is the tree you are looking for. Everything between Post #15 and Post #55 avoids the C++ STL and looks for C solutions instead.

                        I say again, an association table using a multimap will solve this problem.

                        Comment

                        • jerger
                          New Member
                          • May 2007
                          • 77

                          #57
                          it sounds great but i am confused, any examples of this?
                          (previous post)

                          and thanks for the tutorial (other post)

                          Comment

                          • weaknessforcats
                            Recognized Expert Expert
                            • Mar 2007
                            • 9214

                            #58
                            Here you go:
                            [code=cpp]
                            #include <iostream>
                            using namespace std;
                            #include <map>
                            #include <string>
                            #include <algorithm>



                            int main()
                            {
                            ////////////////////////////////////////////////////////////
                            //Build the Dictionary
                            multimap<string , string> ESP; //the English/Spanish dictionary
                            pair<string, string> d1("Hello", "Hola");
                            pair<string, string> d2("Hello", "Como estas?");
                            pair<string, string> d3("Hello", "Como esta usted?");
                            pair<string, string> d4("Hello", "Buenos dias");
                            pair<string, string> d5("Goodbye", "Adios");
                            pair<string, string> d6("Goodbye", "Hasta la vista");
                            pair<string, string> d7("Goodbye", "Hasta entonces");
                            ESP.insert(d1);
                            ESP.insert(d2);
                            ESP.insert(d3);
                            ESP.insert(d4);
                            ESP.insert(d5);
                            ESP.insert(d6);
                            ESP.insert(d7);
                            /////////////////////////////////////////////////////////////////////
                            //Use the distionary
                            multimap<string ,string>::itera tor low = ESP.begin();
                            multimap<string ,string>::itera tor high = ESP.end();

                            pair<multimap<s tring,string>:: const_iterator, multimap<string ,string>::const _iterator> rval;

                            rval = ESP.equal_range (string("Hello" ));
                            /////////////////////////////////////////////////////////////
                            cout << "Possible translations " << endl;
                            while (rval.first != rval.second)
                            {
                            cout << rval.first->first << "----->" << rval.first->second << endl;
                            ++rval.first;
                            }
                            rval = ESP.equal_range (string("Goodby e"));
                            /////////////////////////////////////////////////////////////
                            cout << "Possible translations " << endl;
                            while (rval.first != rval.second)
                            {
                            cout << rval.first->first << "----->" << rval.first->second << endl;
                            ++rval.first;
                            }


                            }
                            [/code]

                            Comment

                            • jerger
                              New Member
                              • May 2007
                              • 77

                              #59
                              that compiles, but it only lists a set of translated words. is there a way to enter input, compare it to the list, then spit out the list with translations for the words they entered?

                              like

                              cout<<"enter your sentance in english";
                              cin>>sentance;

                              run dictionary:

                              then cout the translated terms that are found?

                              this map seems like a good start though. however it lists every word in the dictionary which would be 5000 words long

                              woudln't the multimap be a little redundant? meaning you would have to create 5000 pair strings, 5000 dsp.insert and then code 5000 rval output for translation? that code would be like several hundred thousand lines long... or am i missing something?

                              Comment

                              • jerger
                                New Member
                                • May 2007
                                • 77

                                #60
                                With the following program, how can I get it to loop to search for the next word? my statement does not work with a do or while loop even though it is suppose to subtract a word, then search for the next word, it never can... if you search one word, it translates. if you search two words it does not

                                #include <map>
                                #include <string>
                                #include <iostream>

                                using namespace std;

                                string pause; // pause the program

                                int main()
                                {
                                map<string,stri ng> dictionary;

                                // examples of adding to the dictionary
                                dictionary["I"] = "kuv";
                                dictionary["love"] = "hlub";
                                dictionary["you"] = "kij";

                                // searching the dictionary
                                string translateme; //user input

                                //***
                                int pos; string tempword;
                                #
                                int pointer;

                                //***
                                string s;//////

                                cout<<"Please enter the English words / sentance to be translated to Hmong:" << endl;
                                cin>>translatem e;



                                //insert loop here

                                pos = translateme.fin d(" ");
                                //translateme = translateme.sub str(pos+1, translateme.len gth());

                                s = translateme.sub str(pos+1, translateme.len gth());
                                translateme= translateme.sub str(pointer, pos);

                                map<string,stri ng>::iterator it = dictionary.find (s);

                                if (it != dictionary.end( ))
                                {
                                cout << s << " = " << it->second << "\n" <<endl;
                                }
                                else
                                {
                                cout << s << " not found in the dictionary\n";
                                }





                                cin >>pause;
                                return 0;
                                }

                                Comment

                                Working...