Functions/Get-SorensenDiceDistance.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function Get-SorensenDiceDistance {
    <#
        .SYNOPSIS
            Get the Sorensen Dice Distance between two strings.
        .DESCRIPTION
            Uses the Sorensen Dice Coefficient to calculate the distance between two strings.
        .EXAMPLE
            Get-SorensenDiceDistance -String1 'night' -String2 'nacht'
        .LINK
            https://communary.wordpress.com/
            https://github.com/gravejester/Communary.PASM
        .NOTES
            Author: Øyvind Kallstad
            Date: 03.11.2014
            Version: 1.0
            Dependencies: Get-SorensenDiceCoefficient
    #>

    [CmdletBinding()]
    param (
        [Parameter(Position = 0, Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string] $String1,

        [Parameter(Position = 1, Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string] $String2,

        # Makes matches case-sensitive. By default, matches are not case-sensitive.
        [Parameter()]
        [switch] $CaseSensitive
    )

    Write-Output (1 - (Get-SorensenDiceCoefficient -String1 $String1 -String2 $String2 -CaseSensitive:$CaseSensitive))
}