Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F101108353
PhutilSearchStemmerTestCase.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 5, 20:03
Size
1 KB
Mime Type
text/x-php
Expires
Fri, Feb 7, 20:03 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24093583
Attached To
rPHU libphutil
PhutilSearchStemmerTestCase.php
View Options
<?php
final
class
PhutilSearchStemmerTestCase
extends
PhutilTestCase
{
public
function
testStemTokens
()
{
$tests
=
array
(
// Various real-world cases collected from users before we implemented
// stemming.
'tokens'
=>
'token'
,
'panels'
=>
'panel'
,
'renames'
=>
'renam'
,
'rename'
=>
'renam'
,
'components'
=>
'compon'
,
'component'
=>
'compon'
,
'implementation'
=>
'implement'
,
'implements'
=>
'implement'
,
'implementing'
=>
'implement'
,
'implementer'
=>
'implement'
,
'deleting'
=>
'delet'
,
'deletion'
=>
'delet'
,
'delete'
=>
'delet'
,
'erratically'
=>
'errat'
,
'erratic'
=>
'errat'
,
// Stems should be normalized.
'DOG'
=>
'dog'
,
// If stemming would bring a token under 3 characters, it should not
// be stemmed.
'dns'
=>
'dns'
,
'nis'
=>
'nis'
,
);
$stemmer
=
new
PhutilSearchStemmer
();
foreach
(
$tests
as
$input
=>
$expect
)
{
$stem
=
$stemmer
->
stemToken
(
$input
);
$this
->
assertEqual
(
$expect
,
$stem
,
pht
(
'Token stem of "%s".'
,
$input
));
}
}
public
function
testStemDocuments
()
{
$tests
=
array
(
'The wild boar meandered erratically.'
=>
'the wild boar meander errat'
,
'Fool me onc, shame on you. Fool me twice, shame on me.'
=>
'fool onc shame you twice'
,
'Fireball is a seventh-level spell which deals 2d16 points of damage '
.
'in a 1-meter radius around a target.'
=>
'firebal seventh level spell which deal 2d16 point damag meter '
.
'radiu around target'
,
);
$stemmer
=
new
PhutilSearchStemmer
();
foreach
(
$tests
as
$input
=>
$expect
)
{
$stem
=
$stemmer
->
stemCorpus
(
$input
);
$this
->
assertEqual
(
$expect
,
$stem
,
pht
(
'Corpus stem of: %s'
,
$input
));
}
}
}
Event Timeline
Log In to Comment