Plugin Directory

Changeset 685224


Ignore:
Timestamp:
03/21/2013 02:30:23 PM (13 years ago)
Author:
chr15
Message:

Updated Core Library to 2.0.5

Location:
summy/trunk/lib/Summy
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • summy/trunk/lib/Summy/Core.php

    r664156 r685224  
    33/**
    44 * @package     Summy
    5  * @version     $Id: Core.php 105 2013-02-05 00:44:51Z Tefra $
     5 * @version     $Id: Core.php 128 2013-03-17 23:44:07Z Tefra $
    66 * @author      Christodoulos Tsoulloftas
    77 * @copyright   Copyright 2011-2013, http://www.komposta.net
     
    155155            'language' => 'gr',
    156156            'termScore' => 'tfisf',
    157             'positionScore' => 'news',
     157            'positionScore' => 'article',
    158158            'minWordsLimit' => 6,
    159159            'maxWordsLimit' => 20,
     
    187187        $text = $textFilter->clear($text);
    188188        $text = $textFilter->process($text);
    189         $terms = array_unique(explode(" ", $text));
     189        $terms = array_filter(explode(" ", $text));
    190190        foreach($terms AS $term)
    191191        {
     
    193193            {
    194194                $term = $filter->filter($term);
     195                if($term === false)
     196                {
     197                    break;
     198                }
    195199            }
    196200
     
    238242
    239243            $i = 0;
    240             $total = ceil(($this->config['rate'] / 100)  * $this->totalSentences);
     244            $total = ceil(($this->config['rate'] / 100) * $this->totalSentences);
    241245            $indexes = array_keys($this->sentenceScores);
    242246            //Grab the top x sentences
     
    258262
    259263    /**
    260      * Process senteces, words and produce the core statistics
     264     * Process sentences, words and produce the core statistics
    261265     * - Loop through sentences
    262266     * - Extra text filtering
     
    355359
    356360    /**
    357      * Fetch the summary body
     361     * Returns the summary body
    358362     * @return string
    359363     */
     
    365369
    366370    /**
    367      * Fetch the original text with the summary sentences highlighted
     371     * Returns the original text with the summary sentences highlighted
    368372     * @return string
    369373     */
     
    386390    /**
    387391     *
    388      * @var type 
     392     * @var type
    389393     */
    390394    static $instances = array();
    391395
    392396    /**
    393      * 
     397     *
    394398     * @return type
    395399     */
  • summy/trunk/lib/Summy/Filter/En/Stemmer.php

    r664156 r685224  
    77 *
    88 * @package     Summy
    9  * @version     $Id: Stemmer.php 88 2013-02-04 13:25:53Z Tefra $
     9 * @version     $Id: Stemmer.php 128 2013-03-17 23:44:07Z Tefra $
    1010 * @author      Christodoulos Tsoulloftas
    1111 * @copyright   Copyright 2011-2013, http://www.komposta.net
     
    145145                break;
    146146
    147             case 'S':
     147            case 'T':
    148148                self::replace($word, 'BILITI', 'BLE', 0) OR self::replace($word, 'ALITI', 'AL', 0) OR self::replace($word, 'IVITI', 'IVE', 0);
    149149                break;
  • summy/trunk/lib/Summy/Filter/En/Text.php

    r664156 r685224  
    33/**
    44 * @package     Summy
    5  * @version     $Id: Text.php 103 2013-02-04 21:56:04Z Tefra $
     5 * @version     $Id: Text.php 128 2013-03-17 23:44:07Z Tefra $
    66 * @author      Christodoulos Tsoulloftas
    77 * @copyright   Copyright 2011-2013, http://www.komposta.net
     
    2929            return $string;
    3030        }
    31        
     31
    3232        // Make Paragraphs from html
    3333        $string = str_replace('</p>', "\n", $string);
  • summy/trunk/lib/Summy/Filter/Gr/Stemmer.php

    r664156 r685224  
    1919 *
    2020 * @package     Summy
    21  * @version     $Id: Stemmer.php 88 2013-02-04 13:25:53Z Tefra $
     21 * @version     $Id: Stemmer.php 112 2013-03-06 21:56:52Z Tefra $
    2222 * @author      Christodoulos Tsoulloftas
    2323 * @copyright   Copyright 2011-2013, http://www.komposta.net
     
    119119
    120120        //Step1
    121         if(preg_match($this->step1regexp, $w))
    122         {
    123             preg_match($this->step1regexp, $w, $fp);
     121        if(preg_match($this->step1regexp, $w, $fp))
     122        {
    124123            $stem = $fp[1];
    125124            $suffix = $fp[2];
     
    130129        // Step 2a
    131130        $re = '/^(.+?)(ΑΔΕΣ|ΑΔΩΝ)$/u';
    132         if(preg_match($re, $w))
    133         {
    134             preg_match($re, $w, $fp);
     131        if(preg_match($re, $w, $fp))
     132        {
    135133            $stem = $fp[1];
    136134            $w = $stem;
     
    144142        //Step 2b
    145143        $re = '/^(.+?)(ΕΔΕΣ|ΕΔΩΝ)$/u';
    146         if(preg_match($re, $w))
    147         {
    148             preg_match($re, $w, $fp);
     144        if(preg_match($re, $w, $fp))
     145        {
    149146            $stem = $fp[1];
    150147            $w = $stem;
     
    158155        //Step 2c
    159156        $re = '/^(.+?)(ΟΥΔΕΣ|ΟΥΔΩΝ)$/u';
    160         if(preg_match($re, $w))
    161         {
    162             preg_match($re, $w, $fp);
     157        if(preg_match($re, $w, $fp))
     158        {
    163159            $stem = $fp[1];
    164160            $w = $stem;
     
    173169        //Step 2d
    174170        $re = '/^(.+?)(ΕΩΣ|ΕΩΝ)$/u';
    175         if(preg_match($re, $w))
    176         {
    177             preg_match($re, $w, $fp);
     171        if(preg_match($re, $w, $fp))
     172        {
    178173            $stem = $fp[1];
    179174            $w = $stem;
     
    189184        //Step 3
    190185        $re = '/^(.+?)(ΙΑ|ΙΟΥ|ΙΩΝ)$/u';
    191         if(preg_match($re, $w))
    192         {
    193             preg_match($re, $w, $fp);
     186        if(preg_match($re, $w, $fp))
     187        {
    194188            $stem = $fp[1];
    195189            $w = $stem;
     
    205199        //Step 4
    206200        $re = '/^(.+?)(ΙΚΑ|ΙΚΟ|ΙΚΟΥ|ΙΚΩΝ)$/u';
    207         if(preg_match($re, $w))
    208         {
    209             preg_match($re, $w, $fp);
     201        if(preg_match($re, $w, $fp))
     202        {
    210203            $stem = $fp[1];
    211204            $w = $stem;
     
    228221        }
    229222
    230         if(preg_match($re2, $w))
    231         {
    232             preg_match($re2, $w, $fp);
    233             $stem = $fp[1];
    234             $w = $stem;
    235             $test1 = false;
    236         }
    237 
    238         if(preg_match($re, $w))
    239         {
    240             preg_match($re, $w, $fp);
     223        if(preg_match($re2, $w, $fp))
     224        {
     225            $stem = $fp[1];
     226            $w = $stem;
     227            $test1 = false;
     228        }
     229
     230        if(preg_match($re, $w, $fp))
     231        {
    241232            $stem = $fp[1];
    242233            $w = $stem;
     
    254245        $re3 = '/^(.+?)(ΑΓΑΝΕ|ΗΣΑΝΕ|ΟΥΣΑΝΕ|ΙΟΝΤΑΝΕ|ΙΟΤΑΝΕ|ΙΟΥΝΤΑΝΕ|ΟΝΤΑΝΕ|ΟΤΑΝΕ|ΟΥΝΤΑΝΕ|ΗΚΑΝΕ|ΗΘΗΚΑΝΕ)$/u';
    255246
    256         if(preg_match($re3, $w))
    257         {
    258             preg_match($re3, $w, $fp);
     247        if(preg_match($re3, $w, $fp))
     248        {
    259249            $stem = $fp[1];
    260250            $w = $stem;
     
    268258        }
    269259
    270         if(preg_match($re2, $w))
    271         {
    272             preg_match($re2, $w, $fp);
     260        if(preg_match($re2, $w, $fp))
     261        {
    273262            $stem = $fp[1];
    274263            $w = $stem;
     
    287276        $re4 = '/^(.+?)(ΗΣΕΤΕ)$/u';
    288277
    289         if(preg_match($re4, $w))
    290         {
    291             preg_match($re4, $w, $fp);
    292             $stem = $fp[1];
    293             $w = $stem;
    294             $test1 = false;
    295         }
    296 
    297         if(preg_match($re3, $w))
    298         {
    299             preg_match($re3, $w, $fp);
     278        if(preg_match($re4, $w, $fp))
     279        {
     280            $stem = $fp[1];
     281            $w = $stem;
     282            $test1 = false;
     283        }
     284
     285        if(preg_match($re3, $w, $fp))
     286        {
    300287            $stem = $fp[1];
    301288            $w = $stem;
     
    316303        //Step 5d
    317304        $re = '/^(.+?)(ΟΝΤΑΣ|ΩΝΤΑΣ)$/u';
    318         if(preg_match($re, $w))
    319         {
    320             preg_match($re, $w, $fp);
     305        if(preg_match($re, $w, $fp))
     306        {
    321307            $stem = $fp[1];
    322308            $w = $stem;
     
    337323        //Step 5e
    338324        $re = '/^(.+?)(ΟΜΑΣΤΕ|ΙΟΜΑΣΤΕ)$/u';
    339         if(preg_match($re, $w))
    340         {
    341             preg_match($re, $w, $fp);
     325        if(preg_match($re, $w, $fp))
     326        {
    342327            $stem = $fp[1];
    343328            $w = $stem;
     
    355340        $re2 = '/^(.+?)(ΙΕΣΤΕ)$/u';
    356341
    357         if(preg_match($re2, $w))
    358         {
    359             preg_match($re2, $w, $fp);
     342        if(preg_match($re2, $w, $fp))
     343        {
    360344            $stem = $fp[1];
    361345            $w = $stem;
     
    369353        }
    370354
    371         if(preg_match($re, $w))
    372         {
    373             preg_match($re, $w, $fp);
     355        if(preg_match($re, $w, $fp))
     356        {
    374357            $stem = $fp[1];
    375358            $w = $stem;
     
    387370        $re2 = '/^(.+?)(ΗΘΗΚΑ|ΗΘΗΚΕΣ|ΗΘΗΚΕ)$/u';
    388371
    389         if(preg_match($re2, $w))
    390         {
    391             preg_match($re2, $w, $fp);
    392             $stem = $fp[1];
    393             $w = $stem;
    394             $test1 = false;
    395         }
    396 
    397         if(preg_match($re, $w))
    398         {
    399             preg_match($re, $w, $fp);
     372        if(preg_match($re2, $w, $fp))
     373        {
     374            $stem = $fp[1];
     375            $w = $stem;
     376            $test1 = false;
     377        }
     378
     379        if(preg_match($re, $w, $fp))
     380        {
    400381            $stem = $fp[1];
    401382            $w = $stem;
     
    412393        //Step 5h
    413394        $re = '/^(.+?)(ΟΥΣΑ|ΟΥΣΕΣ|ΟΥΣΕ)$/u';
    414         if(preg_match($re, $w))
    415         {
    416             preg_match($re, $w, $fp);
     395        if(preg_match($re, $w, $fp))
     396        {
    417397            $stem = $fp[1];
    418398            $w = $stem;
     
    430410        $re = '/^(.+?)(ΑΓΑ|ΑΓΕΣ|ΑΓΕ)$/u';
    431411
    432         if(preg_match($re, $w))
    433         {
    434             preg_match($re, $w, $fp);
     412        if(preg_match($re, $w, $fp))
     413        {
    435414            $stem = $fp[1];
    436415            $w = $stem;
     
    450429        //Step 5j
    451430        $re = '/^(.+?)(ΗΣΕ|ΗΣΟΥ|ΗΣΑ)$/u';
    452         if(preg_match($re, $w))
    453         {
    454             preg_match($re, $w, $fp);
     431        if(preg_match($re, $w, $fp))
     432        {
    455433            $stem = $fp[1];
    456434            $w = $stem;
     
    466444        //Step 5k
    467445        $re = '/^(.+?)(ΗΣΤΕ)$/u';
    468         if(preg_match($re, $w))
    469         {
    470             preg_match($re, $w, $fp);
     446        if(preg_match($re, $w, $fp))
     447        {
    471448            $stem = $fp[1];
    472449            $w = $stem;
     
    482459        //Step 5l
    483460        $re = '/^(.+?)(ΟΥΝΕ|ΗΣΟΥΝΕ|ΗΘΟΥΝΕ)$/u';
    484         if(preg_match($re, $w))
    485         {
    486             preg_match($re, $w, $fp);
     461        if(preg_match($re, $w, $fp))
     462        {
    487463            $stem = $fp[1];
    488464            $w = $stem;
     
    498474        //Step 5l
    499475        $re = '/^(.+?)(ΟΥΜΕ|ΗΣΟΥΜΕ|ΗΘΟΥΜΕ)$/u';
    500         if(preg_match($re, $w))
    501         {
    502             preg_match($re, $w, $fp);
     476        if(preg_match($re, $w, $fp))
     477        {
    503478            $stem = $fp[1];
    504479            $w = $stem;
     
    515490        $re = '/^(.+?)(ΜΑΤΑ|ΜΑΤΩΝ|ΜΑΤΟΣ)$/u';
    516491        $re2 = '/^(.+?)(Α|ΑΓΑΤΕ|ΑΓΑΝ|ΑΕΙ|ΑΜΑΙ|ΑΝ|ΑΣ|ΑΣΑΙ|ΑΤΑΙ|ΑΩ|Ε|ΕΙ|ΕΙΣ|ΕΙΤΕ|ΕΣΑΙ|ΕΣ|ΕΤΑΙ|Ι|ΙΕΜΑΙ|ΙΕΜΑΣΤΕ|ΙΕΤΑΙ|ΙΕΣΑΙ|ΙΕΣΑΣΤΕ|ΙΟΜΑΣΤΑΝ|ΙΟΜΟΥΝ|ΙΟΜΟΥΝΑ|ΙΟΝΤΑΝ|ΙΟΝΤΟΥΣΑΝ|ΙΟΣΑΣΤΑΝ|ΙΟΣΑΣΤΕ|ΙΟΣΟΥΝ|ΙΟΣΟΥΝΑ|ΙΟΤΑΝ|ΙΟΥΜΑ|ΙΟΥΜΑΣΤΕ|ΙΟΥΝΤΑΙ|ΙΟΥΝΤΑΝ|Η|ΗΔΕΣ|ΗΔΩΝ|ΗΘΕΙ|ΗΘΕΙΣ|ΗΘΕΙΤΕ|ΗΘΗΚΑΤΕ|ΗΘΗΚΑΝ|ΗΘΟΥΝ|ΗΘΩ|ΗΚΑΤΕ|ΗΚΑΝ|ΗΣ|ΗΣΑΝ|ΗΣΑΤΕ|ΗΣΕΙ|ΗΣΕΣ|ΗΣΟΥΝ|ΗΣΩ|Ο|ΟΙ|ΟΜΑΙ|ΟΜΑΣΤΑΝ|ΟΜΟΥΝ|ΟΜΟΥΝΑ|ΟΝΤΑΙ|ΟΝΤΑΝ|ΟΝΤΟΥΣΑΝ|ΟΣ|ΟΣΑΣΤΑΝ|ΟΣΑΣΤΕ|ΟΣΟΥΝ|ΟΣΟΥΝΑ|ΟΤΑΝ|ΟΥ|ΟΥΜΑΙ|ΟΥΜΑΣΤΕ|ΟΥΝ|ΟΥΝΤΑΙ|ΟΥΝΤΑΝ|ΟΥΣ|ΟΥΣΑΝ|ΟΥΣΑΤΕ|Υ|ΥΣ|Ω|ΩΝ)$/u';
    517         if(preg_match($re, $w))
    518         {
    519             preg_match($re, $w, $fp);
     492        if(preg_match($re, $w, $fp))
     493        {
    520494            $stem = $fp[1];
    521495            $w = $stem . "ΜΑ";
    522496        }
    523497
    524         if(preg_match($re2, $w) && $test1)
    525         {
    526             preg_match($re2, $w, $fp);
     498        if(preg_match($re2, $w, $fp) && $test1)
     499        {
    527500            $stem = $fp[1];
    528501            $w = $stem;
     
    531504        // Step 7 (ΠΑΡΑΘΕΤΙΚΑ)
    532505        $re = '/^(.+?)(ΕΣΤΕΡ|ΕΣΤΑΤ|ΟΤΕΡ|ΟΤΑΤ|ΥΤΕΡ|ΥΤΑΤ|ΩΤΕΡ|ΩΤΑΤ)$/u';
    533         if(preg_match($re, $w))
    534         {
    535             preg_match($re, $w, $fp);
     506        if(preg_match($re, $w, $fp))
     507        {
    536508            $stem = $fp[1];
    537509            $w = $stem;
  • summy/trunk/lib/Summy/Score/Position.php

    r664156 r685224  
    33/**
    44 * @package     Summy
    5  * @version     $Id: Position.php 93 2013-02-04 18:26:25Z Tefra $
     5 * @version     $Id: Position.php 117 2013-03-16 16:37:14Z Tefra $
    66 * @author      Christodoulos Tsoulloftas
    77 * @copyright   Copyright 2011-2013, http://www.komposta.net
     
    3030
    3131    /**
    32      * Return the Position Weight for a sentence based on the Baxendale investigation
     32     * Returns the Position Weight for a sentence based on the Baxendale investigation
    3333     *
    3434     * Baxendale (1958) investigated a sample of 200 paragraphs to determine
     
    5858
    5959    /**
    60      * Return the Position Weight for a sentence based on the hypothesis that
    61      * first paragraphs/sentences are the most meaningfull to a document, which
     60     * Returns the Position Weight for a sentence based on the hypothesis that
     61     * first paragraphs/sentences are the most meaningful to a document, which
    6262     * applies to small articles, like newspaper news.
    6363     *
     
    6868     * @return float
    6969     */
    70     public function news($totalParagraphs, $sentencesInParagraph, $paragraph, $sentence)
     70    public function article($totalParagraphs, $sentencesInParagraph, $paragraph, $sentence)
    7171    {
    7272        return (($totalParagraphs - $paragraph + 1) / $totalParagraphs) * (($sentencesInParagraph - $sentence + 1) / $sentencesInParagraph);
  • summy/trunk/lib/Summy/Score/Term.php

    r664156 r685224  
    33/**
    44 * @package     Summy
    5  * @version     $Id: Term.php 93 2013-02-04 18:26:25Z Tefra $
     5 * @version     $Id: Term.php 125 2013-03-16 17:49:26Z Tefra $
    66 * @author      Christodoulos Tsoulloftas
    77 * @copyright   Copyright 2011-2013, http://www.komposta.net
     
    1616    /**
    1717     * Language identifier (gr,en)
    18      * @var string 
     18     * @var string
    1919     */
    2020    private $_language = null;
     
    2222    /**
    2323     * Database adapter
    24      * @var object 
     24     * @var object
    2525     */
    2626    private $_dbAdapter = null;
     
    122122
    123123    /**
    124      * Rank sentences by TF-ISF http://en.wikipedia.org/wiki/Tf-idf
     124     * Rank sentences by TF-IDF http://en.wikipedia.org/wiki/Tf-idf
    125125     *
    126126     * @param integer $totalSentences
     
    138138        $sql = $db->query("SELECT COUNT(*) as total FROM document WHERE language = ?", array($language))->current();
    139139        $totalDocuments = $sql['total'] + 1;
    140         $terms = $db->platform->quoteValueList(array_keys($tf));
    141         $sql = $db->query("SELECT id, documents FROM term WHERE id IN ({$terms}) AND language = ?", array($language));
    142 
     140        $terms = implode(',', array_map(array($db->driver->getConnection()->getResource(), 'quote'), array_keys($tf)));
     141        $sql = $db->query("SELECT term, documents FROM term WHERE term IN ({$terms}) AND language = ?", array($language));
    143142        foreach($sql AS $row)
    144143        {
    145             $docFreq[$row['id']] = $row['documents'];
     144            $docFreq[$row['term']] = $row['documents'];
    146145        }
    147146
     
    171170    public function tfridf($totalSentences, $tf = array(), $sf = array())
    172171    {
    173         $wordScore = $docFreq =  $totFreq = array();
     172        $wordScore = $docFreq = $totFreq = array();
    174173        $totalWords = array_sum($tf);
    175174        $db = $this->getAdapter();
     
    177176        $sql = $db->query("SELECT COUNT(*) as total FROM document WHERE language = ?", array($language))->current();
    178177        $totalDocuments = $sql['total'] + 1;
    179         $terms = $db->platform->quoteValueList(array_keys($tf));
    180         $sql = $db->query("SELECT id, frequency, documents FROM term WHERE id IN ({$terms}) AND language = ?", array($language));
     178        $terms = implode(',', array_map(array($db->driver->getConnection()->getResource(), 'quote'), array_keys($tf)));
     179        $sql = $db->query("SELECT term, frequency, documents FROM term WHERE term IN ({$terms}) AND language = ?", array($language));
    181180
    182181        foreach($sql AS $row)
    183182        {
    184             $docFreq[$row['id']] = $row['documents'];
    185             $totFreq[$row['id']] = $row['frequency'];
     183            $docFreq[$row['term']] = $row['documents'];
     184            $totFreq[$row['term']] = $row['frequency'];
    186185        }
    187186
    188187        foreach($tf AS $word => $frequency)
    189188        {
    190             $docFreq[$word] += 1;
    191             $totFreq[$word] += $frequency;
     189            $docFreq[$word] = isset($docFreq[$word]) ? $docFreq[$word] + 1 : 1;
     190            $totFreq[$word] = isset($totFreq[$word]) ? $totFreq[$word] + $frequency : $frequency;
    192191            // Normalized frequency
    193192            $_tf = $frequency / $totalWords;
Note: See TracChangeset for help on using the changeset viewer.