Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4793923
SorensenDiceCoefficient.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
SorensenDiceCoefficient.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\Strings
;
use
Keruald\OmniTools\Strings\Multibyte\OmniString
;
class
SorensenDiceCoefficient
{
/**
* @var string[]
*/
private
$x
;
/**
* @var string[]
*/
private
$y
;
///
/// Constructors
///
public
function
__construct
(
string
$left
,
string
$right
)
{
$this
->
x
=
(
new
OmniString
(
$left
))->
getBigrams
();
$this
->
y
=
(
new
OmniString
(
$right
))->
getBigrams
();
}
public
static
function
computeFor
(
string
$left
,
string
$right
)
:
float
{
$instance
=
new
self
(
$left
,
$right
);
return
$instance
->
compute
();
}
///
/// Sørensen formula
///
public
function
compute
()
:
float
{
return
2
*
$this
->
countIntersect
()
/
$this
->
countCharacters
();
}
private
function
countIntersect
()
:
int
{
$intersect
=
array_intersect
(
$this
->
x
,
$this
->
y
);
return
count
(
$intersect
);
}
private
function
countCharacters
()
:
int
{
return
count
(
$this
->
x
)
+
count
(
$this
->
y
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Feb 28, 22:47 (23 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2438034
Default Alt Text
SorensenDiceCoefficient.php (1 KB)
Attached To
Mode
rKOT Keruald OmniTools
Attached
Detach File
Event Timeline
Log In to Comment