Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 511
  • Last Modified:

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

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
tmp09
Asked:
tmp09
  • 4
  • 2
1 Solution
 
CEHJCommented:
Have a look at the StreamTokenizer class
0
 
objectsCommented:
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
 
objectsCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
tmp09Author Commented:
thanks a lot.....i'm not sure about the interface though  some help with that would be appreciated
0
 
objectsCommented:
What exactly don't u understand?
0
 
tmp09Author Commented:
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
 
objectsCommented:
We can't complete your homework for your here we can only provide guidance sorry.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now