Changeset 1827
- Timestamp:
- 2001-01-11T10:04:04+13:00 (23 years ago)
- Location:
- trunk/gsdl/src/phind/client
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/phind/client/Phind.java
r1640 r1827 455 455 // 3 = get another N phrases into same window 456 456 // 4 = get another N documents into same window 457 // 5 = get another N thesaurus links into same window 457 458 458 459 ResultBox lookupPhraseOnServer(ResultBox source, … … 465 466 if (queryMode <= 2) { 466 467 r = new ResultBox(this, collection, key, phrase, source); 467 } else if ((queryMode == 3) || (queryMode == 4) ) {468 } else if ((queryMode == 3) || (queryMode == 4) || (queryMode == 5)) { 468 469 r = source; 469 470 } … … 512 513 int first_d = 0; 513 514 int last_d = 0; 515 int first_l = 0; 516 int last_l = 0; 514 517 515 518 // the initial query … … 517 520 last_e = phraseBlockSize; 518 521 last_d = phraseBlockSize; 519 } 520 522 last_l = phraseBlockSize; 523 } 524 521 525 // add phrases to an existing result set 522 526 else if (queryMode == 3) { … … 533 537 } 534 538 535 query = query + "&f=" + first_d + "&d=" + last_d 536 + "&g=" + first_e + "&e=" + last_e; 539 // add thesaurus links to existing result set 540 else if (queryMode == 5) { 541 first_l = area.nextThesaurusLinkBlock * phraseBlockSize; 542 area.nextThesaurusLinkBlock++; 543 last_l = area.nextThesaurusLinkBlock * phraseBlockSize; 544 } 545 546 query = query + "&e=" + first_e + "&f=" + last_e 547 + "&h=" + first_d + "&i=" + last_d 548 + "&k=" + first_l + "&l=" + last_l; 537 549 538 550 // Send the query to the phindcgi program … … 658 670 String tidy_URL(String address, boolean isCGI) { 659 671 660 System.out.println("tidy URL: " + address);672 // System.out.println("tidy URL: " + address); 661 673 662 674 // make sure the URL has protocol, host, and file … … 677 689 } 678 690 679 // if the URL is a cgi script, make sure it has a "?" 691 // if the URL is a cgi script, make sure it has a "?" in ti, 692 // and that it ends with a "?" or "&" 680 693 if (isCGI) { 681 694 if (address.indexOf((int) '?') == -1) { … … 686 699 } 687 700 688 689 System.out.println("tidy URL returning: " + address);690 701 return address; 691 702 } -
trunk/gsdl/src/phind/client/ResultBox.java
r1809 r1827 76 76 int numberOfExpansions; 77 77 int numberOfDocuments; 78 int numberOfThesaurusLinks; 78 79 79 80 // The number of phrases and documents retrieved, and the number of 80 81 // times the user has requested more phrases or documents. 82 int expansionsRetrieved; 81 83 int documentsRetrieved; 82 int expansionsRetrieved;84 int thesaurusLinksRetrieved; 83 85 int nextPhraseBlock; 84 86 int nextDocumentBlock; 87 int nextThesaurusLinkBlock; 85 88 86 // just why did i add these variables?87 89 int mode; 88 90 final int initMode = 0; … … 115 117 numberOfExpansions = -1; 116 118 numberOfDocuments = -1; 119 numberOfThesaurusLinks = -1; 117 120 118 121 expansionsRetrieved = 0; 119 122 documentsRetrieved = 0; 123 thesaurusLinksRetrieved = 0; 124 120 125 nextPhraseBlock = 1; 121 126 nextDocumentBlock = 1; 127 nextThesaurusLinkBlock = 1; 122 128 123 129 … … 140 146 141 147 static String describeContents(String phrase, String c) { 142 return( "\"" + phrase + "\" in " + c + ".");148 return( "\"" + phrase + "\" in " + c + "."); 143 149 } 144 150 … … 157 163 158 164 numberOfExpansions = -1; 165 numberOfDocuments = -1; 166 numberOfThesaurusLinks = -1; 167 159 168 expansionsRetrieved = 0; 160 numberOfDocuments = -1;161 169 documentsRetrieved = 0; 170 thesaurusLinksRetrieved = 0; 162 171 } 163 172 … … 230 239 231 240 if (finished) { 232 c.updateMorePhrasesMarker(); 233 c.updateMoreDocumentsMarker(); 241 c.updateMarkers(); 234 242 } else { 235 243 // We haven't finished, give some feedback about progress … … 273 281 } 274 282 283 // The <thesaurus> tag 284 else if (buffer.startsWith("<thesaurus ")) { 285 item = buffer.substring(0, eol); 286 buffer = buffer.substring(eol + 1); 287 addThesaurusTag(item); 288 return true; 289 } 290 275 291 // The <phinddata> tag introduces the dataset 276 292 else if (buffer.startsWith("<phinddata ")) { … … 287 303 } 288 304 289 // The <expansionlist> tag290 else if (buffer.startsWith("<expansionlist ")) {291 292 }293 294 // The <documentlist> tag295 else if (buffer.startsWith("<documentlist ")) {296 297 }298 299 305 // The <phinderror> tag contains an error message 300 306 else if (buffer.startsWith("<phinderror")) { … … 307 313 // Ignore the piece we've read 308 314 item = buffer.substring(0, eol); 315 // System.out.println("discarding: " + item); 309 316 buffer = buffer.substring(eol + 1); 310 317 return true; … … 325 332 // System.out.println( "addExpansionListTag: " + line); 326 333 327 String idStr = "", text = "", tfStr = "", efStr = "", dfStr = "" ;328 int tf = 0, ef = 0, df = 0 ;334 String idStr = "", text = "", tfStr = "", efStr = "", dfStr = "", lfStr = ""; 335 int tf = 0, ef = 0, df = 0, lf = 0; 329 336 330 337 // Break the tag down into its component parts … … 390 397 dfStr = line.substring(0, nextSplit); 391 398 df = Integer.valueOf(dfStr).intValue(); 399 line = line.substring(nextSplit + 1); 400 } else { 401 System.err.println("addExpansionListTag: error parsing: " + line); 402 } 403 } 404 405 // Read the thesaurus link frequency 406 else if (line.startsWith("lf")) { 407 line = line.substring(4); 408 nextSplit = line.indexOf((int) '"'); 409 if (nextSplit >= 1) { 410 lfStr = line.substring(0, nextSplit); 411 lf = Integer.valueOf(lfStr).intValue(); 392 412 line = line.substring(nextSplit + 1); 393 413 } else { … … 413 433 numberOfExpansions = ef; 414 434 numberOfDocuments = df; 435 numberOfThesaurusLinks = lf; 415 436 return true; 416 437 } … … 422 443 // <expansion num="3" id="8421" prefix="PEOPLE and" suffix="" tf="3" df="3"/> 423 444 // <expansion num="4" id="8696" prefix="" suffix="products" tf="3" df="3"/> 424 // Create a new ResultItem for display445 // Create a new ResultItemPhrase for display 425 446 // 426 447 // Return true if successful, otherwise false. … … 525 546 526 547 // Create a new ResultItem and add it to the display 527 ResultItem ri = new ResultItem(idStr, tfStr, dfStr, prefix, body, suffix);548 ResultItemPhrase ri = new ResultItemPhrase(idStr, tfStr, dfStr, prefix, body, suffix); 528 549 529 550 if (c.addResultItem(ri)) { … … 542 563 // <document num="3" hash="HASH01f08efd8752ad54ca0a99cf" freq="1" title="Tree mixtures"/> 543 564 // 544 // Create a new ResultItem for display565 // Create a new ResultItemDocument for display 545 566 // 546 567 // Return true if successful, otherwise false. … … 549 570 550 571 // System.out.println( "addDocumentTag: " + line + " (" + documentsRetrieved + ")"); 551 572 552 573 String num = "", hash = "", freq = "", title = ""; 553 574 line = line.substring(9); 554 575 555 576 // Break the tag down into its component parts 556 577 int nextSplit; … … 566 587 line = line.substring(nextSplit + 1); 567 588 } else { 568 System.err.println("ResultBox add ExpansionTag: error parsing: " + line);589 System.err.println("ResultBox addDocumentTag: error parsing: " + line); 569 590 } 570 591 } … … 578 599 line = line.substring(nextSplit + 1); 579 600 } else { 580 System.err.println("ResultBox add ExpansionTag: error parsing: " + line);601 System.err.println("ResultBox addDocumentTag: error parsing: " + line); 581 602 } 582 603 } … … 590 611 line = line.substring(nextSplit + 1); 591 612 } else { 592 System.err.println("ResultBox add ExpansionTag: error parsing: " + line);613 System.err.println("ResultBox addDocumentTag: error parsing: " + line); 593 614 } 594 615 } … … 602 623 line = line.substring(nextSplit + 1); 603 624 } else { 604 System.err.println("ResultBox add ExpansionTag: error parsing: " + line);625 System.err.println("ResultBox addDocumentTag: error parsing: " + line); 605 626 } 606 627 } … … 618 639 619 640 // Create a new ResultItem and add it to the display 620 ResultItem ri = new ResultItem(hash, title, freq);621 641 ResultItemDocument ri = new ResultItemDocument(hash, title, freq); 642 622 643 if (c.addResultItem(ri)) { 623 644 documentsRetrieved++; … … 627 648 return false; 628 649 } 650 651 652 // Add a thesaurus tag 653 // 654 // Given a string containing an XML document tag of the form: 655 // 656 // <thesaurus num="3" id="36506" tf="0" df="0" type="RT" text="ANGLOPHONE AFRICA"/> 657 // <thesaurus num="4" id="28724" tf="0" df="0" type="RT" text="FRANCOPHONE AFRICA"/> 658 // 659 // Create a new ResultItemLink for display 660 // 661 // Return true if successful, otherwise false. 662 663 boolean addThesaurusTag( String line ) { 664 665 // System.out.println( "addThesaurusTag: " + line + " (" + thesaurusLinksRetrieved + ")"); 666 667 String num = "", id = "", tf = "", df = "", type = "", text = ""; 668 line = line.substring(10); 669 670 // Break the tag down into its component parts 671 int nextSplit; 672 while (line.length() > 0) { 673 line = line.trim(); 674 675 // Read the expansion number 676 if (line.startsWith("num")) { 677 line = line.substring(5); 678 nextSplit = line.indexOf((int) '"'); 679 if (nextSplit >= 1) { 680 num = line.substring(0, nextSplit); 681 line = line.substring(nextSplit + 1); 682 } else { 683 System.err.println("ResultBox addThesaurusTag: error parsing: " + line); 684 } 685 } 686 687 // Read the phrase ID 688 else if (line.startsWith("id")) { 689 line = line.substring(4); 690 nextSplit = line.indexOf((int) '"'); 691 if (nextSplit >= 1) { 692 id = line.substring(0, nextSplit); 693 line = line.substring(nextSplit + 1); 694 } else { 695 System.err.println("ResultBox addThesaurusTag: error parsing: " + line); 696 } 697 } 698 699 // Read the phrase link type 700 else if (line.startsWith("type")) { 701 line = line.substring(6); 702 nextSplit = line.indexOf((int) '"'); 703 if (nextSplit >= 1) { 704 type = line.substring(0, nextSplit); 705 line = line.substring(nextSplit + 1); 706 } else { 707 System.err.println("ResultBox addThesaurusTag: error parsing: " + line); 708 } 709 } 710 711 712 // Read the phrase text 713 else if (line.startsWith("text")) { 714 line = line.substring(6); 715 nextSplit = line.indexOf((int) '"'); 716 if (nextSplit >= 1) { 717 text = line.substring(0, nextSplit); 718 line = line.substring(nextSplit + 1); 719 } else { 720 System.err.println("ResultBox addThesaurusTag: error parsing: " + line); 721 } 722 } 723 724 // Read the frequency 725 else if (line.startsWith("tf")) { 726 line = line.substring(4); 727 nextSplit = line.indexOf((int) '"'); 728 if (nextSplit >= 1) { 729 tf = line.substring(0, nextSplit); 730 line = line.substring(nextSplit + 1); 731 } else { 732 System.err.println("ResultBox addExpansionTag: error parsing: " + line); 733 } 734 } 735 736 // Read the document frequency 737 else if (line.startsWith("df")) { 738 line = line.substring(4); 739 nextSplit = line.indexOf((int) '"'); 740 if (nextSplit >= 1) { 741 df = line.substring(0, nextSplit); 742 line = line.substring(nextSplit + 1); 743 } else { 744 System.err.println("ResultBox addExpansionTag: error parsing: " + line); 745 } 746 } 747 748 749 // Read some other tag or close the string off 750 else { 751 nextSplit = line.indexOf((int) ' '); 752 if (nextSplit >= 1) { 753 line = line.substring(nextSplit + 1); 754 } else { 755 line = ""; 756 } 757 } 758 } 759 760 // Create a new ResultItem and add it to the display 761 ResultItemLink ri = new ResultItemLink(id, text, type, tf, df); 762 763 if (c.addResultItem(ri)) { 764 thesaurusLinksRetrieved++; 765 return true; 766 } 767 768 return false; 769 } 629 770 } 630 771 -
trunk/gsdl/src/phind/client/ResultCanvas.java
r1682 r1827 31 31 32 32 The results of a query are displayed on a ResultCanvas object. Each 33 line of the result is stored in a ResultItem, and the ResultCanvas33 entry in the result list is stored in a ResultItem, and the ResultCanvas 34 34 contains a Vector of ResultItems. 35 35 … … 108 108 109 109 110 // add a new item of input.111 // return true if successful, otherwise false.110 // Add a new search result. 111 // Return true if successful, otherwise false. 112 112 boolean addResultItem( ResultItem item ) { 113 113 … … 120 120 ((item.kind > ((ResultItem) phrases.elementAt(index)).kind) || 121 121 ((item.kind == ((ResultItem) phrases.elementAt(index)).kind) && 122 (item.freq <= ((ResultItem) phrases.elementAt(index)).freq)))) {122 (item.frequency <= ((ResultItem) phrases.elementAt(index)).frequency)))) { 123 123 index++; 124 124 } … … 128 128 } 129 129 130 131 // Update more phrases/documents/links markers 132 void updateMarkers() { 133 updateMorePhrasesMarker(); 134 updateMoreDocumentsMarker(); 135 updateMoreLinksMarker(); 136 } 130 137 131 138 // Make sure the more Phrases item only appears in the list … … 140 147 while (!found && (index < numberOfPhrases)) { 141 148 if (((ResultItem) phrases.elementAt(index)).isMorePhrases()) { 142 // System.out.println("found marker at: " + index + " of " + numberOfPhrases);143 149 found = true; 144 150 } else { … … 149 155 if (parent.expansionsRetrieved == parent.numberOfExpansions) { 150 156 // there should be no marker 151 // System.out.println("No marker needed");152 157 if (found) { 153 // System.out.println("Remove marker");154 158 phrases.removeElementAt(index); 155 159 numberOfPhrases--; … … 157 161 158 162 } else if (parent.expansionsRetrieved < parent.numberOfExpansions) { 159 // there should be a marker160 // System.out.println("Needs marker");161 162 163 if (!found) { 163 // System.out.println("Add marker"); 164 ResultItem ri = new ResultItem(ResultItem.morePhrases, parent.searchKey); 164 ResultItem ri = new ResultItem(ResultItem.morePhrases); 165 165 addResultItem(ri); 166 166 } … … 195 195 // there should be a marker 196 196 if (!found) { 197 ResultItem ri = new ResultItem(ResultItem.moreDocuments, parent.searchKey); 197 ResultItem ri = new ResultItem(ResultItem.moreDocuments); 198 addResultItem(ri); 199 } 200 } 201 } 202 203 204 // Make sure the more links marker appears when required 205 void updateMoreLinksMarker() { 206 207 System.out.println("updateMoreLinksMarker() "); 208 System.out.println("retreived: " + parent.thesaurusLinksRetrieved); 209 System.out.println("total: " + parent.numberOfThesaurusLinks); 210 211 // look for a marker 212 boolean found = false; 213 int index = 0; 214 while (!found && (index < numberOfPhrases)) { 215 if (((ResultItem) phrases.elementAt(index)).isMoreLinks()) { 216 found = true; 217 } else { 218 index++; 219 } 220 } 221 222 if (parent.thesaurusLinksRetrieved == parent.numberOfThesaurusLinks) { 223 // there should be no marker 224 if (found) { 225 phrases.removeElementAt(index); 226 numberOfPhrases--; 227 } 228 229 } else if (parent.thesaurusLinksRetrieved < parent.numberOfThesaurusLinks) { 230 // there should be a marker 231 if (!found) { 232 ResultItem ri = new ResultItem(ResultItem.moreLinks); 198 233 addResultItem(ri); 199 234 } … … 270 305 + ((rightMargin - leftMargin 271 306 - g.getFontMetrics().stringWidth(parent.searchPhrase)) / 2); 307 308 String body, prefix, suffix; 272 309 273 310 for (i = scrollValue; … … 290 327 // Draw the item 291 328 329 // Draw a phrase item 292 330 if (result.isPhrase()) { 293 // The item is a Phrase 294 tab = center - g.getFontMetrics().stringWidth(result.prefix) - space; 295 g.drawString(result.prefix, tab, y); 331 prefix = result.prefixText(); 332 body = result.mainText(); 333 suffix = result.suffixText(); 334 335 g.setColor(Color.black); 336 g.setFont(areaPlain); 337 tab = center - g.getFontMetrics().stringWidth(prefix) - space; 338 g.drawString(prefix, tab, y); 339 296 340 g.setFont(areaBold); 297 g.drawString(result.body, center, y); 298 tab = center + space + g.getFontMetrics().stringWidth(result.body); 341 g.drawString(body, center, y); 342 tab = center + space + g.getFontMetrics().stringWidth(body); 343 299 344 g.setFont(areaPlain); 300 g.drawString( result.suffix, tab, y);345 g.drawString(suffix, tab, y); 301 346 302 } else if (result.isDocument()){ 303 // The item is a URL 347 } 348 349 // Draw a document item 350 else if (result.isDocument()){ 351 body = result.mainText(); 352 304 353 g.setFont(areaPlain); 305 354 g.setColor(Color.blue); 306 tab = (rightMargin - g.getFontMetrics().stringWidth(result.body)) / 2; 307 g.drawString(result.body, tab, y); 355 tab = (rightMargin - g.getFontMetrics().stringWidth(body)) / 2; 356 g.drawString(body, tab, y); 357 358 } 359 360 // Draw a thesaurus link item 361 else if (result.isLink()){ 362 prefix = result.prefixText() + ":"; 363 body = result.mainText(); 364 365 g.setFont(areaPlain); 366 g.setColor(new Color(0, 100, 0)); 367 tab = center - g.getFontMetrics().stringWidth(prefix) - space; 368 // tab = margin + margin - g.getFontMetrics().stringWidth(prefix); 369 g.drawString(prefix, tab, y); 370 371 g.setFont(areaBold); 372 g.drawString(body, center, y); 373 374 } 375 376 // Draw a "more phrases/documents/links" marker 377 else if (result.isMorePhrases() 378 || result.isMoreDocuments() 379 || result.isMoreLinks()){ 380 body = result.mainText(); 381 382 if (result.isMorePhrases()) { 383 g.setColor(new Color(255, 200, 200)); 384 } else { 385 g.setColor(new Color(150, 193, 156)); 386 } 387 g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing); 388 308 389 g.setColor(Color.black); 309 310 } else if (result.isMorePhrases()){311 // The item is a More documents marker312 g.setColor(new Color(255, 200, 200));313 g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing);314 g.setColor(Color.black);315 316 390 g.setFont(areaPlain); 317 tab = (rightMargin - g.getFontMetrics().stringWidth("Get more phrases")) / 2; 318 g.drawString("Get more phrases", tab, y); 319 320 } else if (result.isMoreDocuments()){ 321 // The item is a More documents marker 322 g.setColor(new Color(150, 193, 156)); 323 g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing); 324 g.setColor(Color.black); 325 326 g.setFont(areaPlain); 327 tab = (rightMargin - g.getFontMetrics().stringWidth("Get more documents")) / 2; 328 g.drawString("Get more documents", tab, y); 329 330 } 331 391 tab = (rightMargin - g.getFontMetrics().stringWidth(body)) / 2; 392 g.drawString(body, tab, y); 393 } 332 394 } 333 395 … … 355 417 356 418 // Write the document frequency 357 if ( (result.documents > 1) || result.isPhrase()) {358 g.drawString(" " + Integer.toString(result.documents), firstColumn, y);419 if (result.docsText().length() > 0) { 420 g.drawString(" " + result.docsText(), firstColumn, y); 359 421 } 360 422 361 423 // Write the term frequency 362 if (result.freq > 0) {363 g.drawString(" " + Integer.toString(result.freq), secondColumn, y);424 if (result.freqText().length() > 0) { 425 g.drawString(" " + result.freqText(), secondColumn, y); 364 426 } 365 427 } … … 407 469 ResultItem item = (ResultItem) phrases.elementAt(itemSelected); 408 470 409 // System.out.println("Select: " + String.valueOf(rowSelected) );410 471 if (itemSelected <= numberOfPhrases) { 411 472 412 // What do we do with the event? 413 // If user clicks on a phrase, we expand the phrase 414 // or send the phrase to a search engine (right click) 415 473 //User clicks on a phrase 416 474 if (item.isPhrase()) { 417 // Expand the phrase418 475 419 476 phraseSelected = itemSelected; 420 477 update(getGraphics()); 421 478 422 parent.lookupPhrase(item.rule, item.toString(), 2); 423 479 parent.lookupPhrase(item.hiddenText(), item.toString(), 2); 480 481 // If meta key is held down, send query to search engine 424 482 if (event.metaDown()) { 425 // Also send to search engine426 483 if (phind.search_url.equals("none") || phind.search_url.equals("")) { 427 484 System.out.println("No searching in this collection"); … … 435 492 System.out.println("URL error: " + e.toString()); 436 493 } 437 } 494 } 438 495 } 439 496 440 } else if (item.isDocument()) { 441 // The user clicks on a URL; display it. 497 } 498 499 // Click on a thesaurus link 500 else if (item.isLink()) { 501 phraseSelected = itemSelected; 502 update(getGraphics()); 503 parent.lookupPhrase(item.hiddenText(), item.toString(), 2); 504 } 505 506 // The user clicks on a URL; display it. 507 else if (item.isDocument()) { 442 508 phraseSelected = itemSelected; 443 509 update(getGraphics()); … … 447 513 String address = phind.library_address 448 514 + "a=d&c=" + phind.collection 449 + "&d=" + item. rule515 + "&d=" + item.hiddenText() 450 516 + "&q=" + parent.searchPhrase.replace(' ', '+'); 451 517 url = new URL(address); 452 518 System.out.println("URL selected: " + url.toString()); 453 phind.getAppletContext().showDocument(url );519 phind.getAppletContext().showDocument(url, "phinddoc"); 454 520 } catch (Exception e) { 455 521 System.out.println("URL error: " + e.toString()); 456 522 } 457 458 } else if (item.isMorePhrases()){ 459 // The user clicks on a "get more phrases" marker. 460 // We have to send a new query to the host 523 } 524 525 // When the user clicks on "get more phrases" or other marker, 526 // we have to send a new query to the host 527 else if (item.isMorePhrases()){ 461 528 parent.lookupPhrase(parent.searchKey, parent.searchPhrase, 3); 462 463 529 } else if (item.isMoreDocuments()){ 464 530 parent.lookupPhrase(parent.searchKey, parent.searchPhrase, 4); 531 } else if (item.isMoreLinks()){ 532 parent.lookupPhrase(parent.searchKey, parent.searchPhrase, 5); 465 533 466 534 -
trunk/gsdl/src/phind/client/ResultItem.java
r1626 r1827 1 1 /********************************************************************** 2 2 * 3 * Result Box.java -- a list of phrases in the Phind java interface3 * ResultItemDocument.java -- a result in the Phind applet 4 4 * 5 * Copyright 1997-2000 Gordon W. Paynter5 * Copyright 2000 Gordon W. Paynter 6 6 * Copyright 2000 The New Zealand Digital Library Project 7 7 * … … 30 30 This class is used in the Phind java applet (Phind.java). 31 31 32 A result item object holds the data describing a single line returned from 33 a query to the server. It therefore contains either information describing 34 a phrase or a URL. 32 A result item holds the data describing a single line returned from a phind 33 query. The complex functionality of phrase and URL items is implemented in 34 subclasses; the base class handles simpler cases like the "get more phrases" 35 marker. 35 36 36 37 **********************************************************************/ … … 39 40 public class ResultItem { 40 41 41 // There are four kinds of item42 // 1. a phrase 43 // 2. a document (or URL)44 // 3. a "get more phrases" marker42 // There are several kinds of ResultItem 43 // 1. a phrase (expansion) 44 // 2. a "get more phrases" marker 45 // 3. a document (or URL) 45 46 // 4. a "get more documents" marker 46 // These should possibly be written as subclasses of a ResultItem47 // superclass, but I cannot be bothered rewriting it for now.47 // 5. a thesaurus link 48 // 6. a "get more thesaurus links" marker 48 49 49 final static int phraseItem = 1; 50 final static int morePhrases = 2; 51 final static int documentItem = 3; 52 final static int moreDocuments = 4; 50 final static int linkItem = 1; 51 final static int moreLinks = 2; 52 final static int phraseItem = 3; 53 final static int morePhrases = 4; 54 final static int documentItem = 5; 55 final static int moreDocuments = 6; 56 final static int unknownResultItem = 9; 53 57 54 // What kind is this item:55 int kind;58 // A text string describing the item 59 String text = "Generic ResultItem"; 56 60 57 // The "rule" is the unique identifier of this item. For a phrase, 58 // this is its "phrase number", and is also stored as a number in 59 // symbol. For a document it is the document's OID (hash) value. 60 String rule; 61 int symbol; 61 // The kind of the item 62 int kind = unknownResultItem; 62 63 63 // The term frequency of the item 64 int freq; 65 66 // The document frequency of the item 67 int documents; 68 69 // Can this item be expanded? ---- obsolete? 70 int expansion; 71 72 // When the item is a phrase, the text of the item is split into a 73 // prefix, body, and suffix. The body is the search term and the 74 // prefix and suffix the surrounding text in the new phrase. 75 // When the item is a document, its title is stored in the body. 76 String prefix; 77 String body; 78 String suffix; 64 // The frequency of the item 65 int frequency = 0; 79 66 80 67 81 // Create a ResultItem for a phrase 82 ResultItem(String r, String f, String d, 83 String p, String b, String s) { 84 85 kind = phraseItem; 86 rule = r; 87 symbol = Integer.valueOf(rule).intValue(); 88 89 freq = Integer.valueOf(f).intValue(); 90 documents = Integer.valueOf(d).intValue(); 91 expansion = 0; 92 93 prefix = p; 94 body = b; 95 suffix = s; 96 68 // Create a blank ResultItem 69 ResultItem() { 70 text = "Unknown result type"; 71 kind = unknownResultItem; 72 frequency = 0; 97 73 } 98 74 75 // Create a new ResultItem of some given kind 76 ResultItem(int newKind) { 77 kind = newKind; 78 frequency = 0; 99 79 100 // Create a ResultItem for a document 101 ResultItem(String hash, String title, String df) { 102 103 kind = documentItem; 104 rule = hash; 105 body = title; 106 documents = Integer.valueOf(df).intValue(); 107 108 // not needed for a document 109 symbol = 0; 110 freq = 0; 111 expansion = 0; 112 prefix = ""; 113 suffix = ""; 80 if (kind == moreLinks) { 81 text = "get more thesaurus links"; 82 } else if (kind == morePhrases) { 83 text = "get more phrases"; 84 } else if (kind == moreDocuments) { 85 text = "get more documents"; 86 } else { 87 text = "Unknown result type"; 88 } 114 89 } 115 90 91 // Test the type of a ResultItem 92 public boolean isLink() { return false; } 93 public boolean isMoreLinks() { return (kind == moreLinks); } 94 public boolean isPhrase() { return false; } 95 public boolean isMorePhrases() { return (kind == morePhrases); } 96 public boolean isDocument() { return false; } 97 public boolean isMoreDocuments() { return (kind == moreDocuments); } 116 98 117 // Create an empty ResultItem of a given kind118 ResultItem(int k, String r) {99 // Return the bare text of the item 100 public String toString() { return(text); } 119 101 120 kind = k; 121 122 rule = r; 123 symbol = -1; 124 125 freq = 0; 126 expansion = 0; 127 documents = 0; 128 129 prefix = ""; 130 body = ""; 131 suffix = ""; 132 } 133 134 // Return the full phrase described by the item. 135 public String toString() { 136 String result = ""; 137 if (!prefix.equals("")) result = prefix.replace(' ', '+') + "+"; 138 result += body.replace(' ', '+'); 139 if (!suffix.equals("")) result += "+" + suffix.replace(' ', '+'); 140 return(result.trim()); 141 } 142 143 // Is the item a phrase? 144 public boolean isPhrase() { 145 return (kind == phraseItem); 146 } 147 148 // Is the item a document? 149 public boolean isDocument() { 150 return (kind == documentItem); 151 } 152 153 public boolean isMorePhrases() { 154 return (kind == morePhrases); 155 } 156 157 public boolean isMoreDocuments() { 158 return (kind == moreDocuments); 159 } 160 161 102 // Return the text of the item components 103 public String mainText() { return text; } 104 public String freqText() { return Integer.toString(frequency); } 105 public String docsText() { return ""; } 106 public String prefixText() { return ""; } 107 public String suffixText() { return ""; } 108 public String hiddenText() { return ""; } 162 109 } 163 110 164 -
trunk/gsdl/src/phind/client/ResultTitle.java
r1681 r1827 103 103 104 104 // Construct the description phrase 105 String links = ""; 106 if (parent.numberOfThesaurusLinks <= 0) { 107 links = ""; 108 } else if (parent.numberOfThesaurusLinks == 1) { 109 links = "1 link"; 110 } else if (parent.thesaurusLinksRetrieved == parent.numberOfThesaurusLinks) { 111 links = parent.numberOfThesaurusLinks + " links"; 112 } else { 113 links = parent.thesaurusLinksRetrieved + " of " 114 + parent.numberOfThesaurusLinks + " links"; 115 } 116 105 117 String expansions = ""; 106 118 if (parent.numberOfExpansions <= 0) { 107 119 expansions = "no phrases"; 108 120 } else if (parent.numberOfExpansions == 1) { 109 121 expansions = "1 phrase"; 110 122 } else if (parent.expansionsRetrieved == parent.numberOfExpansions) { 111 123 expansions = parent.numberOfExpansions + " phrases"; 112 124 } else { 113 expansions = "first " + parent.expansionsRetrieved + " of " + parent.numberOfExpansions + " phrases"; 125 expansions = parent.expansionsRetrieved + " of " 126 + parent.numberOfExpansions + " phrases"; 114 127 } 115 128 116 129 String documents = ""; 117 130 if (parent.numberOfDocuments <= 0) { 118 131 documents = "no documents"; 119 132 } else if (parent.documentsRetrieved == 1) { 120 133 documents = "1 document"; 121 134 } else if (parent.documentsRetrieved == parent.numberOfDocuments) { 122 135 documents = parent.numberOfDocuments + " documents"; 123 136 } else { 124 documents = "first " + parent.documentsRetrieved + " of " + parent.numberOfDocuments + " documents"; 137 documents = parent.documentsRetrieved + " of " 138 + parent.numberOfDocuments + " documents"; 125 139 } 140 141 String status = "("; 142 if (parent.numberOfThesaurusLinks > 0) { 143 status = status + links + ", "; 144 } 145 status = status + links + expansions + ", " + documents + ")"; 146 126 147 127 148 // Draw the text … … 131 152 132 153 g.setFont(plain); 133 String status = "(" + expansions + ", " + documents + ")";134 154 g.drawString(status, tab, y); 135 155 tab = tab + g.getFontMetrics().stringWidth(status);
Note:
See TracChangeset
for help on using the changeset viewer.