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
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • 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 */
Note: See TracChangeset for help on using the changeset viewer.