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
458 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 103
groovy example issue 10 90
even odd program using while loop 3 29
Why my table column Id is not passed to java object? 4 28
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

862 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

26 Experts available now in Live!

Get 1:1 Help Now