cancer_66
asked on
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 ..
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 ..
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.
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.
ASKER
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. #
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. #
ASKER
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.
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.
OK.
String s = "[your_sentence_goes_here] ";
Pattern p = Pattern.compile("^Graphics \\b.*(is|a re|was|be) (defined|d escribed|d elimited)( by|as).*$" );
Matcher m = p.matcher(s);
if(m.matches()){
//we have a sentence that matches
}
String s = "[your_sentence_goes_here]
Pattern p = Pattern.compile("^Graphics
Matcher m = p.matcher(s);
if(m.matches()){
//we have a sentence that matches
}
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 ?
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 ?
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.
ASKER
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.
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.
ASKER
yes iam using java 1.08.
iam restricted with jdk 1.08 since the software iam using works on that..
iam restricted with jdk 1.08 since the software iam using works on that..
ASKER
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.
which means i can have a sentence like = Computer Science is defined as Graphics.
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(userInpu t) > -1){
if sentence.matches(pattern){
//we have a winner !
}
}
Unfortunately, none of this will work in 1.08.
String pattern = ".*(is|are|was|be)(defined
String sentence = "Computer Science is defined as Graphics"; //or wahetever
//first check to see if the sentence conatins the user input
if (sentence.indexOf(userInpu
if sentence.matches(pattern){
//we have a winner !
}
}
Unfortunately, none of this will work in 1.08.
ASKER
:(
i really cant use jdk 1.4
isnt there any other way of doing it..
i need to modify the code ..
i really cant use jdk 1.4
isnt there any other way of doing it..
i need to modify the code ..
ASKER
can anyone help me please.
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.
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.
ASKER
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","descri bed","deli meted"};
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"
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",
String List2[]={"defined","descri
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"
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.
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.
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("Chec king : " + sentences[i]);
if (sentences[i].toLowerCase( ).indexOf( keyword) > -1){
if ((pos = containsToken(token1,sente nces[i].to LowerCase( ),pos)) != -1){
if ((pos = containsToken(token2,sente nces[i].to LowerCase( ),pos)) != -1){
if ((pos = containsToken(token3,sente nces[i].to LowerCase( ),pos)) != -1){
System.out.println("\t\tMA TCH : " + 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;
}
}
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[]
keyword = args[0].toLowerCase();
for (int i = 0; i < sentences.length; i++){
int pos = 0;
//System.out.println("Chec
if (sentences[i].toLowerCase(
if ((pos = containsToken(token1,sente
if ((pos = containsToken(token2,sente
if ((pos = containsToken(token3,sente
System.out.println("\t\tMA
}else{
//System.out.println("\t\t
}
}else{
//System.out.println("\t\t
}
}else{
//System.out.println("\t\t
}
}else{
//System.out.println("\t\t
}
}
}
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;
}
}
ASKER
ok ill just do that give me a min
ASKER
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.
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.
ASKER
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
String mainMarker[]={"described",
if the MainMarker is equal to one of the words in the sentence then we take one element for token1,..etc
ASKER
guys anyone would help?
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,sente nces[i].to LowerCase( ),0)) > -1){
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(
to
if (sentences[i].toLowerCase(
ASKER
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
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
ASKER
i just have one question.
String List1[]={"is","are","was", "be","can be"};
String List2[]={"defined","descri bed","deli meted"};
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,su ch,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 ?
String List1[]={"is","are","was",
String List2[]={"defined","descri
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,su
therefore i think the pattern from list1[] and list2[] which is "can be","such as" would not match the sentence tokens.
am i right ?
ASKER
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,sente nces[i].to LowerCase( ),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,sente nces[i].to LowerCase( ),0)) > -1){
^
C:\aglets\public\web examples\DefinitionChecker .java:40: Invalid expression statement.
if (sentences[i].toLowerCase( ).indexOf( keyword) > -1 && containsToken(token2,sente nces[i].to LowerCase( ),0)) > -1){
^
C:\aglets\public\web examples\DefinitionChecker .java:40: ';' expected.
if (sentences[i].toLowerCase( ).indexOf( keyword) > -1 && containsToken(token2,sente nces[i].to LowerCase( ),0)) > -1){
^
C:\aglets\public\web examples\DefinitionChecker .java:54: 'else' without 'if'.
}else{
^
if (sentences[i].toLowerCase(
to
if (sentences[i].toLowerCase(
i recieved the following error
C:\aglets\public\web examples\DefinitionChecker
if (sentences[i].toLowerCase(
^
C:\aglets\public\web examples\DefinitionChecker
if (sentences[i].toLowerCase(
^
C:\aglets\public\web examples\DefinitionChecker
if (sentences[i].toLowerCase(
^
C:\aglets\public\web examples\DefinitionChecker
}else{
^
ASKER
forget about the last question. its working fine.
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.
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.
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("Chec king : " + sentences[i]);
if (sentences[i].toLowerCase( ).indexOf( keyword) > -1 && containsToken(token2,sente nces[i].to LowerCase( ),0) > -1){
if ((pos = containsToken(token1,sente nces[i].to LowerCase( ),pos)) != -1){
if ((pos = containsToken(token2,sente nces[i].to LowerCase( ),pos)) != -1){
if ((pos = containsToken(token3,sente nces[i].to LowerCase( ),pos)) != -1){
System.out.println("\t\tMA TCH : " + 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.toArra y(sentence Array);
return sentenceArray;
}
}
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[]
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("Chec
if (sentences[i].toLowerCase(
if ((pos = containsToken(token1,sente
if ((pos = containsToken(token2,sente
if ((pos = containsToken(token3,sente
System.out.println("\t\tMA
}else{
//System.out.println("\t\t
}
}else{
//System.out.println("\t\t
}
}else{
//System.out.println("\t\t
}
}else{
//System.out.println("\t\t
}
}
}
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.toArra
return sentenceArray;
}
}
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.#
ASKER
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.toArra y(sentence Array);
^
2 errors
C:\aglets\public\web examples\DefinitionChecker
sentences.add(sentence);
^
C:\aglets\public\web examples\DefinitionChecker
sentenceArray = (String[])sentences.toArra
^
2 errors
ASKER
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.NoClassDefFoundE rror: 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?
ok i tried java DefinitionChecker graphics TravelPlan1.txt
Exception in thread "main" java.lang.NoClassDefFoundE
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?
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.
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.
ASKER
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 ?
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 ?
Then your classpath must be wrong.
Your classpath must have . or current working directory included in it.
Try :
java -cp .;%CLASSPATH% DefinitionChecker graphics textfile
Your classpath must have . or current working directory included in it.
Try :
java -cp .;%CLASSPATH% DefinitionChecker graphics textfile
ASKER
what shall i add in my Enironment Variables
my jdk1.3.1 is installed in c:\jdk
i mean the class path.
my jdk1.3.1 is installed in c:\jdk
i mean the class path.
BTW, you should have DefinitionChecker1.class as well as DefinitionChecker1.java. You have compiled this code properly haven't you ?
java -cp .;%CLASSPATH% DefinitionChecker graphics textfile
ASKER
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.?
since i have Environment Variable which i have set before are no longer valid.?
ASKER
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 #
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 #
ASKER
aaaahhhhhhhhhhh iam really sorry my mistake i miss spelt one of the words..
i guess iam so tried.
i guess iam so tried.
ASKER
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
i will show this work to my project supervisor.and see what he has to say.
ill let you know tomorrow. thanks a billion
ASKER
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:
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:
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
i really appricate your help.
ASKER
ill be waiting for your response.
ASKER
guess you are busy. anyways ill be waiting for your answer. please reply me soon. thanks
ASKER
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.
thanks for your help.
ASKER
thanks alot.
i have posted a new question "Sequential search continued"
i have posted a new question "Sequential search continued"
ASKER
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",
String List1[]={"is","are","was",
String List2[]={"defined","descri
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,
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.NORTHWE
gridbag.setConstraints (searchlab, c);
add(searchlab);
c.fill = GridBagConstraints.HORIZON
c.gridx = 1;
c.gridy = 0;
c.gridwidth = 1;
c.weightx = 0.5;
c.anchor = GridBagConstraints.NORTHEA
gridbag.setConstraints(sea
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(res
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(che
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(But
add(Buttonpanel);
go.addActionListener(this)
send.addActionListener(thi
close.addActionListener(th
/** 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.
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(agletFra
agletFrame.reshape(20,20,3
agletFrame.setTitle("aglet
agletFrame.show();
/** When user clicks on the "X" icon on the top left corner windows is closed **/
agletFrame.addWindowListen
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
agletFrame.show();
}
public void actionPerformed(ActionEven
{
if (event.getSource() == go){
InputResults = search.getText();
userinput = InputResults;
readFile("c:\\TravelPlan1.
readFile("c:\\TravelPlan2.
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);
fin = new BufferedReader(new InputStreamReader(st)); //put the file in buffer
}
catch(FileNotFoundExceptio
{
System.out.println("File Not Found" + e);
}
try{
while((str=fin.readLine())
StringTokenizer sToken=new StringTokenizer(str); //tokenise the input string
while(sToken.hasMoreElemen
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,fileNam
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.hasMoreEle
dummy=filetoken.nextToken(
for(int t=0;t<mainMarker.length;t+
if(mainMarker[t].equalsIgn
foundNew=true;
}
}
if(foundNew){
filetoken=new StringTokenizer(str);
while(filetoken.hasMoreEle
dummy=filetoken.nextToken(
if(userinput.equalsIgnoreC
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].equalsIgno
find=true;
}
}
}
if(!find){
findResult[countResult]=ne
findFlNme[countResult]=new
countResult++;
find=false;
}
if(countResult==0){
findResult[countResult]=ne
findFlNme[countResult]=new
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].equalsIgnoreCa
return true;
}
}
return false;
}
}