Ignore:
Timestamp:
2011-04-15T13:38:25+12:00 (13 years ago)
Author:
sjm84
Message:

Committing most recent version of ATLAS

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  
    66    <inherits name='com.google.gwt.user.theme.standard.Standard'/>
    77    <inherits name="com.google.gwt.http.HTTP"/>
    8     <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAtgBCR-EMOIox9GYORrWZ4xT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTdn97J3Y4bgIWO98Jw2xGa7SsjVQ"/>
     8    <inherits name="com.google.gwt.xml.XML" />
     9    <!--<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAtgBCR-EMOIox9GYORrWZ4xT20kFGbybagIuCnxcJa_GNd7_aLBSMK71WBmKu2gYDZKoonO56bPhAKQ"/>-->
     10    <!--<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAtgBCR-EMOIox9GYORrWZ4xT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTdn97J3Y4bgIWO98Jw2xGa7SsjVQ"/>-->
     11    <!--<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAtgBCR-EMOIox9GYORrWZ4xRDDXBaPmHH9_0fCH2SRcUU9bjcjhT3cD_2Hv84s1XjkWPxzMb0RT2hQQ"/>-->
    912    <entry-point class='org.greenstone.client.GS3MapLibrary'/>
    1013</module>
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/FindPlaceService.java

    r22272 r23906  
    22
    33import java.util.ArrayList;
    4 import com.google.gwt.dom.client.Element;
    54import com.google.gwt.user.client.rpc.RemoteService;
    65import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
     
    1110    Boolean isGazetteerLoaded();
    1211    Boolean findPlacesInText(String text, String html);
    13     ArrayList<ArrayList<Place>> findPlacesInMultipleTexts(ArrayList<String> texts);
     12    ArrayList<ArrayList<Place>> findPlacesInMultipleTexts(String[] texts);
    1413    Boolean loadGazetteer();
    1514    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  
    33import java.util.ArrayList;
    44
    5 import com.google.gwt.dom.client.Element;
    6 import com.google.gwt.maps.client.geom.LatLng;
    75import com.google.gwt.user.client.rpc.AsyncCallback;
    86
     
    1513    void getPlaces(double maxScore, double minScore, long minPopulation, boolean locality, boolean region, boolean country, int numberOfPlacesToGet, AsyncCallback<ArrayList<Place>> callback);
    1614    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);
    1816    void updateGazetteer(int start, int end,  AsyncCallback<ArrayList<Place>> callback);
    1917    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  
    5252import com.google.gwt.user.client.ui.FlowPanel;
    5353import com.google.gwt.user.client.ui.FormPanel;
    54 import com.google.gwt.user.client.ui.Frame;
    5554import com.google.gwt.user.client.ui.HTML;
    5655import com.google.gwt.user.client.ui.Hidden;
     
    6160import com.google.gwt.user.client.ui.VerticalPanel;
    6261import com.google.gwt.user.client.ui.Widget;
     62import com.google.gwt.xml.client.NamedNodeMap;
     63import com.google.gwt.dom.client.Document;
    6364import com.google.gwt.dom.client.FormElement;
    6465import com.google.gwt.dom.client.InputElement;
    6566import com.google.gwt.dom.client.NativeEvent;
     67import com.google.gwt.dom.client.Node;
    6668import com.google.gwt.dom.client.NodeCollection;
    6769import com.google.gwt.dom.client.NodeList;
     
    8284    protected HorizontalPanel _viewPanel = new HorizontalPanel();
    8385
    84     protected Frame _gsTempFrame = new Frame();
    85 
    86     protected StatusBar _statusBar = new StatusBar();
     86    protected StatusBar _statusBar = null;
    8787
    8888    protected HTML _gsPanel = new HTML();
     
    120120    protected ArrayList<String> _highlightedPlaces = new ArrayList<String>();
    121121    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>();
    124122    protected ArrayList<Boolean> _visiblePlaceSets = new ArrayList<Boolean>();
    125123    protected ArrayList<LatLng> _areaPoints = new ArrayList<LatLng>();
    126 
     124    protected ArrayList<String> _removedPlaces = new ArrayList<String>();
     125   
    127126    protected ArrayList<ArrayList<Place>> _currentMultiPlaces = null;
    128     protected ArrayList<String> _removedPlaces = new ArrayList<String>();
    129127   
    130128    protected HashMap<String, Place> _chosenPlaces = new HashMap<String, Place>(); 
     
    160158    protected String _currentCollection = "";
    161159    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";
    163162    protected final String _GREENSTONEDEVURL = _GREENSTONEURL + "/dev";
    164163
     164    protected com.google.gwt.xml.client.Document _currentNewPageDoc;
     165
    165166    /**
    166167     * GWT module entry point
     
    168169    public void onModuleLoad()
    169170    {
     171        _statusBar = new StatusBar(this);
     172        //Make the Firebug console so that browsers that don't have it don't break
     173        setUpConsole();
     174       
    170175        //Get a Google geocoder to help find places that the Gazetteer does not know the coordinates for
    171176        _geocoder = new Geocoder();
    172177
    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       
    175181        //Setup native Javascript functions
    176182        setUpLoadPageFromUrl(this);
    177183        setUpLoadPageFromForm(this);
    178184        setUpLoadSpatialSearchPage(this);
    179 
     185       
    180186        //Setup the map
    181187        setUpMap();
    182188       
    183         //Make the Firebug console so that browsers that don't have it don't break
    184         setUpConsole();
    185 
    186         //Set up the invisible frame that temporarily stores pages as they load
    187         setUpTempFrame();
    188        
    189189        //Set up the list box that stores the text view options
    190190        setUpTextViewSelector();
    191191
    192192        //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");
    212194    }
    213195
     
    226208     * @param url is the url to load
    227209     */
    228     public void loadPageFromUrl(final String url)
     210    public void loadPageFromUrl(String url)
    229211    {
    230212        //Make sure a url was given
     
    261243        if (url.contains("&c="))
    262244        {
    263             //logToConsole("url contains collection");
    264245            //Store the collection name
    265246            _currentCollection = getCollectionFromURL(url);
     
    268249        //Add the "Page loading" update to the status bar"     
    269250        _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);
    277253    }
    278254   
     
    293269        //Add the "Page loading" update to the status bar"     
    294270        _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        }
    299307    }
    300308   
     
    357365            _spatialSearchClickHandler = null;
    358366        }
    359     }
    360    
    361     /**
    362      * Gets the timer than checks for when the pages is loaded and then loads the page
    363      * @param url is the url being loaded
    364      * @return the timer
    365      */
    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 yet
    375                 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 loaded
    383                 if (tempFrameGetElementById("banner") != null && tempFrameGetElementById("content") != null && tempFrameGetElementById("footer") != null)
    384                 {
    385                     this.cancel();
    386                     showLoadedPage();
    387                 }   
    388             }
    389         };
    390367    }
    391368   
     
    398375        if (!_initialised)
    399376        {
     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
    400392            //Fix webpage elements so that they point to the correct address
    401393            fixForms();
     
    403395            fixImages();
    404396           
    405             initialiseATLAS();
     397            Element newPageElem = getElementById("newpage");
     398            NodeList<com.google.gwt.dom.client.Element> divs = newPageElem.getElementsByTagName("div");
    406399           
    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            }
    419414           
    420415            //Swap the current banner with the new banner
    421             Element oldBanner = getElementById("banner");
    422             Element newBanner = tempFrameGetElementById("banner");
     416            Element oldBanner = getElementById("gs_banner");
    423417            oldBanner.getParentElement().removeChild(oldBanner);
    424418            _headerDiv.insert(HTML.wrap(newBanner), 0);
     
    433427
    434428            //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());
    436430        }
    437431
     
    444438        //The page has now finished being updated
    445439        _statusBar.removeUpdate("LoadPage");
    446 
    447         //Do an initial resize of the page elements
    448         Timer tempResizeTimer = new Timer()
    449         {
    450             public void run()
    451             {
    452                 resizeElements();
    453             }
    454         };
    455         tempResizeTimer.schedule(500);
    456440
    457441        //Check the document's text for places
     
    499483     */
    500484    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    {       
    525486        //Reload the page when the view type is changed
    526487        _textViewSelector.addChangeHandler(new ChangeHandler()
     
    530491                if (getDocTextElement() != null)
    531492                {
    532                     loadPageFromUrl(_gsTempFrame.getUrl());
     493                    loadPageFromUrl(_currentURL);
    533494                }
    534495            }
     
    544505        _viewPanel.add(_textViewSelector);
    545506        _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        }
    546543
    547544        // Add header
    548         _headerDiv.add(HTML.wrap(tempFrameGetElementById("banner")));
     545        //Node newHeader = importNode(newPage, tempFrameGetElementById("banner"), true);
     546        _headerDiv.add(HTML.wrap(headerElem));
    549547        _headerDiv.add(_viewPanel);
    550548        _headerDiv.setWidth("100%");
     
    558556
    559557        // 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);
    562560        _contentDiv.add(_gsPanel);
    563561        _contentDiv.add(_map);
    564562
    565563        // Add footer
    566         _footerDiv.add(HTML.wrap(tempFrameGetElementById("footer")));
     564        //Node newFooter = importNode(Document.get(), tempFrameGetElementById("footer"), true);
     565        _footerDiv.add(HTML.wrap(footerElem));
    567566        _footerDiv.setWidth("100%");
    568567        _footerDiv.getElement().setId("GSFooter");
     
    622621        //Get the response text
    623622        String text = response.getText();
    624 
     623       
    625624        //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)
    659643                    {
    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                        }
    681648                    }
    682649                   
     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();
    683686                    findPlacesInTexts(texts);
    684687                }
    685                 else
    686                 {
    687                     logToConsole("Still getting doc text...");
    688                 }
    689688            }
    690689        };
    691         docsReadyTimer.scheduleRepeating(2000);
     690        checkDoneTimer.scheduleRepeating(500);
    692691    }
    693692   
     
    696695     * @param texts is a list of texts from different documents
    697696     */
    698     private void findPlacesInTexts(ArrayList<String> texts)
     697    private void findPlacesInTexts(String[] texts)
    699698    {
    700699        logToConsole("Finished gettings doc text and gazetteer loaded!");
     
    785784
    786785                    //If this is not the first point then add a line between this and the previous point
    787                     logToConsole("Points array size = " + _areaPoints.size());
    788786                    if (_areaPoints.size() > 1)
    789787                    {
     
    792790
    793791                        Polyline line = new Polyline(new LatLng[] { point, _areaPoints.get(_areaPoints.size() - 2) }, "#FFFFFF", 3, 1, po);
    794                         logToConsole("Adding line");
    795792                        _map.addOverlay(line);
    796793                    }
     
    879876     */
    880877    public void changeCSSLinksAndScripts()
    881     {
     878    {       
    882879        //Get the head section of the HTML page
    883880        Element head = getDocumentHead();
     
    888885        //Get all of the <script> elements from the HTML header
    889886        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("/"))
    908996            {
    909997                e.setAttribute("href", _GREENSTONEURL + "/" + e.getAttribute("href"));
    910998            }
    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") + "');");
    9831001        }
    9841002    }
     
    9891007    public void fixImages()
    9901008    {
    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("/"))
    9961020            {
    9971021                e.setAttribute("src", _GREENSTONEURL + "/" + e.getAttribute("src"));
     
    11011125
    11021126    /**
     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    /**
    11031136     * Prints a given message to the Firebug console
    11041137     * @param msg is the message to print
     
    11061139    public static native void logToConsole(String msg)
    11071140    /*-{
    1108         console.log(msg);
     1141        //alert(msg);
     1142        //console.log(msg);
    11091143    }-*/;
    11101144
     
    11171151        return $doc.getElementsByTagName("head")[0];
    11181152    }-*/;
     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
    11191161
    11201162    /**
     
    11841226        //Get the width and height we want to use for the content div
    11851227        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);
    11871229
    11881230        //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;
    11921234        }
    11931235
     
    11971239       
    11981240        //Set the size of the content div
    1199         _contentDiv.setSize(cwidth + "px", (cheight + 50) + "px");
     1241        _contentDiv.setSize(cwidth + "px", cheight + "px");
    12001242       
    12011243        //Set up the style of the Greenstone panel
     
    12101252        if (_mapVisible && _gsVisible)
    12111253        {
    1212             _map.setSize((cwidth / 2 - 60) + "px", cheight + "px");
     1254            _map.setSize((cwidth / 2 - 60) + "px", (cheight - 25) + "px");
    12131255            _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");
    12151257        }
    12161258
     
    13171359
    13181360        //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       
    13211367        //Create the corner of the polygon
    13221368        LatLng tl = LatLng.newInstance(lat - size, lng + size);
     
    13291375        if (_highlightedPlaces.contains(p.getName()))
    13301376        {
    1331             newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, "#FF0000", 0.75);
     1377            newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, "#FF7F27", transparency);
    13321378        }
    13331379        //Otherwise make it the normal colour
    13341380        else
    13351381        {
    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);
    13371383        }
    13381384
     
    17491795            public void onFailure(Throwable caught)
    17501796            {
    1751                 logToConsole("Find multi places fail" + caught.getMessage());
     1797                alert("Find multi places fail" + caught.getMessage());
    17521798            }
    17531799
     
    17571803                _statusBar.addUpdate("Displaying places", "DisPlaces");
    17581804
    1759                 logToConsole("Find multi places success");
    17601805                _currentMultiPlaces = places;
    17611806                _visiblePlaceSets = new ArrayList<Boolean>();
     
    19191964                for (int j = 0; j < textPlaces.length(); j++)
    19201965                {
    1921                     logToConsole("Attempting to match " + textPlaces.get(j).getAttribute("class") + " with place");
    19221966                    if (textPlaces.get(j).getAttribute("class").equals("place"))
    19231967                    {
     
    20312075        logToConsole("Adding columns to panel");
    20322076
    2033         if (_contentDiv.getWidget(0).getElement().getId() == "content")
     2077        if (_contentDiv.getWidget(0).getElement().getId() == "gs_content")
    20342078        {
    20352079            VerticalPanel newDocTextPanel = new VerticalPanel();
     
    21292173            if (event.getY() < 125)
    21302174            {
    2131                 logToConsole("1");
    21322175                _columnViewBox.getElement().getStyle().setProperty("top", (event.getY() + _label.getAbsoluteTop() + 25) + "px");
    21332176            }
    21342177            else
    21352178            {
    2136                 logToConsole("2");
    21372179                _columnViewBox.getElement().getStyle().setProperty("top", (event.getY() + _label.getAbsoluteTop() - 125) + "px");
    21382180            }
     
    28392881                    form.setWidget(tempForm);
    28402882
    2841                     tempFrameGetElementsByTagName("body").get(0).appendChild(form.getElement());
     2883                    getElementsByTagName("body").get(0).appendChild(form.getElement());
    28422884
    28432885                    logToConsole("Adding hidden form elements");
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/Menu.java

    r22277 r23906  
    55import com.google.gwt.event.dom.client.MouseOutHandler;
    66import com.google.gwt.event.dom.client.MouseOverHandler;
    7 import com.google.gwt.user.client.DOM;
    87import com.google.gwt.user.client.Element;
    98import com.google.gwt.user.client.Timer;
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/MenuItem.java

    r22277 r23906  
    44import com.google.gwt.user.client.DOM;
    55import com.google.gwt.user.client.Element;
    6 import com.google.gwt.user.client.ui.Label;
    76
    87public class MenuItem
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/Place.java

    r22272 r23906  
    22
    33import java.io.Serializable;
    4 import java.sql.Connection;
    5 import java.sql.DriverManager;
    6 import java.sql.ResultSet;
    7 import java.sql.Statement;
    84import java.util.ArrayList;
    9 
    10 import org.greenstone.server.ServerPlace;
    115
    126import com.google.gwt.user.client.rpc.AsyncCallback;
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/StatusBar.java

    r22272 r23906  
    1212    private ArrayList<String> _statusUpdates = new ArrayList<String>();
    1313   
    14     public StatusBar()
     14    private GS3MapLibrary _atlasInstance = null;
     15   
     16    public StatusBar(GS3MapLibrary atlasInstance)
    1517    {
    1618        _statusBarDiv.setStyleName("statusBar");
     19        _atlasInstance = atlasInstance;
    1720    }
    1821   
     
    4144        _statusUpdates.add(update);
    4245        updateStatusBar();
     46        _atlasInstance.resizeElements();
    4347    }
    4448   
     
    5458        _statusUpdates.set(index, null);
    5559        updateStatusBar();
     60        _atlasInstance.resizeElements();
    5661        return true;
    5762    }
     
    8287        {
    8388            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>";
    8590        }
    8691        _statusBarDiv.setHTML(status);
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/FindPlaceServiceImpl.java

    r22272 r23906  
    11package org.greenstone.server;
    22
     3import java.net.URLConnection;
    34import java.sql.Connection;
    45import java.sql.DriverManager;
     
    1011import org.greenstone.client.Place;
    1112
    12 import com.google.gwt.dom.client.Element;
    1313import com.google.gwt.user.server.rpc.RemoteServiceServlet;
    1414
     
    5858    }
    5959
    60     public ArrayList<ArrayList<Place>> findPlacesInMultipleTexts(ArrayList<String> texts)
     60    public ArrayList<ArrayList<Place>> findPlacesInMultipleTexts(String[] texts)
    6161    {
    6262        return _pageScanner.examineMultipleTexts(texts);
     
    9191               
    9292                _places = new ArrayList<Place>();
    93                 int count = 0;
     93
    9494                while(results.next())
    9595                {
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GateScanner.java

    r22272 r23906  
    44import gate.AnnotationSet;
    55import gate.Corpus;
    6 import gate.CorpusController;
    76import gate.Document;
    87import gate.Factory;
     
    109import gate.Gate;
    1110import gate.GateConstants;
    12 import gate.ProcessingResource;
    13 import gate.corpora.RepositioningInfo;
    1411import gate.creole.ANNIEConstants;
    15 import gate.creole.ResourceInstantiationException;
    1612import gate.creole.SerialAnalyserController;
    1713import gate.util.GateException;
     
    2218import java.net.URL;
    2319import java.util.ArrayList;
    24 import java.util.HashSet;
    25 import java.util.Iterator;
    26 import java.util.Set;
     20import java.util.HashMap;
    2721
    2822import org.apache.log4j.BasicConfigurator;
     
    3731        {
    3832            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"));
    4236            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());
    4438            Gate.getUserConfig().put(GateConstants.DOCUMENT_ADD_SPACE_ON_UNPACK_FEATURE_NAME, new Boolean(false));
    4539           
     
    7064    } // execute()
    7165   
    72     public ArrayList<Word> classifyText(String originalText)
     66    public HashMap<String, Word> classifyText(String originalText)
    7367    {
    74         ArrayList<Word> words = new ArrayList<Word>();
     68        HashMap<String, Word> words = new HashMap<String, Word>();
    7569        try
    7670        {
    77             // create a GATE corpus and add a document for each command-line
    78             // argument
    7971            Corpus corpus = (Corpus) Factory.createResource("gate.corpora.CorpusImpl");
    8072            FeatureMap params = Factory.newFeatureMap();
     
    9183            AnnotationSet annotations = doc.getAnnotations();
    9284           
    93             int index = 0;
    9485            for(int j = 0; j < annotations.size(); j++)
    9586            {
     
    10293                if(currentAnnotation.getType().equals("Token"))
    10394                {
    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                    }
    110109                }
    111110            }
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieFullNode.java

    r22272 r23906  
    22
    33import java.io.Serializable;
    4 import java.util.HashMap;
    54
    65public class GazetteerTrieFullNode implements Serializable
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieTopLevelNode.java

    r22272 r23906  
    22
    33import java.io.Serializable;
    4 import java.util.HashMap;
    54
    65public class GazetteerTrieTopLevelNode implements Serializable
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieType1.java

    r22272 r23906  
    22
    33import java.io.BufferedReader;
    4 import java.io.BufferedWriter;
    54import java.io.FileReader;
    6 import java.io.FileWriter;
    75import java.io.Serializable;
    8 import java.sql.Connection;
    9 import java.sql.DriverManager;
    106import java.sql.Statement;
    117import java.util.ArrayList;
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieType2.java

    r22272 r23906  
    22
    33import java.io.BufferedReader;
    4 import java.io.BufferedWriter;
    54import java.io.FileReader;
    6 import java.io.FileWriter;
    75import java.io.Serializable;
    8 import java.sql.Connection;
    9 import java.sql.DriverManager;
    106import java.sql.Statement;
    117import java.util.ArrayList;
     
    163159    public int checkPlaceName(String placeName)
    164160    {
    165         System.out.println("CHECKING PLACE NAME");
    166161        if (placeName.length() == 0)
    167162        {
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieType3.java

    r22272 r23906  
    22
    33import java.io.BufferedReader;
    4 import java.io.BufferedWriter;
    54import java.io.FileReader;
    6 import java.io.FileWriter;
    75import java.io.Serializable;
    8 import java.sql.Connection;
    9 import java.sql.DriverManager;
    106import java.sql.Statement;
    117import java.util.ArrayList;
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieType4.java

    r22272 r23906  
    22
    33import java.io.BufferedReader;
    4 import java.io.BufferedWriter;
    54import java.io.FileReader;
    6 import java.io.FileWriter;
    75import java.io.Serializable;
    8 import java.sql.Connection;
    9 import java.sql.DriverManager;
    106import java.sql.Statement;
    117import java.util.ArrayList;
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/GazetteerTrieType5.java

    r22272 r23906  
    22
    33import java.io.BufferedReader;
    4 import java.io.BufferedWriter;
    54import java.io.FileReader;
    6 import java.io.FileWriter;
    75import java.io.Serializable;
    8 import java.sql.Connection;
    9 import java.sql.DriverManager;
    10 import java.sql.Statement;
    116import java.util.ArrayList;
    127import java.util.HashMap;
    13 import java.util.HashSet;
    14 
    15 import com.sun.org.apache.bcel.internal.generic.NEW;
    168
    179public class GazetteerTrieType5 implements Serializable
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/PageScanner.java

    r22277 r23906  
    11package org.greenstone.server;
    22
     3import gate.util.Out;
     4
    35import java.io.BufferedReader;
     6import java.io.BufferedWriter;
     7import java.io.FileWriter;
    48import java.io.StringReader;
    59import java.util.ArrayList;
     
    2832    protected double _indirectReferencePenaltyPercentage = 0.25;
    2933    protected double _parentLimitPercentage = 0.05;
    30    
     34
    3135    protected ArrayList<String> _prevDoc = null;
    32     protected String _prevFileName = null; 
     36    protected String _prevFileName = null;
    3337
    3438    /**
     
    5963    public ArrayList<Place> examineTextWithGate(String text, String htmlString)
    6064    {
    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    {
    70223        _places.clear();
    71224        try
    72225        {
    73             ArrayList<Word> classifiedWords = _gateScanner.classifyText(text);
    74            
    75             // The file to read from
    76             BufferedReader file = new BufferedReader(new StringReader(text));
    77 
    78226            // Stores the current words being examined
    79227            StringBuilder currentWords = new StringBuilder();
    80228
    81             // Stores the current line being examined
    82             String currentLine = null;
    83 
    84             int htmlIndex = 0;
    85             int textIndex = 0;
    86             int cwindex = 0;
    87 
    88             // The list of words in the line
    89             ArrayList<String> words = new ArrayList<String>();
    90 
    91229            // 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            {
    99232                // Examine the words
    100233                for (int j = 0; j < words.size(); j++)
    101234                {
    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))))
    134238                    {
    135239                        continue;
     
    141245                    // Add the first word to the list of words to be examined
    142246                    currentWords.append(words.get(j));
    143                    
     247
    144248                    // While the gazetteer does not reach a dead end, add
    145249                    // another word and examine them
     
    151255                        {
    152256                            lastGoodPlaceName = currentWords.toString();
     257                            // System.out.println("Current place name part => "
     258                            // + lastGoodPlaceName);
    153259                        }
    154260
     
    169275                    if (lastGoodPlaceName != null)
    170276                    {
    171                         if (htmlString != null)
    172                         {
    173                             if (htmlIndex == -1)
    174                             {
    175                                 htmlIndex = oldHTMLIndex;
    176                             }
    177                             else
    178                             {
    179                                 html.insert(htmlIndex, "<span class=\"place\">");
    180                                 html.insert(htmlIndex + "<span class=\"place\">".length() + lastGoodPlaceName.length(), "</span>");
    181                             }
    182                         }
    183 
    184277                        ArrayList<Place> placeList = PlaceInformation.getPlaces(lastGoodPlaceName);
    185278
     
    188281                            continue;
    189282                        }
    190                        
     283
    191284                        if (_placeNameMap.containsKey(lastGoodPlaceName))
    192285                        {
    193                             for(Place p : _placeNameMap.get(lastGoodPlaceName))
     286                            for (Place p : _placeNameMap.get(lastGoodPlaceName))
    194287                            {
    195288                                p.directReference();
     
    203296                        }
    204297                    }
    205 
    206298                    currentWords = new StringBuilder();
    207299                }
    208300            }
    209             file.close();
    210301        }
    211302        catch (Exception ex)
     
    214305        }
    215306
    216         if (htmlString != null)
    217         {
    218             _markedUpText = html.toString();
    219         }
    220 
    221         if(_places.size() > 0)
    222         {
    223             adjustScores();
    224         }
     307        adjustScores();
    225308
    226309        return _places;
    227310    }
    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>();
    231315        _places.clear();
    232316        try
    233317        {
     318            // The file to read from
     319            BufferedReader file = new BufferedReader(new StringReader(text));
     320
    234321            // Stores the current words being examined
    235322            StringBuilder currentWords = new StringBuilder();
    236323
     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
    237330            // 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
    240338                // Examine the words
    241339                for (int j = 0; j < words.size(); j++)
     
    283381                    if (lastGoodPlaceName != null)
    284382                    {
    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);
    305384                    }
    306385                    currentWords = new StringBuilder();
    307386                }
    308387            }
     388            file.close();
    309389        }
    310390        catch (Exception ex)
     
    313393        }
    314394
     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
    315443        adjustScores();
    316444
     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
    317452        return _places;
    318453    }
    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    {
    323457        _places.clear();
    324458        try
     
    389523                    if (lastGoodPlaceName != null)
    390524                    {
    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             else
    423             {
    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         try
    467         {
    468             // The file to read from
    469             BufferedReader file = new BufferedReader(new StringReader(text));
    470 
    471             // Stores the current words being examined
    472             StringBuilder currentWords = new StringBuilder();
    473 
    474             // Stores the current line being examined
    475             String currentLine = null;
    476 
    477             // The list of words in the line
    478             ArrayList<String> words = new ArrayList<String>();
    479 
    480             // Read each line from the file
    481             while ((currentLine = file.readLine()) != null)
    482             {
    483                 words.clear();
    484 
    485                 // Find the words in those lines and add them to the list
    486                 words.addAll(MarkupService.findWords(currentLine));
    487 
    488                 // Examine the words
    489                 for (int j = 0; j < words.size(); j++)
    490                 {
    491                     // If the word does not begin with an uppercase letter then
    492                     // ignore it
    493                     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 name
    499                     String lastGoodPlaceName = null;
    500 
    501                     // Add the first word to the list of words to be examined
    502                     currentWords.append(words.get(j));
    503 
    504                     // While the gazetteer does not reach a dead end, add
    505                     // another word and examine them
    506                     int count = 1;
    507                     while (_gazetteer.checkPlaceName(currentWords.toString()) != -1)
    508                     {
    509                         // If the words are a place name then store it
    510                         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 next
    518                         // word
    519                         if (j + count < words.size())
    520                         {
    521                             currentWords.append(" " + words.get(j + count++));
    522                         }
    523                         else
    524                         {
    525                             break;
    526                         }
    527                     }
    528 
    529                     // If there was a place name found then find its information
    530                     // and score it
    531                     if (lastGoodPlaceName != null)
    532                     {
    533525                        ArrayList<Place> placeList = PlaceInformation.getPlaces(lastGoodPlaceName);
    534526
     
    540532                        if (_placeNameMap.containsKey(lastGoodPlaceName))
    541533                        {
    542                             for(Place p : _placeNameMap.get(lastGoodPlaceName))
     534                            for (Place p : _placeNameMap.get(lastGoodPlaceName))
    543535                            {
    544536                                p.directReference();
     
    561553            ex.printStackTrace();
    562554        }
    563        
     555
    564556        // System.out.println("Done!");
    565557        // System.out.print("Adjusting Scores... ");
     
    579571        return _markedUpText;
    580572    }
    581    
     573
    582574    public Place getTopScorePlace()
    583575    {
    584576        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())
    589581            {
    590582                p = pp;
     
    600592    public void adjustScores()
    601593    {
    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
    610602        Place topScore = getTopScorePlace();
    611        
    612         for(Place p : _places)
     603
     604        for (Place p : _places)
    613605        {
    614606            if (p.getParentPlaceName() == null)
     
    616608                continue;
    617609            }
    618            
     610
    619611            for (Place pp : _places)
    620612            {
    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)));
    624616                }
    625617            }
     
    651643            p.setScore(scoreToAdd);
    652644            _places.add(p);
    653            
    654             if(_placeNameMap.containsKey(p.getName()))
     645
     646            if (_placeNameMap.containsKey(p.getName()))
    655647            {
    656648                _placeNameMap.get(p.getName()).add(p);
     
    709701        }
    710702    }
    711 
    712703
    713704    public void sortScores()
     
    803794        _indirectReferencePenaltyPercentage = indirectReferencePenaltyPercentage;
    804795    }
    805    
     796
    806797    public void setScoringParams(ScanConfiguration config)
    807798    {
     
    815806    // {
    816807    // HashMap<String, Integer> wordCountMap = new HashMap<String, Integer>();
    817     //     
     808    //
    818809    // try
    819810    // {
    820811    // BufferedReader file = new BufferedReader(new FileReader(fileName));
    821     //     
     812    //
    822813    // StringBuilder currentWord = new StringBuilder();
    823     // 
     814    //
    824815    // String line = "";
    825     //         
     816    //
    826817    // ArrayList<String> words = new ArrayList<String>();
    827     //         
     818    //
    828819    // //System.out.print("Finding words... ");
    829820    // while((line = file.readLine()) != null)
     
    832823    // }
    833824    // //System.out.println("Done!");
    834     //         
     825    //
    835826    // //System.out.print("Adding up scores... ");
    836827    // for(int j = 0; j < words.size(); j++)
     
    840831    // //continue;
    841832    // }
    842     //             
     833    //
    843834    // currentWord.append(words.get(j));
    844     //                 
     835    //
    845836    // int count = 1;
    846837    // while(_gazetteer.checkPlaceName(currentWord.toString()) != -1)
     
    860851    // currentWord.append(" " + words.get(j + count++));
    861852    // }
    862     //             
     853    //
    863854    // currentWord.delete(0, currentWord.length());
    864855    // }
     
    868859    // ex.printStackTrace();
    869860    // }
    870     //     
     861    //
    871862    // return wordCountMap;
    872863    // }
     
    877868    }
    878869
    879     public ArrayList<ArrayList<Place>> examineMultipleTexts(ArrayList<String> texts)
     870    public ArrayList<ArrayList<Place>> examineMultipleTexts(String[] texts)
    880871    {
    881872        ArrayList<ArrayList<Place>> multipleResults = new ArrayList<ArrayList<Place>>();
     
    884875            if (text != null)
    885876            {
    886                 this.examineTextWithGate(text, null);
    887                
    888                 if(_places.size() > 0)
     877                this.examineTextWithGate(null, text);
     878
     879                if (_places.size() > 0)
    889880                {
    890881                    multipleResults.add(new ArrayList<Place>(_places));
     
    903894        return multipleResults;
    904895    }
    905    
     896
    906897    public ArrayList<Place> getPlaces()
    907898    {
    908899        return _places;
    909900    }
    910    
     901
    911902    public void clearPlaces()
    912903    {
     
    917908/*
    918909 *
    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 */
    1008974// Add part of the parent's score to the child
    1009975// *******************************************
    1010976/*
    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  
    2323            System.out.print("Loading postgresql driver... ");
    2424            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");
    2626            System.out.println("Done!");
    2727            _database = c.createStatement();
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/ScanResultSet.java

    r22272 r23906  
    11package org.greenstone.server;
    22
    3 import java.sql.ResultSet;
    43import java.util.ArrayList;
    54import java.util.HashMap;
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/ServerPlace.java

    r22272 r23906  
    22
    33import 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 
    104import org.greenstone.client.Place;
    115
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/ServerSideTests.java

    r22272 r23906  
    22
    33import java.awt.BorderLayout;
    4 import java.awt.FlowLayout;
    54import java.awt.GridLayout;
    65import java.awt.event.ActionEvent;
     
    98import java.io.BufferedWriter;
    109import java.io.DataOutputStream;
    11 import java.io.File;
    12 import java.io.FileInputStream;
    13 import java.io.FileNotFoundException;
    14 import java.io.FileOutputStream;
    1510import java.io.FileReader;
    1611import java.io.FileWriter;
    17 import java.io.IOException;
    1812import java.io.InputStreamReader;
    19 import java.io.ObjectInputStream;
    20 import java.io.ObjectOutputStream;
    21 import java.io.OutputStream;
    22 import java.io.Reader;
    2313import java.net.HttpURLConnection;
    2414import java.net.URL;
     
    2818import java.sql.Statement;
    2919import java.util.ArrayList;
    30 import java.util.Timer;
    31 import java.util.TimerTask;
    3220import java.util.HashMap;
    3321import java.util.TreeMap;
    3422
    35 import javax.servlet.Servlet;
    3623import javax.swing.ButtonGroup;
    3724import javax.swing.JButton;
     
    4734import org.greenstone.client.Place;
    4835
    49 import com.sun.xml.internal.ws.wsdl.writer.document.soap.Body;
    50 
    5136public class ServerSideTests
    5237{
     
    6954    public void go()
    7055    {
     56        DatabaseFix();
     57        //PlacesToPoints();
    7158        // ExperimentSetUp();
    7259        //PrecisionExperiment();
     
    7461        //GazetteerTest();
    7562        //ModPlaceNames();
    76         analyseResults();
     63        //analyseResults();
    7764    }
    7865   
     
    488475                //BufferedReader file = new BufferedReader(new FileReader("/home/sam/Desktop/Research/GNSDocs/" + filenames[i] + ".html"));
    489476
    490                 ArrayList<ArrayList<String>> lines = new ArrayList<ArrayList<String>>();
    491477                StringBuilder text = new StringBuilder();
    492478                String line = null;
     
    682668            while ((line = in.readLine()) != null)
    683669            {   
    684                 if (line == null)
    685                 {
    686                     return;
    687                 }
    688 
    689670                for (String word : line.split(" "))
    690671                {
     
    740721        {
    741722            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");
    743724
    744725            database = c.createStatement();
     
    775756        {
    776757            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");
    778759
    779760            database = c.createStatement();
    780761
    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"));
    782763
    783764            String line = "";
     
    876857        {
    877858            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");
    879860
    880861            database = c.createStatement();
  • gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/Word.java

    r22272 r23906  
    11package org.greenstone.server;
     2
     3import java.util.ArrayList;
    24
    35public class Word
    46{
     7    private int _classificationIndex = 0;
     8    private ArrayList<String> _classifications = new ArrayList<String>();
     9   
    510    private String _value = null;
    6     private String _classification = null;
    7     private long _index = -1;
    811   
    912    public void setValue(String value)
     
    1215    }
    1316   
    14     public void setClassification(String classification)
     17    public void addClassification(String classification)
    1518    {
    16         _classification = classification;
    17     }
    18    
    19     public void setIndex(long index)
    20     {
    21         _index = index;
     19        _classifications.add(classification);
    2220    }
    2321   
     
    2725    }
    2826   
    29     public String getClassification()
     27    public String getNextClassification()
    3028    {
    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++);
    4234    }
    4335}
Note: See TracChangeset for help on using the changeset viewer.