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
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
476 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse buid path vs tomcat lib path 10 34
ejb wildfly example 2 25
How  can  i  resolve  HTTP Status 404 -? 8 43
passing enum to a method 4 23
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.

828 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