?
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
Medium Priority
?
499 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

752 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