Changeset 23906 for gs3-extensions
- Timestamp:
- 2011-04-15T13:38:25+12:00 (13 years ago)
- Location:
- gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas
- Files:
-
- 1 added
- 22 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/GS3MapLibrary.gwt.xml
r23903 r23906 6 6 <inherits name='com.google.gwt.user.theme.standard.Standard'/> 7 7 <inherits name="com.google.gwt.http.HTTP"/> 8 <script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAAtgBCR-EMOIox9GYORrWZ4xT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTdn97J3Y4bgIWO98Jw2xGa7SsjVQ"/> 8 <inherits name="com.google.gwt.xml.XML" /> 9 <!--<script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAAtgBCR-EMOIox9GYORrWZ4xT20kFGbybagIuCnxcJa_GNd7_aLBSMK71WBmKu2gYDZKoonO56bPhAKQ"/>--> 10 <!--<script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAAtgBCR-EMOIox9GYORrWZ4xT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTdn97J3Y4bgIWO98Jw2xGa7SsjVQ"/>--> 11 <!--<script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAAtgBCR-EMOIox9GYORrWZ4xRDDXBaPmHH9_0fCH2SRcUU9bjcjhT3cD_2Hv84s1XjkWPxzMb0RT2hQQ"/>--> 9 12 <entry-point class='org.greenstone.client.GS3MapLibrary'/> 10 13 </module> -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/FindPlaceService.java
r22272 r23906 2 2 3 3 import java.util.ArrayList; 4 import com.google.gwt.dom.client.Element;5 4 import com.google.gwt.user.client.rpc.RemoteService; 6 5 import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; … … 11 10 Boolean isGazetteerLoaded(); 12 11 Boolean findPlacesInText(String text, String html); 13 ArrayList<ArrayList<Place>> findPlacesInMultipleTexts( ArrayList<String>texts);12 ArrayList<ArrayList<Place>> findPlacesInMultipleTexts(String[] texts); 14 13 Boolean loadGazetteer(); 15 14 ArrayList<Place> getPlaces(double maxScore, double minScore, long minPopulation, boolean locality, boolean region, boolean country, int numberOfPlacesToGet); -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/FindPlaceServiceAsync.java
r22272 r23906 3 3 import java.util.ArrayList; 4 4 5 import com.google.gwt.dom.client.Element;6 import com.google.gwt.maps.client.geom.LatLng;7 5 import com.google.gwt.user.client.rpc.AsyncCallback; 8 6 … … 15 13 void getPlaces(double maxScore, double minScore, long minPopulation, boolean locality, boolean region, boolean country, int numberOfPlacesToGet, AsyncCallback<ArrayList<Place>> callback); 16 14 void adjustScoringParams(double penalty, double parentBonus, double indirectReferencePercent, AsyncCallback<Boolean> callback); 17 void findPlacesInMultipleTexts( ArrayList<String>texts, AsyncCallback<ArrayList<ArrayList<Place>>> callback);15 void findPlacesInMultipleTexts(String[] texts, AsyncCallback<ArrayList<ArrayList<Place>>> callback); 18 16 void updateGazetteer(int start, int end, AsyncCallback<ArrayList<Place>> callback); 19 17 void addToDatabase(Place p, float lat, float lng, AsyncCallback<Boolean> callback); -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/GS3MapLibrary.java
r22278 r23906 52 52 import com.google.gwt.user.client.ui.FlowPanel; 53 53 import com.google.gwt.user.client.ui.FormPanel; 54 import com.google.gwt.user.client.ui.Frame;55 54 import com.google.gwt.user.client.ui.HTML; 56 55 import com.google.gwt.user.client.ui.Hidden; … … 61 60 import com.google.gwt.user.client.ui.VerticalPanel; 62 61 import com.google.gwt.user.client.ui.Widget; 62 import com.google.gwt.xml.client.NamedNodeMap; 63 import com.google.gwt.dom.client.Document; 63 64 import com.google.gwt.dom.client.FormElement; 64 65 import com.google.gwt.dom.client.InputElement; 65 66 import com.google.gwt.dom.client.NativeEvent; 67 import com.google.gwt.dom.client.Node; 66 68 import com.google.gwt.dom.client.NodeCollection; 67 69 import com.google.gwt.dom.client.NodeList; … … 82 84 protected HorizontalPanel _viewPanel = new HorizontalPanel(); 83 85 84 protected Frame _gsTempFrame = new Frame(); 85 86 protected StatusBar _statusBar = new StatusBar(); 86 protected StatusBar _statusBar = null; 87 87 88 88 protected HTML _gsPanel = new HTML(); … … 120 120 protected ArrayList<String> _highlightedPlaces = new ArrayList<String>(); 121 121 protected ArrayList<String> _highlightedTextPlaces = new ArrayList<String>(); 122 protected ArrayList<com.google.gwt.dom.client.Element> _mainLinks = new ArrayList<com.google.gwt.dom.client.Element>();123 protected ArrayList<com.google.gwt.dom.client.Element> _mainScripts = new ArrayList<com.google.gwt.dom.client.Element>();124 122 protected ArrayList<Boolean> _visiblePlaceSets = new ArrayList<Boolean>(); 125 123 protected ArrayList<LatLng> _areaPoints = new ArrayList<LatLng>(); 126 124 protected ArrayList<String> _removedPlaces = new ArrayList<String>(); 125 127 126 protected ArrayList<ArrayList<Place>> _currentMultiPlaces = null; 128 protected ArrayList<String> _removedPlaces = new ArrayList<String>();129 127 130 128 protected HashMap<String, Place> _chosenPlaces = new HashMap<String, Place>(); … … 160 158 protected String _currentCollection = ""; 161 159 protected String _currentURL = ""; 162 protected final String _GREENSTONEURL = "http://localhost:8080/greenstone3"; 160 protected final String _GREENSTONEURL = "http://taniwha.resnet.scms.waikato.ac.nz:8080/greenstone3"; 161 //protected final String _GREENSTONEURL = "http://www.nzdl.org/atlasgreenstone3"; 163 162 protected final String _GREENSTONEDEVURL = _GREENSTONEURL + "/dev"; 164 163 164 protected com.google.gwt.xml.client.Document _currentNewPageDoc; 165 165 166 /** 166 167 * GWT module entry point … … 168 169 public void onModuleLoad() 169 170 { 171 _statusBar = new StatusBar(this); 172 //Make the Firebug console so that browsers that don't have it don't break 173 setUpConsole(); 174 170 175 //Get a Google geocoder to help find places that the Gazetteer does not know the coordinates for 171 176 _geocoder = new Geocoder(); 172 177 173 ((ServiceDefTarget) _findPlaceService).setServiceEntryPoint("http://localhost:8080/GS3MapLibrary/gs3maplibrary/findPlace"); 174 178 ((ServiceDefTarget) _findPlaceService).setServiceEntryPoint("http://taniwha.resnet.scms.waikato.ac.nz:8080/ATLAS/findPlace"); 179 //((ServiceDefTarget) _findPlaceService).setServiceEntryPoint("http://www.nzdl.org/ATLAS/findPlace"); 180 175 181 //Setup native Javascript functions 176 182 setUpLoadPageFromUrl(this); 177 183 setUpLoadPageFromForm(this); 178 184 setUpLoadSpatialSearchPage(this); 179 185 180 186 //Setup the map 181 187 setUpMap(); 182 188 183 //Make the Firebug console so that browsers that don't have it don't break184 setUpConsole();185 186 //Set up the invisible frame that temporarily stores pages as they load187 setUpTempFrame();188 189 189 //Set up the list box that stores the text view options 190 190 setUpTextViewSelector(); 191 191 192 192 //Load the Greenstone home page 193 loadPageFromUrl(_GREENSTONEDEVURL); 194 } 195 196 /** 197 * Sets up the invisible frame that temporarily stores pages as they load 198 */ 199 public void setUpTempFrame() 200 { 201 //Get the frame for the web page 202 _gsTempFrame.getElement().setId("tempFrame"); 203 204 //Make the frame have no size 205 _gsTempFrame.setSize("0px", "0px"); 206 207 //Make the frame have no border 208 _gsTempFrame.getElement().getStyle().setProperty("border", "0px"); 209 210 //Add the frame to the main frame 211 RootPanel.get("mainFrame").add(_gsTempFrame); 193 loadPageFromUrl("http://taniwha.resnet.scms.waikato.ac.nz:8080/greenstone3/dev?a=p&sa=home"); 212 194 } 213 195 … … 226 208 * @param url is the url to load 227 209 */ 228 public void loadPageFromUrl( finalString url)210 public void loadPageFromUrl(String url) 229 211 { 230 212 //Make sure a url was given … … 261 243 if (url.contains("&c=")) 262 244 { 263 //logToConsole("url contains collection");264 245 //Store the collection name 265 246 _currentCollection = getCollectionFromURL(url); … … 268 249 //Add the "Page loading" update to the status bar" 269 250 _statusBar.addUpdate("Loading new page", "LoadPage"); 270 271 //Start loading the given url 272 _gsTempFrame.setUrl(url); 273 274 //Create and start the timer that checks if the page is loaded 275 Timer _checkLoadedTimer = getLoadedTimer(); 276 _checkLoadedTimer.scheduleRepeating(500); 251 252 getNewPage(url); 277 253 } 278 254 … … 293 269 //Add the "Page loading" update to the status bar" 294 270 _statusBar.addUpdate("Loading new page", "LoadPage"); 295 296 //Create and start the timer that checks if the page is loaded 297 Timer _checkLoadedTimer = getLoadedTimer(); 298 _checkLoadedTimer.scheduleRepeating(500); 271 } 272 273 public void getNewPage(String url) 274 { 275 RequestBuilder newPageRequest = new RequestBuilder(RequestBuilder.GET, url.contains("?") ? (url + "&excerpttag=body") : (url + "?excerpttag=body")); 276 try{ 277 newPageRequest.sendRequest(null, new RequestCallback() 278 { 279 public void onResponseReceived(Request request, Response response) 280 { 281 if(response.getStatusCode() == Response.SC_OK) 282 { 283 HTML newPage = new HTML(response.getText()); 284 newPage.getElement().setId("newpage"); 285 Element oldNewPage = (Element) Document.get().getElementById("newpage"); 286 if(oldNewPage != null) 287 { 288 oldNewPage.removeFromParent(); 289 } 290 getElementsByTagName("body").get(0).appendChild(newPage.getElement()); 291 newPage.setVisible(false); 292 293 showLoadedPage(); 294 } 295 } 296 297 public void onError(Request request, Throwable exception) 298 { 299 alert("Problem loading new page -> " + exception.getMessage()); 300 } 301 }); 302 } 303 catch(Exception ex) 304 { 305 alert("Exception while creating the new page request -> " + ex.getMessage()); 306 } 299 307 } 300 308 … … 357 365 _spatialSearchClickHandler = null; 358 366 } 359 }360 361 /**362 * Gets the timer than checks for when the pages is loaded and then loads the page363 * @param url is the url being loaded364 * @return the timer365 */366 public Timer getLoadedTimer()367 {368 return new Timer()369 {370 int timercount = 0;371 372 public void run()373 {374 //Check to see if we should timeout yet375 if (timercount++ > 50)376 {377 logToConsole("Failed to load page after 50 attempts");378 this.cancel();379 return;380 }381 382 //Check to see if the page is loaded383 if (tempFrameGetElementById("banner") != null && tempFrameGetElementById("content") != null && tempFrameGetElementById("footer") != null)384 {385 this.cancel();386 showLoadedPage();387 }388 }389 };390 367 } 391 368 … … 398 375 if (!_initialised) 399 376 { 377 //Fix webpage elements so that they point to the correct address 378 fixForms(); 379 fixAnchors(); 380 fixImages(); 381 382 initialiseATLAS(); 383 384 //Add <link> and <script> elements to <head> 385 //changeCSSLinksAndScripts(); 386 } 387 else 388 { 389 //Add <link> and <script> elements to <head> 390 //changeCSSLinksAndScripts(); 391 400 392 //Fix webpage elements so that they point to the correct address 401 393 fixForms(); … … 403 395 fixImages(); 404 396 405 initialiseATLAS(); 397 Element newPageElem = getElementById("newpage"); 398 NodeList<com.google.gwt.dom.client.Element> divs = newPageElem.getElementsByTagName("div"); 406 399 407 //Add <link> and <script> elements to <head> 408 changeCSSLinksAndScripts(); 409 } 410 else 411 { 412 //Add <link> and <script> elements to <head> 413 changeCSSLinksAndScripts(); 414 415 //Fix webpage elements so that they point to the correct address 416 fixForms(); 417 fixAnchors(); 418 fixImages(); 400 Element newBanner = null; 401 Element newContent = null; 402 403 for(int i = 0; i < divs.getLength(); i++) 404 { 405 if(divs.getItem(i).getId().equals("gs_banner")) 406 { 407 newBanner = (Element) divs.getItem(i); 408 } 409 else if(divs.getItem(i).getId().equals("gs_content")) 410 { 411 newContent = (Element) divs.getItem(i); 412 } 413 } 419 414 420 415 //Swap the current banner with the new banner 421 Element oldBanner = getElementById("banner"); 422 Element newBanner = tempFrameGetElementById("banner"); 416 Element oldBanner = getElementById("gs_banner"); 423 417 oldBanner.getParentElement().removeChild(oldBanner); 424 418 _headerDiv.insert(HTML.wrap(newBanner), 0); … … 433 427 434 428 //Swap the current Greenstone content with the new Greenstone content 435 _gsPanel.setHTML(HTML.wrap( tempFrameGetElementById("content")).getHTML());429 _gsPanel.setHTML(HTML.wrap(newContent).getHTML()); 436 430 } 437 431 … … 444 438 //The page has now finished being updated 445 439 _statusBar.removeUpdate("LoadPage"); 446 447 //Do an initial resize of the page elements448 Timer tempResizeTimer = new Timer()449 {450 public void run()451 {452 resizeElements();453 }454 };455 tempResizeTimer.schedule(500);456 440 457 441 //Check the document's text for places … … 499 483 */ 500 484 public void initialiseATLAS() 501 { 502 //Get the head section of the HTML page 503 Element head = getDocumentHead(); 504 505 //Get all of the <link> elements from the HTML header 506 logToConsole("Saving links"); 507 NodeList<com.google.gwt.dom.client.Element> linksToSave = head.getElementsByTagName("link"); 508 509 for(int i = 0; i < linksToSave.getLength(); i++) 510 { 511 logToConsole("Link save = " + linksToSave.getItem(i).getAttribute("href")); 512 _mainLinks.add(linksToSave.getItem(i)); 513 } 514 515 //Get all of the <script> elements from the HTML header 516 logToConsole("Saving scripts"); 517 NodeList<com.google.gwt.dom.client.Element> scriptsToSave = head.getElementsByTagName("script"); 518 519 for(int i = 0; i < scriptsToSave.getLength(); i++) 520 { 521 logToConsole("Script save = " + scriptsToSave.getItem(i).getAttribute("src")); 522 _mainScripts.add(scriptsToSave.getItem(i)); 523 } 524 485 { 525 486 //Reload the page when the view type is changed 526 487 _textViewSelector.addChangeHandler(new ChangeHandler() … … 530 491 if (getDocTextElement() != null) 531 492 { 532 loadPageFromUrl(_ gsTempFrame.getUrl());493 loadPageFromUrl(_currentURL); 533 494 } 534 495 } … … 544 505 _viewPanel.add(_textViewSelector); 545 506 _viewPanel.setVisible(false); 507 508 Element newPageElem = getElementById("newpage"); 509 NodeList<com.google.gwt.dom.client.Element> divs = newPageElem.getElementsByTagName("div"); 510 511 Element headerElem = null; 512 Element bodyElem = null; 513 Element footerElem = null; 514 515 for(int i = 0; i < divs.getLength(); i++) 516 { 517 if(divs.getItem(i).getId().equals("gs_banner")) 518 { 519 headerElem = (Element) divs.getItem(i); 520 } 521 else if(divs.getItem(i).getId().equals("gs_content")) 522 { 523 bodyElem = (Element) divs.getItem(i); 524 } 525 else if(divs.getItem(i).getId().equals("gs_footer")) 526 { 527 footerElem = (Element) divs.getItem(i); 528 } 529 } 530 531 if(headerElem == null) 532 { 533 alert("header is null"); 534 } 535 if(bodyElem == null) 536 { 537 alert("body is null"); 538 } 539 if(footerElem == null) 540 { 541 alert("footer is null"); 542 } 546 543 547 544 // Add header 548 _headerDiv.add(HTML.wrap(tempFrameGetElementById("banner"))); 545 //Node newHeader = importNode(newPage, tempFrameGetElementById("banner"), true); 546 _headerDiv.add(HTML.wrap(headerElem)); 549 547 _headerDiv.add(_viewPanel); 550 548 _headerDiv.setWidth("100%"); … … 558 556 559 557 // Add content 560 Element contentElement = tempFrameGetElementById("content");561 _gsPanel = HTML.wrap( contentElement);558 //Node newContent = importNode(Document.get(), tempFrameGetElementById("content"), true); 559 _gsPanel = HTML.wrap(bodyElem); 562 560 _contentDiv.add(_gsPanel); 563 561 _contentDiv.add(_map); 564 562 565 563 // Add footer 566 _footerDiv.add(HTML.wrap(tempFrameGetElementById("footer"))); 564 //Node newFooter = importNode(Document.get(), tempFrameGetElementById("footer"), true); 565 _footerDiv.add(HTML.wrap(footerElem)); 567 566 _footerDiv.setWidth("100%"); 568 567 _footerDiv.getElement().setId("GSFooter"); … … 622 621 //Get the response text 623 622 String text = response.getText(); 624 623 625 624 //Get the hash codes for the documents 626 ArrayList<String> docURLs = getDocURLsFromResponse(text); 627 628 TemporaryFrame.setCurrentFrameIndex(getNumberOfFrames() - 1); 629 //Load each search result in a temporary frame 630 final ArrayList<TemporaryFrame> tempFrames = new ArrayList<TemporaryFrame>(); 631 for (int j = 0; j < docURLs.size(); j++) 632 { 633 //Create the url of the search result 634 String url = _GREENSTONEURL + "/" + docURLs.get(j); 635 636 //Create the temporary frame 637 TemporaryFrame currentFrame = new TemporaryFrame(url); 638 639 //Add the frame to the footer of the page 640 _footerDiv.add(currentFrame.getFrame()); 641 642 //Begin loading the page 643 currentFrame.loadPage(); 644 645 //Store the frame 646 tempFrames.add(currentFrame); 647 } 648 649 //Create a timer that periodically checks if all the frames have finished loading 650 Timer docsReadyTimer = new Timer() 651 { 652 public void run() 653 { 654 //Check to see if all of the frames have finished loading 655 boolean allDone = true; 656 for (int i = 0; i < tempFrames.size(); i++) 657 { 658 if (!tempFrames.get(i).isFinishedLoading()) 625 final ArrayList<String> docURLs = getDocURLsFromResponse(text); 626 final String[] texts = new String[docURLs.size()]; 627 628 for(int i = 0; i < texts.length; i++) 629 { 630 texts[i] = null; 631 } 632 633 for(int i = 0; i < docURLs.size(); i++) 634 { 635 String url = docURLs.get(i); 636 RequestBuilder xmlRequest = new RequestBuilder(RequestBuilder.GET, _GREENSTONEURL + "/" + (url.contains("?") ? (url + "&excerptid=gs-document-text") : (url + "?excerptid=gs-document-text"))); 637 try 638 { 639 final int index = i; 640 xmlRequest.sendRequest(null, new RequestCallback() 641 { 642 public void onResponseReceived(Request request, Response response) 659 643 { 660 logToConsole(i + " has NOT finished loading"); 661 allDone = false; 662 } 663 else 664 { 665 logToConsole(i + " has finished loading"); 666 } 667 } 668 669 //If all the frames have finished loading 670 if (allDone && _gazetteerLoaded) 671 { 672 this.cancel(); 673 674 //Get all of the texts from the frames 675 ArrayList<String> texts = new ArrayList<String>(); 676 while (tempFrames.size() > 0) 677 { 678 texts.add(tempFrames.get(0).getText()); 679 tempFrames.get(0).removeFromParent(); 680 tempFrames.remove(0); 644 if(response.getStatusCode() == Response.SC_OK) 645 { 646 texts[index] = response.getText(); 647 } 681 648 } 682 649 650 public void onError(Request request, Throwable exception) 651 { 652 alert("Exception requesting new page -> " + exception.getMessage()); 653 texts[index] = ""; 654 } 655 }); 656 } 657 catch(Exception ex) 658 { 659 alert("Exception requesting " + url + " -> " + ex.getMessage()); 660 } 661 } 662 663 Timer checkDoneTimer = new Timer() 664 { 665 int _count = 0; 666 667 public void run() 668 { 669 boolean done = true; 670 if(_count < 20) 671 { 672 for(int i = 0; i < texts.length; i++) 673 { 674 if(texts[i] == null) 675 { 676 done = false; 677 break; 678 } 679 } 680 } 681 _count++; 682 683 if(done) 684 { 685 this.cancel(); 683 686 findPlacesInTexts(texts); 684 687 } 685 else686 {687 logToConsole("Still getting doc text...");688 }689 688 } 690 689 }; 691 docsReadyTimer.scheduleRepeating(2000);690 checkDoneTimer.scheduleRepeating(500); 692 691 } 693 692 … … 696 695 * @param texts is a list of texts from different documents 697 696 */ 698 private void findPlacesInTexts( ArrayList<String>texts)697 private void findPlacesInTexts(String[] texts) 699 698 { 700 699 logToConsole("Finished gettings doc text and gazetteer loaded!"); … … 785 784 786 785 //If this is not the first point then add a line between this and the previous point 787 logToConsole("Points array size = " + _areaPoints.size());788 786 if (_areaPoints.size() > 1) 789 787 { … … 792 790 793 791 Polyline line = new Polyline(new LatLng[] { point, _areaPoints.get(_areaPoints.size() - 2) }, "#FFFFFF", 3, 1, po); 794 logToConsole("Adding line");795 792 _map.addOverlay(line); 796 793 } … … 879 876 */ 880 877 public void changeCSSLinksAndScripts() 881 { 878 { 882 879 //Get the head section of the HTML page 883 880 Element head = getDocumentHead(); … … 888 885 //Get all of the <script> elements from the HTML header 889 886 NodeList<com.google.gwt.dom.client.Element> currentScripts = head.getElementsByTagName("script"); 890 891 //Remove all of the old links on the page 892 for(int i = 0; i < currentLinks.getLength(); i++) 893 { 894 currentLinks.getItem(i).getParentElement().removeChild(currentLinks.getItem(i)); 895 } 896 897 //Remove all of the old scripts on the page 898 for(int i = 0; i < currentScripts.getLength(); i++) 899 { 900 currentScripts.getItem(i).getParentElement().removeChild(currentScripts.getItem(i)); 901 } 902 903 //Add the links present in every page 904 for (int i = 0; i < _mainLinks.size(); i++) 905 { 906 Element e = (Element) _mainLinks.get(i); 907 if(!e.getAttribute("href").startsWith("http://")) 887 888 //Add the new links 889 com.google.gwt.xml.client.NodeList newLinks = _currentNewPageDoc.getElementsByTagName("link"); 890 for (int i = 0; i < newLinks.getLength(); i++) 891 { 892 com.google.gwt.xml.client.Element e = (com.google.gwt.xml.client.Element) newLinks.item(i); 893 boolean found = false; 894 for(int j = 0; j < currentLinks.getLength(); j++) 895 { 896 Element elem = (Element) currentLinks.getItem(j); 897 if(e.getAttribute("href").equals(elem.getAttribute("href")) 898 && e.getAttribute("type").equals(elem.getAttribute("type")) 899 && e.getAttribute("rel").equals(elem.getAttribute("rel"))) 900 { 901 found = true; 902 } 903 } 904 905 if(!found) 906 { 907 Element newElem = DOM.createElement("link"); 908 909 NamedNodeMap map = e.getAttributes(); 910 for(int k = 0; k < e.getAttributes().getLength(); k++) 911 { 912 newElem.setAttribute(map.item(k).getNodeName(), map.item(k).getNodeValue()); 913 } 914 915 if(!newElem.getAttribute("href").startsWith("http://")) 916 { 917 newElem.setAttribute("href", _GREENSTONEURL + "/" + newElem.getAttribute("href")); 918 } 919 head.appendChild(newElem); 920 } 921 } 922 923 //Add the new scripts on the page 924 com.google.gwt.xml.client.NodeList newScripts = _currentNewPageDoc.getElementsByTagName("script"); 925 for (int i = 0; i < newScripts.getLength(); i++) 926 { 927 com.google.gwt.xml.client.Element e = (com.google.gwt.xml.client.Element) newScripts.item(i); 928 boolean found = false; 929 for(int j = 0; j < currentScripts.getLength(); j++) 930 { 931 Element elem = (Element) currentLinks.getItem(j); 932 if(e.getAttribute("src").equals(elem.getAttribute("src")) 933 && e.getAttribute("type").equals(elem.getAttribute("type")) 934 && e.getAttribute("charset").equals(elem.getAttribute("charset"))) 935 { 936 found = true; 937 } 938 } 939 940 if(!found) 941 { 942 Element newElem = DOM.createElement("link"); 943 944 NamedNodeMap map = e.getAttributes(); 945 for(int k = 0; k < e.getAttributes().getLength(); k++) 946 { 947 newElem.setAttribute(map.item(k).getNodeName(), map.item(k).getNodeValue()); 948 } 949 950 951 if(!e.getAttribute("src").startsWith("http://")) 952 { 953 e.setAttribute("src", _GREENSTONEURL + "/" + e.getAttribute("src")); 954 } 955 head.appendChild(newElem); 956 } 957 } 958 } 959 960 /** 961 * Go through each form on the page and add a javascript function in place of its action attribute 962 */ 963 public void fixForms() 964 { 965 NodeList<com.google.gwt.dom.client.Element> forms = getElementById("newpage").getElementsByTagName("form"); 966 for (int i = 0; i < forms.getLength(); i++) 967 { 968 Element e = (Element)forms.getItem(i); 969 e.setAttribute("id", "form" + i); 970 971 if(e.getAttribute("action").isEmpty()) 972 { 973 continue; 974 } 975 if (!e.getAttribute("action").startsWith("http://") && !e.getAttribute("action").startsWith("/")) 976 { 977 e.setAttribute("action", "javascript:loadPageFromFormJS(document.getElementById('form" + i + "'))"); 978 } 979 } 980 } 981 982 /** 983 * Go through each anchor on the page and add a javascript function in place of the href attribute 984 */ 985 public void fixAnchors() 986 { 987 NodeList<com.google.gwt.dom.client.Element> anchors = getElementById("newpage").getElementsByTagName("a"); 988 for (int i = 0; i < anchors.getLength(); i++) 989 { 990 Element e = (Element)anchors.getItem(i); 991 if(e.getAttribute("href").isEmpty()) 992 { 993 continue; 994 } 995 if (!e.getAttribute("href").startsWith("http://") && !e.getAttribute("href").startsWith("/")) 908 996 { 909 997 e.setAttribute("href", _GREENSTONEURL + "/" + e.getAttribute("href")); 910 998 } 911 head.appendChild(e); 912 } 913 914 //Add the scripts present in every page 915 for (int i = 0; i < _mainScripts.size(); i++) 916 { 917 Element e = (Element) _mainScripts.get(i); 918 if(!e.getAttribute("src").startsWith("http://")) 919 { 920 e.setAttribute("src", _GREENSTONEURL + "/" + e.getAttribute("src")); 921 } 922 head.appendChild(e); 923 } 924 925 //Add the new links 926 JsArray<Element> newLinks = tempFrameGetElementsByTagName("link"); 927 for (int i = 0; i < newLinks.length(); i++) 928 { 929 Element e = newLinks.get(i); 930 if(!e.getAttribute("href").startsWith("http://")) 931 { 932 e.setAttribute("href", _GREENSTONEURL + "/" + e.getAttribute("href")); 933 } 934 head.appendChild(e); 935 } 936 937 //Add the new scripts on the page 938 JsArray<Element> scripts = tempFrameGetElementsByTagName("script"); 939 for (int i = 0; i < scripts.length(); i++) 940 { 941 Element e = scripts.get(i); 942 if(!e.getAttribute("src").startsWith("http://")) 943 { 944 e.setAttribute("src", _GREENSTONEURL + "/" + e.getAttribute("src")); 945 } 946 head.appendChild(e); 947 } 948 } 949 950 /** 951 * Go through each form on the page and add a javascript function in place of its action attribute 952 */ 953 public void fixForms() 954 { 955 JsArray<Element> forms = tempFrameGetElementsByTagName("form"); 956 for (int i = 0; i < forms.length(); i++) 957 { 958 Element e = forms.get(i); 959 e.setAttribute("id", "form" + i); 960 961 if (!e.getAttribute("action").startsWith("http://")) 962 { 963 e.setAttribute("action", "javascript:loadPageFromFormJS(document.getElementById('form" + i + "'))"); 964 } 965 } 966 } 967 968 /** 969 * Go through each anchor on the page and add a javascript function in place of the href attribute 970 */ 971 public void fixAnchors() 972 { 973 JsArray<Element> anchors = tempFrameGetElementsByTagName("a"); 974 for (int i = 0; i < anchors.length(); i++) 975 { 976 Element e = anchors.get(i); 977 978 if (!e.getAttribute("href").startsWith("http://")) 979 { 980 e.setAttribute("href", _GREENSTONEURL + "/" + e.getAttribute("href")); 981 e.setAttribute("onClick", "loadPageFromUrlJS('" + e.getAttribute("href") + "'); return false;"); 982 } 999 //e.setAttribute("onClick", "loadPageFromUrlJS('" + e.getAttribute("href") + "'); return false;"); 1000 e.setAttribute("href", "javascript:loadPageFromUrlJS('" + e.getAttribute("href") + "');"); 983 1001 } 984 1002 } … … 989 1007 public void fixImages() 990 1008 { 991 JsArray<Element> images = tempFrameGetElementsByTagName("img"); 992 for (int i = 0; i < images.length(); i++) 993 { 994 Element e = images.get(i); 995 if (!e.getAttribute("src").startsWith("http://")) 1009 NodeList<com.google.gwt.dom.client.Element> images = getElementById("newpage").getElementsByTagName("img"); 1010 for (int i = 0; i < images.getLength(); i++) 1011 { 1012 Element e = (Element)images.getItem(i); 1013 1014 if(e.getAttribute("src").isEmpty()) 1015 { 1016 continue; 1017 } 1018 1019 if (!e.getAttribute("src").startsWith("http://") && !e.getAttribute("src").startsWith("/")) 996 1020 { 997 1021 e.setAttribute("src", _GREENSTONEURL + "/" + e.getAttribute("src")); … … 1101 1125 1102 1126 /** 1127 * Prints a given message to screen in a window 1128 * @param msg is the message to print 1129 */ 1130 public static native void alert(String msg) 1131 /*-{ 1132 alert(msg); 1133 }-*/; 1134 1135 /** 1103 1136 * Prints a given message to the Firebug console 1104 1137 * @param msg is the message to print … … 1106 1139 public static native void logToConsole(String msg) 1107 1140 /*-{ 1108 console.log(msg); 1141 //alert(msg); 1142 //console.log(msg); 1109 1143 }-*/; 1110 1144 … … 1117 1151 return $doc.getElementsByTagName("head")[0]; 1118 1152 }-*/; 1153 1154 /** 1155 * Patch GWT Document.importNode, which fails to return the imported nodes 1156 */ 1157 public static final native Node importNode(Document doc, Node node, boolean deep) /*-{ 1158 return doc.importNode(node, deep); 1159 }-*/; 1160 1119 1161 1120 1162 /** … … 1184 1226 //Get the width and height we want to use for the content div 1185 1227 int cwidth = Window.getClientWidth() - 45; 1186 int cheight = (int) (Window.getClientHeight() - _headerDiv.getOffsetHeight() - _footerDiv.getOffsetHeight() - 70);1228 int cheight = (int) (Window.getClientHeight() - _headerDiv.getOffsetHeight() - _footerDiv.getOffsetHeight() - _statusBar.getStatusBarDiv().getOffsetHeight() - 50); 1187 1229 1188 1230 //If the height is less than 300 then set it to 300 1189 if (cheight < 300)1190 { 1191 cheight = 300;1231 if (cheight < 200) 1232 { 1233 cheight = 200; 1192 1234 } 1193 1235 … … 1197 1239 1198 1240 //Set the size of the content div 1199 _contentDiv.setSize(cwidth + "px", (cheight + 50)+ "px");1241 _contentDiv.setSize(cwidth + "px", cheight + "px"); 1200 1242 1201 1243 //Set up the style of the Greenstone panel … … 1210 1252 if (_mapVisible && _gsVisible) 1211 1253 { 1212 _map.setSize((cwidth / 2 - 60) + "px", cheight+ "px");1254 _map.setSize((cwidth / 2 - 60) + "px", (cheight - 25) + "px"); 1213 1255 _map.getElement().getStyle().setProperty("left", (cwidth / 2 + 50) + "px"); 1214 _gsPanel.setSize((cwidth / 2) + "px", cheight+ "px");1256 _gsPanel.setSize((cwidth / 2) + "px", (cheight - 25) + "px"); 1215 1257 } 1216 1258 … … 1317 1359 1318 1360 //Work out the size of the new marker based on the current zoom level 1319 double size = 4.0 / (_map.getZoomLevel() * (_map.getZoomLevel() / 2)); 1320 1361 double zoomLevel = _map.getZoomLevel(); 1362 double size = (8.0 * Math.pow(2.0, -zoomLevel)) + (0.05 * (zoomLevel / 20.0)); 1363 1364 //Work out the transparency of the new marker based on the current zoom level 1365 double transparency = 0.8 * ((20.0 - zoomLevel) / 20.0); 1366 1321 1367 //Create the corner of the polygon 1322 1368 LatLng tl = LatLng.newInstance(lat - size, lng + size); … … 1329 1375 if (_highlightedPlaces.contains(p.getName())) 1330 1376 { 1331 newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, "#FF 0000", 0.75);1377 newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, "#FF7F27", transparency); 1332 1378 } 1333 1379 //Otherwise make it the normal colour 1334 1380 else 1335 1381 { 1336 newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, fillColour, 0.75);1382 newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, fillColour, transparency); 1337 1383 } 1338 1384 … … 1749 1795 public void onFailure(Throwable caught) 1750 1796 { 1751 logToConsole("Find multi places fail" + caught.getMessage());1797 alert("Find multi places fail" + caught.getMessage()); 1752 1798 } 1753 1799 … … 1757 1803 _statusBar.addUpdate("Displaying places", "DisPlaces"); 1758 1804 1759 logToConsole("Find multi places success");1760 1805 _currentMultiPlaces = places; 1761 1806 _visiblePlaceSets = new ArrayList<Boolean>(); … … 1919 1964 for (int j = 0; j < textPlaces.length(); j++) 1920 1965 { 1921 logToConsole("Attempting to match " + textPlaces.get(j).getAttribute("class") + " with place");1922 1966 if (textPlaces.get(j).getAttribute("class").equals("place")) 1923 1967 { … … 2031 2075 logToConsole("Adding columns to panel"); 2032 2076 2033 if (_contentDiv.getWidget(0).getElement().getId() == " content")2077 if (_contentDiv.getWidget(0).getElement().getId() == "gs_content") 2034 2078 { 2035 2079 VerticalPanel newDocTextPanel = new VerticalPanel(); … … 2129 2173 if (event.getY() < 125) 2130 2174 { 2131 logToConsole("1");2132 2175 _columnViewBox.getElement().getStyle().setProperty("top", (event.getY() + _label.getAbsoluteTop() + 25) + "px"); 2133 2176 } 2134 2177 else 2135 2178 { 2136 logToConsole("2");2137 2179 _columnViewBox.getElement().getStyle().setProperty("top", (event.getY() + _label.getAbsoluteTop() - 125) + "px"); 2138 2180 } … … 2839 2881 form.setWidget(tempForm); 2840 2882 2841 tempFrameGetElementsByTagName("body").get(0).appendChild(form.getElement());2883 getElementsByTagName("body").get(0).appendChild(form.getElement()); 2842 2884 2843 2885 logToConsole("Adding hidden form elements"); -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/Menu.java
r22277 r23906 5 5 import com.google.gwt.event.dom.client.MouseOutHandler; 6 6 import com.google.gwt.event.dom.client.MouseOverHandler; 7 import com.google.gwt.user.client.DOM;8 7 import com.google.gwt.user.client.Element; 9 8 import com.google.gwt.user.client.Timer; -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/MenuItem.java
r22277 r23906 4 4 import com.google.gwt.user.client.DOM; 5 5 import com.google.gwt.user.client.Element; 6 import com.google.gwt.user.client.ui.Label;7 6 8 7 public class MenuItem -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/Place.java
r22272 r23906 2 2 3 3 import java.io.Serializable; 4 import java.sql.Connection;5 import java.sql.DriverManager;6 import java.sql.ResultSet;7 import java.sql.Statement;8 4 import java.util.ArrayList; 9 10 import org.greenstone.server.ServerPlace;11 5 12 6 import com.google.gwt.user.client.rpc.AsyncCallback; -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/StatusBar.java
r22272 r23906 12 12 private ArrayList<String> _statusUpdates = new ArrayList<String>(); 13 13 14 public StatusBar() 14 private GS3MapLibrary _atlasInstance = null; 15 16 public StatusBar(GS3MapLibrary atlasInstance) 15 17 { 16 18 _statusBarDiv.setStyleName("statusBar"); 19 _atlasInstance = atlasInstance; 17 20 } 18 21 … … 41 44 _statusUpdates.add(update); 42 45 updateStatusBar(); 46 _atlasInstance.resizeElements(); 43 47 } 44 48 … … 54 58 _statusUpdates.set(index, null); 55 59 updateStatusBar(); 60 _atlasInstance.resizeElements(); 56 61 return true; 57 62 } … … 82 87 { 83 88 GS3MapLibrary.logToConsole("Adding progress image"); 84 status += "<br/><img src=\"http://localhost:8080/ GS3MapLibrary/images/progress.gif\"></img>";89 status += "<br/><img src=\"http://localhost:8080/ATLAS/images/progress.gif\"></img>"; 85 90 } 86 91 _statusBarDiv.setHTML(status); -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/FindPlaceServiceImpl.java
r22272 r23906 1 1 package org.greenstone.server; 2 2 3 import java.net.URLConnection; 3 4 import java.sql.Connection; 4 5 import java.sql.DriverManager; … … 10 11 import org.greenstone.client.Place; 11 12 12 import com.google.gwt.dom.client.Element;13 13 import com.google.gwt.user.server.rpc.RemoteServiceServlet; 14 14 … … 58 58 } 59 59 60 public ArrayList<ArrayList<Place>> findPlacesInMultipleTexts( ArrayList<String>texts)60 public ArrayList<ArrayList<Place>> findPlacesInMultipleTexts(String[] texts) 61 61 { 62 62 return _pageScanner.examineMultipleTexts(texts); … … 91 91 92 92 _places = new ArrayList<Place>(); 93 int count = 0; 93 94 94 while(results.next()) 95 95 { -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GateScanner.java
r22272 r23906 4 4 import gate.AnnotationSet; 5 5 import gate.Corpus; 6 import gate.CorpusController;7 6 import gate.Document; 8 7 import gate.Factory; … … 10 9 import gate.Gate; 11 10 import gate.GateConstants; 12 import gate.ProcessingResource;13 import gate.corpora.RepositioningInfo;14 11 import gate.creole.ANNIEConstants; 15 import gate.creole.ResourceInstantiationException;16 12 import gate.creole.SerialAnalyserController; 17 13 import gate.util.GateException; … … 22 18 import java.net.URL; 23 19 import java.util.ArrayList; 24 import java.util.HashSet; 25 import java.util.Iterator; 26 import java.util.Set; 20 import java.util.HashMap; 27 21 28 22 import org.apache.log4j.BasicConfigurator; … … 37 31 { 38 32 BasicConfigurator.configure(); 39 Gate.setGateHome(new File(" /home/sam/Desktop/Research/Gate5"));40 Gate.setPluginsHome(new File(" /home/sam/Desktop/Research/Gate5/plugins"));41 Gate.setUserConfigFile(new File(" /home/sam/Desktop/Research/Gate5/gate.xml"));33 Gate.setGateHome(new File("C:\\Users\\sjm84\\Desktop\\stuff\\Gate5.2")); 34 Gate.setPluginsHome(new File("C:\\Users\\sjm84\\Desktop\\stuff\\Gate5.2\\plugins")); 35 Gate.setUserConfigFile(new File("C:\\Users\\sjm84\\Desktop\\stuff\\Gate5.2\\gate.xml")); 42 36 Gate.init(); 43 Gate.getCreoleRegister().registerDirectories(new URL("file:///home/sam/Desktop/Research/Gate5/plugins/ANNIE"));37 Gate.getCreoleRegister().registerDirectories(new File("C:\\Users\\sjm84\\Desktop\\stuff\\Gate5.2\\plugins\\ANNIE").toURI().toURL()); 44 38 Gate.getUserConfig().put(GateConstants.DOCUMENT_ADD_SPACE_ON_UNPACK_FEATURE_NAME, new Boolean(false)); 45 39 … … 70 64 } // execute() 71 65 72 public ArrayList<Word> classifyText(String originalText)66 public HashMap<String, Word> classifyText(String originalText) 73 67 { 74 ArrayList<Word> words = new ArrayList<Word>();68 HashMap<String, Word> words = new HashMap<String, Word>(); 75 69 try 76 70 { 77 // create a GATE corpus and add a document for each command-line78 // argument79 71 Corpus corpus = (Corpus) Factory.createResource("gate.corpora.CorpusImpl"); 80 72 FeatureMap params = Factory.newFeatureMap(); … … 91 83 AnnotationSet annotations = doc.getAnnotations(); 92 84 93 int index = 0;94 85 for(int j = 0; j < annotations.size(); j++) 95 86 { … … 102 93 if(currentAnnotation.getType().equals("Token")) 103 94 { 104 Word w = new Word(); 105 w.setIndex(index++); 106 w.setClassification((String)currentAnnotation.getFeatures().get("category")); 107 w.setValue((String)currentAnnotation.getFeatures().get("string")); 108 109 words.add(w); 95 Word w = null; 96 if(words.containsKey((String)currentAnnotation.getFeatures().get("string"))) 97 { 98 w = words.get((String)currentAnnotation.getFeatures().get("string")); 99 w.addClassification((String)currentAnnotation.getFeatures().get("category")); 100 w.setValue((String)currentAnnotation.getFeatures().get("string")); 101 } 102 else 103 { 104 w = new Word(); 105 w.addClassification((String)currentAnnotation.getFeatures().get("category")); 106 w.setValue((String)currentAnnotation.getFeatures().get("string")); 107 words.put(w.getValue(), w); 108 } 110 109 } 111 110 } -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieFullNode.java
r22272 r23906 2 2 3 3 import java.io.Serializable; 4 import java.util.HashMap;5 4 6 5 public class GazetteerTrieFullNode implements Serializable -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieTopLevelNode.java
r22272 r23906 2 2 3 3 import java.io.Serializable; 4 import java.util.HashMap;5 4 6 5 public class GazetteerTrieTopLevelNode implements Serializable -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieType1.java
r22272 r23906 2 2 3 3 import java.io.BufferedReader; 4 import java.io.BufferedWriter;5 4 import java.io.FileReader; 6 import java.io.FileWriter;7 5 import java.io.Serializable; 8 import java.sql.Connection;9 import java.sql.DriverManager;10 6 import java.sql.Statement; 11 7 import java.util.ArrayList; -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieType2.java
r22272 r23906 2 2 3 3 import java.io.BufferedReader; 4 import java.io.BufferedWriter;5 4 import java.io.FileReader; 6 import java.io.FileWriter;7 5 import java.io.Serializable; 8 import java.sql.Connection;9 import java.sql.DriverManager;10 6 import java.sql.Statement; 11 7 import java.util.ArrayList; … … 163 159 public int checkPlaceName(String placeName) 164 160 { 165 System.out.println("CHECKING PLACE NAME");166 161 if (placeName.length() == 0) 167 162 { -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieType3.java
r22272 r23906 2 2 3 3 import java.io.BufferedReader; 4 import java.io.BufferedWriter;5 4 import java.io.FileReader; 6 import java.io.FileWriter;7 5 import java.io.Serializable; 8 import java.sql.Connection;9 import java.sql.DriverManager;10 6 import java.sql.Statement; 11 7 import java.util.ArrayList; -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieType4.java
r22272 r23906 2 2 3 3 import java.io.BufferedReader; 4 import java.io.BufferedWriter;5 4 import java.io.FileReader; 6 import java.io.FileWriter;7 5 import java.io.Serializable; 8 import java.sql.Connection;9 import java.sql.DriverManager;10 6 import java.sql.Statement; 11 7 import java.util.ArrayList; -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieType5.java
r22272 r23906 2 2 3 3 import java.io.BufferedReader; 4 import java.io.BufferedWriter;5 4 import java.io.FileReader; 6 import java.io.FileWriter;7 5 import java.io.Serializable; 8 import java.sql.Connection;9 import java.sql.DriverManager;10 import java.sql.Statement;11 6 import java.util.ArrayList; 12 7 import java.util.HashMap; 13 import java.util.HashSet;14 15 import com.sun.org.apache.bcel.internal.generic.NEW;16 8 17 9 public class GazetteerTrieType5 implements Serializable -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/PageScanner.java
r22277 r23906 1 1 package org.greenstone.server; 2 2 3 import gate.util.Out; 4 3 5 import java.io.BufferedReader; 6 import java.io.BufferedWriter; 7 import java.io.FileWriter; 4 8 import java.io.StringReader; 5 9 import java.util.ArrayList; … … 28 32 protected double _indirectReferencePenaltyPercentage = 0.25; 29 33 protected double _parentLimitPercentage = 0.05; 30 34 31 35 protected ArrayList<String> _prevDoc = null; 32 protected String _prevFileName = null; 36 protected String _prevFileName = null; 33 37 34 38 /** … … 59 63 public ArrayList<Place> examineTextWithGate(String text, String htmlString) 60 64 { 61 System.out.println(htmlString); 62 // System.out.println("Examining text"); 63 64 StringBuilder html = null; 65 if (htmlString != null) 66 { 67 html = new StringBuilder(htmlString); 68 } 69 65 _places.clear(); 66 67 if(htmlString != null && text == null) 68 { 69 text = HTMLParser.removeTags(htmlString); 70 } 71 72 if (text == null || text.length() < 1 || htmlString == null || htmlString.length() < 1) 73 { 74 return new ArrayList<Place>(); 75 } 76 77 HTMLParser htmlParser = new HTMLParser(htmlString); 78 79 ArrayList<String> betweenChars = htmlParser.getFullBetweenWordList(); 80 ArrayList<String> htmlWords = htmlParser.getFullHTMLWordList(); 81 82 HashMap<Integer, Integer> placeNameIndexesAndLength = new HashMap<Integer, Integer>(); 83 84 try 85 { 86 // Classify all the text with Gate 87 HashMap<String, Word> classifiedWords = _gateScanner.classifyText(text); 88 89 // Stores the current words being examined 90 StringBuilder currentPotentialPlaceNames = new StringBuilder(); 91 92 // Get the next word from the HTML 93 for (int i = 0; i < htmlWords.size(); i++) 94 { 95 String currentWord = htmlWords.get(i); 96 97 Word classifiedWord = classifiedWords.get(currentWord); 98 if (classifiedWord == null) 99 { 100 continue; 101 } 102 103 String classification = classifiedWord.getNextClassification(); 104 105 // If the word does not begin with an uppercase letter then ignore it 106 if (classification == null || Character.isLowerCase(currentWord.charAt(0)) || !(classification.equals("NNP"))) 107 { 108 continue; 109 } 110 111 // Add the first word to the list of words to be examined 112 currentPotentialPlaceNames.append(currentWord); 113 114 // While the gazetteer does not reach a dead end, add another word and examine them 115 int count = 1; 116 String lastGoodPlaceName = null; 117 while (_gazetteer.checkPlaceName(currentPotentialPlaceNames.toString()) != -1) 118 { 119 // If the words are a place name then store it 120 if (_gazetteer.checkPlaceName(currentPotentialPlaceNames.toString()) == 1) 121 { 122 lastGoodPlaceName = currentPotentialPlaceNames.toString(); 123 } 124 125 // If it is not the end of the words the add the next word 126 if (i + count < htmlWords.size()) 127 { 128 currentPotentialPlaceNames.append(betweenChars.get(i + count) + htmlWords.get(i + count++)); 129 } 130 else 131 { 132 break; 133 } 134 } 135 136 // If there was a place name found then find its information and score it 137 if (lastGoodPlaceName != null) 138 { 139 placeNameIndexesAndLength.put(i, count); 140 141 ArrayList<Place> placeList = PlaceInformation.getPlaces(lastGoodPlaceName); 142 143 if (placeList == null) 144 { 145 continue; 146 } 147 148 if (_placeNameMap.containsKey(lastGoodPlaceName)) 149 { 150 for (Place p : _placeNameMap.get(lastGoodPlaceName)) 151 { 152 p.directReference(); 153 } 154 } 155 156 for (Place p : placeList) 157 { 158 p.directReference(); 159 addScore(p, 256); 160 } 161 } 162 163 currentPotentialPlaceNames = new StringBuilder(); 164 } 165 } 166 catch (Exception ex) 167 { 168 ex.printStackTrace(); 169 } 170 171 172 // Tidy up the places found by removing overlapping places 173 for(int i = 0; i < htmlWords.size(); i++) 174 { 175 if(placeNameIndexesAndLength.get(i) != null) 176 { 177 int length = placeNameIndexesAndLength.get(i); 178 for(int j = 1; j < length; j++) 179 { 180 if(placeNameIndexesAndLength.get(i + j) != null) 181 { 182 placeNameIndexesAndLength.remove(i + j); 183 } 184 } 185 } 186 } 187 188 StringBuilder htmlBuilder = new StringBuilder(); 189 190 int placeEnd = -1; 191 for(int i = 0; i < htmlWords.size(); i++) 192 { 193 if(i == placeEnd) 194 { 195 htmlBuilder.append("</span>"); 196 } 197 198 if(i < betweenChars.size() && betweenChars.get(i) != null) 199 { 200 htmlBuilder.append(betweenChars.get(i)); 201 } 202 203 if(placeNameIndexesAndLength.get(i) != null) 204 { 205 htmlBuilder.append("<span class=\"place\">"); 206 placeEnd = i + (placeNameIndexesAndLength.get(i) - 1); 207 } 208 htmlBuilder.append(htmlWords.get(i)); 209 } 210 211 _markedUpText = htmlBuilder.toString(); 212 213 if (_places.size() > 0) 214 { 215 adjustScores(); 216 } 217 218 return _places; 219 } 220 221 public ArrayList<Place> examineTextWithoutGate(ArrayList<ArrayList<String>> lines) 222 { 70 223 _places.clear(); 71 224 try 72 225 { 73 ArrayList<Word> classifiedWords = _gateScanner.classifyText(text);74 75 // The file to read from76 BufferedReader file = new BufferedReader(new StringReader(text));77 78 226 // Stores the current words being examined 79 227 StringBuilder currentWords = new StringBuilder(); 80 228 81 // Stores the current line being examined82 String currentLine = null;83 84 int htmlIndex = 0;85 int textIndex = 0;86 int cwindex = 0;87 88 // The list of words in the line89 ArrayList<String> words = new ArrayList<String>();90 91 229 // Read each line from the file 92 while ((currentLine = file.readLine()) != null) 93 { 94 words.clear(); 95 96 // Find the words in those lines and add them to the list 97 words.addAll(MarkupService.findWords(currentLine)); 98 230 for (ArrayList<String> words : lines) 231 { 99 232 // Examine the words 100 233 for (int j = 0; j < words.size(); j++) 101 234 { 102 int oldHTMLIndex = 0; 103 if (htmlString != null) 104 { 105 oldHTMLIndex = htmlIndex; 106 htmlIndex = html.indexOf(words.get(j), htmlIndex); 107 } 108 textIndex = text.indexOf(words.get(j), textIndex); 109 Word currentWord = null; 110 int cwindexBefore = cwindex; 111 for (; cwindex < classifiedWords.size(); cwindex++) 112 { 113 if (textIndex > 0 && text.charAt(textIndex - 1) == '\'') 114 { 115 break; 116 } 117 118 //System.out.println("Looking for \"" + words.get(j) + "\" got \"" + classifiedWords.get(cwindex) + "\""); 119 if (classifiedWords.get(cwindex).getValue().equals(words.get(j))) 120 { 121 currentWord = classifiedWords.get(cwindex); 122 break; 123 } 124 } 125 126 if (currentWord == null) 127 { 128 cwindex = cwindexBefore; 129 continue; 130 } 131 132 // If the word does not begin with an uppercase letter then ignore it 133 if (Character.isLowerCase(words.get(j).charAt(0)) || !(words.get(j).length() > 1 && Character.isLowerCase(words.get(j).charAt(1))) || !(currentWord.getClassification().equals("NNP"))) 235 // If the word does not begin with an uppercase letter then 236 // ignore it 237 if (Character.isLowerCase(words.get(j).charAt(0)) || !(words.get(j).length() > 1 && Character.isLowerCase(words.get(j).charAt(1)))) 134 238 { 135 239 continue; … … 141 245 // Add the first word to the list of words to be examined 142 246 currentWords.append(words.get(j)); 143 247 144 248 // While the gazetteer does not reach a dead end, add 145 249 // another word and examine them … … 151 255 { 152 256 lastGoodPlaceName = currentWords.toString(); 257 // System.out.println("Current place name part => " 258 // + lastGoodPlaceName); 153 259 } 154 260 … … 169 275 if (lastGoodPlaceName != null) 170 276 { 171 if (htmlString != null)172 {173 if (htmlIndex == -1)174 {175 htmlIndex = oldHTMLIndex;176 }177 else178 {179 html.insert(htmlIndex, "<span class=\"place\">");180 html.insert(htmlIndex + "<span class=\"place\">".length() + lastGoodPlaceName.length(), "</span>");181 }182 }183 184 277 ArrayList<Place> placeList = PlaceInformation.getPlaces(lastGoodPlaceName); 185 278 … … 188 281 continue; 189 282 } 190 283 191 284 if (_placeNameMap.containsKey(lastGoodPlaceName)) 192 285 { 193 for (Place p : _placeNameMap.get(lastGoodPlaceName))286 for (Place p : _placeNameMap.get(lastGoodPlaceName)) 194 287 { 195 288 p.directReference(); … … 203 296 } 204 297 } 205 206 298 currentWords = new StringBuilder(); 207 299 } 208 300 } 209 file.close();210 301 } 211 302 catch (Exception ex) … … 214 305 } 215 306 216 if (htmlString != null) 217 { 218 _markedUpText = html.toString(); 219 } 220 221 if(_places.size() > 0) 222 { 223 adjustScores(); 224 } 307 adjustScores(); 225 308 226 309 return _places; 227 310 } 228 229 public ArrayList<Place> examineTextWithoutGate(ArrayList<ArrayList<String>> lines) 230 { 311 312 public ArrayList<String> getPlaceNames(String text) 313 { 314 ArrayList<String> placeNames = new ArrayList<String>(); 231 315 _places.clear(); 232 316 try 233 317 { 318 // The file to read from 319 BufferedReader file = new BufferedReader(new StringReader(text)); 320 234 321 // Stores the current words being examined 235 322 StringBuilder currentWords = new StringBuilder(); 236 323 324 // Stores the current line being examined 325 String currentLine = null; 326 327 // The list of words in the line 328 ArrayList<String> words = new ArrayList<String>(); 329 237 330 // Read each line from the file 238 for(ArrayList<String> words : lines) 239 { 331 while ((currentLine = file.readLine()) != null) 332 { 333 words.clear(); 334 335 // Find the words in those lines and add them to the list 336 words.addAll(MarkupService.findWords(currentLine)); 337 240 338 // Examine the words 241 339 for (int j = 0; j < words.size(); j++) … … 283 381 if (lastGoodPlaceName != null) 284 382 { 285 ArrayList<Place> placeList = PlaceInformation.getPlaces(lastGoodPlaceName); 286 287 if (placeList == null) 288 { 289 continue; 290 } 291 292 if (_placeNameMap.containsKey(lastGoodPlaceName)) 293 { 294 for(Place p : _placeNameMap.get(lastGoodPlaceName)) 295 { 296 p.directReference(); 297 } 298 } 299 300 for (Place p : placeList) 301 { 302 p.directReference(); 303 addScore(p, 256); 304 } 383 placeNames.add(lastGoodPlaceName); 305 384 } 306 385 currentWords = new StringBuilder(); 307 386 } 308 387 } 388 file.close(); 309 389 } 310 390 catch (Exception ex) … … 313 393 } 314 394 395 return placeNames; 396 } 397 398 public ArrayList<Place> examineArrayOfStrings(ArrayList<String> placeNames) 399 { 400 _places.clear(); 401 for (int i = 0; i < placeNames.size(); i++) 402 { 403 String currentPlaceName = placeNames.get(i); 404 405 ArrayList<Place> placeList = null; 406 if (_placeCache.containsKey(currentPlaceName)) 407 { 408 placeList = _placeCache.get(currentPlaceName); 409 for (Place p : placeList) 410 { 411 p.unDirectReference(); 412 } 413 } 414 else 415 { 416 placeList = PlaceInformation.getPlaces(currentPlaceName); 417 _placeCache.put(currentPlaceName, placeList); 418 } 419 420 if (placeList == null) 421 { 422 continue; 423 } 424 425 if (_placeNameMap.containsKey(currentPlaceName)) 426 { 427 for (Place p : _placeNameMap.get(currentPlaceName)) 428 { 429 p.directReference(); 430 } 431 } 432 433 for (Place p : placeList) 434 { 435 p.directReference(); 436 addScore(p, 256); 437 } 438 } 439 440 // System.out.println("Done!"); 441 // System.out.print("Adjusting Scores... "); 442 315 443 adjustScores(); 316 444 445 // System.out.println("Done!"); 446 // System.out.print("Sorting Scores... "); 447 448 // System.out.println("Done!"); 449 450 // System.out.println("Places found = " + _places); 451 317 452 return _places; 318 453 } 319 320 public ArrayList<String> getPlaceNames(String text) 321 { 322 ArrayList<String> placeNames = new ArrayList<String>(); 454 455 public ArrayList<Place> examineTextWithoutGate(String text) 456 { 323 457 _places.clear(); 324 458 try … … 389 523 if (lastGoodPlaceName != null) 390 524 { 391 placeNames.add(lastGoodPlaceName);392 }393 currentWords = new StringBuilder();394 }395 }396 file.close();397 }398 catch (Exception ex)399 {400 ex.printStackTrace();401 }402 403 return placeNames;404 }405 406 public ArrayList<Place> examineArrayOfStrings(ArrayList<String> placeNames)407 {408 _places.clear();409 for(int i = 0; i < placeNames.size(); i++)410 {411 String currentPlaceName = placeNames.get(i);412 413 ArrayList<Place> placeList = null;414 if(_placeCache.containsKey(currentPlaceName))415 {416 placeList = _placeCache.get(currentPlaceName);417 for(Place p : placeList)418 {419 p.unDirectReference();420 }421 }422 else423 {424 placeList = PlaceInformation.getPlaces(currentPlaceName);425 _placeCache.put(currentPlaceName, placeList);426 }427 428 if (placeList == null)429 {430 continue;431 }432 433 if (_placeNameMap.containsKey(currentPlaceName))434 {435 for(Place p : _placeNameMap.get(currentPlaceName))436 {437 p.directReference();438 }439 }440 441 for (Place p : placeList)442 {443 p.directReference();444 addScore(p, 256);445 }446 }447 448 // System.out.println("Done!");449 // System.out.print("Adjusting Scores... ");450 451 adjustScores();452 453 // System.out.println("Done!");454 // System.out.print("Sorting Scores... ");455 456 // System.out.println("Done!");457 458 // System.out.println("Places found = " + _places);459 460 return _places;461 }462 463 public ArrayList<Place> examineTextWithoutGate(String text)464 {465 _places.clear();466 try467 {468 // The file to read from469 BufferedReader file = new BufferedReader(new StringReader(text));470 471 // Stores the current words being examined472 StringBuilder currentWords = new StringBuilder();473 474 // Stores the current line being examined475 String currentLine = null;476 477 // The list of words in the line478 ArrayList<String> words = new ArrayList<String>();479 480 // Read each line from the file481 while ((currentLine = file.readLine()) != null)482 {483 words.clear();484 485 // Find the words in those lines and add them to the list486 words.addAll(MarkupService.findWords(currentLine));487 488 // Examine the words489 for (int j = 0; j < words.size(); j++)490 {491 // If the word does not begin with an uppercase letter then492 // ignore it493 if (Character.isLowerCase(words.get(j).charAt(0)) || !(words.get(j).length() > 1 && Character.isLowerCase(words.get(j).charAt(1))))494 {495 continue;496 }497 498 // Used to store a good place name499 String lastGoodPlaceName = null;500 501 // Add the first word to the list of words to be examined502 currentWords.append(words.get(j));503 504 // While the gazetteer does not reach a dead end, add505 // another word and examine them506 int count = 1;507 while (_gazetteer.checkPlaceName(currentWords.toString()) != -1)508 {509 // If the words are a place name then store it510 if (_gazetteer.checkPlaceName(currentWords.toString()) == 1)511 {512 lastGoodPlaceName = currentWords.toString();513 // System.out.println("Current place name part => "514 // + lastGoodPlaceName);515 }516 517 // If it is not the end of the words the add the next518 // word519 if (j + count < words.size())520 {521 currentWords.append(" " + words.get(j + count++));522 }523 else524 {525 break;526 }527 }528 529 // If there was a place name found then find its information530 // and score it531 if (lastGoodPlaceName != null)532 {533 525 ArrayList<Place> placeList = PlaceInformation.getPlaces(lastGoodPlaceName); 534 526 … … 540 532 if (_placeNameMap.containsKey(lastGoodPlaceName)) 541 533 { 542 for (Place p : _placeNameMap.get(lastGoodPlaceName))534 for (Place p : _placeNameMap.get(lastGoodPlaceName)) 543 535 { 544 536 p.directReference(); … … 561 553 ex.printStackTrace(); 562 554 } 563 555 564 556 // System.out.println("Done!"); 565 557 // System.out.print("Adjusting Scores... "); … … 579 571 return _markedUpText; 580 572 } 581 573 582 574 public Place getTopScorePlace() 583 575 { 584 576 Place p = _places.get(0); 585 586 for (Place pp : _places)587 { 588 if (pp.getScore() > p.getScore())577 578 for (Place pp : _places) 579 { 580 if (pp.getScore() > p.getScore()) 589 581 { 590 582 p = pp; … … 600 592 public void adjustScores() 601 593 { 602 for (Place p : _places)603 { 604 if (!p.isDirectlyReferenced())605 { 606 p.setScore((int) (p.getScore() * _penaltyPercentage));607 } 608 } 609 594 for (Place p : _places) 595 { 596 if (!p.isDirectlyReferenced()) 597 { 598 p.setScore((int) (p.getScore() * _penaltyPercentage)); 599 } 600 } 601 610 602 Place topScore = getTopScorePlace(); 611 612 for (Place p : _places)603 604 for (Place p : _places) 613 605 { 614 606 if (p.getParentPlaceName() == null) … … 616 608 continue; 617 609 } 618 610 619 611 for (Place pp : _places) 620 612 { 621 if (p.isIn(pp) && (topScore.getScore() - pp.getScore()) <= (int)(topScore.getScore() * 0.1 * _parentLimitPercentage))622 { 623 p.setScore((int) (p.getScore() + (pp.getScore() * _parentBonusPercentage)));613 if (p.isIn(pp) && (topScore.getScore() - pp.getScore()) <= (int) (topScore.getScore() * 0.1 * _parentLimitPercentage)) 614 { 615 p.setScore((int) (p.getScore() + (pp.getScore() * _parentBonusPercentage))); 624 616 } 625 617 } … … 651 643 p.setScore(scoreToAdd); 652 644 _places.add(p); 653 654 if (_placeNameMap.containsKey(p.getName()))645 646 if (_placeNameMap.containsKey(p.getName())) 655 647 { 656 648 _placeNameMap.get(p.getName()).add(p); … … 709 701 } 710 702 } 711 712 703 713 704 public void sortScores() … … 803 794 _indirectReferencePenaltyPercentage = indirectReferencePenaltyPercentage; 804 795 } 805 796 806 797 public void setScoringParams(ScanConfiguration config) 807 798 { … … 815 806 // { 816 807 // HashMap<String, Integer> wordCountMap = new HashMap<String, Integer>(); 817 // 808 // 818 809 // try 819 810 // { 820 811 // BufferedReader file = new BufferedReader(new FileReader(fileName)); 821 // 812 // 822 813 // StringBuilder currentWord = new StringBuilder(); 823 // 814 // 824 815 // String line = ""; 825 // 816 // 826 817 // ArrayList<String> words = new ArrayList<String>(); 827 // 818 // 828 819 // //System.out.print("Finding words... "); 829 820 // while((line = file.readLine()) != null) … … 832 823 // } 833 824 // //System.out.println("Done!"); 834 // 825 // 835 826 // //System.out.print("Adding up scores... "); 836 827 // for(int j = 0; j < words.size(); j++) … … 840 831 // //continue; 841 832 // } 842 // 833 // 843 834 // currentWord.append(words.get(j)); 844 // 835 // 845 836 // int count = 1; 846 837 // while(_gazetteer.checkPlaceName(currentWord.toString()) != -1) … … 860 851 // currentWord.append(" " + words.get(j + count++)); 861 852 // } 862 // 853 // 863 854 // currentWord.delete(0, currentWord.length()); 864 855 // } … … 868 859 // ex.printStackTrace(); 869 860 // } 870 // 861 // 871 862 // return wordCountMap; 872 863 // } … … 877 868 } 878 869 879 public ArrayList<ArrayList<Place>> examineMultipleTexts( ArrayList<String>texts)870 public ArrayList<ArrayList<Place>> examineMultipleTexts(String[] texts) 880 871 { 881 872 ArrayList<ArrayList<Place>> multipleResults = new ArrayList<ArrayList<Place>>(); … … 884 875 if (text != null) 885 876 { 886 this.examineTextWithGate( text, null);887 888 if (_places.size() > 0)877 this.examineTextWithGate(null, text); 878 879 if (_places.size() > 0) 889 880 { 890 881 multipleResults.add(new ArrayList<Place>(_places)); … … 903 894 return multipleResults; 904 895 } 905 896 906 897 public ArrayList<Place> getPlaces() 907 898 { 908 899 return _places; 909 900 } 910 901 911 902 public void clearPlaces() 912 903 { … … 917 908 /* 918 909 * 919 * // Halve the scores for places that do not have their parents 920 // mentioned 921 // ******************************************************************** 922 923 String[] parentPlaceNames = p.getParentPlaceName().split(", "); 924 if (parentPlaceNames.length == 1) 925 { 926 ArrayList<Place> parentList = PlaceInformation.getSpecificPlace(parentPlaceNames[0], null); 927 Place parent = null; 928 929 if (parentList != null && parentList.size() > 0) 930 { 931 parent = parentList.get(0); 932 933 if (!_places.contains(parent) || !_places.get(_places.indexOf(parent)).isDirectlyReferenced()) 934 { 935 p.setScore((int) (p.getScore() * (1 - _penaltyPercentage))); 936 } 937 } 938 } 939 else if (parentPlaceNames.length == 2) 940 { 941 ArrayList<Place> parentList = PlaceInformation.getSpecificPlace(parentPlaceNames[0], parentPlaceNames[1]); 942 ArrayList<Place> ancestorList = PlaceInformation.getSpecificPlace(parentPlaceNames[1], null); 943 944 Place parent = null; 945 Place ancestor = null; 946 947 if (parentList != null && parentList.size() > 0) 948 { 949 parent = parentList.get(0); 950 951 if (!_places.contains(parent) || !_places.get(_places.indexOf(parent)).isDirectlyReferenced()) 952 { 953 p.setScore((int) (p.getScore() * (1 - _penaltyPercentage))); 954 } 955 } 956 957 if (ancestorList != null && ancestorList.size() > 0) 958 { 959 ancestor = ancestorList.get(0); 960 961 if (!_places.contains(ancestor) || !_places.get(_places.indexOf(ancestor)).isDirectlyReferenced()) 962 { 963 p.setScore((int) (p.getScore() * (1 - _penaltyPercentage))); 964 } 965 } 966 } 967 else if (parentPlaceNames.length == 3) 968 { 969 ArrayList<Place> parentList = PlaceInformation.getSpecificPlace(parentPlaceNames[0], parentPlaceNames[1] + ", " + parentPlaceNames[2]); 970 ArrayList<Place> firstAncestorList = PlaceInformation.getSpecificPlace(parentPlaceNames[1], parentPlaceNames[2]); 971 ArrayList<Place> secondAncestorList = PlaceInformation.getSpecificPlace(parentPlaceNames[2], null); 972 973 Place parent = null; 974 Place firstAncestor = null; 975 Place secondAncestor = null; 976 977 if (parentList != null && parentList.size() > 0) 978 { 979 parent = parentList.get(0); 980 981 if (!_places.contains(parent) || !_places.get(_places.indexOf(parent)).isDirectlyReferenced()) 982 { 983 p.setScore((int) (p.getScore() * (1 - _penaltyPercentage))); 984 } 985 } 986 987 if (firstAncestorList != null && firstAncestorList.size() > 0) 988 { 989 firstAncestor = firstAncestorList.get(0); 990 991 if (!_places.contains(firstAncestor) || !_places.get(_places.indexOf(firstAncestor)).isDirectlyReferenced()) 992 { 993 p.setScore((int) (p.getScore() * (1 - _penaltyPercentage))); 994 } 995 } 996 997 if (secondAncestorList != null && secondAncestorList.size() > 0) 998 { 999 secondAncestor = secondAncestorList.get(0); 1000 1001 if (!_places.contains(secondAncestor) || !_places.get(_places.indexOf(secondAncestor)).isDirectlyReferenced()) 1002 { 1003 p.setScore((int) (p.getScore() * (1 - _penaltyPercentage))); 1004 } 1005 } 1006 } 1007 */ 910 * // Halve the scores for places that do not have their parents // mentioned // 911 * ******************************************************************** 912 * 913 * String[] parentPlaceNames = p.getParentPlaceName().split(", "); if 914 * (parentPlaceNames.length == 1) { ArrayList<Place> parentList = 915 * PlaceInformation.getSpecificPlace(parentPlaceNames[0], null); Place parent = 916 * null; 917 * 918 * if (parentList != null && parentList.size() > 0) { parent = 919 * parentList.get(0); 920 * 921 * if (!_places.contains(parent) || 922 * !_places.get(_places.indexOf(parent)).isDirectlyReferenced()) { 923 * p.setScore((int) (p.getScore() * (1 - _penaltyPercentage))); } } } else if 924 * (parentPlaceNames.length == 2) { ArrayList<Place> parentList = 925 * PlaceInformation.getSpecificPlace(parentPlaceNames[0], parentPlaceNames[1]); 926 * ArrayList<Place> ancestorList = 927 * PlaceInformation.getSpecificPlace(parentPlaceNames[1], null); 928 * 929 * Place parent = null; Place ancestor = null; 930 * 931 * if (parentList != null && parentList.size() > 0) { parent = 932 * parentList.get(0); 933 * 934 * if (!_places.contains(parent) || 935 * !_places.get(_places.indexOf(parent)).isDirectlyReferenced()) { 936 * p.setScore((int) (p.getScore() * (1 - _penaltyPercentage))); } } 937 * 938 * if (ancestorList != null && ancestorList.size() > 0) { ancestor = 939 * ancestorList.get(0); 940 * 941 * if (!_places.contains(ancestor) || 942 * !_places.get(_places.indexOf(ancestor)).isDirectlyReferenced()) { 943 * p.setScore((int) (p.getScore() * (1 - _penaltyPercentage))); } } } else if 944 * (parentPlaceNames.length == 3) { ArrayList<Place> parentList = 945 * PlaceInformation.getSpecificPlace(parentPlaceNames[0], parentPlaceNames[1] + 946 * ", " + parentPlaceNames[2]); ArrayList<Place> firstAncestorList = 947 * PlaceInformation.getSpecificPlace(parentPlaceNames[1], parentPlaceNames[2]); 948 * ArrayList<Place> secondAncestorList = 949 * PlaceInformation.getSpecificPlace(parentPlaceNames[2], null); 950 * 951 * Place parent = null; Place firstAncestor = null; Place secondAncestor = null; 952 * 953 * if (parentList != null && parentList.size() > 0) { parent = 954 * parentList.get(0); 955 * 956 * if (!_places.contains(parent) || 957 * !_places.get(_places.indexOf(parent)).isDirectlyReferenced()) { 958 * p.setScore((int) (p.getScore() * (1 - _penaltyPercentage))); } } 959 * 960 * if (firstAncestorList != null && firstAncestorList.size() > 0) { 961 * firstAncestor = firstAncestorList.get(0); 962 * 963 * if (!_places.contains(firstAncestor) || 964 * !_places.get(_places.indexOf(firstAncestor)).isDirectlyReferenced()) { 965 * p.setScore((int) (p.getScore() * (1 - _penaltyPercentage))); } } 966 * 967 * if (secondAncestorList != null && secondAncestorList.size() > 0) { 968 * secondAncestor = secondAncestorList.get(0); 969 * 970 * if (!_places.contains(secondAncestor) || 971 * !_places.get(_places.indexOf(secondAncestor)).isDirectlyReferenced()) { 972 * p.setScore((int) (p.getScore() * (1 - _penaltyPercentage))); } } } 973 */ 1008 974 // Add part of the parent's score to the child 1009 975 // ******************************************* 1010 976 /* 1011 if (parentPlaceNames.length == 1) 1012 { 1013 ArrayList<Place> parentList = PlaceInformation.getSpecificPlace(parentPlaceNames[0], null); 1014 1015 Place parent = null; 1016 1017 if (parentList != null && parentList.size() > 0) 1018 { 1019 parent = parentList.get(0); 1020 1021 if (_places.contains(parent)) 1022 { 1023 p.setScore(p.getScore() + (int) (_places.get(_places.indexOf(parent)).getScore() * _parentBonusPercentage)); 1024 } 1025 } 1026 } 1027 else if (parentPlaceNames.length == 2) 1028 { 1029 ArrayList<Place> parentList = PlaceInformation.getSpecificPlace(parentPlaceNames[0], parentPlaceNames[1]); 1030 ArrayList<Place> ancestorList = PlaceInformation.getSpecificPlace(parentPlaceNames[1], null); 1031 1032 Place parent = null; 1033 Place ancestor = null; 1034 1035 if (parentList != null && parentList.size() > 0) 1036 { 1037 parent = parentList.get(0); 1038 1039 if (_places.contains(parent)) 1040 { 1041 p.setScore(p.getScore() + (int) (_places.get(_places.indexOf(parent)).getScore() * _parentBonusPercentage)); 1042 } 1043 } 1044 1045 if (ancestorList != null && ancestorList.size() > 0) 1046 { 1047 ancestor = ancestorList.get(0); 1048 1049 if (_places.contains(ancestor)) 1050 { 1051 p.setScore(p.getScore() + (int) (_places.get(_places.indexOf(ancestor)).getScore() * _parentBonusPercentage)); 1052 } 1053 } 1054 } 1055 else if (parentPlaceNames.length == 3) 1056 { 1057 ArrayList<Place> parentList = PlaceInformation.getSpecificPlace(parentPlaceNames[0], parentPlaceNames[1] + ", " + parentPlaceNames[2]); 1058 ArrayList<Place> firstAncestorList = PlaceInformation.getSpecificPlace(parentPlaceNames[1], parentPlaceNames[2]); 1059 ArrayList<Place> secondAncestorList = PlaceInformation.getSpecificPlace(parentPlaceNames[2], null); 1060 1061 Place parent = null; 1062 Place firstAncestor = null; 1063 Place secondAncestor = null; 1064 1065 if (parentList != null && parentList.size() > 0) 1066 { 1067 parent = parentList.get(0); 1068 1069 if (_places.contains(parent)) 1070 { 1071 p.setScore(p.getScore() + (int) (_places.get(_places.indexOf(parent)).getScore() * _parentBonusPercentage)); 1072 } 1073 } 1074 1075 if (firstAncestorList != null && firstAncestorList.size() > 0) 1076 { 1077 firstAncestor = firstAncestorList.get(0); 1078 1079 if (_places.contains(firstAncestor)) 1080 { 1081 p.setScore(p.getScore() + (int) (_places.get(_places.indexOf(firstAncestor)).getScore() * _parentBonusPercentage)); 1082 } 1083 } 1084 1085 if (secondAncestorList != null && secondAncestorList.size() > 0) 1086 { 1087 secondAncestor = secondAncestorList.get(0); 1088 1089 if (_places.contains(secondAncestor)) 1090 { 1091 p.setScore(p.getScore() + (int) (_places.get(_places.indexOf(secondAncestor)).getScore() * _parentBonusPercentage)); 1092 } 1093 } 1094 } 1095 */ 977 * if (parentPlaceNames.length == 1) { ArrayList<Place> parentList = 978 * PlaceInformation.getSpecificPlace(parentPlaceNames[0], null); 979 * 980 * Place parent = null; 981 * 982 * if (parentList != null && parentList.size() > 0) { parent = 983 * parentList.get(0); 984 * 985 * if (_places.contains(parent)) { p.setScore(p.getScore() + (int) 986 * (_places.get(_places.indexOf(parent)).getScore() * _parentBonusPercentage)); 987 * } } } else if (parentPlaceNames.length == 2) { ArrayList<Place> parentList = 988 * PlaceInformation.getSpecificPlace(parentPlaceNames[0], parentPlaceNames[1]); 989 * ArrayList<Place> ancestorList = 990 * PlaceInformation.getSpecificPlace(parentPlaceNames[1], null); 991 * 992 * Place parent = null; Place ancestor = null; 993 * 994 * if (parentList != null && parentList.size() > 0) { parent = 995 * parentList.get(0); 996 * 997 * if (_places.contains(parent)) { p.setScore(p.getScore() + (int) 998 * (_places.get(_places.indexOf(parent)).getScore() * _parentBonusPercentage)); 999 * } } 1000 * 1001 * if (ancestorList != null && ancestorList.size() > 0) { ancestor = 1002 * ancestorList.get(0); 1003 * 1004 * if (_places.contains(ancestor)) { p.setScore(p.getScore() + (int) 1005 * (_places.get(_places.indexOf(ancestor)).getScore() * 1006 * _parentBonusPercentage)); } } } else if (parentPlaceNames.length == 3) { 1007 * ArrayList<Place> parentList = 1008 * PlaceInformation.getSpecificPlace(parentPlaceNames[0], parentPlaceNames[1] + 1009 * ", " + parentPlaceNames[2]); ArrayList<Place> firstAncestorList = 1010 * PlaceInformation.getSpecificPlace(parentPlaceNames[1], parentPlaceNames[2]); 1011 * ArrayList<Place> secondAncestorList = 1012 * PlaceInformation.getSpecificPlace(parentPlaceNames[2], null); 1013 * 1014 * Place parent = null; Place firstAncestor = null; Place secondAncestor = null; 1015 * 1016 * if (parentList != null && parentList.size() > 0) { parent = 1017 * parentList.get(0); 1018 * 1019 * if (_places.contains(parent)) { p.setScore(p.getScore() + (int) 1020 * (_places.get(_places.indexOf(parent)).getScore() * _parentBonusPercentage)); 1021 * } } 1022 * 1023 * if (firstAncestorList != null && firstAncestorList.size() > 0) { 1024 * firstAncestor = firstAncestorList.get(0); 1025 * 1026 * if (_places.contains(firstAncestor)) { p.setScore(p.getScore() + (int) 1027 * (_places.get(_places.indexOf(firstAncestor)).getScore() * 1028 * _parentBonusPercentage)); } } 1029 * 1030 * if (secondAncestorList != null && secondAncestorList.size() > 0) { 1031 * secondAncestor = secondAncestorList.get(0); 1032 * 1033 * if (_places.contains(secondAncestor)) { p.setScore(p.getScore() + (int) 1034 * (_places.get(_places.indexOf(secondAncestor)).getScore() * 1035 * _parentBonusPercentage)); } } } 1036 */ -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/PlaceInformation.java
r22272 r23906 23 23 System.out.print("Loading postgresql driver... "); 24 24 Class.forName("org.postgresql.Driver"); 25 Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/GS3MapDB", " sam", "password");//DriverManager.getConnection("jdbc:postgresql://localhost/test", "sjm84", "password");25 Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/GS3MapDB", "postgres", "admin");//DriverManager.getConnection("jdbc:postgresql://localhost/test", "sjm84", "password"); 26 26 System.out.println("Done!"); 27 27 _database = c.createStatement(); -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/ScanResultSet.java
r22272 r23906 1 1 package org.greenstone.server; 2 2 3 import java.sql.ResultSet;4 3 import java.util.ArrayList; 5 4 import java.util.HashMap; -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/ServerPlace.java
r22272 r23906 2 2 3 3 import java.io.Serializable; 4 import java.sql.Connection;5 import java.sql.DriverManager;6 import java.sql.ResultSet;7 import java.sql.Statement;8 import java.util.ArrayList;9 10 4 import org.greenstone.client.Place; 11 5 -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/ServerSideTests.java
r22272 r23906 2 2 3 3 import java.awt.BorderLayout; 4 import java.awt.FlowLayout;5 4 import java.awt.GridLayout; 6 5 import java.awt.event.ActionEvent; … … 9 8 import java.io.BufferedWriter; 10 9 import java.io.DataOutputStream; 11 import java.io.File;12 import java.io.FileInputStream;13 import java.io.FileNotFoundException;14 import java.io.FileOutputStream;15 10 import java.io.FileReader; 16 11 import java.io.FileWriter; 17 import java.io.IOException;18 12 import java.io.InputStreamReader; 19 import java.io.ObjectInputStream;20 import java.io.ObjectOutputStream;21 import java.io.OutputStream;22 import java.io.Reader;23 13 import java.net.HttpURLConnection; 24 14 import java.net.URL; … … 28 18 import java.sql.Statement; 29 19 import java.util.ArrayList; 30 import java.util.Timer;31 import java.util.TimerTask;32 20 import java.util.HashMap; 33 21 import java.util.TreeMap; 34 22 35 import javax.servlet.Servlet;36 23 import javax.swing.ButtonGroup; 37 24 import javax.swing.JButton; … … 47 34 import org.greenstone.client.Place; 48 35 49 import com.sun.xml.internal.ws.wsdl.writer.document.soap.Body;50 51 36 public class ServerSideTests 52 37 { … … 69 54 public void go() 70 55 { 56 DatabaseFix(); 57 //PlacesToPoints(); 71 58 // ExperimentSetUp(); 72 59 //PrecisionExperiment(); … … 74 61 //GazetteerTest(); 75 62 //ModPlaceNames(); 76 analyseResults();63 //analyseResults(); 77 64 } 78 65 … … 488 475 //BufferedReader file = new BufferedReader(new FileReader("/home/sam/Desktop/Research/GNSDocs/" + filenames[i] + ".html")); 489 476 490 ArrayList<ArrayList<String>> lines = new ArrayList<ArrayList<String>>();491 477 StringBuilder text = new StringBuilder(); 492 478 String line = null; … … 682 668 while ((line = in.readLine()) != null) 683 669 { 684 if (line == null)685 {686 return;687 }688 689 670 for (String word : line.split(" ")) 690 671 { … … 740 721 { 741 722 Class.forName("org.postgresql.Driver"); 742 Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/GS3MapDB", " sam", "password");723 Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/GS3MapDB", "postgres", "admin"); 743 724 744 725 database = c.createStatement(); … … 775 756 { 776 757 Class.forName("org.postgresql.Driver"); 777 Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/GS3MapDB", "postgres", " password");758 Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/GS3MapDB", "postgres", "admin"); 778 759 779 760 database = c.createStatement(); 780 761 781 BufferedReader gazetteerFile = new BufferedReader(new FileReader(" /home/sam/Desktop/Research/Greenstone3-gate-svn2/web/GPNMS/dataen.txt"));762 BufferedReader gazetteerFile = new BufferedReader(new FileReader("C:\\Users\\sjm84\\Desktop\\EclipseWorkspace\\ATLAS\\war\\dataen.txt")); 782 763 783 764 String line = ""; … … 876 857 { 877 858 Class.forName("org.postgresql.Driver"); 878 Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/GS3MapDB", " sam", "password");859 Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/GS3MapDB", "postgres", "admin"); 879 860 880 861 database = c.createStatement(); -
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/Word.java
r22272 r23906 1 1 package org.greenstone.server; 2 3 import java.util.ArrayList; 2 4 3 5 public class Word 4 6 { 7 private int _classificationIndex = 0; 8 private ArrayList<String> _classifications = new ArrayList<String>(); 9 5 10 private String _value = null; 6 private String _classification = null;7 private long _index = -1;8 11 9 12 public void setValue(String value) … … 12 15 } 13 16 14 public void setClassification(String classification)17 public void addClassification(String classification) 15 18 { 16 _classification = classification; 17 } 18 19 public void setIndex(long index) 20 { 21 _index = index; 19 _classifications.add(classification); 22 20 } 23 21 … … 27 25 } 28 26 29 public String get Classification()27 public String getNextClassification() 30 28 { 31 return _classification; 32 } 33 34 public long getIndex() 35 { 36 return _index; 37 } 38 39 public String toString() 40 { 41 return "Index = " + _index + " value = " + _value + " classification = " + _classification; 29 if(_classificationIndex >= _classifications.size()) 30 { 31 return null; 32 } 33 return _classifications.get(_classificationIndex++); 42 34 } 43 35 }
Note:
See TracChangeset
for help on using the changeset viewer.