weighted-regexp 0.2.0.0 → 0.3.0.0
raw patch · 9 files changed
+144/−97 lines, 9 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Text.RegExp.Matching.LeftLong: LeftLong :: !Int -> !Int -> LeftLong
- Text.RegExp.Matching.LeftLong: Matching :: !Int -> !Int -> Matching
- Text.RegExp.Matching.LeftLong: One :: LeftLong
- Text.RegExp.Matching.LeftLong: Zero :: LeftLong
- Text.RegExp.Matching.LeftLong: instance Eq LeftLong
- Text.RegExp.Matching.LeftLong: instance Semiring LeftLong
- Text.RegExp.Matching.LeftLong: instance Show LeftLong
- Text.RegExp.Matching.LeftLong: instance Weight c (Int, c) LeftLong
- Text.RegExp.Matching.Leftmost: Leftmost :: !Int -> Leftmost
- Text.RegExp.Matching.Leftmost: Matching :: !Int -> Matching
- Text.RegExp.Matching.Leftmost: One :: Leftmost
- Text.RegExp.Matching.Leftmost: Zero :: Leftmost
- Text.RegExp.Matching.Leftmost: instance Eq Leftmost
- Text.RegExp.Matching.Leftmost: instance Semiring Leftmost
- Text.RegExp.Matching.Leftmost: instance Show Leftmost
- Text.RegExp.Matching.Leftmost: instance Weight c (Int, c) Leftmost
- Text.RegExp.Matching.Longest: Longest :: !Int -> Longest
- Text.RegExp.Matching.Longest: Matching :: !Int -> Matching
- Text.RegExp.Matching.Longest: One :: Longest
- Text.RegExp.Matching.Longest: Zero :: Longest
- Text.RegExp.Matching.Longest: instance Eq Longest
- Text.RegExp.Matching.Longest: instance Semiring Longest
- Text.RegExp.Matching.Longest: instance Show Longest
- Text.RegExp.Matching.Longest: instance Weight c c Longest
- Text.RegExp.Matching.LeftLong: matchingIndex :: Matching -> !Int
+ Text.RegExp.Matching.LeftLong: matchingIndex :: Matching -> Int
- Text.RegExp.Matching.LeftLong: matchingLength :: Matching -> !Int
+ Text.RegExp.Matching.LeftLong: matchingLength :: Matching -> Int
- Text.RegExp.Matching.Leftmost: matchingIndex :: Matching -> !Int
+ Text.RegExp.Matching.Leftmost: matchingIndex :: Matching -> Int
- Text.RegExp.Matching.Longest: matchingLength :: Matching -> !Int
+ Text.RegExp.Matching.Longest: matchingLength :: Matching -> Int
Files
- src/Text/RegExp/Matching.hs +13/−0
- src/Text/RegExp/Matching/LeftLong.hs +5/−36
- src/Text/RegExp/Matching/LeftLong/Type.hs +39/−0
- src/Text/RegExp/Matching/Leftmost.hs +5/−27
- src/Text/RegExp/Matching/Leftmost/Type.hs +29/−0
- src/Text/RegExp/Matching/Longest.hs +7/−27
- src/Text/RegExp/Matching/Longest/Type.hs +27/−0
- src/quickcheck.lhs +6/−3
- weighted-regexp.cabal +13/−4
src/Text/RegExp/Matching.hs view
@@ -5,6 +5,10 @@ import Data.Semiring import Text.RegExp.Data +import Text.RegExp.Matching.Leftmost.Type+import Text.RegExp.Matching.Longest.Type+import Text.RegExp.Matching.LeftLong.Type+ -- | -- Checks whether a regular expression matches the given word. For -- example, @acceptFull (fromString \"b|abc\") \"b\"@ yields @True@@@ -47,6 +51,9 @@ {-# SPECIALIZE fullMatch :: RegExp c -> [c] -> Bool #-} {-# SPECIALIZE fullMatch :: RegExp c -> [c] -> Numeric Int #-} {-# SPECIALIZE fullMatch :: Num a => RegExp c -> [c] -> Numeric a #-}+{-# SPECIALIZE fullMatch :: RegExp c -> [(Int,c)] -> Leftmost #-}+{-# SPECIALIZE fullMatch :: RegExp c -> [c] -> Longest #-}+{-# SPECIALIZE fullMatch :: RegExp c -> [(Int,c)] -> LeftLong #-} -- | -- Matches a regular expression against substrings of a word computing@@ -61,6 +68,9 @@ {-# SPECIALIZE partialMatch :: RegExp c -> [c] -> Bool #-} {-# SPECIALIZE partialMatch :: RegExp c -> [c] -> Numeric Int #-} {-# SPECIALIZE partialMatch :: Num a => RegExp c -> [c] -> Numeric a #-}+{-# SPECIALIZE partialMatch :: RegExp c -> [(Int,c)] -> Leftmost #-}+{-# SPECIALIZE partialMatch :: RegExp c -> [c] -> Longest #-}+{-# SPECIALIZE partialMatch :: RegExp c -> [(Int,c)] -> LeftLong #-} matchW :: Semiring w => RegW w c -> [c] -> w matchW r [] = empty r@@ -69,6 +79,9 @@ {-# SPECIALIZE matchW :: RegW Bool c -> [c] -> Bool #-} {-# SPECIALIZE matchW :: RegW (Numeric Int) c -> [c] -> Numeric Int #-} {-# SPECIALIZE matchW :: Num a => RegW (Numeric a) c -> [c] -> Numeric a #-}+{-# SPECIALIZE matchW :: RegW Leftmost (Int,c) -> [(Int,c)] -> Leftmost #-}+{-# SPECIALIZE matchW :: RegW Longest c -> [c] -> Longest #-}+{-# SPECIALIZE matchW :: RegW LeftLong (Int,c) -> [(Int,c)] -> LeftLong #-} shiftW :: Semiring w => w -> RegW w c -> c -> RegW w c shiftW w r c | active r || w /= zero = shift w (reg r) c
src/Text/RegExp/Matching/LeftLong.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE MultiParamTypeClasses, FlexibleContexts, FlexibleInstances #-}- -- | -- Module : Text.RegExp.Matching.LeftLong -- Copyright : Thomas Wilke, Frank Huch, and Sebastian Fischer@@ -13,13 +11,16 @@ -- module Text.RegExp.Matching.LeftLong ( - LeftLong(..), Matching(..),+ matching, - matching, getLeftLong+ Matching, matchingIndex, matchingLength, + LeftLong, getLeftLong+ ) where import Text.RegExp+import Text.RegExp.Matching.LeftLong.Type -- | -- Subwords of words that match a regular expression are represented@@ -50,40 +51,8 @@ matching :: RegExp c -> [c] -> Maybe Matching matching r = getLeftLong . partialMatch r . zip [(0::Int)..] --- | --- Semiring used for leftmost longest matching.--- --- The `LeftLong` type satisfies the distributive laws only with a--- precondition on all involved multiplications: multiplied matches--- must be adjacent and the start position must be smaller than the--- end position. This precondition is satisfied for all--- multiplications during regular expression matching.--- -data LeftLong = Zero | One | LeftLong !Int !Int- deriving (Eq,Show)- getLeftLong :: LeftLong -> Maybe Matching getLeftLong Zero = Nothing getLeftLong One = Just $ Matching 0 0 getLeftLong (LeftLong x y) = Just $ Matching x (y-x+1)--instance Semiring LeftLong where- zero = Zero; one = One-- Zero .+. y = y- x .+. Zero = x- One .+. y = y- x .+. One = x- LeftLong a b .+. LeftLong c d- | a<c || a==c && b>=d = LeftLong a b- | otherwise = LeftLong c d-- Zero .*. _ = Zero- _ .*. Zero = Zero- One .*. y = y- x .*. One = x- LeftLong a _ .*. LeftLong _ b = LeftLong a b--instance Weight c (Int,c) LeftLong where- symWeight p (n,c) = p c .*. LeftLong n n
+ src/Text/RegExp/Matching/LeftLong/Type.hs view
@@ -0,0 +1,39 @@+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}++module Text.RegExp.Matching.LeftLong.Type where++import Data.Semiring+import Text.RegExp.Data++-- | +-- Semiring used for leftmost longest matching.+-- +-- The `LeftLong` type satisfies the distributive laws only with a+-- precondition on all involved multiplications: multiplied matches+-- must be adjacent and the start position must be smaller than the+-- end position. This precondition is satisfied for all+-- multiplications during regular expression matching.+-- +data LeftLong = Zero | One | LeftLong !Int !Int+ deriving (Eq,Show)++instance Semiring LeftLong where+ zero = Zero; one = One++ Zero .+. y = y+ x .+. Zero = x+ One .+. y = y+ x .+. One = x+ LeftLong a b .+. LeftLong c d+ | a<c || a==c && b>=d = LeftLong a b+ | otherwise = LeftLong c d++ Zero .*. _ = Zero+ _ .*. Zero = Zero+ One .*. y = y+ x .*. One = x+ LeftLong a _ .*. LeftLong _ b = LeftLong a b++instance Weight c (Int,c) LeftLong where+ symWeight p (n,c) = p c .*. LeftLong n n+
src/Text/RegExp/Matching/Leftmost.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE MultiParamTypeClasses, FlexibleContexts, FlexibleInstances #-}- -- | -- Module : Text.RegExp.Matching.Leftmost -- Copyright : Thomas Wilke, Frank Huch, and Sebastian Fischer@@ -13,13 +11,16 @@ -- module Text.RegExp.Matching.Leftmost ( - Leftmost(..), Matching(..),+ matching, - matching, getLeftmost+ Matching, matchingIndex, + Leftmost, getLeftmost+ ) where import Text.RegExp+import Text.RegExp.Matching.Leftmost.Type -- | -- A 'Matching' records the leftmost start index of a matching subword.@@ -45,30 +46,7 @@ matching :: RegExp c -> [c] -> Maybe Matching matching r = getLeftmost . partialMatch r . zip [(0::Int)..] --- | Semiring used for leftmost matching.--- -data Leftmost = Zero | One | Leftmost !Int- deriving (Eq,Show)- getLeftmost :: Leftmost -> Maybe Matching getLeftmost Zero = Nothing getLeftmost One = Just $ Matching 0 getLeftmost (Leftmost x) = Just $ Matching x--instance Semiring Leftmost where- zero = Zero; one = One-- Zero .+. y = y- x .+. Zero = x- One .+. y = y- x .+. One = x- Leftmost a .+. Leftmost b = Leftmost (min a b)-- Zero .*. _ = Zero- _ .*. Zero = Zero- One .*. y = y- x .*. One = x- Leftmost a .*. Leftmost b = Leftmost (min a b)--instance Weight c (Int,c) Leftmost where- symWeight p (n,c) = p c .*. Leftmost n
+ src/Text/RegExp/Matching/Leftmost/Type.hs view
@@ -0,0 +1,29 @@+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}++module Text.RegExp.Matching.Leftmost.Type where++import Data.Semiring+import Text.RegExp.Data++-- | Semiring used for leftmost matching.+-- +data Leftmost = Zero | One | Leftmost !Int+ deriving (Eq,Show)++instance Semiring Leftmost where+ zero = Zero; one = One++ Zero .+. y = y+ x .+. Zero = x+ One .+. y = y+ x .+. One = x+ Leftmost a .+. Leftmost b = Leftmost (min a b)++ Zero .*. _ = Zero+ _ .*. Zero = Zero+ One .*. y = y+ x .*. One = x+ Leftmost a .*. Leftmost b = Leftmost (min a b)++instance Weight c (Int,c) Leftmost where+ symWeight p (n,c) = p c .*. Leftmost n
src/Text/RegExp/Matching/Longest.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE MultiParamTypeClasses, FlexibleContexts, FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-} -- | -- Module : Text.RegExp.Matching.Longest@@ -13,16 +13,19 @@ -- module Text.RegExp.Matching.Longest ( - Longest(..), Matching(..),+ matching, - matching, getLongest+ Matching, matchingLength, + Longest, getLongest+ ) where import Text.RegExp+import Text.RegExp.Matching.Longest.Type -- |--- A 'Matching' records the leftmost start index of a matching subword.+-- A 'Matching' records the largest length of a matching subword. -- data Matching = Matching { @@ -44,30 +47,7 @@ matching :: RegExp c -> [c] -> Maybe Matching matching r = getLongest . partialMatch r --- | Semiring used for longest matching.--- -data Longest = Zero | One | Longest !Int- deriving (Eq,Show)- getLongest :: Longest -> Maybe Matching getLongest Zero = Nothing getLongest One = Just $ Matching 0 getLongest (Longest x) = Just $ Matching x--instance Semiring Longest where- zero = Zero; one = One-- Zero .+. y = y- x .+. Zero = x- One .+. y = y- x .+. One = x- Longest a .+. Longest b = Longest (max a b)-- Zero .*. _ = Zero- _ .*. Zero = Zero- One .*. y = y- x .*. One = x- Longest a .*. Longest b = Longest (a+b)--instance Weight c c Longest where- symWeight p c = p c .*. Longest 1
+ src/Text/RegExp/Matching/Longest/Type.hs view
@@ -0,0 +1,27 @@+module Text.RegExp.Matching.Longest.Type where++import Data.Semiring+import Text.RegExp.Data++-- | Semiring used for longest matching.+-- +data Longest = Zero | One | Longest !Int+ deriving (Eq,Show)++instance Semiring Longest where+ zero = Zero; one = One++ Zero .+. y = y+ x .+. Zero = x+ One .+. y = y+ x .+. One = x+ Longest a .+. Longest b = Longest (max a b)++ Zero .*. _ = Zero+ _ .*. Zero = Zero+ One .*. y = y+ x .*. One = x+ Longest a .*. Longest b = Longest (a+b)++instance Weight c c Longest where+ symWeight p c = p c .*. Longest 1
src/quickcheck.lhs view
@@ -30,9 +30,12 @@ > import Text.RegExp > import Text.RegExp.Data-> import Text.RegExp.Matching.Leftmost ( Leftmost(..), getLeftmost )-> import Text.RegExp.Matching.Longest ( Longest(..), getLongest )-> import Text.RegExp.Matching.LeftLong ( LeftLong(..), getLeftLong )+> import Text.RegExp.Matching.Leftmost.Type ( Leftmost(..) )+> import Text.RegExp.Matching.Longest.Type ( Longest(..) )+> import Text.RegExp.Matching.LeftLong.Type ( LeftLong(..) )+> import Text.RegExp.Matching.Leftmost ( getLeftmost )+> import Text.RegExp.Matching.Longest ( getLongest )+> import Text.RegExp.Matching.LeftLong ( getLeftLong ) > import qualified Text.RegExp.Matching.Leftmost as Leftmost > import qualified Text.RegExp.Matching.Longest as Longest > import qualified Text.RegExp.Matching.LeftLong as LeftLong
weighted-regexp.cabal view
@@ -1,5 +1,5 @@ Name: weighted-regexp-Version: 0.2.0.0+Version: 0.3.0.0 Cabal-Version: >= 1.6 Synopsis: Weighted Regular Expression Matcher Description:@@ -32,7 +32,10 @@ Data.Semiring.Properties Other-Modules: Text.RegExp.Data, Text.RegExp.Parser,- Text.RegExp.Matching+ Text.RegExp.Matching,+ Text.RegExp.Matching.Leftmost.Type,+ Text.RegExp.Matching.Longest.Type,+ Text.RegExp.Matching.LeftLong.Type Extensions: RankNTypes, FlexibleContexts, FlexibleInstances,@@ -56,7 +59,10 @@ Data.Semiring.Properties Text.RegExp.Data, Text.RegExp.Parser,- Text.RegExp.Matching+ Text.RegExp.Matching,+ Text.RegExp.Matching.Leftmost.Type,+ Text.RegExp.Matching.Longest.Type,+ Text.RegExp.Matching.LeftLong.Type Extensions: RankNTypes, FlexibleContexts, FlexibleInstances,@@ -84,7 +90,10 @@ Data.Semiring, Text.RegExp.Data, Text.RegExp.Parser,- Text.RegExp.Matching+ Text.RegExp.Matching,+ Text.RegExp.Matching.Leftmost.Type,+ Text.RegExp.Matching.Longest.Type,+ Text.RegExp.Matching.LeftLong.Type Extensions: RankNTypes, FlexibleContexts, FlexibleInstances,