473,722 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

77 New Member
I want to help teach to a minority group in Milwaukee, so I want to create a dictionary program that translates a sentence (like a homework problem or teacher instructions), from English into Hmong.

I have one Idea, and that is to have an English text file of all the A-words, then a Hmong text file of the proper translations. Each text file would have the same amount of lines, with one english word per line, then translated to hmong. Would it be even possible to..

1. user inputs question, "Describe the holocaust"
2. describe is looked in the d text (like if d, search d.txt), then the word is found. then it either compares it to a translation txt (like hmong-d.txt), spitting out the word. then it would prompt to the next word to translate, one line at a time.

A different way was to have 1 giant text file for each letter. like look up "albino", when it finds the word in the a a-dictionary, it searches for the albino string, then finds the comma, then spits out the word/words after the comma. would this be possible as well? which method is easiest for someone that hasn't c++ in a few years?

so far I have a useless code typed up. i just want to start simple getting a-words to work, then get more complex from there. once i have a start i can go with it. please help me, i would love to reach the needs of my esl students who could use this greatly in the US.

summary,i want to take a line of words, compare each word to a specific dictionary, then output one line at a time, the translation. thank you so much!

this code is not correct:

#include <iostream> // I/O
#include <fstream> // file I/O
#include <iomanip> // format manipulation
#include <string>

//This program will hopefully translate english to hmong
using namespace std;
string english; //declare english word to translate
string search; //what to search

int main()
{

cout << "Type the english words here, then press enter. Make sure to copy the words correctly. If you need to spell check use www.google.com" ;
cin >> english;

ifstream myFile;
myFile.open ("c:\\eAh.txt") ;

string* search = english; //search using input
int offset; // where it was found (or not (-1))
if ((offset = line.find(searc h, 0)) != string::npos) {
cout << "found '" << search << "' @ offset " << offset << endl;
}

return 0;
}
May 22 '07
91 7778
ahammad
79 New Member
I'm not sure what you posted, but it sounds to me like the CMapStringToStr ing thing would work. You need to be using Visual Studio though.

Expand|Select|Wrap|Line Numbers
  1.         while (getline(myFile, word, myFile.widen('='))) {    //reads in characters until the '='
  2.  
  3.             getline(myFile, definition);                            //reads in remaining characters in the line, the definition
This simple loop will read the contents of the file called myFile. It will separate the line of data at the equals sign, and then store it into 2 different strings, word and definition.

So let's say the first line has:

house = blabla

Then, after the first iteration of the while loop, "house = blabla" will be stored into the two strings:

word = house
definition = blabla

If you stor this into a CMapStringToStr ing object called CMSTS (for example), you would do this:

CMSTS[word] = definition;

You can also retrieve the definition in the same fashion...it works just like an array.

Of course this code need a few adjustments before it can work. Some variable types have to be changed at some places (from string to CString) and the entire program may need some things defined if you're using UNICODE.

If you're interested I can help you with this.
May 29 '07 #71
jerger
77 New Member
great idea, but i think i wrote unclear..

what i need is user input to be seperated...

so if i ask:

"enter your homework question in english"
cin>question

then i want the program to translate the question, word by word... so i need to find a way to translate one word at a time. i can get it to translate the first word, but not the 2nd and so on.

so ask question, get input, translate input word by word then stop when "." or no more text... or when pointers are equal.... i have no clue how to break up the input string into individual words to search in my dictionary
May 29 '07 #72
ahammad
79 New Member
I understand now. The thing with C++ is that everything you type goes into a pipeline, and the program retrieves the entries (separated by a space) from that pipeline when it needs them.

So I would assume that if you type in a bunch of words one after another, the program will read them all in and give the answer. The only issue is the formatting, it may look awkward.

Edit- Forget what I said, you can just use the same algorithm that I mentioned earlier (the one that splits the lines from the file into a word and a definition), and process them idividually, then show the answer with the series of words one after another.
May 29 '07 #73
jerger
77 New Member
hmm... what about splitting the string input line, not a file line.

1. program asks for a question
2. the program inputs the question into a string
3. the program pulls out one word from the string or it could break up the string altogether and put each word into a temp location
4. program takes one word from the input sentance, then translates it (which my code works for)
5. program moves onto the next word
6. finishes at a period or when its done with words

how can i get it to go onto the next word? that is where i am stuck. it can do one word, but then crash...
May 31 '07 #74
weaknessforcats
9,208 Recognized Expert Moderator Expert
With all this translating of words, have you considered that this will not translate one language into another language?

English: I've been down that path.
Russian: I've stepped on that rake before
Spanish: Me paso otra vez

English: Do not make a fool of me
Spanish: Do not take me by the hair

I mean,like, the metaphors are different.
May 31 '07 #75
ahammad
79 New Member
I'm pretty sure that my code can be modified to do that one way or another
May 31 '07 #76
DeMan
1,806 Top Contributor
With all this translating of words, have you considered that this will not translate one language into another language?
Too true, this may be an urban myth, but apparently someone tried to create somethuing like this for English-Russian and Russian-English.

Entering the phrase "The spirit is willing, but the flesh is weak" and translating it first to Russian then back to English, gave "The Vodka is strong, but the meat is rotten" - Not quite the same thing
May 31 '07 #77
ahammad
79 New Member
Okay, I've made a few tweks to my program and I can get it to do this:

In the Console window:
Expand|Select|Wrap|Line Numbers
  1. Please enter the source file name: test.txt
  2. Abdomen = Plab mog
  3. Able = Rooj
  4. Able = Ua tau
  5. Abortion = Rho menyuam tawm
  6. About = Li ntawm
  7. Above = Saum toj
  8. Please enter a word (type 'abort' to exit>: Abdomen Abortion About Above
  9. Plab mog  Rho menyuam tawm  Li ntawm  Saum toj
It still needs more work with making it loop and getting it to correctly display new lines after every sentence. As it stands now, it simply translates each word individually
May 31 '07 #78
jerger
77 New Member
wow cool! can i see what you mean? did you post the code? that sounds awesome!

i'm also going to research this getline thingy...

ideally what is needed is a breakdown of words, so that kids can use it like an instant dictionary for social studies, so if the question is confusing at least 3-4 words would be helpful (expecially social studies terms that are rare)


**** wait???

what does your program do lol. i need it to translate a specific sentance... so like ask user "please enter your sentance to be translated"... then look either in the program or a text file and search for the specific words that the person inputed in english, then translated them into hmong. is that what it does?


i'm just confused on the program maybe, it looks promising... is there a way to input like 5000 words without saying each word in the dictionary? (maybe im wrong but it looks like it read in every line of the text)... then you typed english and it worte in hmong.

thats cool!

it might not make sense in hmong which is ok. but idealy i would like it to say each word on a seperate line to reduce confusion.

why? well you have to study the language.

love = hlub
i = kuv
you= koj

but if you take like 5 different words and put them near eachother you might make a new word...

for instance.... maj mam swb means crawl but ... maj mam =slowly and speak = maj mam hais

so if you accidently have a word like slowly and then hais which means sais, scoop... it might translate as "speaks slowly" instead of crawl speak... i dont know how to say it, this might work... but might get confusing...

since if you write a whole bunch of words together in hmong, they create a new word...

word 1=definition
word 2 = definition

but if you put word 1 next to word 2 it COULD create a new word if not in proper sentance structure... so it might be best to output each word seperatly.. so i could break up your output in hmong to one line each right?


*** update i see that you spaced stuff out when i looked more closely i can simply put an asterisk between it to seperate words... so cool! but still confused on the first part ... is there a way to input text file behind scenes, load it behind scenese then translate? such a cool way to do it tho)

i guess to make it behind scenes i could load dictionary.txt in the background? before asking hte question... saying like "please wait while dictionary loads, if you recieve an error message please make sure dictionary.txt is located in the same folder as this program"
May 31 '07 #79
ahammad
79 New Member
Expand|Select|Wrap|Line Numbers
  1. i'm just confused on the program maybe, it looks promising... is there a way to input like 5000 words without saying each word in the dictionary? (maybe im wrong but it looks like it read in every line of the text)... then you typed english and it worte in hmong.
You are right, it does display every single line of the text file. I only put that in for testing purposes though, to make sure everything was read in properly.

Here is the console output with some changes made to it:

Expand|Select|Wrap|Line Numbers
  1. Please wait while the dictionary loads...
  2. Please enter a word or a sentence:
  3. Abdomen
  4. Abdomen = Plab mog
  5. Able
  6. Able = Ua tau
  7. Abortion
  8. Abortion = Rho menyuam tawm
  9. About
  10. About = Li ntawm
  11. Above
  12. Above = Saum toj
  13. Abdomen Above About Able
  14. Abdomen = Plab mog
  15. Above = Saum toj
  16. About = Li ntawm
  17. Able = Ua tau

I just did a few test cases with single words and whole sentences. I "hard-coded" the file containing all the definitions in the program's code and made each word show separately on different lines. I didn't add a termination command, so the program keeps taking words in forever (it wouldn't be hard to fix that though).
Jun 1 '07 #80

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1765
by: Derek Fountain | last post by:
I'm just starting another PHP project and can see a familiar task not far on the horizon. I have several database record tuples that I need to manipulate - person, department, client, job, etc. - and each one needs a form where the user can enter new details to create a new tuple in the DB, another form where the user can enter a name/id/whatever to query the DB and display the results, another form where the user can modify the existing...
8
1793
by: Aziz McTang | last post by:
Hi Group, I am not an experienced programmer at all. I've learned html and css well enough to hand-write simple websites. I'm now looking to move to the next step. Initially, I'd like to do 3 things: 1) Generate web pages This one's fairly obvious maybe. 2) Create a simplified translation package specific to my line of work:
52
9656
by: piaseckiac | last post by:
I am producing a website on air and need a link to change the entire website from standard to metric for temperature, pressure, miles-kilometers, and volume. Thank you.
46
12541
by: vvk4 | last post by:
I have an excel spreadsheet that I need to parse. I was thinking of saving this as a CSV file. And then reading the file using C. The actual in EXCEL looks like: a,b a"b a","b a,",b In CSV format looks like: "a,b","a""b","a"",""b","a,"",b" Does anybody have suggestions or have C program based code to parse CSV. Please reply to the message board itself. I do not wish to get spam.
39
2107
by: Quick Fox | last post by:
Hi All, Please help for following case: How to Load a Assembly from DLL file and create instance of the class in the loaded file. I want make a function that get 2 string parameters (Assembly file Name and Class Name) and create a instance. Thanks
182
7529
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
4
2131
by: Chris F Clark | last post by:
Please excuse the length of this post, I am unfortunately long-winded, and don't know how to make my postings more brief. I have a C++ class library (and application generator, called Yacc++(r) and the Language Objects Library) that I have converted over to C#. It works okay. However, in the C# version, one has to build the class library into the generated application, because I haven't structured this one thing right. I would like to...
13
3044
by: jerger | last post by:
my program takes users input (words/sentance) and translates it from english to hmong. I have to main variables, but cannot post my entire code. char In; CString in; basically the user cin >> In; then later in = In, then computes using the dictionary. is there anyway i can remove ! commas and periods from the input before translating in my dictionary? i keep getting error codes. if i do this (first idea) if (strcmp(In, "!") == 0)...
0
1703
by: bvdb | last post by:
Hi Everyone, One of my customers lives in Taiwan and can only make my program work if he changes his Regional and Language Options to English from the Simplifies Chinese that his computer is normally set to use. Switching back and forth is very inconvenient for him. Is there a way that I can compile my program so that it works with the Regional Options set to Simplified Chinese? I set my PC Regional Options to Simplified Chinese,...
0
8867
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9158
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6685
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5996
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2148
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.