ac-machine-conduit (empty) → 0.1.0.0
raw patch · 5 files changed
+96/−0 lines, 5 filesdep +ac-machinedep +basedep +conduitsetup-changed
Dependencies added: ac-machine, base, conduit, text
Files
- Data/AhoCorasick/Conduit.hs +23/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- ac-machine-conduit.cabal +25/−0
- examples/Simple.hs +16/−0
+ Data/AhoCorasick/Conduit.hs view
@@ -0,0 +1,23 @@+module Data.AhoCorasick.Conduit+ ( conduitACMachineText+ ) where++import Data.AhoCorasick (ACMachine, Match(..), root, step)+import Data.Conduit (Conduit, await)+import qualified Data.Conduit.List as CL+import Data.Text (Text)+import qualified Data.Text as T+++conduitACMachineText :: Monad m => ACMachine Char v -> Conduit Text m (Match v)+conduitACMachineText acm = go root 1 T.empty+ where+ go s i buf = case T.uncons buf of+ Nothing -> await >>= maybe (return ()) (go s i)+ Just (c, buf') -> do+ let (s', vs) = step acm c s+ CL.sourceList $ map toMatch vs+ let i' = i + 1+ i' `seq` go s' i' buf'+ where+ toMatch (l, v) = Match { matchPos = i - l + 1, matchValue = v }
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Yuta Taniguchi++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 Yuta Taniguchi 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ ac-machine-conduit.cabal view
@@ -0,0 +1,25 @@+name: ac-machine-conduit+version: 0.1.0.0+synopsis: Drive Aho-Corasick machines in Conduit pipelines+description: Drive Aho-Corasick machines in Conduit pipelines.+license: BSD3+license-file: LICENSE+author: Yuta Taniguchi <yuta.taniguchi.y.t@gmail.com>+maintainer: Yuta Taniguchi <yuta.taniguchi.y.t@gmail.com>+category: Data+build-type: Simple+extra-source-files: examples/Simple.hs+cabal-version: >=1.10++library+ exposed-modules: Data.AhoCorasick.Conduit+ build-depends: base >=4.6 && <4.7+ , ac-machine >=0.2 && <0.3+ , conduit >=1.0 && <1.1+ , text >=0.11 && <0.12+ default-language: Haskell2010+ ghc-options: -Wall++source-repository head+ type: git+ location: git://github.com/yuttie/ac-machine-conduit.git
+ examples/Simple.hs view
@@ -0,0 +1,16 @@+{-# LANGUAGE OverloadedStrings #-}+module Main where++import Control.Monad.IO.Class (liftIO)+import Data.AhoCorasick+import Data.AhoCorasick.Conduit+import Data.Conduit+import Data.Text+++main :: IO ()+main = do+ let acm = construct ["he", "she", "his", "hers"]+ yield "ushers" $$ conduitACMachineText acm =$ awaitForever (liftIO . print)+ let acm' = constructWithValues [("he", 1.2), ("she", 3.4), ("his", 5.6), ("hers", 7.8)]+ yield "ushers" $$ conduitACMachineText acm' =$ awaitForever (liftIO . print)