nlp-scores (empty) → 0.1.0
raw patch · 4 files changed
+147/−0 lines, 4 filesdep +basedep +containerssetup-changed
Dependencies added: base, containers
Files
- LICENSE +30/−0
- NLP/Scores.hs +54/−0
- Setup.hs +2/−0
- nlp-scores.cabal +61/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2011, Grzegorz Chrupala++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * 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.++ * Neither the name of Grzegorz Chrupala 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.
+ NLP/Scores.hs view
@@ -0,0 +1,54 @@+{-# LANGUAGE BangPatterns #-}+module NLP.Scores + ( + sum+ , mean+ , accuracy+ , recipRank+ , avgPrecision+ )+where+import Data.List hiding (sum)+import qualified Data.Set as Set+import Prelude hiding (sum)++-- | The sum of a list of numbers (without overflowing stack, +-- unlike 'Prelude.sum').+sum :: (Num a) => [a] -> a+sum = foldl' (+) 0++-- | The mean of a list of numbers.+mean :: (Fractional n, Real a) => [a] -> n+mean xs = + let (sum,len) = foldl' (\(!s,!l) x -> (s+x,l+1)) (0,0) xs+ in realToFrac sum/len++-- | Accuracy: the proportion of elements in the first list equal to +-- elements at corresponding positions in second list. Lists should be+-- of equal lengths.+accuracy :: (Eq a, Fractional n) => [a] -> [a] -> n+accuracy xs = mean . map fromEnum . zipWith (==) xs+ +-- | Reciprocal rank: the reciprocal of the rank at which the first arguments+-- occurs in the list given as the second argument.+recipRank :: (Eq a, Fractional n) => a -> [a] -> n+recipRank y ys = + case [ r | (r,y') <- zip [1..] ys , y' == y ] of+ [] -> 0+ r:_ -> 1/fromIntegral r++-- | Average precision. +-- <http://en.wikipedia.org/wiki/Information_retrieval#Average_precision>+avgPrecision :: (Fractional n, Ord a) => Set.Set a -> [a] -> n+avgPrecision gold _ | Set.size gold == 0 = 0+avgPrecision gold xs =+ (/fromIntegral (Set.size gold))+ . sum + . map (\(r,rel,cum) -> if rel == 0 + then 0 + else fromIntegral cum / fromIntegral r)+ . takeWhile (\(_,_,cum) -> cum <= Set.size gold) + . snd + . mapAccumL (\z (r,rel) -> (z+rel,(r,rel,z+rel))) 0+ $ [ (r,fromEnum $ x `Set.member` gold) | (x,r) <- zip xs [1..]]+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ nlp-scores.cabal view
@@ -0,0 +1,61 @@+-- nlp-scores.cabal auto-generated by cabal init. For additional+-- options, see+-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.+-- The name of the package.+Name: nlp-scores++-- The package version. See the Haskell package versioning policy+-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for+-- standards guiding when and how versions should be incremented.+Version: 0.1.0++-- A short (one-line) description of the package.+Synopsis: Scoring functions commonly used for evaluation in NLP and IR++-- A longer description of the package.+Description: Scoring functions commonly used for evaluation in NLP and IR ++-- URL for the project homepage or repository.+Homepage: https://bitbucket.org/gchrupala/lingo++-- The license under which the package is released.+License: BSD3++-- The file containing the license text.+License-file: LICENSE++-- The package author(s).+Author: Grzegorz Chrupala++-- An email address to which users can send suggestions, bug reports,+-- and patches.+Maintainer: gchrupala@lsv.uni-saarland.de++-- A copyright notice.+-- Copyright: ++Category: NLP++Build-type: Simple++-- Extra files to be distributed with the package, such as examples or+-- a README.+-- Extra-source-files: ++-- Constraint on the version of Cabal needed to build this package.+Cabal-version: >=1.2+++Library+ -- Modules exported by the library.+ Exposed-modules: NLP.Scores+ + -- Packages needed in order to build this package.+ Build-depends: base >= 3 && < 5 , containers >= 0.4 + + -- Modules not exported by this package.+ -- Other-modules: + + -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.+ -- Build-tools: +