/** Thanks to David Warner and ACM Wash U for these fortunes */ import kwic.*; import java.util.Iterator; import java.util.Set; public class Demo { public static void main(String[] args) { (new Demo()).doit(); } private KWIC kwic; public Demo() { kwic = new KWIC(); } private void dump(Word w) { System.out.println("Word: " + w); for (Iterator phrases = kwic.getPhrases(w); phrases.hasNext();) { Phrase p = (Phrase) phrases.next(); System.out.println(" " + p); } } public void doit() { for (int i=0; i < fortunes.length; ++i) { kwic.addPhrase(fortunes[i]); } System.out.println("---------"); System.out.println("Probe for a hug: "); dump(new Word("Hug")); System.out.println("---------"); System.out.println("\n\"surrounded\" probe should have two responses:"); dump(new Word("surrounded")); String rem = "You will soon be surrounded by good friends and laughter."; System.out.println("Now remove one: " + rem); kwic.deletePhrase(new Phrase(rem)); System.out.println("Surrounded probe should have one responses:"); dump(new Word("surrounded")); System.out.println("---------"); System.out.println("Look at all the hits for \"you\""); dump(new Word("YOU")); System.out.println(""); System.out.println("Now we eliminate \"you\" from the KWIC"); kwic.deleteWord(new Word("you")); System.out.println("Now we should get nothing from looking \"you\" up"); dump(new Word("YOU")); System.out.println("---------"); System.out.println("All words: "); dumpall(); System.out.println(""); System.out.println("Done."); } private void dumpall() { for (Iterator words = kwic.getWords(); words.hasNext();) { Word w = (Word) words.next(); dump(w); } } /** This is put at the bottom to move it out of your way. Instance * vars should go at the top really. */ private final static String[] fortunes = { "A new chapter in your life is being written.", "A modest man never talks of himself.", "You are faithful in the execution of any public trust.", "You are heading for a land of sunshine.", "A close friend reveals a hidden talent.", "Good to begin well, better to end well.", "Keep your nose to the grindstone.", "You sense subtle changes in people.", "Age can never hope to win you while your heart is young.", "You are a lover of words, someday you will write a book.", "Your luck has been completely changed today.", "You are vigorous in words and action.", "Skill comes from diligence.", "There's a good chance of a romantic encounter soon.", "We are very happy together.", "Keep true to the dreams of your youth.", "Happy event will take place shortly in your home.", "Your sense of humor reveals itself at just the right times!", "You have an active mind and a keen imagination.", "You will seriously consider a move by year end.", "You believe in the goodness of mankind.", "You are kind and friendly.", "Speak only well of people and you need never whisper.", "A friend asks only for your time not your money.", "You have great physical powers and an iron construction.", "You will inherit a large sum of money.", "You will have a pleasant trip.", "Don't be hasty; prosperity will knock on your door soon.", "Your home is a pleasant place from which you draw happiness.", "You constantly struggle for self improvement.", "There are always more fish in the sea; some not as smart and some not as attractive, but fish nonetheless.", "Simplicity of character is the natural result of profound thought.", "Enjoy your god company, they are your true friends.", "You shall soon make a long overdue personal decision.", "You shall soon gain the attention of those who count.", "You will be advanced socially, without any special effort.", "Try to channel excess energies into rejuvenation.", "Next month shall be hectic, yet delightful.", "Look for new outlets for your own creative abilities.", "Pray for what you want, but work for the things you need.", "Keep in close touch with what your competition is doing.", "You will receive some high prize or reward.", "Because of your melodic nature, the moonlight never misses an appointment.", "Your skills will accomplish what the force of many cannot.", "What makes an apple fall to the ground?", "Practice makes perfect.", "Accept the next proposition you hear.", "You will witness a special ceremony.", "Back away from individuals who are impulsive.", "Golden investment opportunities are arising.", "You will participate in a gala affair.", "A handful of patience is worth more than a bushel of brains.", "When winter comes heaven will rain success on you.", "Courage & optimism are your best traits.", "There is a true and sincere friendship between you and your friends.", "Your past success will be overshadowed by your future success.", "The time is right to make new friends.", "The joyfulness of a man prolongs his day.", "Family relations will improve with time.", "Security is in the offering.", "Second thoughts are often wiser than first impressions.", "Fear creates danger, and courage dispels it.", "God will give you everything that you want.", "You are a practical person with your feet on the ground.", "You like participating in competitive sports.", "Please follow more cautiously Life's Golden Rule.", "Courage and optimism are your best traits.", "From now on your kindness will lead you to success.", "An admirer holds the key to more happiness.", "Avoid a hasty decision.", "If your desires are not extravagent they will be granted.", "Your life will be full of true friendships.", "You are independant politically.", "An investment in enthusiasm ought to start to pay off.", "Progress is in the reach of all who wish to make it.", "You will make change for the better.", "Our first and last love is . . .self-love.", "You will take a chance in something in near future.", "A good evening is one spent in good company.", "A good time to finish up old tasks.", "You will enjoy good health, you will be surrounded by luxury.", "Society prepares the crime; the criminal commits it.", "Your talents will be recognized and suitably rewarded.", "Never trouble trouble till trouble troubles you.", "You will enjoy true success in whatever you do.", "You are very expressive and positive in words, act and feeling.", "Idleness is the holiday of fools.", "A truly good person does nothing, yet leaves nothing undone.", "You will make many changes before settling satisfactorily.", "The only good is knowledge and the only evil ignorance.", "The heart is wiser than the intellect.", "Your happiness is intertwined with your outlook on life.", "Success in the end eclipses the mistakes along the way.", "In God we trust; all others must pay cash.", "Your life will be happy and peaceful.", "If you would be loved, love and be lovable.", "You are talented in many ways.", "A pound of pluck is worth a ton of luck.", "A friend is a present you give yourself.", "He who is afraid of asking is ashamed of learning.", "You love peace.", "You will be the best.", "You have a reputation for being thoroughly reliable and trustworthy.", "We are not older with age, but wiser.", "One day you will become rich and famous.", "It is much wiser to take advice than to give it.", "Don't let friends impose on you.", "Time is precious, but truth is more precious than time.", "Find release from your cares have a good time.", "A merry heart maketh a cheerful counntenance.", "You are the center of every group's attention.", "Versatility is one of your outstanding traits.", "Executive ability is prominent in your make up.", "You are courteous, diplomatic and affable and may find happiness in politics and public service.", "You have the ability to analyse and solve any problem.", "Give a hug to someone who needs one more than you.", "You will take a chance in something in the near future.", "The best profit of the future is the past.", "You would make a good lawyer.", "You have a yearning for perfection.", "Trust your intuition. The universe is guiding your life.", "Honesty and integrity are just some of your best attributes.", "You should be able to make money and hold on to it.", "If you promise someone something, keep it.", "No man is without enemies.", "Nothing in the world is accomplished without passion.", "Trouble brings experience and experience brings wisdom.", "You will soon be honored by someone you respect.", "You will soon be surrounded by good friends and laughter.", "The first step to better times is to imagine them.", "An unexpected event will bring you riches.", "You are soon going to change your present line of work.", "Haste does not bring success.", "He who knows he has enough is rich.", "You long to see the great pyramids in Egypt.", "Many receive advice, only the wise profit by it.", "There is a true and sincere friendship between you both.", "A journey must begin with a single step.", "Place special emphasis on old friendship.", "The wheel of fortune is finally turning in your direction!", "Love truth, but pardon error.", "A pleasant experience is ahead: don't pass it by.", "Your present plans are going to succeed.", "From listening comes wisdom and from speaking repentance.", "We must not become complacent over any success.", "May life throw you a pleasant curve.", "Every excess becomes a vice.", "You will never be last in line, you will always excel!", "You have a keen sense of humor and love a good time.", "One look is worth ten thousand words.", "Your destiny lies before you, choose wisely.", "Don't let friends impose on you, work calmly and silently.", "The important thing is to express yourself.", "Nater, time and patience are the three great healers.", "Your priciples mean more to you than any money or success.", "You will spend old age in comfort and material wealth.", "You never hesitate to tackle the most difficult problems.", "Where there is a will, there is a way.", "Pardon is the choicest flower of victory.", "You will have a party.", "The happiest circumstances are close to home.", "Your love of music will be an important part of your life.", "Your ideals are well within your reach.", "A merry heart maketh a cheerful countenance.", "To be beautiful externally is like a glass rose; one false move and it can crack.", "You are pretty." }; }