<commit_before>TrailDB Haskell bindings
========================

![TrailDB logo](traildb_logo_512.png?raw=true)

These are the official Haskell bindings to [TrailDB](http://traildb.io/). Most
of the API is covered. Check out System.TrailDB module for some examples and
documentation.

How to build
------------

These bindings can be installed using `cabal-install` or `stack` on Linux.

Fetch the code in some way. You can clone
git://github.com/SemanticSugar/traildb-haskell. Then follow these instructions.

You need at least `traildb`, `Judy` and `cmph` libraries installed to compile
and use these bindings. The latter two are dependencies of TrailDB itself so if
you have TrailDB the C library installed properly, then most likely you don't
need to do anything else regarding dependencies.

### cabal-install

Cabal is usually in the package repositories of your distribution.

    $ apt-get install cabal-install      # Debian/Mint/Ubuntu
    $ dnf install ghc cabal-install      # Fedora 22
    $ pacman -S ghc cabal-install        # Arch Linux
    $ pkg install hs-cabal-install       # FreeBSD

    $ cabal install                      # Run this in the root of traildb-haskell

After this, bindings should be usable in other Haskell projects by requiring `traildb`.

### stack

Stack is a new fancy Haskell build tool. Because it's new and fancy, it doesn't
quite have the same level of presence in Linux package repositories than
`cabal-install`.

You can manually download `stack` from [http://www.haskellstack.org/] if it's
not in your repositories.

    # Once you have `stack` in your PATH:

    $ stack setup      # May be optional if you have GHC already installed and it can be used
    $ stack install

License
-------

These bindings are licensed under the MIT license.

How to contribute or report bugs
--------------------------------

You can use our [GitHub page](https://github.com/SemanticSugar/traildb-haskell/) to report issues or pull requests. 

<commit_msg>Add example program to README.md.<commit_after>TrailDB Haskell bindings
========================

![TrailDB logo](traildb_logo_512.png?raw=true)

These are the official Haskell bindings to [TrailDB](http://traildb.io/). Most
of the API is covered. Check out System.TrailDB module for some examples and
documentation.

How to build
------------

These bindings can be installed using `cabal-install` or `stack` on Linux.

Fetch the code in some way. You can clone
git://github.com/SemanticSugar/traildb-haskell. Then follow these instructions.

You need at least `traildb`, `Judy` and `cmph` libraries installed to compile
and use these bindings. The latter two are dependencies of TrailDB itself so if
you have TrailDB the C library installed properly, then most likely you don't
need to do anything else regarding dependencies.

### cabal-install

Cabal is usually in the package repositories of your distribution.

    $ apt-get install cabal-install      # Debian/Mint/Ubuntu
    $ dnf install ghc cabal-install      # Fedora 22
    $ pacman -S ghc cabal-install        # Arch Linux
    $ pkg install hs-cabal-install       # FreeBSD

    $ cabal install                      # Run this in the root of traildb-haskell

After this, bindings should be usable in other Haskell projects by requiring `traildb`.

### stack

Stack is a new fancy Haskell build tool. Because it's new and fancy, it doesn't
quite have the same level of presence in Linux package repositories than
`cabal-install`.

You can manually download `stack` from [http://www.haskellstack.org/] if it's
not in your repositories.

    # Once you have `stack` in your PATH:

    $ stack setup      # May be optional if you have GHC already installed and it can be used
    $ stack install

License
-------

These bindings are licensed under the MIT license.

How to contribute or report bugs
--------------------------------

You can use our [GitHub page](https://github.com/SemanticSugar/traildb-haskell/) to report issues or pull requests. 

Example program
---------------

    import qualified Data.ByteString as B
    import qualified Data.Vector.Unboxed as V
    import System.TrailDB
 
    main :: IO ()
    main = do
      tdb <- openTrailDB "some-trail-db"
      number_of_trails <- getNumTrails tdb
 
      let arbitrarily_chosen_trail_id = 12345 `mod` number_of_trails
 
      cursor <- makeCursor tdb
      setCursor cursor arbitrarily_chosen_trail_id
 
      -- Read the first event in the arbitrary chosen trail
      crumb <- stepCursor cursor
      case crumb of
        Nothing -> putStrLn "Cannot find this particular trail."
        Just (timestamp, features) ->
          V.forM_ features $ \feature -> do
            field_name <- getFieldName tdb (feature^.field)
            putStr "Field: "
            B.putStr field_name
            putStr " contains value "
            value <- getValue tdb feature
            B.putStrLn value


{'fraction_non_alphanumeric': 0.09586810502747813, 'fraction_numerical': 0.003053124363932424, 'mean_word_length': 2.8601728201099763, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4240956', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1308, 'n_words': 584}