Solved

How do I create a pipes and filters pattern based program that will tell how many unique words are in an input text file?

Posted on 2004-04-19
7
449 Views
Last Modified: 2012-05-04
I need to  create a pipes and filters pattern based program that will tell how many unique words are in an input text file.  I must write the program in java.  It can use either active or passive filters, meaning either a function waits to be called to do something, or does something automatically, I think.  Each filter or function should do a specific defined task that could be interchangeable with another program if necessary.  I must complete the program by this Thursday. (April 22, 2004)  Somewhat Urgent!!
0
Comment
Question by:tmp09
  • 4
  • 2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10863664
Have a look at the StreamTokenizer class
0
 
LVL 92

Expert Comment

by:objects
ID: 10865036
create an interface for your filter eg.

public interface Filter
{
   /**
   *  Process a word and pass it to next filter for processing
   */

   public String process(String word);
}

You can then create your own Filter implementations, and pass words thru your filters as you read them.

eg.

public class UniqueCounterFilter implements Filter
{
   private Set Words = new HashSet();

   public int getWordCount()
   {
      return Words.size();
   }

   public String filter(String word)
   {
      Words.add(word);
      return word;
   }
}
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 10865056
you couldf use something like the following to read the words from the file:

BufferedReader in = new BufferedReader(new FileReader(filename));
String line = null;
while (null!=(line=in.readLine()))
{
   StringTokenizer st = new StringTokenizer(line);
   while (st.hasMoreTokens())
   {
       String word = st.nextToken();
       // pass word thru your filters
   }
}

Let me know if u have any q's :)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:tmp09
ID: 10865367
thanks a lot.....i'm not sure about the interface though  some help with that would be appreciated
0
 
LVL 92

Expert Comment

by:objects
ID: 10865379
What exactly don't u understand?
0
 

Author Comment

by:tmp09
ID: 10901702
I've been working on this program and still can't figure it out.  Is there any waysomeone could write out some actual code to make this work?  Anything would help.
0
 
LVL 92

Expert Comment

by:objects
ID: 10904518
We can't complete your homework for your here we can only provide guidance sorry.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now