First draft
This commit is contained in:
parent
e19b0ab042
commit
77370e5015
7 changed files with 90 additions and 22 deletions
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Revision history for alphabetDistance
|
||||||
|
|
||||||
|
## 0.1.0.0 -- YYYY-mm-dd
|
||||||
|
|
||||||
|
* First version. Released on an unsuspecting world.
|
46
LICENSE
46
LICENSE
|
@ -1,26 +1,30 @@
|
||||||
Copyright (c) <year> <owner> . All rights reserved.
|
Copyright (c) 2020, Tissevert
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
All rights reserved.
|
||||||
are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice,
|
Redistribution and use in source and binary forms, with or without
|
||||||
this list of conditions and the following disclaimer.
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
* Redistributions of source code must retain the above copyright
|
||||||
this list of conditions and the following disclaimer in the documentation
|
notice, this list of conditions and the following disclaimer.
|
||||||
and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
3. Neither the name of the copyright holder nor the names of its contributors
|
* Redistributions in binary form must reproduce the above
|
||||||
may be used to endorse or promote products derived from this software without
|
copyright notice, this list of conditions and the following
|
||||||
specific prior written permission.
|
disclaimer in the documentation and/or other materials provided
|
||||||
|
with the distribution.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* Neither the name of Tissevert nor the names of other
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
contributors may be used to endorse or promote products derived
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
from this software without specific prior written permission.
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
2
Setup.hs
Normal file
2
Setup.hs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import Distribution.Simple
|
||||||
|
main = defaultMain
|
34
alphabetDistance.cabal
Normal file
34
alphabetDistance.cabal
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
cabal-version: >=1.10
|
||||||
|
-- Initial package description 'alphabetDistance.cabal' generated by 'cabal
|
||||||
|
-- init'. For further documentation, see
|
||||||
|
-- http://haskell.org/cabal/users-guide/
|
||||||
|
|
||||||
|
name: alphabetDistance
|
||||||
|
version: 0.1.0.0
|
||||||
|
synopsis: A library to implement a norm and a distance on strings useful to quantify intervals in dictionaries
|
||||||
|
-- description:
|
||||||
|
homepage: https://git.marvid.fr/~Tissevert/alphabetDistance
|
||||||
|
-- bug-reports:
|
||||||
|
license: BSD3
|
||||||
|
license-file: LICENSE
|
||||||
|
author: Tissevert
|
||||||
|
maintainer: tissevert+devel@marvid.fr
|
||||||
|
-- copyright:
|
||||||
|
category: Text
|
||||||
|
build-type: Simple
|
||||||
|
extra-source-files: CHANGELOG.md
|
||||||
|
|
||||||
|
library
|
||||||
|
exposed-modules: Text.AlphabetDistance
|
||||||
|
-- other-modules:
|
||||||
|
-- other-extensions:
|
||||||
|
build-depends: base >=4.11 && <4.12
|
||||||
|
hs-source-dirs: lib
|
||||||
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
test-suite alphabetDistance-test
|
||||||
|
default-language: Haskell2010
|
||||||
|
type: exitcode-stdio-1.0
|
||||||
|
hs-source-dirs: test
|
||||||
|
main-is: MyLibTest.hs
|
||||||
|
build-depends: base >=4.11 && <4.12
|
19
lib/Text/AlphabetDistance.hs
Normal file
19
lib/Text/AlphabetDistance.hs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
module Text.AlphabetDistance (
|
||||||
|
distance
|
||||||
|
, norm
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Data.Char (toLower)
|
||||||
|
|
||||||
|
rank :: Char -> Int
|
||||||
|
rank c = 1 + fromEnum (toLower c) - fromEnum 'a'
|
||||||
|
|
||||||
|
norm :: String -> Float
|
||||||
|
norm "" = 0
|
||||||
|
norm (c:cs) = (fromIntegral (rank c) + norm cs) / 27
|
||||||
|
|
||||||
|
distance :: String -> String -> Float
|
||||||
|
distance "" "" = 0
|
||||||
|
distance "" s = norm s
|
||||||
|
distance s "" = norm s
|
||||||
|
distance (ca:sa) (cb:sb) = (abs $ fromIntegral (rank ca - rank cb) + distance sa sb) / 27
|
4
test/MyLibTest.hs
Normal file
4
test/MyLibTest.hs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
module Main (main) where
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = putStrLn "Test suite not yet implemented."
|
Loading…
Reference in a new issue