Error when calling Amarok::decapitateString()

Pavel Shved pavel.shved at gmail.com
Sat Jan 17 03:14:44 UTC 2009


Bart Cerneels wrote:
> On Thu, Jan 8, 2009 at 10:56 PM, Pavel Shved <pavel.shved at gmail.com> wrote:
>> Mark Kretschmann wrote:
>>
>>> Cool. It would be great if you could send us a patch when you are done
>>> fixing it :)
>> Hm, now i tihnk i should've just sent a patch instead of long description.
>>
>> Please, check the file attached and test cases there--in case i
>> misunderstood the function's purpose.  If it's OK, commit it to appropriate
>> place; don't think you allow anonymous users into your svn.
>>
>>
>>
>>
>> #include <iostream>
>>
>> #include <qt4/QtCore/QString>
>>
>>    /* Strip the common prefix of two strings from the first one and trim
>>     * whitespaces from the beginning of the resultant string.
>>     * Case-insensitive.
>>     *
>>     * @param input the string being processed
>>     * @param ref the string used to determine prefix
>>     */
>>    QString decapitateString( const QString &input, const QString &ref )
>>    {
>>        //Sometimes it's good to be c-like...
>>        int len;    //the length of common prefix calculated so far
>>        for (len = 0; len<input.length() && len<ref.length(); len++){
>>            if (input.at(len).toUpper() != ref.at(len).toUpper())
>>                break;
>>        }
>>
>>        return input.right(input.length() - len).trimmed();
>>    }
>>
>>
>>
>> int main()
>> {
>>    using namespace std;
>>    //let's test it
>>    QString p[][3] = {
>>        //argument1, argument2, correct answer
>>        {"simple prefix","simple test","prefix"},
>>        {"just", "test", "just"},
>>        {"ContainsOther","Contains","Other"},
>>        {"Contains","ContainsOther",""},
>>        {"Equals","Equals",""},
>>        {"","",""},
>>        {"","AnotherIsEmpty",""},
>>        {"AnotherIsEmpty","","AnotherIsEmpty"},
>>        {"","something",""},
>>        {"something","","something"},
>>        {"   \t  ","   whatever",""},
>>        {"sEvERal wOrDs in One StrinG","several words indeed!","One StrinG"},
>>        {"sEvERal wOrDs  --  now it's more simple","several words, yeah!","--
>>  now it's more simple"},
>>    };
>>    int const num = 13;
>>    int failed = num;
>>    for (int i = 0; i<num ; i++){
>>        cout << "Test "<<(i+1)<<" ";
>>        QString res = decapitateString(p[i][0],p[i][1]);
>>        if (res == p[i][2]){
>>            cout <<"ok"<<endl;
>>            failed--;
>>        }else{
>>            cout <<"FAIL:
>> "<<"f(`"<<p[i][0].toStdString()<<"',`"<<p[i][1].toStdString()<<"')"<<endl
>>                <<"  yields  "<<res.toStdString()<<endl
>>                <<"  must be "<<p[i][2].toStdString()<<endl;
>>        }
>>    }
>>    cerr << failed << " tests failed."<<endl;
>>    return failed;
>> }
>>
> 
> Hey Pavel,
> 
> If you can also solve these cases I'll probably use your code.
> 
> {"This Podcast","This Podcast: January 14, 2009","January 14, 2009"}
> {"Podcast Title","Podcast Title #001","#001"}
> {"The funnycast","Funnycast 042: The Answer","042: The Answer"}
> 
> 
> Perhaps you have suggestions of how to solve these without false positives:
> {"::Title with ascii art::","::Title with ascii art:: for January 14,
> 2009","January 14, 2009"}
> 
> Look here to find more examples of the "creative" naming Podcasters
> practice: http://podcastpickle.com/index/featured.php?id=top100audio
> 
> Remember, the reason we have decapitateString is because the
> PlaylistBrowser has a limited width. We try to strip common data in
> titles so we don't lose all relevant info to
> QFontMetrics::elidedText().


It seems i forgot to post mail to the mailig list or something. sorry 
for duplicate if any...

Bart Cerneels wrote:
 > If you can also solve these cases I'll probably use your code.
 >
 > {"This Podcast","This Podcast: January 14, 2009","January 14, 2009"}
 > {"Podcast Title","Podcast Title #001","#001"} {"The
 > funnycast","Funnycast 042: The Answer","042: The Answer"}

You obviously meant
{"This Podcast: January 14, 2009","This Podcast","January 14, 2009"},
{"Podcast Title #001","Podcast Title","#001"},
{"Funnycast 042: The Answer","The funnycast","042: The Answer"}.

 > Look here to find more examples of the "creative" naming Podcasters
 > practice: http://podcastpickle.com/index/featured.php?id=top100audio

Then i propose the following algorithm: we compare podcast title and two
`episode' names.  The prefix to withdraw is obtained from tow episode
names, not from one episode and total title (like it's done now).

The podcast title is then used to decide whether the prefix being
withdrawn is podcast title, not just common part of two songs: if common
substring of prefix and title takes reasonable part of title (like 80%),
then we calmly think that we found common prefix.  If it's not, then we
do nothing and leave long titles.

Pavel.






More information about the Amarok mailing list