From 77370e50152d8bd7de1f82a5d0d262e760f1b27f Mon Sep 17 00:00:00 2001 From: Tissevert Date: Wed, 19 Aug 2020 18:45:46 +0200 Subject: [PATCH] First draft --- CHANGELOG.md | 5 ++++ LICENSE | 46 ++++++++++++++++++++---------------- README.md | 2 +- Setup.hs | 2 ++ alphabetDistance.cabal | 34 ++++++++++++++++++++++++++ lib/Text/AlphabetDistance.hs | 19 +++++++++++++++ test/MyLibTest.hs | 4 ++++ 7 files changed, 90 insertions(+), 22 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 Setup.hs create mode 100644 alphabetDistance.cabal create mode 100644 lib/Text/AlphabetDistance.hs create mode 100644 test/MyLibTest.hs diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..09b2430 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for alphabetDistance + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/LICENSE b/LICENSE index b2a9c51..a58e302 100644 --- a/LICENSE +++ b/LICENSE @@ -1,26 +1,30 @@ -Copyright (c) . All rights reserved. +Copyright (c) 2020, Tissevert -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: +All rights reserved. -1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: -2. Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. -3. Neither the name of the copyright holder nor the names of its contributors -may be used to endorse or promote products derived from this software without -specific prior written permission. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 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. + * Neither the name of Tissevert nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +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. diff --git a/README.md b/README.md index f79dc87..f7b494d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # alphabetDistance -A library to implement a norm and a distance on strings useful to quantify intervals in dictionaries. +A library to implement a norm and a distance on strings useful to quantify intervals in dictionaries. diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/alphabetDistance.cabal b/alphabetDistance.cabal new file mode 100644 index 0000000..4bbc630 --- /dev/null +++ b/alphabetDistance.cabal @@ -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 diff --git a/lib/Text/AlphabetDistance.hs b/lib/Text/AlphabetDistance.hs new file mode 100644 index 0000000..391b59d --- /dev/null +++ b/lib/Text/AlphabetDistance.hs @@ -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 diff --git a/test/MyLibTest.hs b/test/MyLibTest.hs new file mode 100644 index 0000000..3e2059e --- /dev/null +++ b/test/MyLibTest.hs @@ -0,0 +1,4 @@ +module Main (main) where + +main :: IO () +main = putStrLn "Test suite not yet implemented."