alfred-margaret alternatives and similar packages
Based on the "Data" category.
Alternatively, view alfred-margaret alternatives based on common mentions on social networks and blogs.
-
semantic-source
Parsing, analyzing, and comparing source code across many languages -
lens
Lenses, Folds, and Traversals - Join us on web.libera.chat #haskell-lens -
code-builder
Packages for defining APIs, running them, generating client code and documentation. -
text
Haskell library for space- and time-efficient operations over Unicode text. -
unordered-containers
Efficient hashing-based container types -
cassava
A CSV parsing and encoding library optimized for ease of use and high performance -
compendium-client
Mu (μ) is a purely functional framework for building micro services. -
holmes
A reference library for constraint-solving with propagators and CDCL. -
resource-pool
A high-performance striped resource pooling implementation for Haskell -
binary
Efficient, pure binary serialisation using ByteStrings in Haskell. -
primitive
This package provides various primitive memory-related operations. -
hashable
A class for types that can be converted to a hash value -
json-autotype
Automatic Haskell type inference from JSON input -
discrimination
Fast linear time sorting and discrimination for a large class of data types -
IORefCAS
A collection of different packages for CAS based data structures. -
audiovisual
Extensible records, variants, structs, effects, tangles -
dependent-sum
Dependent sums and supporting typeclasses for comparing and displaying them -
dependent-map
Dependently-typed finite maps (partial dependent products) -
safecopy
An extension to Data.Serialize with built-in version control -
orgmode-parse
Attoparsec parser combinators for parsing org-mode structured text! -
streaming
An optimized general monad transformer for streaming applications, with a simple prelude of functions -
bifunctors
Haskell 98 bifunctors, bifoldables and bitraversables -
reflection
Reifies arbitrary Haskell terms into types that can be reflected back into terms -
scientific
Arbitrary-precision floating-point numbers represented using scientific notation -
protobuf
An implementation of Google's Protocol Buffers in Haskell. -
text-icu
This package provides the Haskell Data.Text.ICU library, for performing complex manipulation of Unicode text. -
uuid-types
A Haskell library for creating, printing and parsing UUIDs
InfluxDB - Power Real-Time Data Analytics at Scale
Do you think we are missing an alternative of alfred-margaret or a related project?
README
Alfred–Margaret
Alfred–Margaret is a fast implementation of the Aho–Corasick string searching algorithm in Haskell. It powers many string-related operations in Channable.
The library is designed to work with the text
package. It matches
directly on the internal UTF-16 representation of Text
for efficiency. See the
announcement blog post for a deeper dive into Aho–Corasick, and the
optimizations that make this library fast.
Alfred–Margaret is named after Alfred Aho and Margaret Corasick.
Performance
Running time to count all matches, in a real-world data set, comparing a Java implementation and a Rust implementation against Alfred–Margaret, and against memcopy to establish a lower bound:
<img title="Graph that shows that Alfred–Margaret is fast." src="performance.png" width="80%"
For the full details of this benchmark, see our announcement blog post, which includes more details about the data set, the benchmark setup, and a few things to keep in mind when interpreting this graph.
LLVM
If you are using LLVM instead of the GHC backend, make sure to compare different versions. Using LLVM 9 instead of LLVM 12 with GHC 8.10.7 made a significant dent in benchmark times. For more information, see this issue.
Example
Check if a string contains one of the needles:
import qualified Data.Text.AhoCorasick.Automaton as Aho
import qualified Data.Text.AhoCorasick.Searcher as Searcher
searcher = Searcher.build Aho.CaseSensitive ["tshirt", "shirts", "shorts"]
Searcher.containsAny searcher "short tshirts"
> True
Searcher.containsAny searcher "long shirt"
> False
Searcher.containsAny searcher "Short TSHIRTS"
> False
searcher' = Searcher.build Aho.IgnoreCase ["tshirt", "shirts", "shorts"]
Searcher.containsAny searcher' "Short TSHIRTS"
> True
Sequentially replace many needles:
import Data.Text.AhoCorasick.Automaton (CaseSensitivity (..))
import qualified Data.Text.AhoCorasick.Replacer as Replacer
replacer = Replacer.build CaseSensitive [("tshirt", "banana"), ("shirt", "pear")]
Replacer.run replacer "tshirts for sale"
> "bananas for sale"
Replacer.run replacer "tshirts and shirts for sale"
> "bananas and pears for sale"
Replacer.run replacer "sweatshirts and shirtshirts"
> "sweabananas and shirbananas"
Replacer.run replacer "sweatshirts and shirttshirts"
> "sweabananas and pearbananas"
Get all matches, possibly overlapping:
import qualified Data.Text.AhoCorasick.Automaton as Aho
pairNeedleWithSelf text = (Aho.unpackUtf16 text, text)
automaton = Aho.build $ fmap pairNeedleWithSelf ["tshirt", "shirts", "shorts"]
allMatches = Aho.runText [] (\matches match -> Aho.Step (match : matches))
allMatches automaton "short tshirts"
> [ Match {matchPos = CodeUnitIndex 13, matchValue = "shirts"}
> , Match {matchPos = CodeUnitIndex 12, matchValue = "tshirt"}
> ]
allMatches automaton "sweatshirts and shirtshirts"
> [ Match {matchPos = CodeUnitIndex 27, matchValue = "shirts"}
> , Match {matchPos = CodeUnitIndex 26, matchValue = "tshirt"}
> , Match {matchPos = CodeUnitIndex 22, matchValue = "shirts"}
> , Match {matchPos = CodeUnitIndex 11, matchValue = "shirts"}
> , Match {matchPos = CodeUnitIndex 10, matchValue = "tshirt"}
> ]
License
Alfred–Margaret is licensed under the 3-clause BSD license.
*Note that all licence references and agreements mentioned in the alfred-margaret README section above
are relevant to that project's source code only.