[NGRAMS-REPO]: uniformize TermList constructors

parent 9e778543
...@@ -26,21 +26,22 @@ termSizes = [ { desc: "All types", mval: Nothing } ...@@ -26,21 +26,22 @@ termSizes = [ { desc: "All types", mval: Nothing }
] ]
data TermList = GraphTerm | StopTerm | CandidateTerm data TermList = GraphTerm | StopTerm | CandidateTerm
-- TODO use generic JSON instance
derive instance eqTermList :: Eq TermList derive instance eqTermList :: Eq TermList
instance encodeJsonTermList :: EncodeJson TermList where instance encodeJsonTermList :: EncodeJson TermList where
encodeJson GraphTerm = encodeJson "GraphList" encodeJson GraphTerm = encodeJson "GraphTerm"
encodeJson StopTerm = encodeJson "StopList" encodeJson StopTerm = encodeJson "StopTerm"
encodeJson CandidateTerm = encodeJson "CandidateList" encodeJson CandidateTerm = encodeJson "CandidateTerm"
instance decodeJsonTermList :: DecodeJson TermList where instance decodeJsonTermList :: DecodeJson TermList where
decodeJson json = do decodeJson json = do
s <- decodeJson json s <- decodeJson json
case s of case s of
"GraphList" -> pure GraphTerm "GraphTerm" -> pure GraphTerm
"StopList" -> pure StopTerm "StopTerm" -> pure StopTerm
"CandidateList" -> pure CandidateTerm "CandidateTerm" -> pure CandidateTerm
_ -> Left "Unexpected list name" _ -> Left "Unexpected list name"
type ListTypeId = Int type ListTypeId = Int
...@@ -51,14 +52,14 @@ listTypeId StopTerm = 2 ...@@ -51,14 +52,14 @@ listTypeId StopTerm = 2
listTypeId CandidateTerm = 3 listTypeId CandidateTerm = 3
instance showTermList :: Show TermList where instance showTermList :: Show TermList where
show GraphTerm = "Graph" show GraphTerm = "GraphTerm"
show StopTerm = "Stop" show StopTerm = "StopTerm"
show CandidateTerm = "Candidate" show CandidateTerm = "CandidateTerm"
readTermList :: String -> Maybe TermList readTermList :: String -> Maybe TermList
readTermList "Graph" = Just GraphTerm readTermList "GraphTerm" = Just GraphTerm
readTermList "Stop" = Just StopTerm readTermList "StopTerm" = Just StopTerm
readTermList "Candidate" = Just CandidateTerm readTermList "CandidateTerm" = Just CandidateTerm
readTermList _ = Nothing readTermList _ = Nothing
termLists :: Array { desc :: String, mval :: Maybe TermList } termLists :: Array { desc :: String, mval :: Maybe TermList }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment