001 /*
002 * WordNetViewer.java
003 *
004 * Copyright (c) 1995-2010, The University of Sheffield. See the file
005 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
006 *
007 * This file is part of GATE (see http://gate.ac.uk/), and is free
008 * software, licenced under the GNU Library General Public License,
009 * Version 2, June 1991 (in the distribution as file licence.html,
010 * and also available at http://gate.ac.uk/gate/licence.html).
011 *
012 * Rosen Marinov, 29/05/2002
013 *
014 */
015 package gate.gui.wordnet;
016
017 import java.awt.*;
018 import java.awt.event.ActionEvent;
019 import java.awt.event.ActionListener;
020 import java.net.URL;
021
022 import javax.swing.*;
023
024 import gate.Gate;
025 import gate.creole.AbstractVisualResource;
026 import gate.wordnet.*;
027
028 public class WordNetViewer extends AbstractVisualResource
029 implements ActionListener{
030
031 protected JLabel searchLabel = new JLabel();
032 protected JTextField searchWordTextField = new JTextField();
033 protected JButton searchButton = new JButton();
034 protected JTextPane resultPane = new JTextPane();
035 protected JLabel searchLabel2 = new JLabel();
036 protected JButton nounButton = new JButton();
037 protected JButton verbButton = new JButton();
038 protected JButton adjectiveButton = new JButton();
039 protected JButton adverbButton = new JButton();
040 protected JScrollPane scrollPane = new JScrollPane();
041 protected GridBagLayout gridBagLayout1 = new GridBagLayout();
042
043 protected JPopupMenu nounPopup;
044 protected JPopupMenu verbPopup;
045 protected JPopupMenu adjectivePopup;
046 protected JPopupMenu adverbPopup;
047
048 private static final String propertiesFile = "file://D:/Gate/temp/file_properties.xml";
049 private WordNet wnMain = null;
050
051 private boolean sentenceFrames = false;
052 public final static int SENTENCE_FRAMES = 33001;
053
054 public WordNetViewer(){
055 searchLabel.setText("Search Word:");
056 this.setLayout(gridBagLayout1);
057 searchButton.setText("Search");
058 searchButton.addActionListener(new java.awt.event.ActionListener() {
059 public void actionPerformed(ActionEvent e) {
060 searchButton_actionPerformed(e);
061 }
062 });
063 searchWordTextField.addActionListener(new java.awt.event.ActionListener() {
064 public void actionPerformed(ActionEvent e) {
065 searchWordTextField_actionPerformed(e);
066 }
067 });
068 searchLabel2.setText("Searches for ... :");
069 nounButton.setText("Noun");
070 verbButton.setText("Verb");
071 adjectiveButton.setText("Adjective");
072 adverbButton.setText("Adverb");
073
074 nounButton.addActionListener(new java.awt.event.ActionListener() {
075 public void actionPerformed(ActionEvent e) {
076 nounButton_actionPerformed(e);
077 }
078 });
079 verbButton.addActionListener(new java.awt.event.ActionListener() {
080 public void actionPerformed(ActionEvent e) {
081 verbButton_actionPerformed(e);
082 }
083 });
084 adjectiveButton.addActionListener(new java.awt.event.ActionListener() {
085 public void actionPerformed(ActionEvent e) {
086 adjectiveButton_actionPerformed(e);
087 }
088 });
089 adverbButton.addActionListener(new java.awt.event.ActionListener() {
090 public void actionPerformed(ActionEvent e) {
091 adverbButton_actionPerformed(e);
092 }
093 });
094 nounButton.setEnabled(false);
095 verbButton.setEnabled(false);
096 adjectiveButton.setEnabled(false);
097 adverbButton.setEnabled(false);
098
099 resultPane.setEditable(false);
100 scrollPane.getViewport().add(resultPane);
101
102 this.add(searchLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
103 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
104 this.add(searchWordTextField, new GridBagConstraints(1, 0, 5, 1, 1.0, 0.0
105 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
106 this.add(scrollPane, new GridBagConstraints(0, 2, 7, 1, 1.0, 1.0
107 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
108 this.add(searchLabel2, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0
109 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
110 this.add(searchButton, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0
111 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
112 this.add(adjectiveButton, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0
113 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
114 this.add(verbButton, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0
115 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
116 this.add(nounButton, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
117 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
118 this.add(adverbButton, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0
119 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
120 }
121
122 private void searchButton_actionPerformed(ActionEvent e) {
123 actionSearch();
124 }
125
126 private void searchWordTextField_actionPerformed(ActionEvent e) {
127 actionSearch();
128 }
129
130 private void actionSearch(){
131 String text = searchWordTextField.getText().trim();
132 text = text.replace(' ','_');
133 searchLabel2.setText("Searches for " + text + ":");
134
135 nounButton.setEnabled(false);
136 verbButton.setEnabled(false);
137 adjectiveButton.setEnabled(false);
138 adverbButton.setEnabled(false);
139
140 nounPopup = new JPopupMenu();
141 verbPopup = new JPopupMenu();
142 adjectivePopup = new JPopupMenu();
143 adverbPopup = new JPopupMenu();
144
145 StringBuffer display = new StringBuffer("");
146
147 addToResult(display, text, WordNet.POS_NOUN);
148 addToResult(display, text, WordNet.POS_VERB);
149 addToResult(display, text, WordNet.POS_ADJECTIVE);
150 addToResult(display, text, WordNet.POS_ADVERB);
151
152 resultPane.setText(display.toString());
153
154 }
155
156 private void addToResult(StringBuffer display, String text, int wordType) {
157 java.util.List senses = null;
158 try {
159 wnMain.cleanup();
160 senses = wnMain.lookupWord(text, wordType);
161 } catch (WordNetException wne) {
162 wne.printStackTrace();
163 }
164
165 if ( senses!=null && senses.size()>0){
166
167 String wordIdentifier = "";
168 switch (wordType){
169 case WordNet.POS_NOUN:
170 wordIdentifier = "noun";
171 nounButton.setEnabled(true);
172 break;
173 case WordNet.POS_VERB:
174 wordIdentifier = "verb";
175 verbButton.setEnabled(true);
176 break;
177 case WordNet.POS_ADJECTIVE:
178 wordIdentifier = "adjective";
179 adjectiveButton.setEnabled(true);
180 break;
181 case WordNet.POS_ADVERB:
182 wordIdentifier = "adverb";
183 adverbButton.setEnabled(true);
184 break;
185 }
186
187 display.append("\n");
188 display.append("The ");
189 display.append(wordIdentifier);
190 display.append(" ");
191 display.append(text);
192 display.append(" has ");
193 display.append(senses.size());
194 display.append(" senses:");
195 display.append("\n\n");
196 for (int i=0; i< senses.size(); i++) {
197 WordSense currSense = (WordSense) senses.get(i);
198 Synset currSynset = currSense.getSynset();
199 addToPopupMenu(currSense, currSynset, wordType, senses);
200 java.util.List words = currSynset.getWordSenses();
201 String wordsString = getWords(words);
202
203 display.append(" " + (i+1) + ". " + wordsString + " -- " + currSynset.getGloss());
204 display.append("\n");
205 }
206 }
207 }
208
209 private void addToPopupMenu(WordSense wordSense, Synset synset, int wordType, java.util.List senses){
210 java.util.List semRelations = null;
211 try {
212 semRelations = synset.getSemanticRelations();
213 } catch (Exception e){
214 e.printStackTrace();
215 }
216
217 java.util.List lexRelations = null;
218 try {
219 lexRelations = wordSense.getLexicalRelations();
220 } catch (Exception e){
221 e.printStackTrace();
222 }
223
224 for (int i=0; i<(semRelations.size()+lexRelations.size()); i++) {
225 Relation relation;
226 if (i<semRelations.size()){
227 relation = (SemanticRelation) semRelations.get(i);
228 } else {
229 relation = (LexicalRelation) lexRelations.get(i-semRelations.size());
230 }
231
232 switch (wordType) {
233 case WordNet.POS_NOUN:
234 if (false == existInPopup(nounPopup, getLabel(relation)) ){
235 nounPopup.add(new RelationItem(getLabel(relation), relation.getType(), senses));
236 }
237 break;
238 case WordNet.POS_VERB:
239 //commented because problem with WN API and Sentence Frames
240 if (!sentenceFrames){
241 verbPopup.add(new RelationItem("Sentence Frames", SENTENCE_FRAMES, senses));
242 sentenceFrames = true;
243 }
244 if (false == existInPopup(verbPopup, getLabel(relation)) ){
245 verbPopup.add(new RelationItem(getLabel(relation), relation.getType(), senses));
246 }
247 break;
248 case WordNet.POS_ADJECTIVE:
249 if (false == existInPopup(adjectivePopup, getLabel(relation)) ){
250 adjectivePopup.add(new RelationItem(getLabel(relation), relation.getType(), senses));
251 }
252 break;
253 case WordNet.POS_ADVERB:
254 if (false == existInPopup(adverbPopup, getLabel(relation)) ){
255 adverbPopup.add(new RelationItem(getLabel(relation), relation.getType(), senses));
256 }
257 break;
258 }
259 }
260 }
261
262 private boolean existInPopup(JPopupMenu menu, String name){
263 boolean result = false;
264 for (int i=0; i<menu.getComponents().length; i++){
265 if ( menu.getComponents()[i].getName().equals(name)){
266 result = true;
267 break;
268 }
269 }
270 return result;
271 }
272
273 void nounButton_actionPerformed(ActionEvent e) {
274 nounPopup.show(nounButton, 0, nounButton.getHeight());
275 }
276
277 void verbButton_actionPerformed(ActionEvent e) {
278 verbPopup.show(verbButton, 0, verbButton.getHeight());
279 }
280
281 void adjectiveButton_actionPerformed(ActionEvent e) {
282 adjectivePopup.show(adjectiveButton, 0, adjectiveButton.getHeight());
283 }
284
285 void adverbButton_actionPerformed(ActionEvent e) {
286 if (adverbPopup.getComponentCount()>0){
287 adverbPopup.show(adverbButton, 0, adverbButton.getHeight());
288 }
289 }
290
291 public void actionPerformed(ActionEvent e){
292 RelationItem ri = (RelationItem) e.getSource();
293 switch (ri.getRelationType()){
294 case Relation.REL_ANTONYM:
295 relAntonymSeeAlso(ri.getSenses(), Relation.REL_ANTONYM,"=> ");
296 break;
297 case Relation.REL_ATTRIBUTE:
298 relAtributeSimilarTo(ri.getSenses(), Relation.REL_ATTRIBUTE, "=> ");
299 break;
300 case Relation.REL_CAUSE:
301 relHoloMeroHypo(ri.getSenses(), Relation.REL_CAUSE, "=> ");
302 break;
303 case Relation.REL_DERIVED_FROM_ADJECTIVE:
304 relAntonymSeeAlso(ri.getSenses(), Relation.REL_DERIVED_FROM_ADJECTIVE,"=> ");
305 break;
306 case Relation.REL_ENTAILMENT:
307 relHoloMeroHypo(ri.getSenses(), Relation.REL_ENTAILMENT, "=> ");
308 break;
309 case Relation.REL_HYPERNYM:
310 relHypernym(ri.getSenses());
311 break;
312 case Relation.REL_HYPONYM:
313 relHoloMeroHypo(ri.getSenses(), Relation.REL_HYPONYM, "=> ");
314 break;
315 case Relation.REL_MEMBER_HOLONYM:
316 relHoloMeroHypo(ri.getSenses(), Relation.REL_MEMBER_HOLONYM,"MEMBER OF: ");
317 break;
318 case Relation.REL_MEMBER_MERONYM:
319 relHoloMeroHypo(ri.getSenses(), Relation.REL_MEMBER_MERONYM, "HAS MEMBER: ");
320 break;
321 case Relation.REL_PARTICIPLE_OF_VERB:
322 relAntonymSeeAlso(ri.getSenses(), Relation.REL_PARTICIPLE_OF_VERB,"=> ");
323 break;
324 case Relation.REL_PART_HOLONYM:
325 relHoloMeroHypo(ri.getSenses(), Relation.REL_PART_HOLONYM, "PART OF: ");
326 break;
327 case Relation.REL_PART_MERONYM:
328 relHoloMeroHypo(ri.getSenses(), Relation.REL_PART_MERONYM, "HAS PART: ");
329 break;
330 case Relation.REL_PERTAINYM:
331 break;
332 case Relation.REL_SEE_ALSO:
333 relAntonymSeeAlso(ri.getSenses(), Relation.REL_SEE_ALSO,"=> ");
334 break;
335 case Relation.REL_SIMILAR_TO:
336 relAtributeSimilarTo(ri.getSenses(), Relation.REL_SIMILAR_TO, "=> ");
337 break;
338 case Relation.REL_SUBSTANCE_HOLONYM:
339 relHoloMeroHypo(ri.getSenses(), Relation.REL_SUBSTANCE_HOLONYM,
340 " SUBSTANCE OF: ");
341 break;
342 case Relation.REL_SUBSTANCE_MERONYM:
343 relHoloMeroHypo(ri.getSenses(), Relation.REL_SUBSTANCE_MERONYM, "HAS SUBSTANCE: ");
344 break;
345 case Relation.REL_VERB_GROUP:
346 relAtributeSimilarTo(ri.getSenses(), Relation.REL_VERB_GROUP, "=> ");
347 break;
348 case SENTENCE_FRAMES:
349 sentenceFrames(ri.getSenses());
350 break;
351 }
352 }
353
354 private void relHypernym(java.util.List senses){
355 StringBuffer display = new StringBuffer("");
356 for (int i = 0; i<senses.size(); i++){
357 //display.append(getDescription(Relation.REL_HYPERNYM));
358 display.append("\n");
359 display.append("Sense ");
360 display.append(i+1);
361 display.append("\n");
362
363 WordSense currSense = (WordSense) senses.get(i);
364 Synset currSynset = currSense.getSynset();
365 recursiveHypernym(currSynset, display, " =>");
366 }
367
368 resultPane.setText(display.toString());
369 }
370
371 private void recursiveHypernym(Synset synset, StringBuffer display, String prefix){
372 java.util.List words = synset.getWordSenses();
373 String wordsString = getWords(words);
374
375 display.append(prefix);
376 display.append(" ");
377 display.append(wordsString);
378 display.append(" -- ");
379 display.append(synset.getGloss());
380 display.append("\n");
381
382 java.util.List hList = null;
383 try {
384 hList = synset.getSemanticRelations(Relation.REL_HYPERNYM);
385 } catch (Exception e){
386 e.printStackTrace();
387 }
388 if (hList!=null && hList.size()>0){
389 SemanticRelation rel = (SemanticRelation) hList.get(0);
390 prefix = " " + prefix;
391 recursiveHypernym(rel.getTarget(), display, prefix);
392 }
393 }
394
395
396 private void relHoloMeroHypo(java.util.List senses, int relationType,
397 String relRefString){
398 StringBuffer display = new StringBuffer("");
399 for (int i = 0; i<senses.size(); i++){
400 WordSense currSense = (WordSense) senses.get(i);
401 Synset currSynset = currSense.getSynset();
402 try {
403 if (currSynset.getSemanticRelations(relationType).size()>0){
404 //display.append(getDescription(relationType));
405 display.append("\n");
406 display.append("Sense ");
407 display.append(i+1);
408 display.append("\n");
409 recursiveHoloMeroHypo(currSynset, display, " ", false,
410 relationType, relRefString);
411 }
412 } catch (Exception e){
413 e.printStackTrace();
414 }
415 }
416
417 resultPane.setText(display.toString());
418 }
419
420 private void recursiveHoloMeroHypo(Synset synset, StringBuffer display,
421 String prefix, boolean symbPrefix,
422 int relationType, String relRefString){
423
424 java.util.List words = synset.getWordSenses();
425 String wordsString = getWords(words);
426
427 display.append(prefix);
428 if (symbPrefix) {
429 display.append(relRefString);
430 }
431 display.append(wordsString);
432 display.append(" -- ");
433 display.append(synset.getGloss());
434 display.append("\n");
435
436 java.util.List holoList = null;
437 try {
438 holoList = synset.getSemanticRelations(relationType);
439 } catch (Exception e){
440 e.printStackTrace();
441 }
442 if (holoList!=null && holoList.size()>0){
443 for (int i = 0; i<holoList.size(); i++){
444 SemanticRelation rel = (SemanticRelation) holoList.get(i);
445 prefix = " " + prefix;
446 recursiveHoloMeroHypo(rel.getTarget(), display, prefix, true,
447 relationType, relRefString);
448 prefix = prefix.substring(4, prefix.length());
449 }
450 }
451 }
452
453 private void relAntonymSeeAlso(java.util.List senses,
454 int relType, String relRefString){
455 StringBuffer display = new StringBuffer("");
456 boolean semantic_see_also = true;
457 for (int i = 0; i<senses.size(); i++){
458 WordSense currSense = (WordSense) senses.get(i);
459 Synset currSynset = currSense.getSynset();
460 try {
461 java.util.List antonyms = currSense.getLexicalRelations(relType);
462 if (antonyms!=null && antonyms.size()>0){
463 semantic_see_also = false;
464 //display.append(getDescription(relType));
465 display.append("\n");
466 display.append("Sense ");
467 display.append(i+1);
468 display.append("\n ");
469 display.append(getWords(currSynset.getWordSenses()));
470 display.append(" -- ");
471 display.append(currSynset.getGloss());
472 display.append("\n");
473 for (int j=0; j<antonyms.size(); j++){
474 LexicalRelation rel = (LexicalRelation) antonyms.get(j);
475 WordSense word = rel.getTarget();
476 display.append(" ");
477 display.append(relRefString);
478 display.append(word.getWord().getLemma());
479 display.append(" -- ");
480 display.append(word.getSynset().getGloss());
481 display.append("\n");
482 }
483 display.append("\n");
484 }
485 } catch (Exception e){
486 e.printStackTrace();
487 }
488 }
489
490 resultPane.setText(display.toString());
491 if (semantic_see_also){
492 relAtributeSimilarTo(senses, Relation.REL_SEE_ALSO,"=> ");
493 }
494 }
495
496 private void relAtributeSimilarTo(java.util.List senses, int releationType,
497 String relRefString){
498 StringBuffer display = new StringBuffer("");
499 for (int i = 0; i<senses.size(); i++){
500 WordSense currSense = (WordSense) senses.get(i);
501 Synset currSynset = currSense.getSynset();
502 try {
503 java.util.List atributes = currSynset.getSemanticRelations(releationType);
504 if (atributes!=null && atributes.size()>0){
505 //display.append(getDescription(releationType));
506 display.append("\n");
507 display.append("Sense ");
508 display.append(i+1);
509 display.append("\n ");
510 display.append(getWords(currSynset.getWordSenses()));
511 display.append(" -- ");
512 display.append(currSynset.getGloss());
513 display.append("\n");
514 for (int j=0; j<atributes.size(); j++){
515 SemanticRelation rel = (SemanticRelation) atributes.get(j);
516 Synset synset = rel.getTarget();
517 display.append(" ");
518 display.append(relRefString);
519 display.append(getWords(synset.getWordSenses()));
520
521 display.append(" -- ");
522 display.append(synset.getGloss());
523 display.append("\n");
524 }
525 display.append("\n");
526 }
527 } catch (Exception e){
528 e.printStackTrace();
529 }
530 }
531
532 resultPane.setText(display.toString());
533 }
534
535
536 private String getWords(java.util.List words){
537 StringBuffer wordsString = new StringBuffer("");
538 for (int j = 0; j<words.size(); j++){
539 WordSense word = (WordSense) words.get(j);
540 wordsString.append(word.getWord().getLemma().replace('_',' '));
541 if (j<(words.size()-1)){
542 wordsString.append(", ");
543 }
544 }
545 return wordsString.toString();
546 }
547
548 private void sentenceFrames(java.util.List senses){
549 StringBuffer display = new StringBuffer("");
550 for (int i=0; i<senses.size(); i++) {
551 WordSense currSense = (WordSense) senses.get(i);
552 Synset currSynset = currSense.getSynset();
553 Verb currVerb = (Verb) currSense;
554 java.util.List frames = currVerb.getVerbFrames();
555
556 display.append("\nSense ");
557 display.append(i+1);
558 display.append("\n ");
559 display.append(getWords(currSynset.getWordSenses()));
560 display.append(" -- ");
561 display.append(currSynset.getGloss());
562 display.append("\n");
563
564 for (int j=0; j<frames.size(); j++){
565 display.append(" *> ");
566 display.append(((VerbFrame) frames.get(j)).getFrame());
567 display.append("\n");
568 }
569 }
570 resultPane.setText(display.toString());
571 }
572
573
574 public String getLabel(Relation r){
575
576 String result = "";
577 switch (r.getType()){
578 case Relation.REL_ANTONYM:
579 result = "Antonym";
580 break;
581 case Relation.REL_ATTRIBUTE:
582 result = "Attribute";
583 break;
584 case Relation.REL_CAUSE:
585 result = "Cause";
586 break;
587 case Relation.REL_DERIVED_FROM_ADJECTIVE:
588 result = "Derived From Adjective";
589 break;
590 case Relation.REL_ENTAILMENT:
591 result = "Entailment";
592 break;
593 case Relation.REL_HYPERNYM:
594 result = "Hypernym";
595 break;
596 case Relation.REL_HYPONYM:
597 result = "Hyponym";
598 break;
599 case Relation.REL_MEMBER_HOLONYM:
600 result = "Member Holonym";
601 break;
602 case Relation.REL_MEMBER_MERONYM:
603 result = "Member Meronym";
604 break;
605 case Relation.REL_PARTICIPLE_OF_VERB:
606 result = "Participle Of Verb";
607 break;
608 case Relation.REL_PART_HOLONYM:
609 result = "Holonym";
610 break;
611 case Relation.REL_PART_MERONYM:
612 result = "Meronym";
613 break;
614 case Relation.REL_PERTAINYM:
615 result = "Pertainym";
616 break;
617 case Relation.REL_SEE_ALSO:
618 result = "See Also";
619 break;
620 case Relation.REL_SIMILAR_TO:
621 result = "Similar To";
622 break;
623 case Relation.REL_SUBSTANCE_HOLONYM:
624 result = "Substance Holonym";
625 break;
626 case Relation.REL_SUBSTANCE_MERONYM:
627 result = "Substance Meronym";
628 break;
629 case Relation.REL_VERB_GROUP:
630 result = "Verb Group";
631 break;
632 }
633 return result;
634 }
635
636 public String getDescription(int rel){
637
638 String result = "";
639 switch (rel){
640 case Relation.REL_ANTONYM:
641 result = "Antonyms:";
642 break;
643 case Relation.REL_ATTRIBUTE:
644 result = "Attributes:";
645 break;
646 case Relation.REL_CAUSE:
647 result = "Cause:";
648 break;
649 case Relation.REL_DERIVED_FROM_ADJECTIVE:
650 result = "Derived From Adjective:";
651 break;
652 case Relation.REL_ENTAILMENT:
653 result = "Entailments:";
654 break;
655 case Relation.REL_HYPERNYM:
656 result = "Hypernyms:";
657 break;
658 case Relation.REL_HYPONYM:
659 result = "Hyponyms:";
660 break;
661 case Relation.REL_MEMBER_HOLONYM:
662 result = "Member Holonyms:";
663 break;
664 case Relation.REL_MEMBER_MERONYM:
665 result = "Member Meronyms:";
666 break;
667 case Relation.REL_PARTICIPLE_OF_VERB:
668 result = "Participle Of Verb:";
669 break;
670 case Relation.REL_PART_HOLONYM:
671 result = "Holonyms:";
672 break;
673 case Relation.REL_PART_MERONYM:
674 result = "Meronyms:";
675 break;
676 case Relation.REL_PERTAINYM:
677 result = "Pertainyms:";
678 break;
679 case Relation.REL_SEE_ALSO:
680 result = "See Also:";
681 break;
682 case Relation.REL_SIMILAR_TO:
683 result = "Similar To:";
684 break;
685 case Relation.REL_SUBSTANCE_HOLONYM:
686 result = "Substance Holonyms:";
687 break;
688 case Relation.REL_SUBSTANCE_MERONYM:
689 result = "Substance Meronyms:";
690 break;
691 case Relation.REL_VERB_GROUP:
692 result = "Verb Group:";
693 break;
694 }
695 return result;
696 }
697
698
699 /**
700 * Called by the GUI when this viewer/editor has to initialise itself for a
701 * specific object.
702 * @param target the object (be it a {@link gate.Resource},
703 * {@link gate.DataStore} or whatever) this viewer has to display
704 */
705 public void setTarget(Object target){
706
707 if (false == target instanceof WordNet) {
708 throw new IllegalArgumentException();
709 }
710
711 this.wnMain = (WordNet)target;
712 }
713
714 private class RelationItem extends JMenuItem{
715
716 int relType;
717 java.util.List senses;
718
719 public RelationItem(String name, int type, java.util.List sen) {
720 super(name);
721 this.addActionListener(WordNetViewer.this);
722 relType = type;
723 senses = sen;
724 setName(name);
725 }
726
727 public int getRelationType() {
728 return relType;
729 }
730
731 public java.util.List getSenses(){
732 return senses;
733 }
734
735 }
736
737 }
|