473,597 Members | 2,341 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A program reads a file and corrects a word

1 New Member
I need to write a program that reads a text file, which contains words that are followed with a preposition. If the preposition is wrong for the word, the program is supposed to warn the reader and suggest the correct preposition that follows a specific word.

Ex:

>> The decrease *of* (in) diseases is a positive development...

the preposition of is not correct, in is.

I am having a hard time starting, I don't know how the whole structure should look? maybe a dicitionary with the words (as keys) and prepositon. {"decrease":"of "} ?

Could anybody help =)??
Oct 15 '07 #1
2 1828
KaezarRex
52 New Member
I need to write a program that reads a text file, which contains words that are followed with a preposition. If the preposition is wrong for the word, the program is supposed to warn the reader and suggest the correct preposition that follows a specific word.

Ex:

>> The decrease *of* (in) diseases is a positive development...

the preposition of is not correct, in is.

I am having a hard time starting, I don't know how the whole structure should look? maybe a dicitionary with the words (as keys) and prepositon. {"decrease":"of "} ?

Could anybody help =)??
A dictionary sounds like a good idea to me. You'll also probably want a list of all the prepositions you might encounter so your program knows where to check for the proper prepositions. Id suggest reading in the whole text file as a string, and then using "split(' ')" to break the string into a list that you can look through word by word. That way when you come across a preposition, you can back up one index and check the word in front of it.
Oct 15 '07 #2
KaezarRex
52 New Member
Maybe something like this:

Expand|Select|Wrap|Line Numbers
  1. prepositions = [] #put all your prepositions in here
  2. words = {} #put {word : preposition} pairs in here
  3. file = open("file.txt", "r")
  4. text = file.read()
  5. text = text.split(' ')
  6. for i in range(len(text)):
  7.     if text[i] in prepositions and i > 0:
  8.         #make sure that text[i - 1] is the right word
  9.         #then suggest the right preposition if needed
Remember that your also going to have to ignore punctuation some how.
Oct 15 '07 #3

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

Similar topics

44
4024
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are identical with which. Write a program that prints out which file are redundant copies. Here's the spec. -------------------------- The program is to be used on the command line. Its arguments are one or
9
2345
by: santosh | last post by:
Hello all, I've put together a small program to count the number of characters and 'words' in a text file. The minimum length of a word, (in terms of no. of characters), as well as word delimiting characters can be specified on the command line. The default delimiting characters built into the program are space, newline, tab, carriage return, form feed, vertical tab, comma and null. If a 'u' or 'U' is specified as the last command line...
66
5329
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it occurs. After the program has read the file, it should offer a menu with three choices. the first is to list all the words along with the number of occurences. The second is to let you enter a word, with the program reporting how many times the...
0
1543
by: joestevens232 | last post by:
I need some serious help...I got the first part of the program done the accountant part but i can't figure out how to do the checker..i have been trying for hours and nothings workin any help or reccomendations woulde be greatly appreciated... 1. Accountant. Write a program that accepts a sequence of integers (some of which may repeat) as input and prints every integer exactly once. You can assume that there are no more than 20 integers in...
1
1858
by: tnt84 | last post by:
I want to write a program that reads a text file and prints out the word frequencies using structure but I don't know exactly what the word frequency is and how can I write that program using structure
9
1642
by: tiwarinitin.3108 | last post by:
An interactive program that reads 3 list of numbers, which are stored in three seperate files, and creates one sorted list. Each file should contain not more than 15 numbers.
3
2944
by: kaka_hunter | last post by:
#include <iostream> #include <fstream> using namespace std; const int max_tries=7; int earnings=0; int wordnum; void getword () { ifstream fin;
82
3658
by: Bill David | last post by:
SUBJECT: How to make this program more efficient? In my program, a thread will check update from server periodically and generate a stl::map for other part of this program to read data from. Let's name the update method as doUpdate and stl::map read methods as getData and copyData. Since stl::map is not thread-safe, we should do synchronization by ourselves. A usable solution is to create a boost::mutex::scoped_lock object in all above...
0
7893
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8276
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...
1
8040
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
8259
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...
0
6698
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5436
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
3889
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...
0
3932
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1243
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.