Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

Sequential Search

Guys a new some help in my Sequential Search.

ill explain with an example. since i feel it is easier for me to explain

let assume ive got

user input: Graphics
Pattern: is defined as
Sentence in file: Graphics is purely defined as a field in Computer Science

1)u.input = Graphics = first token of the sentence (Sentence_token)

2)pattern_token = "is" = Sentence_token

3)pattern_token = "defined" NOTEQUALTO "purely"= Sentence_token  
therefore,Pattern_token (remains same we dont get the next token) = "defined" BUT Sentence_token = "defined"

4)pattern_token = "as" = Sentence_token

5) print Sentence.

take the input from the user and compare it with SENTENCE
     if found than we take the secound token from the SENTENCE and compare it with the first token in the PATTERN
          if equal than get the next token of the PAttern and next token of the SENTENCE and compare again. continue                till we reach have no more tokens.

     else if the token from the PATTERN does not match the token from the SENTENCE than only get the next token for the SENTENCE while keeping the old token of the PATTERN and compare again.

note this is not a Strict sequential search in other words its not nesscary that all the Patterns such as (is defined as) have to come after one another with no words in between.

Hope i made things clear..i written a code but it doesnt work properly..

can anyone help me ..


0
cancer_66
Asked:
cancer_66
  • 32
  • 17
1 Solution
 
cancer_66Author Commented:
below is the code i have Written

import java.io.*;
import java.io.IOException;
import java.util.*;
import java.awt.*;
import java.awt.event.*;



public class MainMarkerGUI extends Panel implements ActionListener{

String userinput;
String mainMarker[]={"described","defined","delimeted"};
String List1[]={"is","are","was","be"};
String List2[]={"defined","described","delimeted"};
String List3[]={"as","by"};
String patternFound="";
boolean patternFoundF=false;
String findResult[]=new String[30];
String findFlNme[]=new String[30];
int countResult=0;
StringTokenizer token;
StringTokenizer filetoken;

String InputResults="";

/*
     * UI Components
     */
    TextField search =new TextField(18);
    Label searchlab = new Label("Search for");
    Scrollbar bar = new Scrollbar();
    TextArea results      = new TextArea("",15,40,10);;      
       Button go             = new Button("GO!");          
    Button send       = new Button("Send CLONE!");        
    Button close       = new Button("CLOSE");        
      Panel Resultpanel = new Panel();
      Panel Buttonpanel = new Panel();
      Panel Inputpanel =new Panel();
      Panel checkbox =new Panel();
      
      
      CheckboxGroup cbg = new CheckboxGroup();
      Checkbox ran = new Checkbox("Random",cbg,true);
      Checkbox seq = new Checkbox("Sequential",cbg,false);
      
      
      
 public MainMarkerGUI(){

   
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    setLayout(gridbag);

    c.insets = new Insets(3,3,3,3);

    c.fill = GridBagConstraints.NONE;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 1;
    c.weightx = 0.5;
    c.anchor = GridBagConstraints.NORTHWEST;
    gridbag.setConstraints (searchlab, c);
    add(searchlab);

    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 1;
    c.gridy = 0;
    c.gridwidth = 1;
    c.weightx = 0.5;
    c.anchor = GridBagConstraints.NORTHEAST;
    gridbag.setConstraints(search, c);
    add(search);
   
      c.fill = GridBagConstraints.BOTH;
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.anchor = GridBagConstraints.CENTER;
    gridbag.setConstraints(results, c);
    add(results);
    c.weighty = 0.0;

    c.fill = GridBagConstraints.NONE;
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.CENTER;
   checkbox.setLayout(new GridLayout(1,3));
   checkbox.add(ran);
   checkbox.add(seq);
    gridbag.setConstraints(checkbox, c);
    add(checkbox);

    c.fill = GridBagConstraints.NONE;
    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.CENTER;
   Buttonpanel.setLayout(new GridLayout(1,4));
   Buttonpanel.add(go);
   Buttonpanel.add(close);
   Buttonpanel.add(send);
   gridbag.setConstraints(Buttonpanel, c);
   add(Buttonpanel);

   go.addActionListener(this);
   send.addActionListener(this);
   close.addActionListener(this);
   
                     /** WHEN THE USER PRESSES THE ENTER BUTTON RESULT IS DISPLAYED ON THE SCREEN **/
                     
            KeyListener kl = new KeyListener() {
        public void keyPressed(KeyEvent e) {}

           public void keyReleased(KeyEvent e) {
               if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                 InputResults = search.getText();
                             userinput = InputResults;
                            readFile("c:\\TravelPlan1.txt");
                            readFile("c:\\XYZ.txt");
                             printResults();
               
                }
           }

         public void keyTyped(KeyEvent e) {}
    };

   search.addKeyListener(kl);



           }
   
public static void main(String args[]){

      

      Frame agletFrame = new Frame();
    MainMarkerGUI f = new MainMarkerGUI();
    agletFrame.setLayout(new BorderLayout());
    agletFrame.add("Center", f);
    agletFrame.pack();
         agletFrame.resize(agletFrame.preferredSize());
    agletFrame.reshape(20,20,350,400);
    agletFrame.setTitle("aglet interface Example");
    agletFrame.show();
   
      /** When user clicks on the "X" icon on the top left corner windows is closed **/
   
    agletFrame.addWindowListener(
        new WindowAdapter() {
             public void windowClosing(WindowEvent e) {
                  System.exit(0);
             }
       }
   );
    agletFrame.show();
   
   
}

public void actionPerformed(ActionEvent event)
    {
    if (event.getSource() == go){
                InputResults = search.getText();
                userinput = InputResults;
                readFile("c:\\TravelPlan1.txt");
                readFile("c:\\TravelPlan2.txt");
                printResults();
               
               
         }
         
     else if (event.getSource() == close)
     {
           System.exit(0);
     
     }
     else if(event.getSource()==send){
     
           
           }
     
       
    }

public void readFile(String fileName){
            BufferedReader fin;
            fin=null;
            String str;
            String dummy="";
            String sDummy="";
            str=null;
            
            try{
                  FileInputStream st = new FileInputStream(fileName); //reading the file
                  fin = new BufferedReader(new InputStreamReader(st)); //put the file in buffer
                  
            }
            catch(FileNotFoundException e) //catch exception if file not found
            {
                  System.out.println("File Not Found" + e);
            }
            
      
            try{
                  while((str=fin.readLine())!=null) { //reads the strings from the file
                        
                        
                        StringTokenizer sToken=new StringTokenizer(str); //tokenise the input string
                        
                                    
                        while(sToken.hasMoreElements()){      //makes token for whole string
                              dummy=sToken.nextToken();            //gets next token stored in dummy            
                              if(!dummy.equals("#"))                  //checks condition for #
                                    sDummy=sDummy + " " + dummy; // if # not found than add string sDummy
                              
                              if(dummy.equals("#")){ //if # found send the string to function to resolve the pattens
                                    PattrnsSolv(sDummy,fileName);
                        
                                    sDummy=""; //reset sDummy
                              }                  
                        }
                  
                  }
            }
            catch(IOException ex){ //catch exception if cannot read from file
             System.out.println("IO Exception" + ex);
             ex.printStackTrace();

                  }
      }



private void PattrnsSolv(String str, String fileName){ //funcation for solving patterns after # character is met
      
      boolean find=false;//if patterns are already found = true, otherwise =false
      int ntokens,nTokens; //gets the total tokens from the file string and patterns
      String newStr; //used to get the new token from the pattern
      String dummy="";//get the next token from the file string
      newStr=" "; //intialise the string
      ntokens=0;
      nTokens=0;
      String nPatterns=""; //make new patterns by adding user input to the patterns
      StringTokenizer filetoken=null;
               filetoken=new StringTokenizer(str);
                  boolean foundNew=false;
                  while(filetoken.hasMoreElements()){ //loops through file string token
                        dummy=filetoken.nextToken(); //gets the next token file string
                        for(int t=0;t<mainMarker.length;t++)
                        if(mainMarker[t].equalsIgnoreCase(dummy)){
                              foundNew=true;                  
                              
                              }            
                  }
            
      if(foundNew){
                        filetoken=new StringTokenizer(str);
                          while(filetoken.hasMoreElements()){ //loops through file string token
                              dummy=filetoken.nextToken(); //gets the next token file string
                                    if(userinput.equalsIgnoreCase(dummy)){
                                          dummy=filetoken.nextToken();
                                          if(foundInList(List1,dummy)){
                                                dummy=filetoken.nextToken();
                                                if(foundInList(List2,dummy)){
                                                      dummy=filetoken.nextToken();
                                                      if(foundInList(List3,dummy)){
                                                            
                                                            if(countResult>0){
                                                                        for(int k=0;k<countResult;k++){
                                                                              if ((findResult[k].equalsIgnoreCase(str))){
                                                                                    find=true;      
                                                                              }
                                                                        }
                                                                  }
                                                                        if(!find){      
                                                                                    findResult[countResult]=new String(str);
                                                                                    findFlNme[countResult]=new String(fileName);
                                                                                    countResult++;
                                                                                    find=false;
                                                                        
                                                                        }      
                                                                        if(countResult==0){
                                                                              
                                                                              findResult[countResult]=new String(str);
                                                                              findFlNme[countResult]=new String(fileName);
                                                                              countResult++;                              
                                                
                                                                        }
                                          
                                                                  }
                                                            }
                                                      }
                                          }
                         
                              
                  }
      }
}

      private void printResults(){ //prints the final results
                  String foundLet="";
            for(int j=0;j<countResult;j++)
                  foundLet =foundLet+"\n\n" + " "+ "The Result at File" + findFlNme[j] + " is: " +  findResult[j];
                  results.setText(foundLet);
                  
      }
      

private boolean foundInList(String Lists[],String word){
      
      for(int i=0;i<Lists.length;i++){
                                                            
                                          if(Lists[i].equalsIgnoreCase(word)){
                                                                  
                                          
                                                return true;
                                                
                                          }            
                          

                        }
                            return false;
      }
      
      

}
0
 
ozymandiasCommented:
It's not clear what you are trying to do.

Let's say you have sentence1 : "mary had a little lamb" : and you have sentence2 to compare it to.

You are going to compare the two sentences token by token to see if they match.

Strictly speaking, the only match that will be correct is if sentence2 is also "mary had a little lamb".

However, from your question if sentence2 was : "mary and jane went to a restaurant and had a little plate of lamb samosas" : it would still match because all the tokens in sentence1 exist in sentence2 in the same order, even though the sentences are different.
0
 
cancer_66Author Commented:
Note TravelPlan1.txt Contains the followimg Sentences

Graphics is defined as a pictorial computer output produced on a display screen, plotter, or printer # Graphics is purely delimeted by science # Graphics is delimeted by science # Graphicsis defined as science #

TravelPlan2.txt Contains

Graphics be defined as the science of calculating by  diagrams. # Graphics defined t t t is t as # Graphics was defined by the Science Acadamy in london # Graphics is the an important subject in the computer strand # Graphics is described as the art of drawing used in mathematics and engineering. #

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!

 
cancer_66Author Commented:
Well let say iam only searching for definitions
there fore ill have patterns such as

Patterns = is defined as, was defined as, can be defined as, is described as, ..etc

Sentences = Graphics is defined as a field in Computer Science, Graphics was defined as a complex image, Graphics is purely defined as a field and so on.

what i mean is that iam going to specify the sentences in the file there fore they are all going to be related to the definition.
0
 
ozymandiasCommented:
OK.


String s = "[your_sentence_goes_here]";
Pattern p = Pattern.compile("^Graphics\\b.*(is|are|was|be)(defined|described|delimited)(by|as).*$");
Matcher m = p.matcher(s);
if(m.matches()){
    //we have a sentence that matches
}
0
 
ozymandiasCommented:
The above code uses java.util.regex to pattern match a sentence against a regular expression that :

1. Starts with the word "Graphics".
2. Followed by anything
3. Followed by either is, are, was or be
4. Followed by defined, described or delimited
5. Followed by by or as
6. followed by anything


Much simpler, don't you think ?
0
 
ozymandiasCommented:
java.util.regex was only recently introduced, so if you don't have Java 1.4 or later you can use the method matches() in String, which does the same sort of thing.
0
 
cancer_66Author Commented:
Hmm. iam going to read the sentences from a File therefore whenever i read "#" i take that sentence and tokenize it. i also tokenize the patterns

will it still work? your solution?

secondly the user input can vary he can search for graphics, internet ..etc therefore iam not restricted to only one input.

0
 
cancer_66Author Commented:
yes iam using java 1.08.
iam restricted with jdk 1.08 since the software iam using works on that..

0
 
cancer_66Author Commented:
one more thing the user input = Graphics needs not to be in the begining of the sentence.

which means i can have a sentence like = Computer Science is defined as Graphics.

0
 
ozymandiasCommented:
String userInput = "Graphics"; //or wahetever.
String pattern = ".*(is|are|was|be)(defined|described|delimited)(by|as).*";
String sentence = "Computer Science is defined as Graphics"; //or wahetever

//first check to see if the sentence conatins the user input

if (sentence.indexOf(userInput) > -1){
    if sentence.matches(pattern){
        //we have a winner !
    }
}

Unfortunately, none of this will work in 1.08.
0
 
cancer_66Author Commented:
:(

i really cant use jdk 1.4

isnt there any other way of doing it..

i need to modify the code ..
0
 
cancer_66Author Commented:
can anyone help me please.
0
 
ozymandiasCommented:
I would simplify things.
Firstly I would not look for the first set of tokens, i.e. is, was, be or are at all.
That leaves a reduced set of patters to find.

defined as
defined by
described as
described by
delimited as
delimited by

Then I would not tokenize each sentence.
I would just check each sentence to see if it contained both the keyword (e.g. Graphics") and one of the patterns.
0
 
cancer_66Author Commented:
the problem is this is the way my supervisor told me to do.

he said to check to the MainMarker = defined,described..etc

if it equal in the sentence then take one element from List1 compare it with the sentence if it equal
else take second element from list1..etc till one matches

then take one elemet from list2 and compare with the sentence if equal than go to the list3 and take one elemet

therefore if boolean found in list1, list2 and list3 are true

print sentence.

String List1[]={"is","are","was","be"};
String List2[]={"defined","described","delimeted"};
String List3[]={"as","by"};

Graphics is TOKEN defined TOKEN as Computer science (this is printed)

Graphics defined TOKEN TOKEN is TOKEN as (not printed)

sequence of pattern should be considered
i.e is TOKEN defined TOKEN as notice "is then defined then as"


0
 
ozymandiasCommented:
OK, how about this.
Copy and paste the code below into a file and name it DefinitionChecker.java and then compile it.

You should then be able to run :

    java DefinitionChecker Graphics

I have put all the sentences into an array because I can be aresed with setting up all the file IO etc.
0
 
ozymandiasCommented:
public class DefinitionChecker{

     String keyword;

     String[] token1 = new String[]{" is "," are "," was "," be "};
     String[] token2 = new String[]{" defined "," described "," delimited "};
     String[] token3 = new String[]{" as "," by "};
     String[] sentences = new String[]{
          "1.Graphics are described as pictures",
          "2.Pictures are described as Graphics",
          "3.Graphics is defined as a pictorial computer output produced on a display screen, plotter, or printer",
          "4.Graphics is purely delimited by science",
          "5.Graphics is usualy delimited by science",
          "6.Graphics is delimited by science",
          "7.Graphics is defined as science",
          "8.Graphics be defined as the science of calculating by diagrams.",
          "9.Graphics defined t t t is t as",
          "10.Graphics was defined by the Science Acadamy in london",
          "11.Graphics is the an important subject in the computer strand",
          "12.Graphics is described as the art of drawing used in mathematics and engineering."
     };

     public static void main(String[] args){
          if (args.length < 1){
               System.out.println("USAGE : DefintionChecker keyword");
          }
          DefinitionChecker dc = new DefinitionChecker(args);
     }

     public DefinitionChecker(String[] args){
          keyword = args[0].toLowerCase();
          for (int i = 0; i < sentences.length; i++){
               int pos = 0;
               //System.out.println("Checking : " + sentences[i]);
               if (sentences[i].toLowerCase().indexOf(keyword) > -1){
                    if ((pos = containsToken(token1,sentences[i].toLowerCase(),pos)) != -1){
                         if ((pos = containsToken(token2,sentences[i].toLowerCase(),pos)) != -1){
                              if ((pos = containsToken(token3,sentences[i].toLowerCase(),pos)) != -1){
                                   System.out.println("\t\tMATCH : " + sentences[i]);
                              }else{
                                   //System.out.println("\t\t" + sentences[i] + " has no token3.");
                              }
                         }else{
                              //System.out.println("\t\t" + sentences[i] + " has no token2.");
                         }
                    }else{
                         //System.out.println("\t\t" + sentences[i] + " has no token1.");
                    }
               }else{
                    //System.out.println("\t\t" + sentences[i] + " has no keyword.");
               }
          }
     }

     private int containsToken(String[] tokens, String s, int pos){
          int tPosition = -1;
          for (int i = 0; i < tokens.length && tPosition == -1; i++){
               tPosition = s.indexOf(tokens[i],pos);
          }
          return tPosition;
     }
}
0
 
cancer_66Author Commented:
ok ill just do that give me a min
0
 
cancer_66Author Commented:
hmmmm this work fine ..

but as i said i need to read the sentences from a file! Graphics are described as pictures # Pictures are described as Graphics # Graphics defined t t t is t as #

once the  meet a "#" i take the sentence eg. "Graphics are described as picture" tokenizer it and then compare it.
       
0
 
cancer_66Author Commented:
Hmmm one more thing before we start comparing with the token1[],token2,token3 we have to preform a check to see whether out MainMarker is in the sentence

String mainMarker[]={"described","defined","delimeted"};

if the MainMarker is equal to one of the words in the sentence then we take one element for token1,..etc
0
 
cancer_66Author Commented:
guys anyone would help?
0
 
ozymandiasCommented:
Yes, so I'm sure you can write the code that will read the text from a file and tokenise it into an array. I'm not going to write whole thing for you.

If you need to check the sentence to see if it contains on of the "mainMarker" values first then just change the following line :

    if (sentences[i].toLowerCase().indexOf(keyword) > -1){
 to

    if (sentences[i].toLowerCase().indexOf(keyword) > -1 && containsToken(token2,sentences[i].toLowerCase(),0)) > -1){
0
 
cancer_66Author Commented:
iam so sorry i didnt mean to sound that way.
its just that iam not good in programming.
fine i would give it a try and then print it here to take your view if you dont mind?

thanks alot
0
 
cancer_66Author Commented:
i just have one question.

String List1[]={"is","are","was","be","can be"};
String List2[]={"defined","described","delimeted"};
String List3[]={"as","by","such as"};

as you can see above i have added one more token to list1 which is "can be" and another to list3 which is "such as"

now when iam going to tokenize the sentence lets assume

Graphics can be defined such as cs

tokens would be Graphics,can,be,defined,such,as,cs

therefore i think the pattern from list1[] and list2[] which is "can be","such as" would not match the sentence tokens.

am i right ?

0
 
cancer_66Author Commented:
i didnt what you told me to change

   if (sentences[i].toLowerCase().indexOf(keyword) > -1){
to

   if (sentences[i].toLowerCase().indexOf(keyword) > -1 && containsToken(token2,sentences[i].toLowerCase(),0)) > -1){

i recieved the following error
C:\aglets\public\web examples\DefinitionChecker.java:40: Missing term.
                 if (sentences[i].toLowerCase().indexOf(keyword) > -1 && containsToken(token2,sentences[i].toLowerCase(),0)) > -1){
                                                                                                                            ^
C:\aglets\public\web examples\DefinitionChecker.java:40: Invalid expression statement.
                 if (sentences[i].toLowerCase().indexOf(keyword) > -1 && containsToken(token2,sentences[i].toLowerCase(),0)) > -1){
                                                                                                                             ^
C:\aglets\public\web examples\DefinitionChecker.java:40: ';' expected.
                 if (sentences[i].toLowerCase().indexOf(keyword) > -1 && containsToken(token2,sentences[i].toLowerCase(),0)) > -1){
                                                                                                                                 ^
C:\aglets\public\web examples\DefinitionChecker.java:54: 'else' without 'if'.
              }else{
               ^
0
 
cancer_66Author Commented:
forget about the last question. its working fine.
0
 
ozymandiasCommented:
OK. Here is what I have :

The first thing is the code with the modifications you asked for and it now reads the sentences from a file specified on the command line like so :

    java DefinionChecker graphics sentences.txt

the second is the contents of my sentences.txt file.

It all works fine for me.

0
 
ozymandiasCommented:
import java.util.Vector;
import java.io.*;

public class DefinitionChecker{

     String keyword;

     String[] token1 = new String[]{" is "," are "," was "," be "," can be "};
     String[] token2 = new String[]{" defined "," described "," delimited "};
     String[] token3 = new String[]{" as "," by "};
     String sentences[];

     public static void main(String[] args){
          if (args.length < 1){
               System.out.println("USAGE : DefintionChecker keyword file");
          }
          DefinitionChecker dc = new DefinitionChecker(args);
     }

     public DefinitionChecker(String[] args){
          try{
               sentences = getArrayFromFile(new File(args[1]));
          }catch(IOException ioe){
               System.out.println(ioe);
          }
          keyword = args[0].toLowerCase();
          for (int i = 0; i < sentences.length; i++){
               int pos = 0;
               //System.out.println("Checking : " + sentences[i]);
               if (sentences[i].toLowerCase().indexOf(keyword) > -1 && containsToken(token2,sentences[i].toLowerCase(),0) > -1){
                    if ((pos = containsToken(token1,sentences[i].toLowerCase(),pos)) != -1){
                         if ((pos = containsToken(token2,sentences[i].toLowerCase(),pos)) != -1){
                              if ((pos = containsToken(token3,sentences[i].toLowerCase(),pos)) != -1){
                                   System.out.println("\t\tMATCH : " + sentences[i]);
                              }else{
                                   //System.out.println("\t\t" + sentences[i] + " has no token3.");
                              }
                         }else{
                              //System.out.println("\t\t" + sentences[i] + " has no token2.");
                         }
                    }else{
                         //System.out.println("\t\t" + sentences[i] + " has no token1.");
                    }
               }else{
                    //System.out.println("\t\t" + sentences[i] + " has no keyword or has no token2.");
               }
          }
     }

     private int containsToken(String[] tokens, String s, int pos){
          int tPosition = -1;
          for (int i = 0; i < tokens.length && tPosition == -1; i++){
               tPosition = s.indexOf(tokens[i],pos);
          }
          return tPosition;
     }

     private String[] getArrayFromFile(File f) throws IOException{
          FileReader reader = new FileReader(f);
          Vector sentences = new Vector();
          char[] cbuf = new char[1];
          String delimiter = "#";
          String sentence = "";
          String c = "";
          while (reader.read(cbuf) != -1){
               c = new String(cbuf);
               if (c.equals(delimiter)){
                    sentences.add(sentence);
                    sentence = "";
               }else{
                    sentence += c;
               }
          }
          String[] sentenceArray = new String[sentences.size()];
          sentenceArray = (String[])sentences.toArray(sentenceArray);
          return sentenceArray;
     }
}
0
 
ozymandiasCommented:
1.Graphics are described as pictures#2.Pictures are described as Graphics#3.Graphics is defined as a pictorial computer output produced on a display screen plotter or printer#4.Graphics is purely delimited by science#5.graphics defined is by nonsense#6.Graphics is delimited by science#7.Graphics is defined as science#8.Graphics be defined as the science of calculating by diagrams.#9.Graphics defined t t t is t as#10.Graphics was defined by the Science Acadamy in london#11.Graphics is the an important subject in the computer strand#12.Graphics is described as the art of drawing used in mathematics and engineering.#
0
 
cancer_66Author Commented:
i just copied and pasted the above code and got the following errors?

C:\aglets\public\web examples\DefinitionChecker.java:68: Method add(java.lang.String) not found in class java.util.Vector.
                   sentences.add(sentence);
                                ^
C:\aglets\public\web examples\DefinitionChecker.java:75: Method toArray(java.lang.String[]) not found in class java.util.Vector.
         sentenceArray = (String[])sentences.toArray(sentenceArray);
                                                    ^
2 errors
0
 
cancer_66Author Commented:
forget about the last question. i think it has to do with the JDK version iam using. it compiled now

ok i tried java DefinitionChecker graphics TravelPlan1.txt

Exception in thread "main" java.lang.NoClassDefFoundError: DefinitionChecker

where should the TravelPlan.txt file be? should it be in the same directory as DefinitionChecker file ? hmm i tried that and got the same error message?
0
 
ozymandiasCommented:
The problem you have is not to do with the text file, it is related to the class file.

The error you are getting suggests that java cannot find DefinitionChecker.class which probably means that either your have a problem with your classpath or you are not running the program from the correct location.

You should have DefinitionChecker.java.
Compile it into DefinitionChecker.class.

In the same directory as DefinitionChecker.class run :

    java DefinitionChecker graphics textfile

If the texfile is in the same directory you just put the name of the file. If not, you should put the full path to the file.
0
 
cancer_66Author Commented:
hmm..i think what cause the problem is that i had jdk 1.08 installed

so i deleted that and installed jdk 1.3.1?

eventhough i have my DefinitionChecker1.java in c:/jdk/bin
as well as my TravelPlan1.txt

but still get the same error ?
0
 
ozymandiasCommented:
Then your classpath must be wrong.
Your classpath must have . or current working directory included in it.

Try :

java -cp .;%CLASSPATH% DefinitionChecker graphics textfile
0
 
cancer_66Author Commented:
what shall i add in my Enironment Variables
my jdk1.3.1 is installed in c:\jdk

i mean the class path.
0
 
ozymandiasCommented:
BTW, you should have DefinitionChecker1.class as well as DefinitionChecker1.java. You have compiled this code properly haven't you ?
0
 
ozymandiasCommented:
java -cp .;%CLASSPATH% DefinitionChecker graphics textfile
0
 
cancer_66Author Commented:
ok i have done what u have just told me and it worked. but how can i fix the classpath. i think the error occured when i deleted the Jdk1.08 and installed the JDk 1.3.1

since i have Environment Variable which i have set before are no longer valid.?
0
 
cancer_66Author Commented:
yes i have compiled the DefinitionChecker1.java

and i have done java -cp %CLASSPATH% DefinitionChecker graphics c:\TravelPlan1.txt

the only match was: Graphics is defined as a pictorial computer output produced on a display screen plotter or printer#4.Graphics is purely delimited by science

eventhough my file contained :

Graphics is defined as a pictorial computer output produced on a display screen, plotter, or printer # Graphics is purely delimeted by science # Graphics is delimeted by science # Graphicsis defined as science #
0
 
cancer_66Author Commented:
aaaahhhhhhhhhhh iam really sorry my mistake i miss spelt one of the words..

i guess iam so tried.

0
 
cancer_66Author Commented:
Thanks alot for your help, its really appricated.

i will show this work to my project supervisor.and see what he has to say.

ill let you know tomorrow. thanks a billion
0
 
cancer_66Author Commented:
hi again,

i just showed the work to my supervisor. well he was happy about it. thanks to you.

now i need to extend the code. inorder to allow it to read
from a file automatically. i.e i sepcify the path of the file in the code(there many be more than one file to be read). the result should also include name of the file from which it obtained the data.

for example output : from file C:\TravelPlan1.txt
                               Match:graphics is defined..
                               Match:



0
 
ozymandiasCommented:
OK. However, I would suggest that I have more than adequately answered your original question.

Plesae award points and a grade and then open a new question if you wish to extend the code further.
0
 
cancer_66Author Commented:
i would definatly give you points. that goes without saying.

why open another question. its better to do everything here. since its all in sequence. anyways its not a big deal ozymandias if u want ill open up a new question.

The supervisor just commented that searching for a single word i.e graphics, is not enough. he said that i should extend it to search for Terms such as "Computer Graphics"

which means User Input = "computer graphics"?

anyways let me know if you want me to post a new question.there is no problems.
0
 
cancer_66Author Commented:
i really appricate your help.
0
 
cancer_66Author Commented:
ill be waiting for your response.
0
 
cancer_66Author Commented:
guess you are busy. anyways ill be waiting for your answer. please reply me soon. thanks
0
 
cancer_66Author Commented:
since i wont be on my seat for a 2hours. i already posted a new question titled "Sequential search continued to Mr ozymandias and other Experts welcomed"

thanks for your help.

0
 
cancer_66Author Commented:
thanks alot.

i have posted a new question "Sequential search continued"
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.

  • 32
  • 17
Tackle projects and never again get stuck behind a technical roadblock.
Join Now