Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module Classifier | ||
( | ||
Classifier, | ||
newClassifier, | ||
trainClassifier, | ||
classifyWithClassifier, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module JSON.Results where | ||
|
||
import Text.JSON | ||
|
||
import Data.Functor | ||
import Control.Applicative | ||
import Data.Aeson | ||
import Classifier | ||
|
||
instance JSON Score where | ||
-- readJSON :: JSValue -> Result Point | ||
readJSON (JSObject j) = case (i,s) of | ||
(Ok i, Ok s) -> Ok (Score i s) | ||
_ -> Error "Unable to read JSScore" | ||
where i = valFromObj "id" j | ||
s = valFromObj "score" j | ||
readJSON _ = Error "Unable to read JSScore" | ||
-- showJSON :: Point -> JSValue | ||
showJSON (Score i s) = showJSON $ toJSObject [("id",showJSON i),("score", showJSON s)] | ||
instance FromJSON Score where | ||
parseJSON (Object v) = Score <$> v .: "id" <*> v .: "score" | ||
|
||
instance ToJSON Score where | ||
toJSON (Score id score) = | ||
object ["id" .= id, "score" .= score] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module JSON.Strokes where | ||
|
||
import Text.JSON | ||
|
||
import Data.Functor | ||
import Control.Applicative | ||
import Data.Aeson | ||
import Strokes | ||
|
||
instance JSON Point where | ||
-- readJSON :: JSValue -> Result Point | ||
readJSON (JSObject j) = case (rx,ry) of | ||
(Ok x, Ok y) -> Ok (Point (x,y)) | ||
_ -> Error "Unable to read JSPoint" | ||
where rx = valFromObj "x" j | ||
ry = valFromObj "y" j | ||
readJSON _ = Error "Unable to read JSPoint" | ||
-- showJSON :: Point -> JSValue | ||
showJSON (Point (x,y)) = showJSON $ toJSObject [("x",x),("y",y)] | ||
toPoint a b = Point (a,b) | ||
|
||
instance FromJSON Point where | ||
parseJSON (Object v) = toPoint <$> v .: "x" <*> v .: "y" | ||
|
||
-- main = do | ||
-- let rp = (decode "[[{\"x\":1,\"y\":3}]]") :: Result Strokes | ||
-- putStrLn $ show rp | ||
-- case rp of | ||
-- Ok p -> putStrLn $ encode $ p | ||
-- Error e -> putStrLn e | ||
instance ToJSON Point where | ||
toJSON (Point (x,y)) = | ||
object [ "x" .= x, "y" .= y] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters