Browse files

make derivation easier

  • Loading branch information...
1 parent c735025 commit a8199714d7dcdee4d2ce1e7663a27ecc7195f48d @srush committed Sep 16, 2009
Showing with 13 additions and 3 deletions.
  1. +12 −2 NLP/Semiring/Derivation.hs
  2. +1 −1 semiring.cabal
View
14 NLP/Semiring/Derivation.hs
@@ -1,5 +1,5 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-module NLP.Semiring.Derivation (Derivation(..), MultiDerivation(..)) where
+module NLP.Semiring.Derivation (Derivation(..), MultiDerivation(..), mkDerivation, fromDerivation) where
import NLP.Semiring
import NLP.Semiring.Helpers
import qualified Data.Set as S
@@ -16,7 +16,7 @@ import Data.Maybe (isNothing)
-- Derivation takes a Monoid as an argument that describes how to build up paths or
-- more complicated structures.
newtype Derivation m = Derivation (Maybe m)
- deriving (Eq, Show, Ord)
+ deriving (Eq, Ord)
instance (Monoid m) => Multiplicative (Derivation m) where
one = Derivation $ Just mempty
@@ -35,6 +35,16 @@ instance (Ord m) => Monoid (Derivation m) where
instance (Monoid m, Eq m, Ord m) => Semiring (Derivation m)
+instance (Show m) => Show (Derivation m) where
+ show (Derivation (Just m)) = show m
+ show (Derivation Nothing) = "[]"
+
+mkDerivation :: (Monoid m ) => m -> Derivation m
+mkDerivation = Derivation . Just
+
+fromDerivation :: (Monoid m ) => Derivation m -> m
+fromDerivation (Derivation (Just m)) = m
+
-- | The 'MultiDerivation' semiring keeps track of a all paths or derivations
-- that led to the known output. This can be useful for debugging output.
View
2 semiring.cabal
@@ -26,7 +26,7 @@ library
NLP.Semiring.Counting
NLP.Semiring.Derivation
NLP.Semiring.ViterbiNBestDerivation
- other-modules: NLP.SemiRing.Helpers
+ other-modules: NLP.Semiring.Helpers
if flag(testing)
buildable: False

0 comments on commit a819971

Please sign in to comment.