Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Files  RSS feed

 
Lesole Mphinyane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was asked to prepare a file named abstract with atleast 5 paragraphs.
the lecture is intersted to find out the following about this file:
*how many paragraphs are below 90 words
*given a paragraph number the program should list all sentences which have more than 10 words, these sentences should appear one per line and in alphabetical order...
[ October 08, 2006: Message edited by: Lesole Mphinyane ]
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reply what? Do you have any particular doubt that this community could help you with?

Because the way you posted does not sound like a question.
[ October 07, 2006: Message edited by: Edwin Dalorzo ]
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a homework assignment I was given once. Alot like a homeworks assignment I was given once.

How are you approaching the problem? At what point are you running into trouble? How are you loading the paragraphs into your code? How are you parsing them?

You could read in the program, and chunk the file based on periods. Then, for each chunck, you could count the number of spaces. From there, using higher calculus, you could figure out how many words there are.

There are many options. Let us know which option you are having trouble with.
 
Lesole Mphinyane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guys i still need your help..
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We've already offered you help, buddy, but you have not ask the right questions.


How many paragraphs are below 90 words.


1. You need to read the parragraphs that your file contains. For this purpose you could use a java.util.Scanner.

2. Since every parragraph is separated by a line separator you will need to use a regex in the Scanner. probably somewhat that takes into account line terminators like carriage returns (\r) and new line feeds (\n).

3. Store the all parragraphs in a java.util.Collection object like an java.util.ArrayList.

4. Now go over every parragraph, and split the parragraphs into words, for this purpose you could use String.split() method to get all the words.

5. Now count all the words per parragraph that are not empty strings, when the parragraph is bigger than 90 words store the number of the parragraph (the current index of the parragraph in the List) in another Collection for later use.

6. At the end return a Collection containing the number of the parragraphs with more than 90 word.


Given a paragraph number the program should list all sentences which have more than 10 words


1. Go to the desired parragrah (already obtain in the previous steps) in the parragraph Collection and divide it in sentences.

2. In order to do this you could use the String.split() method again. Take into account that every setence can be separated by period or a semicolon, therefore use a regular expression in the String.split() to get all sentences taking into account this requirements.

3. Once you have the setence, split it in words and count the number of
words.

4. If the sentences is valid, then it is better that you remove line terminators from the sentence (like new line feeds (\n) and carriage returns (\r)).

5. And add the setence fullfilling the requirement of more than 10 words to a java.util.TreeSet so that they are ordered alphabetically.

6. Than display all the elements in the TreeSet.

Good luck, buddy. And when you come back bring some specific doubts!
[ October 09, 2006: Message edited by: Edwin Dalorzo ]
 
Lesole Mphinyane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think i get what you are saying but if you could help me with the coding part of it... Edwin Dalorzo
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Give it a start and see how far you get. Right now we don't know if you can open a file, read a line, store the lines and paragraphs in some form you can work with, etc. Even if your start is very small it's something we can build on together.

I'd like to see if you can open a file and read it a line at a time. This isn't the ideal way to solve the problem, but it will give us a launching point. When problems seem large and imposing, it's comforting to work in very, very small increments, make one thing work before trying the next. The alternative is to write a thousand lines of code and then see if it works. It won't, for any of us.
 
Lesole Mphinyane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please if you could rescue me, i'm submitting tomorow and what i can do is to read the file, count the file words, and search any given word in the file....
if you read what the scenario ontop states you will see that i'm very far..
please help...Stan James
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us what you have so far. Use the "CODE" button below the message-entry box to create CODE tags so the formatting of your code is preserved.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!