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: 509
  • Last Modified:

Search:- 3 For Mr ozymandias

Please answer questions 11,12
forget 10 for the time being.
0
cancer_66
Asked:
cancer_66
  • 56
  • 37
  • 3
  • +1
1 Solution
 
TimYatesCommented:
Mr Ozymandias still not finished your School project for you?

:-P ;-)
0
 
girionisCommented:
Tim lol ]:-)
0
 
ozymandiasCommented:
11) No. The chnage I gave you was so that the number would start from 1 rather than 0. It will still be 1,2,3 etc. As I said the ranking is based on the score. Where the scores are equal then the order of precedence is based on the order in which the sentences were found. I would advise against having joint rankings.


12) OK. This works for me but I have a question for you.
Consider the following sentence :

"computer graphics is the display of digital images which is defined by science"

This matches both pattern1 ("is defined by") and pattern2("is the"). When it is given its score do you want the score to be :

a) the total of all sucessful matches
b) the highest score from any individual match
c) the score from the first match found

Option a) would be the best representation of its true rank i.e. high score = very good match. Option c) would be the most efficient in terms of speed, i.e. you could stop the matching once one match was successful and save time. Option b) has no particular advantages I can think of, but it is an option all the same.
0
Independent Software Vendors: 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!

 
ozymandiasCommented:
10) I don't know very much about Aglets other than the papers from IBM and others that I have skimmed over. I have never implemented an aglet before. I assumed that you already had that bit done actually.
0
 
ozymandiasCommented:
12) I added the pattern "is the" to my search.
It didn;t match any sentences because no sentence in the current files contains the word "the", hard to believe, but true.

So I added the test sentence I mentioned above :

"computer graphics is the display of digital images which is defined by science"

and it worked fine.

As for the question I asked above I have implemented both options a) and c) and called them "Full" and "Fast" respectively. I have added a new option box to the GUI so that the user can choose between Full Scoring and Fast Scoring.

I have mailed you all the new code and copies of the test files etc.
0
 
cancer_66Author Commented:
11)in answer to question 11 you commented " I would advise against having joint rankings." what do u mean by that.

lets say i have two identical sentence. therefore they both should be ranked first isnt it ? but the program ranks it 1,2.. eventhough it should be 1,1..

hmm or are u saying that if they score the same result than the order that the sentence come in the file effects the ranking ?

12)acually when i added the pattern "is the" i also added a sentence in file a1.txt inorder to check if it is working, and it does work but the only sentences that it retrives are the one's with pattern "is the".

sentences with "is defined as"..etc are not matched?

0
 
cancer_66Author Commented:
13)just downloaded the new code. as i compiled Defintion.java got the following error

C:\aglets\public\Expert Exchange +ranking 2\DefinitionChecker.java:39: cannot resolve symbol
symbol  : class PatternMatcher  
location: class DefinitionChecker
          PatternMatcher pm = new PatternMatcher();
                ^
C:\aglets\public\Expert Exchange +ranking 2\DefinitionChecker.java:39: cannot resolve symbol
symbol  : class PatternMatcher  
location: class DefinitionChecker
          PatternMatcher pm = new PatternMatcher();
                                        ^
C:\aglets\public\Expert Exchange +ranking 2\DefinitionChecker.java:60: cannot resolve symbol
symbol  : class PatternMatcher  
location: class DefinitionChecker
          PatternMatcher km = new PatternMatcher();
                ^
C:\aglets\public\Expert Exchange +ranking 2\DefinitionChecker.java:60: cannot resolve symbol
symbol  : class PatternMatcher  
location: class DefinitionChecker
          PatternMatcher km = new PatternMatcher();
                                        ^
4 errors
0
 
ozymandiasCommented:
11) I don't think that any 2 sentences should ever have exactly the same rank. If they have the same score then something else has to differentiate them. In this case it is which one was found first.

12) Try the new code I sent you. It works fine with both patterns.
0
 
cancer_66Author Commented:
13)you forgot to add the PatternMatcher file in the "definitions" sub directory.
0
 
ozymandiasCommented:
13) Make sure that you have unzipped all the files and that all the files that are supposed to be in the definitions subdirectory are in there, and not in the same directory as the DefinitionChecker.
0
 
ozymandiasCommented:
Hold on ! Scrap that. I just checked the zip file and PatternMatcher.java was not in there, I must have missed it out.

I will mail it to you now.
0
 
cancer_66Author Commented:
13) i have unzipped it properly. i have the following file only

DefinitionChecker.java + UI1.java

definition (sub -directory)
contains:-sentence,stemmer,wordlist and wordPattern.java only. PatternMatcher is not there?

0
 
cancer_66Author Commented:
13)ok thanks ill just check it,
0
 
cancer_66Author Commented:
13)ok thanks ill just check it,
0
 
cancer_66Author Commented:
14)ok. now it will work if i added new patterns. ill try adding "can be defined as".
0
 
cancer_66Author Commented:
14)private static WordList list5 = new WordList("the",",",false);

what is the "false" for at the end?
0
 
cancer_66Author Commented:
15)ok it worked. fine. ill test it properly tomorrow.

16)about the aglets i have done some basic examples. but the master-slave pattern didnt work with me for some reason. it suppose to be quite straight forward if you know java. frankly speaking i find it complicated. anyways we will talk about this tomorrow.

its quite later over here. so ill call it a day. ill talk to you tomorrow.

thanks for all the help.

0
 
ozymandiasCommented:
14) The boolean value on the end of the constructor for the WordList class tells the WordList whether to use stemming or not. If you set it to true then whenever a word from a sentence is compared to the WordList it will try to match it. If that fails it will try to match the stems of the words.

For instance you will notice that the WordLists containing the keywords "computer" and "graphics" use stemming, which is why you get a match for "computers" and "graphic".

You will also see that the WordList that contains "defined", "described" and "delimited" are set to use stemming, so it will match :

defined
defines
defining
define
described
decribes
describing
describe
delimited
delimit
delimiting
delimits

and so on.
0
 
ozymandiasCommented:
15) OK. Let me know how you get on.

16) I would need to see some of these examples. If the whole idea is to make the program mobile, i.e. it is able to persist its state, move to another machine, and then carry on processing where it left off, then presumably you need at least two machines running aglet-supporting environments to test all this ?
0
 
TimYatesCommented:
Can we post the code here?

It is against the EE rules to email each other, as someone may find this on Google, and be royally fed-up that the code isn't here for their usage...

And someone is bound to be on the same course as cancer_66 next year, and will want their projects doing for them too ;-)
0
 
ozymandiasCommented:
Yes. At the end of each question I have been posting the full code of the program at that stage. I am about to post the current code to the previous question http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20534863.html and I will do the same for this question.

>>And someone is bound to be on the same course as cancer_66 next year, and will want their projects doing for them too ;-)

True, but I believe it is customary (with tutor approval) for students to pick their own projects, rather than have the same ones assigned year on year ;-)
0
 
TimYatesCommented:
> Yes. At the end of each question I have been posting the full code of the program at that stage. I am about to post the current code to the previous question

Sorry, I didn't notice that... :-/

Sorry for jumping the gun :-/

WOW!  What a lot of code!!  You should be paid for this, not getting points... ;-)

> True, but I believe it is customary (with tutor approval) for students to pick their own projects, rather than have the same ones assigned year on year ;-)

Hee hee, not in England, where the tutors are lazy ;-)
0
 
ozymandiasCommented:
>>Sorry for jumping the gun :-/

It's OK. It was a valid point and they are long threads to have to read through and check.

>>WOW!  What a lot of code!!  You should be paid for this, not getting points... ;-)

Thanks. I'm sure it's quantity not quality there though :0)

Actually the largest file is Stemmer.java which I didn't write, it was borrowed from here http://www.tartarus.org/~martin/PorterStemmer/ and then had some modifications added to it by me to make it more useful to this sepcific program.
0
 
ozymandiasCommented:
>>Hee hee, not in England, where the tutors are lazy ;-)


!!! That's not true in all cases. When I wrote my thesis I was specifcally prohibited from choosing any subject that came to close to any previous thesis. Titles and subjects submitted for approval were vetted pretty thoroughly by the faculty to prevent "recycling" :0)
0
 
cancer_66Author Commented:
17)hello, ill just try testing it right away. thanks
0
 
cancer_66Author Commented:
18)regarding the "fasle" at the end of the "wordList" i should only make it true for the mainMarkers right? i.e {defined,described,delimited..etc}

in case of two Patterns such as "is the" in this case its ambigous there isnt a mainMarker. but you cannot say its not a definition.
0
 
cancer_66Author Commented:
19)can you give me an example of a sentence and how would "full" and "fast" scoring effect it. please.

lets assume:-
"computer graphics is the display of digital images which is defined by science"

take ur time.
0
 
cancer_66Author Commented:
20)give me a while ill test it. i want to just finish the presentation first.

ill be waiting 4 ur answers.plz
0
 
cancer_66Author Commented:
please answer me whenever ill be waiting
0
 
ozymandiasCommented:
18) There is no point setting stemming to on in a wordlist that only contains words that cannot be stemmed :

"is","are","were","be","by" and "as" etc have no stem value.

19) Sentence 25 is the only sentence in the current test set that is affected by Full/Fast scoring. Full/Fast scoring only affects the pattern score, not the key score.

"computer graphics is the display of digital images which is defined by science"

scored against two patterns "is defined by" and "is the" using STRICT matching

in FAST SCORING

is = 2 points
defined = 2 points
by = 2 points
strict match = 3 points

1st pattern score = 9

At this point, because we are fast scoring, the final pattern score returned is 9 because once a pattern match is found the program does not go on to check for any others.

However, in FULL SCORING, it would continue :

is = 2 points
the = 2 points
strict match = 3 points

2nd pattern score = 7 points


Total Pattern Score = 16

So, FULL and FAST will not make any difference to which sentences get returned, but it will chnage the way they are ranked. However, the major difference over greater volumes of data should be speed because fast matching will generally be quicker.
0
 
cancer_66Author Commented:
19)

sorry wasnt at my seat. yes i thought as much.
ok i understood now ! how it works.
ill test it in a short while.
thanks
0
 
cancer_66Author Commented:
20)would you help me with integrating it with the aglet? please.

am not sure if you recived my mail.
0
 
cancer_66Author Commented:
21)guess u r busy. take ur time. ill be waiting 4 ur reply
0
 
ozymandiasCommented:
20) I got your mail and I have been looking at the resources you sent me.

Firstly, the IBM Aglet SDK will not run on JDK 1.2 or later. I cannot get Tahiti to run at all.

It looks like the project went open source and is now being run from SourceForge and Aglets.org and the specification has now reached verysion 2.0.2.

I have downloaded this and I am trying to set up and aglets 2.0.2 environment.
0
 
cancer_66Author Commented:
20)ok thanks, i think the aglets 2.02 works with jdk 1.2 and later versions.
0
 
cancer_66Author Commented:
21)iam using aglets1.1 and i was using JDk1.1.8 in the begining. but then started using jdk1.3.1 since the program u've written wasnt compiling.

Tahiti server works?
0
 
cancer_66Author Commented:
21)just to stay on the safe side its better to use aglets2.02
0
 
ozymandiasCommented:
Yes. I now have two instances of Tahiti running on my machine and I can dispatch and retarct sample aglets etc etc.

I now have to work out how to :

Convert eitheer UI1 or DefinitionChecker or both to an Aglet or AgletProxy.
Sort out the cloning and dispatching and communications between the master & slave etc.
0
 
cancer_66Author Commented:
21)ok thanks alot. (am testing the scoring have some comments but would save them for later)
0
 
cancer_66Author Commented:
21)take ur time. thanks 4 all the help
0
 
ozymandiasCommented:
How do you actually envisage this working ?
Do you expect to run/deploy the application from within Tahiti or what ?

This is looking like a very big job in territory with which I am not familiar.
0
 
cancer_66Author Commented:
22)yes exatcly after compiling the code simply add it to the list in Tahiti server , then create it. user interface should appear (note the destination of the slave is hard coded)

23)i think its better to try the basic master and slave pattern first. from example when the slave reaches the destination it prints something, then comes back to the master and prints "iam back"

0
 
cancer_66Author Commented:
sorry for the trouble..
0
 
cancer_66Author Commented:
please try and help me out
0
 
cancer_66Author Commented:
take ur time. i can wait,there is no hurry
0
 
cancer_66Author Commented:
i hope something worked. iam very worrid.
0
 
cancer_66Author Commented:
hi. iam back. any news?
0
 
cancer_66Author Commented:
hi. iam back. any news?
0
 
cancer_66Author Commented:
please answer me whenever u can. ill be waiting
0
 
cancer_66Author Commented:
guess you r busy, take ur time.. i dont mind waiting
0
 
ozymandiasCommented:
I am not having much luck with this.

I have tried to create an aglet version of the DefinitinChecker class which uses then UI1.class as its GUI. It all compiles OK but I am getting instantiation errors when I try to create it as an aglet in tahiti.
0
 
ozymandiasCommented:
OK. I now have an aglet I can create but I am having trouble working out how to set the tahiti server's ecdurity settings so that the aglet is allowed to read the text files. Any ideas.
0
 
cancer_66Author Commented:
1) are u getting security errors?

run the tahiti at command prompt using "agletsd -nosecurity"
0
 
cancer_66Author Commented:
2)after running the Tahiti server go to "options" sercurity" then for both trusted and untrusted option add the file name e.g "c:\b1.txt;"
0
 
cancer_66Author Commented:
2) this is another way of getting permission.
0
 
cancer_66Author Commented:
3)hope it works
0
 
cancer_66Author Commented:
please answer me whenever you are free.. ill be waiting, i really hope something works !
0
 
cancer_66Author Commented:
take ur time ill wait !
0
 
ozymandiasCommented:
1) Yes. I have alreday tried adding files to the security options. It does not work. In my version of tahiti there is no option for trusted and untrusted aglets. You have to upply the codebase for each aglet and then specify its individual security permissions.

I will try running it with nosecurity.
0
 
cancer_66Author Commented:
1)i.c ok try it with no security.
0
 
ozymandiasCommented:
OK. The -nosecurity option makes no difference. I have managed to make it work. In the end I had toi manually edit the .aglets/aglets.policy file. I think there may be a bug in the Securty Options dialog code in my version of tahiti.

OK, now I will see if I can dispatch the aglet to another server etc.
0
 
cancer_66Author Commented:
2)any luck ??
0
 
cancer_66Author Commented:
2)yes i guess there are bugs, thats a good news. at least one step ahead. hope something works.

thanks 4 ur help
0
 
cancer_66Author Commented:
0
 
cancer_66Author Commented:
ill be waiting. take ur time
0
 
cancer_66Author Commented:
any progress ??;/

thanks
0
 
ozymandiasCommented:
I have made some progress. I now have an aglet (DefinitionChecker) which uses UI1 as its GUI. The problem was that when I tried to dispatch it to another server the dispatch fails because it could't serialize the PatternMatcher class as part of the dispatch.

It sems that any class that is going to take part in the aglet code must also extend aglet.

I think I'm nearly there, I just have to work out the inter-aglet communications.
0
 
cancer_66Author Commented:
THANKKKKKKKKKSSSSSSSS Alot you really made my day.seriously you dont know how happy u've made me.
iam glad something worked.

thanks for all the help.
0
 
cancer_66Author Commented:
take your time, iam ready to wait.
thanks for all the help and support
0
 
ozymandiasCommented:
It's done.

I will mail you the code.
0
 
ozymandiasCommented:
First here are the instructions :

1) You need to run two versions of Tahiti.
The first version keeps all defaults. The second one must run on post 5434 instaed of 4434.

2) You will need to find your aglets security policy file and replace it with the one I am sending you. It will probabkly be located in your home or user directory in a subdirectory called .aglets/security/aglets.policy.

3) The othe files I have sent need to be unzipped and put in %AGLETS_HOME%/public.
DefinitionChecker.java, UI1.java and all the text files go in public all the others must go in a subdirectory called definitions.

4) Now compile DefinitionChecker.java and that should cause everything to be compiled.

5) In the tahiti console for the instance of tahiti running on port 4434 create an instance of DefinitionChecker by simply adding "DefinitionChecker" to the list and then creating an instance of it.

6) To bring up the gui either double click on the running instance in the console or click on the "dialog" button.

7) First run a local search by typing in "computer graphics" and clicking on the go button. You should get a set of results. You will notice that there is an extra column in the results which indicates which host the file was found on.

8) Now run a remote search by clicking on the "Send Clone" button. This will create another instance of the DefinitionChecker which will be dispatched to the other tahiti server. It will run a search there and then revert back to its home and deliver its results to the original DefinitionChecker which will incorporate them into its own result set, re-sort it and display the whole lot.
0
 
ozymandiasCommented:
Oh, there's one extra thing.

3a) You will need to modify line 32 on DefinitionChecker.java. It currently has the location of the text files on my machine hard coded in it so you will need to change the paths to point to the location on your machine.
0
 
cancer_66Author Commented:
a)sory i wasnt at my seat i just came back. ill check it right away..

thanks alot
0
 
cancer_66Author Commented:
b)this configuration looks quite complex. hope everything goes fine.

ill just do it. give me few min
0
 
ozymandiasCommented:
I have just mailed you some new files.
0
 
cancer_66Author Commented:
c)shall i install aglets 2.02??
0
 
cancer_66Author Commented:
c)which version are you using. so that i could use the same.
0
 
ozymandiasCommented:
0
 
ozymandiasCommented:
You need to extract the jar file into a directory where you want to install Aglets and the run ant from the bin directory.

You may also then need to run ant install-home after than.

Then copy in all the new files I gave you including the security and props files.

Then compile DefinitionChecker.java in the public directory.

Then run "runboth.bat" in the bin directory.
0
 
cancer_66Author Commented:
d)ok just so we stay on track iam going to extact the jar file in C:\aglets
0
 
cancer_66Author Commented:
e)i extracted the jar file in aglets2

i have the following folder:-bin,cnf,lib,META-INF,Public

correct?
0
 
cancer_66Author Commented:
f)its saying java_home environment not set?

iam using windows xp
0
 
cancer_66Author Commented:
please answer me whenever iam waiting
0
 
ozymandiasCommented:
Did you run ant from within the c:\aglets\bin durectory ?
0
 
cancer_66Author Commented:
d)i managed to run the two server 4434+5545

i extracted the DefinitionChecker.zip in

c:\aglets\public

now when i compile it

i get many errors

pakage import.ibm...etc not found

package defintions not found?
0
 
ozymandiasCommented:
OK. You need to make sure that when you compile the code that the aglets_2.0.2.jar file is in your classpath.

Try running this command from within the public directory:

javac -cp .;c:\aglets\lib\aglets_2.0.2.jar;%classpath% DefinitionChecker.java
0
 
cancer_66Author Commented:
i added ur to my msn list but u r offline
0
 
ozymandiasCommented:
Spectators may be interested to hear that the aglet code worked fine. I will post the current version of it below.

Make sure you read the instructions first :

1) You will need the Aglet SDK from :

http://prdownloads.sourceforge.net/aglets/aglets-2.0.2.jar?download 

2) Unpack the jar to the directory where you want to insall it and then run ant from the bin directory. Examine the output from ant. You may be directed to run ant -install-home.

2) You will need to find your aglets security policy file and replace it with the one I am sending you. It will probabkly be located in your home or user directory in a subdirectory called .aglets/security/aglets.policy.

3) The othe files I have sent need to be unzipped and put in %AGLETS_HOME%/public.
DefinitionChecker.java, UI1.java and all the text files go in public all the others must go in a subdirectory called definitions.

4) You will need to modify line 32 on DefinitionChecker.java. It currently has the location of the text files on my machine hard coded in it so you will need to change the paths to point to the location on your machine.

5) Now compile DefinitionChecker.java and that should cause everything to be compiled.

6) You now need to run two versions of Tahiti.
The first version keeps all defaults. The second one must run on port 5434 instaed of 4434. You can do this by making a copy of aglets.props in the aglets/cnf directory and aclling it aglets5434.props. Edit the copy and change the maf.port=4434 entry to maf.port=5434. Then in the bin directory run :

agletsd -f ../cnf/aglets.props

and

agletsd -f ../cnf/aglets5434.props

7) In the tahiti console for the instance of tahiti running on port 4434 create an instance of DefinitionChecker by simply adding "DefinitionChecker" to the list and then creating an instance of it.

8) To bring up the gui either double click on the running instance in the console or click on the "dialog" button.

9) First run a local search by typing in "computer graphics" and clicking on the go button. You should get a set of results. You will notice that there is an extra column in the results which indicates which host the file was found on.

10) Now run a remote search by clicking on the "Send Clone" button. This will create another instance of the DefinitionChecker which will be dispatched to the other tahiti server. It will run a search there and then revert back to its home and deliver its results to the original DefinitionChecker which will incorporate them into its own result set, re-sort it and display the whole lot.
0
 
ozymandiasCommented:
Sorry, for instruction 2) above [yes, the second one :0)] the security policy file should read as follows :

grant
 codeBase "file:///-/"
{
  // can do anything
  permission java.security.AllPermission "*", "*";
};

grant
 codeBase "file://e:\\java\\aglets\\public\\DefinitionChecker"
{
  // can do anything
  permission java.security.AllPermission "*", "*";
};

grant
 codeBase "atp://*:*/"
{
  // can do anything
  permission java.security.AllPermission "*", "*";
};

grant
 codeBase "http://*:*/"
{
  // can do anything
  permission java.security.AllPermission "*", "*";
};

This is a completly open and unsecure policy so it should only be used for tseting.
0
 
ozymandiasCommented:
/*
*
* UI1.java : this is the GUI for the DefinitionChecker class.
*
*/


import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.Vector;
import java.net.URL;

import com.ibm.aglet.*;
import com.ibm.aglet.system.*;

import definitions.*;

public class UI1 extends Aglet implements ActionListener{

      /*
      * UI Components
      */
      transient JFrame frame;
      DefinitionChecker dc;
      TextField search = new TextField(18);
      Label searchlab = new Label("Search for");
      Scrollbar bar = new Scrollbar();
      JTable table;
      JScrollPane scroller;
      Vector columns = new Vector();
      Vector rows = new Vector();
      Button go = new Button("Go...");
      Button send = new Button("Send Clone");
      Button close = new Button("Close");
      Button clear = new Button("Clear");
      Panel Resultpanel = new Panel();
      Panel Buttonpanel = new Panel();
      Panel Inputpanel = new Panel();
      Panel checkbox = new Panel();

      CheckboxGroup cbg1 = new CheckboxGroup();
      Checkbox ran = new Checkbox("Random",cbg1,false);
      Checkbox seq = new Checkbox("Normal",cbg1,true);
      Checkbox sseq = new Checkbox("Strict",cbg1,false);

      CheckboxGroup cbg2 = new CheckboxGroup();
      Checkbox full = new Checkbox("Full",cbg2,false);
      Checkbox fast = new Checkbox("Fast",cbg2,true);

      public UI1(DefinitionChecker dc){

            this.dc = dc;
            frame = new JFrame("Aglet Interface Example");
            frame.addWindowListener(new WindowAdapter(){
                  public void windowClosing(WindowEvent e){
                        frame.hide();
                  }
            });

            GridBagLayout gridbag = new GridBagLayout();
            GridBagConstraints c = new GridBagConstraints();
            Container content = frame.getContentPane();
            content.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.0;
            c.anchor = GridBagConstraints.NORTHWEST;
            gridbag.setConstraints (searchlab, c);
            content.add(searchlab);

            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 1;
            c.gridy = 0;
            c.gridwidth = 1;
            c.weightx = 1.0;
            c.anchor = GridBagConstraints.NORTHEAST;
            gridbag.setConstraints(search, c);
            content.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;
            columns.add("Rank");
            columns.add("Text");
            columns.add("S1");
            columns.add("S2");
            columns.add("Host");
            columns.add("File");
            table = new JTable(rows,columns);
            scroller = new JScrollPane(table);
            gridbag.setConstraints(scroller, c);
            content.add(scroller);

            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,8));
            checkbox.add(new Label("Search : "));
            checkbox.add(ran);
            checkbox.add(seq);
            checkbox.add(sseq);
            checkbox.add(new Label("         "));
            checkbox.add(new Label("Scoring : "));
            checkbox.add(full);
            checkbox.add(fast);
            gridbag.setConstraints(checkbox, c);
            content.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,7));
            Buttonpanel.add(go);
            Buttonpanel.add(new Label("    "));
            Buttonpanel.add(clear);
            Buttonpanel.add(new Label("    "));
            Buttonpanel.add(close);
            Buttonpanel.add(new Label("    "));
            Buttonpanel.add(send);
            gridbag.setConstraints(Buttonpanel, c);
            content.add(Buttonpanel);

            go.addActionListener(this);
            send.addActionListener(this);
            close.addActionListener(this);
            clear.addActionListener(this);

            KeyListener kl = new KeyListener() {
                  public void keyPressed(KeyEvent e) {}

                  public void keyReleased(KeyEvent e) {
                        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                              System.out.println(search.getText());
                        }
                  }

                  public void keyTyped(KeyEvent e) {}
            };

            search.addKeyListener(kl);
      }

      public void showDialog(){
            if (frame != null){
                  frame.pack();
                  frame.resize(frame.preferredSize());
                  frame.reshape(20,20,600,400);
                  setColumnWidths();
                  frame.show();
            }
      }

      public static void main(String args[]){
            DefinitionChecker dc = new DefinitionChecker();
            UI1 agletFrame = new UI1(dc);
            agletFrame.showDialog();
      }

      private boolean validSearch(String s){

            // if the search term list less that 7 characters it can't be valid
            if (s.length() < 7){
                  return false;
            }
            // if the search term does not have a space it can't be valid
            if (s.indexOf(" ") == -1){
                  return false;
            }
            // if any of the search terms words are less than 3 characters
            // it can't be valid.
            StringTokenizer st = new StringTokenizer(s);
            while (st.hasMoreTokens()){
                  if (st.nextToken().length() < 3){
                        return false;
                  }
            }
            return true;
      }

      private void showMsg(String msg){
            JOptionPane.showMessageDialog(frame,msg);
      }

      public void actionPerformed(ActionEvent event){

            if (event.getSource() == go){
                  if (validSearch(search.getText())){
                        int mode = 2;
                        if (cbg1.getSelectedCheckbox() == ran){
                              mode = 1;
                        }else if(cbg1.getSelectedCheckbox() == seq){
                              mode = 2;
                        }else{
                              mode = 3;
                        }
                        boolean quick = true;
                        if (cbg2.getSelectedCheckbox() == full){
                              quick = false;
                        }
                        dc.setQuickScoring(quick);
                        dc.setMatchMode(mode);
                        dc.setKeyString(search.getText());
                        dc.check();
                  }else{
                        showMsg("You must provide a valid search term.\n\nA valid search term must have a minimum of two words\neach of which must have at least three chracaters.");
                  }
            }else if (event.getSource() == close){
                  frame.hide();
            }else if(event.getSource() == send){
                  if (validSearch(search.getText())){
                        int mode = 2;
                        if (cbg1.getSelectedCheckbox() == ran){
                              mode = 1;
                        }else if(cbg1.getSelectedCheckbox() == seq){
                              mode = 2;
                        }else{
                              mode = 3;
                        }
                        boolean quick = true;
                        if (cbg2.getSelectedCheckbox() == full){
                              quick = false;
                        }
                        dc.setQuickScoring(quick);
                        dc.setMatchMode(mode);
                        dc.setKeyString(search.getText());
                        try{
                              dc.sendClone(new URL("atp://localhost:5434/"));
                        }catch(Exception e){
                              showMsg(e.getMessage());
                        }
                  }else{
                        showMsg("You must provide a valid search term.\n\nA valid search term must have a minimum of two words\neach of which must have at least three chracaters.");
                  }
            }else if(event.getSource() == clear){
                  rows = new Vector();
                  table.setModel(new DefaultTableModel(rows,columns));
                  setColumnWidths();
                  dc.clearMatches();
            }
      }

      public void doUpdates(Sentence[] sentences){
            rows = new Vector();
            for (int i = 0; i < sentences.length; i++){
                  Vector v = new Vector();
                  v.add(Integer.toString(i+1));
                  v.add(sentences[i].getSentence());
                  v.add(Integer.toString(sentences[i].getKeyScore()));
                  v.add(Integer.toString(sentences[i].getPatternScore()));
                  v.add(sentences[i].getHostingURL().getHost() + ":" + sentences[i].getHostingURL().getPort());
                  v.add(sentences[i].getLocation().toString());
                  rows.add(v);
            }
            table.setModel(new DefaultTableModel(rows,columns));
            setColumnWidths();
      }

      private void setColumnWidths(){
            table.getColumnModel().getColumn(0).setPreferredWidth(15);
            table.getColumnModel().getColumn(1).setPreferredWidth(350);
            table.getColumnModel().getColumn(2).setPreferredWidth(15);
            table.getColumnModel().getColumn(3).setPreferredWidth(15);
            table.getColumnModel().getColumn(4).setPreferredWidth(75);
            table.getColumnModel().getColumn(5).setPreferredWidth(75);
      }
}
0
 
ozymandiasCommented:
/*
* DefinitionChecker.java
*
*/

import com.ibm.aglet.*;
import com.ibm.aglet.system.*;
import com.ibm.aglet.event.*;

import java.util.Vector;
import java.util.StringTokenizer;
import java.io.*;
import java.net.URL;
import definitions.*;

public class DefinitionChecker extends Aglet{


      /*
      *
      * These are some static WordLists which can be used to create
      * the WordPatterns that this PatterMatcher will use
      *
      */
      private static WordList list1 = new WordList("is,was,are,be",",",false);
      private static WordList list2 = new WordList("described,defined,delimited",",",true);
      private static WordList list3 = new WordList("as,by",",",false);
      private static WordList list4 = new WordList("is",",",false);
      private static WordList list5 = new WordList("the",",",false);

      private String keyword;
      private String[] files = new String[]{"e:\\java\\aglets\\public\\a1.txt","e:\\java\\aglets\\public\\b1.txt","e:\\java\\aglets\\public\\c1.txt","e:\\java\\aglets\\public\\d1.txt"};
      private Sentence[] sentences;
      private Vector matches = new Vector();
      private boolean quick = true;
      private int matchMode = WordPattern.NORMAL_MATCH;
      private String keyString = "";
      private boolean atHome = true;
      private URL home;

      private AgletProxy myParent;

      private PatternMatcher pm;
      private PatternMatcher km;
      private UI1 gui = null;


      /**
      *
      * Constructor for the DefinitionChecker
      *
      */
      //public DefinitionChecker(int matchMode, boolean quick){
      public void onCreation(Object init){

            if (init != null){
                  myParent = (AgletProxy) init;
            }

            home = getAgletContext().getHostingURL();
            addMobilityListener(new MobilityAdapter(){
                  public void onArrival(MobilityEvent me){
                        if (atHome){
                              atHome = false;
                              System.out.println("I'm out on the prowl...");
                              check();
                        }else{
                              atHome = true;
                              System.out.println("Honey, I'm home and I found " + matches.size() + " matches.");
                              if (myParent != null & matches.size() > 0){
                                    try{
                                          DefinitionChecker dc = (DefinitionChecker)myParent.getAglet();
                                          dc.addMatches(matches);
                                          dispose();
                                    }catch(Exception e){
                                          e.printStackTrace();
                                    }
                              }
                        }
                  }
            });

            // let's build our PatternMatcher
            pm = new PatternMatcher();

            // create a WordPattern
            WordPattern pattern1 = new WordPattern();
            // add the appropriate WordLists
            pattern1.addList(list1);
            pattern1.addList(list2);
            pattern1.addList(list3);
            // add the WordPattern to the vector
            pm.addPattern(pattern1);

            // create a WordPattern
            WordPattern pattern2 = new WordPattern();
            // add the appropriate WordLists
            pattern2.addList(list4);
            pattern2.addList(list5);
            // add the WordPattern to the vector
            pm.addPattern(pattern2);

      }

      public void dialog(Message msg){
            if (gui == null){
                  gui = new UI1(this);
            }
            gui.showDialog();
      }

      public void run(){
            //gui.showDialog();
      }

      public void sendClone(URL destination) throws Exception{
            AgletContext ac = getAgletContext();
            AgletProxy thisProxy = getProxy();
            AgletProxy proxy = ac.createAglet(null, "DefinitionChecker", thisProxy);
            DefinitionChecker dc = (DefinitionChecker)proxy.getAglet();
            dc.setMatchMode(this.matchMode);
            dc.setQuickScoring(this.quick);
            dc.setKeyString(this.keyString);
            proxy = proxy.dispatch(destination);
      }

      public void addMatches(Vector v){
            for (int i = 0; i < v.size(); i++){
                  matches.add(v.elementAt(i));
            }
            sortMatches();
            gui.doUpdates(getMatchedSentences());
      }

      public void setKeyString(String s){
            keyString = s;
      }

      public String getKeyString(){
            return keyString;
      }

      public boolean handleMessage(Message msg) {
            if (msg.sameKind("dialog")) {
                  dialog(msg);
            }else{
                  return false;
            }
            return true;
      }

      public void setMatchMode(int mode){
            this.matchMode = mode;
      }

      public void setQuickScoring(boolean quick){
            this.quick = quick;
      }

      public void check(){

            // let's build a PatternMatcher to hold our keyword pattern
            // and use a StemmedWordList to do so.
            matches = new Vector();
            km = new PatternMatcher();
            WordPattern keyPattern = new WordPattern();
            StringTokenizer st = new StringTokenizer(keyString);
            while (st.hasMoreTokens()){
                  keyPattern.addList(new WordList(st.nextToken()," ",true));
            }
            km.addPattern(keyPattern);

            // loop through each file in the list of files
            for (int f = 0; f < files.length; f++){
                  File file = null;
                  try{
                        // get all the sentences
                        file = new File(files[f]);
                        sentences = getSentencesFromFile(file);
                  }catch(IOException ioe){
                        System.out.println(ioe);
                  }
                  // loop through all the sentences
                  for (int i = 0; i < sentences.length; i++){
                        // if any sentence contains the keyword and matches any of the patterns specified in the PatternMatcher
                        int keyScore = km.scoreSentence(sentences[i],WordPattern.STRICT_MATCH,false,false);
                        int patternScore = pm.scoreSentence(sentences[i],matchMode,quick,false);
                        if (keyScore > 0 && patternScore > 0){
                              sentences[i].setKeyScore(keyScore);
                              sentences[i].setPatternScore(patternScore);
                              // if this is the first match found in this file
                              matches.add(sentences[i]);
                        }
                  }
            }
            if (atHome){
                  sortMatches();
                  gui.doUpdates(getMatchedSentences());
            }else{
                  try{
                        URL u = null;
                        dispatch(home);
                  }catch(Exception e){
                        System.out.println("Poor little aglet unable to return home...");
                  }
            }
      }

      private void sortMatches(){
            Object[] o = matches.toArray();
            java.util.Arrays.sort(o);
            matches = new Vector();
            for (int i = 0; i < o.length; i++){
                  matches.add(o[i]);
            }
      }

      /**
      * getMatches()
      *
      * Returns an array of strings which are all the matched sentences found by the DefinitionChecker.
      *
      */
      public String[] getMatches(){
            String[] m = new String[matches.size()];
            for (int i = 0; i < matches.size(); i++){
                  m[i] = ((Sentence)matches.elementAt(i)).toString();
            }
            return m;
      }

      public void clearMatches(){
            matches = new Vector();
      }

      /**
      * getMatchedSentences()
      *
      * Returns an array of sentences which are all the matched sentences found by the DefinitionChecker.
      *
      */
      public Sentence[] getMatchedSentences(){
            Sentence[] s = new Sentence[matches.size()];
            s = (Sentence[])matches.toArray(s);
            return s;
      }

      /**
      *
      * GetArrayFromFile
      *
      * This function reads a specified file and breaks the contents into
      * and array of strings (sentences) using the # character as a delimiter
      *
      */
      private Sentence[] getSentencesFromFile(File f) throws IOException{
            FileReader reader = new FileReader(f);
            Vector sentences = new Vector();
            char[] cbuf = new char[1];
            String delimiter = "#";
            String sentence = "";
            String c = "";
            // read the file character by character
            while (reader.read(cbuf) != -1){
                  c = new String(cbuf);
                  // if the chracter is a delimiter (#)
                  if (c.equals(delimiter)){
                        // add the sentence to the Vector and start a new blank sentence
                        Sentence s = new Sentence(sentence);
                        s.setLocation(f);
                        s.setHostingURL(getAgletContext().getHostingURL());
                        sentences.add(s);
                        sentence = "";
                  }else{
                        // otherwise just add the character to the current sentence string
                        sentence += c;
                  }
            }
            reader.close();
            Sentence[] sentenceArray = new Sentence[sentences.size()];
            // convert the Vector to an array and return it
            sentenceArray = (Sentence[])sentences.toArray(sentenceArray);
            return sentenceArray;
      }

/*
// this  main method has been commeneted out as it seems to stop this class being instantiated properly as an aglet

      public static void main(String[] args){

            int matchMode = WordPattern.NORMAL_MATCH;
            boolean quick = true;
            String s = "";
            int numKeywords = 0;
            // first lets check what the arguments are
            for (int i = 0;i < args.length;i++){
                  //if any of them are -? then we print the usage message
                  if (args[i].equalsIgnoreCase("-?")){
                        printUsage("");
                        System.exit(1);
                  }
                  //if any of them are -q then we are in quick mode
                  if (args[i].equalsIgnoreCase("-q")){
                        quick = true;
                        continue;
                  }
                  //if any of them are -f then we are in full mode
                  if (args[i].equalsIgnoreCase("-f")){
                        quick = false;
                        continue;
                  }
                  //if any of them are -s then we are in strict mode
                  if (args[i].equalsIgnoreCase("-s")){
                        matchMode = WordPattern.STRICT_MATCH;
                        continue;
                  }
                  //if any of them are -r then we are in random mode
                  if (args[i].equalsIgnoreCase("-r")){
                        matchMode = WordPattern.RANDOM_MATCH;
                        continue;
                  }
                  //if any of them are -r then we are in normal mode
                  if (args[i].equalsIgnoreCase("-n")){
                        matchMode = WordPattern.NORMAL_MATCH;
                        continue;
                  }
                  // make sure they are all 3 chracaters or longer
                  if (args[i].length() < 3){
                        printUsage("Input Error : " + args[i] + "\nAll component words of the SearchTerm must be three characters or more.");
                        System.exit(1);
                  }
                  // concatenate the arguments into one search string
                  s = s + args[i] + " ";
                  numKeywords++;
            }
            // now make sure that we have at least two valid keywords
            if (numKeywords < 2){
                  printUsage("");
                  System.exit(1);
            }
            s = s.trim();
            // finally instantiate a DefinitionChecker and pass it the string and tell it which match mode to use
            DefinitionChecker dc = new DefinitionChecker(matchMode,true);
            dc.check(s);
            String[] matches = dc.getMatches();
            for (int m = 0; m < matches.length; m++){
                  System.out.println(matches[m]);
            }

      }

      private static void printUsage(String msg){
            if (msg.length() > 0){
                  System.out.println("\n" + msg);
            }
            System.out.println("\nUSAGE : DefintionChecker [Mode] [Scoring] SearchTerm\n\n\tMode Options :\n\t-r\trandom pattern matching\n\t-n\tnormal pattern matching (default)\n\t-s\tstrict pattern matching\n\n\tScoring Options :\n\t-q\tquick scoring (default)\n\t-f\tfull scoring\n\n\tSearchTerm : \n\tA minimum of 2 words each consisting of 3 chracters\n\tor more must be provided to make a valid SearchTerm.");
      }
*/
}
0
 
ozymandiasCommented:
/*
* PatternMatcher.java
*
*/

package definitions;

import java.util.StringTokenizer;
import java.util.Vector;
import com.ibm.aglet.*;

public class PatternMatcher extends Aglet{

     private Vector patterns;

     /**
     *
     * Constructor for the PatternMatcher. This adds the
     * WordPatterns to the PatternMatchers list of patterns
     * ready for matching.
     *
     */
     public PatternMatcher(){
          // create the vector to store our WordPatterns
          patterns = new Vector();
     }

     /**
     *
     * This is just a function for adding WordPatterns
     * to the PatternMatcher. It's not used currently
     * but it will probably come in handy.
     */
     public void addPattern(WordPattern pattern){
          patterns.add(pattern);
     }

     /**
     *
     * This is the key function on the PatternMatcher. It is
     * passed a String (sentence) and information on "strictnesss".
     * It thens cycles through all its patterns seeing if any of them
     * are found in the sentence.
     *
     */
     public int scoreSentence(Sentence s, int matchMode, boolean quick, boolean all){

          // loop through all the WordPatterns checking to see if
          // any of them match the sentence.
          int hiScore = 0;
          for (int i = 0; i < patterns.size();i++){
               int score = 0;
               WordPattern wp = (WordPattern)patterns.elementAt(i);
               if ((score = wp.containsPattern(s,matchMode,all)) > 0){
                    if (quick){
                         return score;
                    }else{
                         hiScore += score;
                    }
               }
          }
          return hiScore;
     }

}
0
 
ozymandiasCommented:
/**
*
* WordPattern.java
*
* This class contains the core of the "comparison logic". Each WordPattern
* contains one or more word lists which it uses in sequence to do a word by
* word comparison with the sentence provided.
*
*/

package definitions;

import java.util.Vector;
import java.util.StringTokenizer;
import com.ibm.aglet.*;


public class WordPattern extends Aglet{

      /*
      *
      * Some static integers to denote the various modes
      * available for pattern matching
      */
      public final static int STRICT_MATCH = 3;
      public final static int NORMAL_MATCH = 2;
      public final static int RANDOM_MATCH = 1;

      private Vector lists;

      /**
      *
      * This constructor takes an array of WordLists
      * and uses them to populate its own Vector
      * of WordLists
      */
      public WordPattern(WordList[] wl){
            lists = new Vector();
            for (int i = 0; i < wl.length; i++){
                  lists.add(wl[i]);
            }
      }

      /**
      *
      * This constructor simply initialises a blank Vector
      * to be used to store the WordLists which can be added
      * using the addList() method
      */
      public WordPattern(){
            lists = new Vector();
      }

      /**
      *
      * This function adds a WordList to the Word Pattern
      *
      */
      public void addList(WordList list){
            lists.add(list);
      }

      /**
      *
      * This function does all the real work. It breaks the supplied
      * String into iuts component words and then compares them either
      * strictly or not, to the words in the WordLists.
      *
      */
      public int containsPattern(Sentence s, int matchMode, boolean all){
            //System.out.println(s);
            String[] words = s.getWordArray();
            int totalScore = 0;
            int score = 0;
            int stop = 0;
            if (!all){
                  stop = (matchMode - 1);
            }
            // if there are less words that lists then the sentence cannot
            // possibly contain a full pattern, so return false
            if (words.length < lists.size()){
                  return 0;
            }
            for (int m = matchMode; m > stop; m--){
                  totalScore = 0;
                  // this counter will hold the number of words matched
                  int count = 0;
                  // this counter will hold the number of words matched contiguously (i.e. in strict sequence)
                  int sequence = 0;
                  // this value will tell us whether the previous word was a match
                  boolean inSequence = false;
                  // simultaneously loop through the array of words and the Vector
                  // of WordLists, starting by comparing the first word with the first WordList
                  for (int l = 0, w = 0; ((l < lists.size()) && (w < words.length));){
                        WordList wordlist = (WordList)lists.elementAt(l);
                        String word = words[w];
                        // if the wordlist contains the word then we can move to the next wordlist
                        // and to the next word in the word array, unless we are in random mode.
                        // If we are in random mode, we move back to the beginning of the word array
                        // and start checking from the beginning becuase the words can appear in any order.
                        if ((score = wordlist.containsWord(word)) > 0){
                              totalScore += score;
                              //System.out.println(word + " : scores : " + score + " : total = " + totalScore);
                              l++;
                              if (m == RANDOM_MATCH){
                                    w = 0;
                              }else{
                                    w++;
                              }
                              count++;
                              // if we are are in sequence (i.e. the previous word was a match
                              // then we increment the number of seqential words found
                              if (inSequence || sequence == 0){
                                    sequence++;
                              }
                              // set the value to indicate that this word was matched
                              inSequence = true;
                        }else{
                              // if the wordlist does not contain the word then we can move to the next word
                              // but we do not move to the next wordlist
                              w++;
                              // if we are in strict mode and had started a sequence but not finished it then
                              // we may as well abandon it and start with the  first list again just in case
                              // there is a full sequence later in the sentence.
                              if (m == STRICT_MATCH && inSequence && sequence < lists.size()){
                                    l = 0;
                                    w--;
                                    sequence = 0;
                                    count = 0;
                                    totalScore = 0;
                              }
                              // set the value to indicate that we are no longer in strict sequence
                              inSequence = false;
                        }
                  }

                  // if the number of words matched is the same as the number of lists
                  // then we have a match
                  if (count == lists.size()){
                        switch (m){
                              case STRICT_MATCH:
                                    if(sequence == lists.size()){
                                          //System.out.println("strict : scored " + totalScore);
                                          return totalScore + 3;
                                    }else{
                                          totalScore = 0;
                                    }
                                    break;
                              case NORMAL_MATCH:
                                    //System.out.println("normal : scored " + totalScore);
                                    return (totalScore + 2);
                              case RANDOM_MATCH:
                                    //System.out.println("random : scored " + totalScore);
                                    return (totalScore + 1);
                        }
                  }
            }
            //System.out.println("fail : scored " + totalScore);
            return 0;
      }

      /**
      *
      * This function returns the length of the longest word list.
      * It's not used at the moment but may be useful
      *
      */
      public int maxListLength(){
            int length = 0;
            for (int l = 0; l < lists.size(); l ++){
                  if (((WordList)lists.elementAt(l)).numWords() > length){
                        length = ((WordList)lists.elementAt(l)).numWords();
                  }
            }
            return length;
      }

}
0
 
ozymandiasCommented:
/**
*
* WordList.java
*
* This class holds an array of strings (words) which
* can be combined in a WordPattern with other WordLists
*
*/

package definitions;

import java.util.StringTokenizer;
import java.util.Vector;
import com.ibm.aglet.*;

public class WordList extends Aglet{

     private Vector words;
     private Stemmer stemmer;
     private boolean stemming = false;

     /**
     *
     * This constructor takes a string and a delimiter string
     * and then uses a StringTokenizer to break the string into
     * an array of words
     */
     public WordList(String s, String delimiter, boolean stem){
          if (stem){
               stemmer = new Stemmer();
               stemming = true;
          }
          StringTokenizer st = new StringTokenizer(s,delimiter);
          words = new Vector();
          while (st.hasMoreTokens()){
               words.add(st.nextToken());
          }
     }

     /**
     *
     * This is just an accessor function that lets you get the words
     * held in the list. Not used at the moment, but probably useful
     * for debugging.
     */
     public String[] getWords(){
          String[] wordArray = new String[words.size()];
          wordArray = (String[])words.toArray(wordArray);
          return wordArray;
     }

     /**
     *
     * This is just an accessor function that lets you get the number of
     * words held in the list. Not used at the moment, but probably useful
     * for debugging.
     */
     public int numWords(){
          return words.size();
     }

     /**
     *
     * This function takes a string (word) and checks to
     * see if it matches any of the words in its list.
     */
     public int containsWord(String s){
          //System.out.println("Looking for " + s + " in :");
          //this.print();
          String word1 = s.trim();
          for (int i = 0; i < words.size(); i++){
               String word2 = (String)words.elementAt(i);
               if (word1.equalsIgnoreCase(word2)){
                    //System.out.println("match : "+ word1 + " : " + word2);
                    return 2;
               }
          }
          if (stemming){
               word1 = stemmer.getStem(word1);
               for (int i = 0; i < words.size(); i++){
                    String word2 = stemmer.getStem((String)words.elementAt(i));
                    if (word1.equalsIgnoreCase(word2)){
                         //System.out.println("stem match : "+ word1 + " : " + word2);
                         return 1;
                    }
               }
          }
          return 0;
     }

     /**
     *
     * This is just an accessor function that prints out the words
     * held in the list. Not used at the moment, but probably useful
     * for debugging.
     */
     public void print(){
          for (int i = 0; i < words.size(); i++){
               System.out.println((String)words.elementAt(i));
          }
     }

     public boolean isStemming(){
          return stemming;
     }

}
0
 
ozymandiasCommented:
/**
*
* Sentence.java
*
*/

package definitions;

import java.util.StringTokenizer;
import java.io.File;
import java.net.URL;
import com.ibm.aglet.*;

public class Sentence  extends Aglet implements Comparable{

     private String sentence;
     private int keyScore;
     private int patternScore;
     private File location;
     private URL host;

     public Sentence(String s){
          sentence = s;
          keyScore = 0;
          patternScore = 0;
     }

     public String[] getWordArray(){
          int token = 0;
          StringTokenizer st = new StringTokenizer(sentence);
          String[] words = new String[st.countTokens()];
          while (st.hasMoreTokens()){
               words[token++] = st.nextToken();
          }
          return words;
     }

     public int getScore(){
          return (keyScore + patternScore);
     }

     public URL getHostingURL(){
          return host;
     }

     public void setHostingURL(URL host){
          this.host = host;
     }

     public int getKeyScore(){
          return keyScore;
     }

     public void setKeyScore(int s){
          keyScore = s;
     }

     public void addKeyScore(int s){
          keyScore += s;
     }

     public int getPatternScore(){
          return patternScore;
     }

     public void setPatternScore(int s){
          patternScore = s;
     }

     public void addSPatterncore(int s){
          patternScore += s;
     }

     public void setLocation(File f){
          location = f;
     }

     public File getLocation(){
          return location;
     }

     public int compareTo(Object o){
          int c = ((Sentence)o).getScore();
          if (c == this.getScore()){
               return 0;
          }else{
               return (c - this.getScore());
          }
     }

     public String getSentence(){
          return sentence;
     }

     public String toString(){
          return sentence + "[" + keyScore + "][" + patternScore + "](" + location.toString() + ")";
     }
}
0
 
ozymandiasCommented:
/*

   Porter stemmer in Java. The original paper is in

       Porter, 1980, An algorithm for suffix stripping, Program, Vol. 14,
       no. 3, pp 130-137,

   See also http://www.tartarus.org/~martin/PorterStemmer

   History:

   Release 1

   Bug 1 (reported by Gonzalo Parra 16/10/99) fixed as marked below.
   The words 'aed', 'eed', 'oed' leave k at 'a' for step 3, and b[k-1]
   is then out outside the bounds of b.

   Release 2

   Similarly,

   Bug 2 (reported by Steve Dyrdahl 22/2/00) fixed as marked below.
   'ion' by itself leaves j = -1 in the test for 'ion' in step 5, and
   b[j] is then outside the bounds of b.

   Release 3

   Considerably revised 4/9/00 in the light of many helpful suggestions
   from Brian Goetz of Quiotix Corporation (brian@quiotix.com).

   Release 4

*/

package definitions;

import java.io.*;
import com.ibm.aglet.*;

/**
  * Stemmer, implementing the Porter Stemming Algorithm
  *
  * The Stemmer class transforms a word into its root form.  The input
  * word can be provided a character at time (by calling add()), or at once
  * by calling one of the various stem(something) methods.
  */

public class Stemmer extends Aglet
{  private char[] b;
   private int i,     /* offset into b */
               i_end, /* offset to end of stemmed word */
               j, k;
   private static final int INC = 50;
                     /* unit of size whereby b is increased */
   public Stemmer()
   {  b = new char[INC];
      i = 0;
      i_end = 0;
   }

   /**
    * Function to allow the Stemmer to be reused
      *
      * Ozymandias 04/03/03
    */

   public void reset()
   {
         b = new char[INC];
         i = 0;
         i_end = 0;
   }

   /**
    * Add a character to the word being stemmed.  When you are finished
    * adding characters, you can call stem(void) to stem the word.
    */

   public void add(char ch)
   {  if (i == b.length)
      {  char[] new_b = new char[i+INC];
         for (int c = 0; c < i; c++) new_b[c] = b[c];
         b = new_b;
      }
      b[i++] = ch;
   }


   /** Adds wLen characters to the word being stemmed contained in a portion
    * of a char[] array. This is like repeated calls of add(char ch), but
    * faster.
    */

   public void add(char[] w, int wLen)
   {  if (i+wLen >= b.length)
      {  char[] new_b = new char[i+wLen+INC];
         for (int c = 0; c < i; c++) new_b[c] = b[c];
         b = new_b;
      }
      for (int c = 0; c < wLen; c++) b[i++] = w[c];
   }

   /**
    * Quick and dirty method for adding a word as a string
    *
    * Ozymandias 04/03/03
    */

      public void add(String word){
            int length = word.length();
            char[] buf = new char[length];
            for (int c = 0; c < length; c++){
                  buf[c] = word.charAt(c);
            }
            add(buf,length);
      }

   /**
    * Quick and dirty method for getting the stem of a word
    *
    * Ozymandias 04/03/03
    */

      public String getStem(String s){
            this.reset();
            this.add(s);
            this.stem();
            return this.toString();
      }

   /**
    * After a word has been stemmed, it can be retrieved by toString(),
    * or a reference to the internal buffer can be retrieved by getResultBuffer
    * and getResultLength (which is generally more efficient.)
    */
   public String toString() { return new String(b,0,i_end); }

   /**
    * Returns the length of the word resulting from the stemming process.
    */
   public int getResultLength() { return i_end; }

   /**
    * Returns a reference to a character buffer containing the results of
    * the stemming process.  You also need to consult getResultLength()
    * to determine the length of the result.
    */
   public char[] getResultBuffer() { return b; }

   /* cons(i) is true <=> b[i] is a consonant. */

   private final boolean cons(int i)
   {  switch (b[i])
      {  case 'a': case 'e': case 'i': case 'o': case 'u': return false;
         case 'y': return (i==0) ? true : !cons(i-1);
         default: return true;
      }
   }

   /* m() measures the number of consonant sequences between 0 and j. if c is
      a consonant sequence and v a vowel sequence, and <..> indicates arbitrary
      presence,

         <c><v>       gives 0
         <c>vc<v>     gives 1
         <c>vcvc<v>   gives 2
         <c>vcvcvc<v> gives 3
         ....
   */

   private final int m()
   {  int n = 0;
      int i = 0;
      while(true)
      {  if (i > j) return n;
         if (! cons(i)) break; i++;
      }
      i++;
      while(true)
      {  while(true)
         {  if (i > j) return n;
               if (cons(i)) break;
               i++;
         }
         i++;
         n++;
         while(true)
         {  if (i > j) return n;
            if (! cons(i)) break;
            i++;
         }
         i++;
       }
   }

   /* vowelinstem() is true <=> 0,...j contains a vowel */

   private final boolean vowelinstem()
   {  int i; for (i = 0; i <= j; i++) if (! cons(i)) return true;
      return false;
   }

   /* doublec(j) is true <=> j,(j-1) contain a double consonant. */

   private final boolean doublec(int j)
   {  if (j < 1) return false;
      if (b[j] != b[j-1]) return false;
      return cons(j);
   }

   /* cvc(i) is true <=> i-2,i-1,i has the form consonant - vowel - consonant
      and also if the second c is not w,x or y. this is used when trying to
      restore an e at the end of a short word. e.g.

         cav(e), lov(e), hop(e), crim(e), but
         snow, box, tray.

   */

   private final boolean cvc(int i)
   {  if (i < 2 || !cons(i) || cons(i-1) || !cons(i-2)) return false;
      {  int ch = b[i];
         if (ch == 'w' || ch == 'x' || ch == 'y') return false;
      }
      return true;
   }

   private final boolean ends(String s)
   {  int l = s.length();
      int o = k-l+1;
      if (o < 0) return false;
      for (int i = 0; i < l; i++) if (b[o+i] != s.charAt(i)) return false;
      j = k-l;
      return true;
   }

   /* setto(s) sets (j+1),...k to the characters in the string s, readjusting
      k. */

   private final void setto(String s)
   {  int l = s.length();
      int o = j+1;
      for (int i = 0; i < l; i++) b[o+i] = s.charAt(i);
      k = j+l;
   }

   /* r(s) is used further down. */

   private final void r(String s) { if (m() > 0) setto(s); }

   /* step1() gets rid of plurals and -ed or -ing. e.g.

          caresses  ->  caress
          ponies    ->  poni
          ties      ->  ti
          caress    ->  caress
          cats      ->  cat

          feed      ->  feed
          agreed    ->  agree
          disabled  ->  disable

          matting   ->  mat
          mating    ->  mate
          meeting   ->  meet
          milling   ->  mill
          messing   ->  mess

          meetings  ->  meet

   */

   private final void step1()
   {  if (b[k] == 's')
      {  if (ends("sses")) k -= 2; else
         if (ends("ies")) setto("i"); else
         if (b[k-1] != 's') k--;
      }
      if (ends("eed")) { if (m() > 0) k--; } else
      if ((ends("ed") || ends("ing")) && vowelinstem())
      {  k = j;
         if (ends("at")) setto("ate"); else
         if (ends("bl")) setto("ble"); else
         if (ends("iz")) setto("ize"); else
         if (doublec(k))
         {  k--;
            {  int ch = b[k];
               if (ch == 'l' || ch == 's' || ch == 'z') k++;
            }
         }
         else if (m() == 1 && cvc(k)) setto("e");
     }
   }

   /* step2() turns terminal y to i when there is another vowel in the stem. */

   private final void step2() { if (ends("y") && vowelinstem()) b[k] = 'i'; }

   /* step3() maps double suffices to single ones. so -ization ( = -ize plus
      -ation) maps to -ize etc. note that the string before the suffix must give
      m() > 0. */

   private final void step3() { if (k == 0) return; /* For Bug 1 */ switch (b[k-1])
   {
       case 'a': if (ends("ational")) { r("ate"); break; }
                 if (ends("tional")) { r("tion"); break; }
                 break;
       case 'c': if (ends("enci")) { r("ence"); break; }
                 if (ends("anci")) { r("ance"); break; }
                 break;
       case 'e': if (ends("izer")) { r("ize"); break; }
                 break;
       case 'l': if (ends("bli")) { r("ble"); break; }
                 if (ends("alli")) { r("al"); break; }
                 if (ends("entli")) { r("ent"); break; }
                 if (ends("eli")) { r("e"); break; }
                 if (ends("ousli")) { r("ous"); break; }
                 break;
       case 'o': if (ends("ization")) { r("ize"); break; }
                 if (ends("ation")) { r("ate"); break; }
                 if (ends("ator")) { r("ate"); break; }
                 break;
       case 's': if (ends("alism")) { r("al"); break; }
                 if (ends("iveness")) { r("ive"); break; }
                 if (ends("fulness")) { r("ful"); break; }
                 if (ends("ousness")) { r("ous"); break; }
                 break;
       case 't': if (ends("aliti")) { r("al"); break; }
                 if (ends("iviti")) { r("ive"); break; }
                 if (ends("biliti")) { r("ble"); break; }
                 break;
       case 'g': if (ends("logi")) { r("log"); break; }
   } }

   /* step4() deals with -ic-, -full, -ness etc. similar strategy to step3. */

   private final void step4() { switch (b[k])
   {
       case 'e': if (ends("icate")) { r("ic"); break; }
                 if (ends("ative")) { r(""); break; }
                 if (ends("alize")) { r("al"); break; }
                 break;
       case 'i': if (ends("iciti")) { r("ic"); break; }
                 break;
       case 'l': if (ends("ical")) { r("ic"); break; }
                 if (ends("ful")) { r(""); break; }
                 break;
       case 's': if (ends("ness")) { r(""); break; }
                 break;
   } }

   /* step5() takes off -ant, -ence etc., in context <c>vcvc<v>. */

   private final void step5()
   {   if (k == 0) return; /* for Bug 1 */ switch (b[k-1])
       {  case 'a': if (ends("al")) break; return;
          case 'c': if (ends("ance")) break;
                    if (ends("ence")) break; return;
          case 'e': if (ends("er")) break; return;
          case 'i': if (ends("ic")) break; return;
          case 'l': if (ends("able")) break;
                    if (ends("ible")) break; return;
          case 'n': if (ends("ant")) break;
                    if (ends("ement")) break;
                    if (ends("ment")) break;
                    /* element etc. not stripped before the m */
                    if (ends("ent")) break; return;
          case 'o': if (ends("ion") && j >= 0 && (b[j] == 's' || b[j] == 't')) break;
                                    /* j >= 0 fixes Bug 2 */
                    if (ends("ou")) break; return;
                    /* takes care of -ous */
          case 's': if (ends("ism")) break; return;
          case 't': if (ends("ate")) break;
                    if (ends("iti")) break; return;
          case 'u': if (ends("ous")) break; return;
          case 'v': if (ends("ive")) break; return;
          case 'z': if (ends("ize")) break; return;
          default: return;
       }
       if (m() > 1) k = j;
   }

   /* step6() removes a final -e if m() > 1. */

   private final void step6()
   {  j = k;
      if (b[k] == 'e')
      {  int a = m();
         if (a > 1 || a == 1 && !cvc(k-1)) k--;
      }
      if (b[k] == 'l' && doublec(k) && m() > 1) k--;
   }

   /** Stem the word placed into the Stemmer buffer through calls to add().
    * Returns true if the stemming process resulted in a word different
    * from the input.  You can retrieve the result with
    * getResultLength()/getResultBuffer() or toString().
    */
   public void stem()
   {  k = i - 1;
      if (k > 1) { step1(); step2(); step3(); step4(); step5(); step6(); }
      i_end = k+1; i = 0;
   }

   /** Test program for demonstrating the Stemmer.  It reads text from a
    * a list of files, stems each word, and writes the result to standard
    * output. Note that the word stemmed is expected to be in lower case:
    * forcing lower case must be done outside the Stemmer class.
    * Usage: Stemmer file-name file-name ...
    */
   /**
   *
   * Commenting out this main method to add one that is more useful
   * for my immediate needs.
   *
   * Ozymandias 04/03/03
   *
   public static void main(String[] args)
   {
      char[] w = new char[501];
      Stemmer s = new Stemmer();
      for (int i = 0; i < args.length; i++)
      try
      {
         FileInputStream in = new FileInputStream(args[i]);

         try
         { while(true)

           {  int ch = in.read();
              if (Character.isLetter((char) ch))
              {
                 int j = 0;
                 while(true)
                 {  ch = Character.toLowerCase((char) ch);
                    w[j] = (char) ch;
                    if (j < 500) j++;
                    ch = in.read();
                    if (!Character.isLetter((char) ch))
                    {
                       // to test add(char ch)
                       for (int c = 0; c < j; c++) s.add(w[c]);

                       // or, to test add(char[] w, int j)
                       // s.add(w, j);

                       s.stem();
                       {  String u;

                          // and now, to test toString() :
                          u = s.toString();

                          // to test getResultBuffer(), getResultLength() :
                          // u = new String(s.getResultBuffer(), 0, s.getResultLength());

                          System.out.print(u);
                       }
                       break;
                    }
                 }
              }
              if (ch < 0) break;
              System.out.print((char)ch);
           }
         }
         catch (IOException e)
         {  System.out.println("error reading " + args[i]);
            break;
         }
      }
      catch (FileNotFoundException e)
      {  System.out.println("file " + args[i] + " not found");
         break;
      }
   }
   */

      public static void main(String[] args){
            Stemmer stemmer = new Stemmer();

            for (int i = 0; i < args.length; i++){
                  String word = args[i];
                  stemmer.reset();
                  stemmer.add(word);
                  stemmer.stem();
                  System.out.println(word + " was stemmed to " + stemmer.toString());
            }
      }
}

0
 
cancer_66Author Commented:
ill open up a new thread "Title: Search:- 4 For Mr ozymandias"
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

  • 56
  • 37
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now