NaturalLanguageAlphabets (empty) → 0.0.0.1
raw patch · 5 files changed
+156/−0 lines, 5 filesdep +basedep +bytestringdep +hashablesetup-changed
Dependencies added: base, bytestring, hashable, intern, unordered-containers
Files
- LICENSE +30/−0
- NLP/Alphabet/MultiChar.hs +78/−0
- NaturalLanguageAlphabets.cabal +40/−0
- Setup.hs +2/−0
- changelog +6/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Christian Hoener zu Siederdissen 2014++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 Christian Hoener zu Siederdissen 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/Alphabet/MultiChar.hs view
@@ -0,0 +1,78 @@+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}++-- | An alphabet, where each character is a short bytestring.+--+-- Due to the overhead this incurs, we use 'ShortByteString's internally. We+-- also provide an 'Interned' instance to further reduce overhead using+-- hash-consing.+--+-- TODO we'd like to use the @stringable@ library but it depends on+-- @system-filepath@ which is not yet compatible with @text>=1@.++module NLP.Alphabet.MultiChar where++import Data.Function (on)+import Data.Hashable+import Data.Interned+import Data.String+import qualified Data.ByteString.Short as S+import qualified Data.ByteString.Short.Internal as S++++-- | Interns a 'MultiChar' character.++internMultiChar :: MultiChar -> MultiChar+internMultiChar = uninternMultiChar . intern++-- | Wrap a short bytestring. Read and Show instances behave like for normal+-- strings.++newtype MultiChar = MultiChar { unMultiChar :: S.ShortByteString }+ deriving (Eq,Ord)++instance Show MultiChar where+ showsPrec p (MultiChar ps) r = showsPrec p ps r++instance Read MultiChar where+ readsPrec p str = [ (MultiChar x, y) | (x,y) <- readsPrec p str ]++instance Hashable MultiChar where+ hashWithSalt salt (MultiChar s@(S.SBS sbs)) = hashByteArrayWithSalt sbs 0 (S.length s) salt++instance IsString MultiChar where+ fromString = MultiChar . fromString++++-- * Interned++data InternedMultiChar = InternedMultiChar+ { internedMultiCharId :: {-# UNPACK #-} !Id+ , uninternMultiChar :: {-# UNPACK #-} !MultiChar+ }++instance IsString InternedMultiChar where+ fromString = intern . fromString++instance Eq InternedMultiChar where+ (==) = (==) `on` internedMultiCharId++instance Ord InternedMultiChar where+ compare = compare `on` internedMultiCharId++instance Show InternedMultiChar where+ showsPrec d (InternedMultiChar _ mc) = showsPrec d mc++instance Interned InternedMultiChar where+ type Uninterned InternedMultiChar = MultiChar+ newtype Description InternedMultiChar = DMC MultiChar deriving (Eq,Hashable)+ describe = DMC+ identify = InternedMultiChar+ cache = imcCache++imcCache :: Cache InternedMultiChar+imcCache = mkCache+{-# NOINLINE imcCache #-}+
+ NaturalLanguageAlphabets.cabal view
@@ -0,0 +1,40 @@+name: NaturalLanguageAlphabets+version: 0.0.0.1+author: Christian Hoener zu Siederdissen+maintainer: choener@tbi.univie.ac.at+homepage: http://www.tbi.univie.ac.at/~choener/+copyright: Christian Hoener zu Siederdissen, 2014+category: Natural Language Processing+synopsis: Alphabet and word representations+license: BSD3+license-file: LICENSE+build-type: Simple+stability: experimental+cabal-version: >= 1.6.0+description:+ Provides different encoding for characters and words in natural+ language processing. A character will often be encoded as a+ bytestring as we deal with multi-symbol characters.++++extra-source-files:+ changelog++library+ build-depends:+ base >3 && <5 ,+ bytestring >= 0.10.4 ,+ hashable >= 1.2 ,+ intern >= 0.9 ,+ unordered-containers >= 0.2.3++ exposed-modules:+ NLP.Alphabet.MultiChar++ ghc-options:++source-repository head+ type: git+ location: git://github.com/choener/NaturalLanguageAlphabets+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ changelog view
@@ -0,0 +1,6 @@+0.0.0.1+-------++- initial checkin+- internable MultiChar characters+