Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F111456252
PhutilSearchStemmer.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
Thu, May 1, 19:31
Size
1 KB
Mime Type
text/x-php
Expires
Sat, May 3, 19:31 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
25926499
Attached To
rPHU libphutil
PhutilSearchStemmer.php
View Options
<?php
final
class
PhutilSearchStemmer
extends
Phobject
{
public
function
stemToken
(
$token
)
{
$token
=
$this
->
normalizeToken
(
$token
);
return
$this
->
applyStemmer
(
$token
);
}
public
function
stemCorpus
(
$corpus
)
{
$tokens
=
preg_split
(
'/[^a-zA-Z0-9
\x
7F-
\x
FF]+/'
,
$corpus
);
$words
=
array
();
foreach
(
$tokens
as
$key
=>
$token
)
{
if
(
strlen
(
$token
)
<
3
)
{
continue
;
}
$normal_word
=
$this
->
normalizeToken
(
$token
);
$words
[
$normal_word
]
=
$normal_word
;
}
$stems
=
array
();
foreach
(
$words
as
$normal_word
)
{
$stems
[]
=
$this
->
applyStemmer
(
$normal_word
);
}
return
implode
(
' '
,
$stems
);
}
private
function
normalizeToken
(
$token
)
{
return
phutil_utf8_strtolower
(
$token
);
}
/**
* @phutil-external-symbol class Porter
*/
private
function
applyStemmer
(
$normalized_token
)
{
static
$loaded
;
if
(
$loaded
===
null
)
{
$root
=
dirname
(
phutil_get_library_root
(
'phutil'
));
require_once
$root
.
'/externals/porter-stemmer/src/Porter.php'
;
$loaded
=
true
;
}
return
Porter
::
stem
(
$normalized_token
);
}
}
Event Timeline
Log In to Comment