MoeDict 0.0.2 → 0.0.3
raw patch · 2 files changed
+40/−15 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Text.MoeDict: Pronounciation :: Str -> Str -> Str -> Pronounciation
- Text.MoeDict: data Pronounciation
- Text.MoeDict: instance Eq Pronounciation
- Text.MoeDict: instance FromJSON Pronounciation
- Text.MoeDict: instance Ord Pronounciation
- Text.MoeDict: instance Show Pronounciation
- Text.MoeDict: instance ToJSON Pronounciation
- Text.MoeDict: pronounciation :: Heteronym -> Pronounciation
+ Text.MoeDict: Antonym :: Part
+ Text.MoeDict: Cantonese :: Part
+ Text.MoeDict: Composition :: Part
+ Text.MoeDict: Derivative :: Part
+ Text.MoeDict: Loanword :: Part
+ Text.MoeDict: None :: Part
+ Text.MoeDict: Pronunciation :: Str -> Str -> Str -> Pronunciation
+ Text.MoeDict: PuTongHua :: Part
+ Text.MoeDict: Reference :: Maybe POS -> Text -> Reference
+ Text.MoeDict: Slang :: Part
+ Text.MoeDict: Synonym :: Part
+ Text.MoeDict: data Pronunciation
+ Text.MoeDict: data Reference
+ Text.MoeDict: instance Eq Pronunciation
+ Text.MoeDict: instance Eq Reference
+ Text.MoeDict: instance FromJSON Pronunciation
+ Text.MoeDict: instance FromJSON Reference
+ Text.MoeDict: instance Ord Pronunciation
+ Text.MoeDict: instance Ord Reference
+ Text.MoeDict: instance Show Pronunciation
+ Text.MoeDict: instance Show Reference
+ Text.MoeDict: instance ToJSON Pronunciation
+ Text.MoeDict: maybeList :: Maybe [t] -> [t]
+ Text.MoeDict: pronunciation :: Heteronym -> Pronunciation
+ Text.MoeDict: refText :: Reference -> Text
+ Text.MoeDict: refType :: Reference -> Maybe POS
+ Text.MoeDict: references :: Entry -> [Reference]
+ Text.MoeDict: shapeDescription :: Radical -> Maybe Text
- Text.MoeDict: Entry :: Title -> Maybe Radical -> [Heteronym] -> Entry
+ Text.MoeDict: Entry :: Title -> Maybe Radical -> [Heteronym] -> [Reference] -> Entry
- Text.MoeDict: Heteronym :: Pronounciation -> [Definition] -> Heteronym
+ Text.MoeDict: Heteronym :: Pronunciation -> [Definition] -> Heteronym
- Text.MoeDict: Radical :: Char -> Count -> Count -> Radical
+ Text.MoeDict: Radical :: Char -> Count -> Count -> Maybe Text -> Radical
- Text.MoeDict: bopomofo :: Pronounciation -> Str
+ Text.MoeDict: bopomofo :: Pronunciation -> Str
- Text.MoeDict: bopomofo2 :: Pronounciation -> Str
+ Text.MoeDict: bopomofo2 :: Pronunciation -> Str
- Text.MoeDict: pinyin :: Pronounciation -> Str
+ Text.MoeDict: pinyin :: Pronunciation -> Str
Files
- MoeDict.cabal +1/−1
- Text/MoeDict.hs +39/−14
MoeDict.cabal view
@@ -1,5 +1,5 @@ name: MoeDict-version: 0.0.2+version: 0.0.3 license: PublicDomain cabal-version: >= 1.6 author: Audrey Tang
Text/MoeDict.hs view
@@ -17,20 +17,29 @@ import Data.Function (on) type Str = Text-data Pronounciation = Pronounciation { bopomofo :: Str, bopomofo2 :: Str, pinyin :: Str } deriving (Show, Eq, Ord)-$(deriveJSON defaultOptions ''Pronounciation)+data Pronunciation = Pronunciation { bopomofo :: Str, bopomofo2 :: Str, pinyin :: Str } deriving (Show, Eq, Ord)+$(deriveJSON defaultOptions ''Pronunciation) newtype Quote = Quote Str deriving (Show, IsString, FromJSON, ToJSON, Eq, Ord) data Radical = Radical { letter :: Char , strokeCount :: Count , nonRadicalStrokeCount :: Count+ , shapeDescription :: Maybe Text -- "解形" } deriving (Show, Ord, Eq) newtype Example = Example Str deriving (Show, IsString, FromJSON, ToJSON, Eq, Ord) newtype Title = Title { titleText :: Str } deriving (Show, IsString, FromJSON, ToJSON, Ord, Eq) newtype Link = Link Str deriving (Show, IsString, FromJSON, ToJSON, Eq, Ord) newtype Count = Count Int deriving (Show, Ord, Eq, FromJSON, ToJSON, Enum)-data Part = Preposition | Pronoun | Adverb | Particle | Verb | Noun | Adjective | Exclamation | Onomatopoeia | Affix | Conjunction | Note deriving (Show, Eq, Ord)+data Part = Preposition | Pronoun | Adverb | Particle | Verb | Noun | Adjective | Exclamation | Onomatopoeia | Affix | Conjunction | Note+ | Slang | Loanword | Derivative+ | Composition | Synonym | Antonym+ | Cantonese | PuTongHua | None+ deriving (Show, Eq, Ord) data POS = POS { label :: Text, part :: Part } deriving (Show, Eq, Ord)+data Reference = Reference+ { refType :: Maybe POS+ , refText :: Text+ } deriving (Show, Eq, Ord) instance FromJSON POS where parseJSON (String s) = maybe (fail $ show s) (pure . POS s) $ lookup s@@ -38,6 +47,10 @@ , ("助", Particle), ("動", Verb), ("名", Noun) , ("形", Adjective), ("歎", Exclamation), ("狀", Onomatopoeia) , ("綴", Affix), ("連", Conjunction), ("辨似", Note)+ , ("俚", Slang), ("外", Loanword), ("衍", Derivative)+ , ("孳", Composition), ("同", Synonym), ("反", Antonym)+ , ("廣東話", Cantonese), ("普通話", PuTongHua)+ , ("", None) ] parseJSON x = fail $ show x @@ -45,10 +58,12 @@ { title :: Title , radical :: Maybe Radical , heteronyms :: [Heteronym]+ , references :: [Reference]+ -- TODO: Translations? } deriving (Show, Eq, Ord) data Heteronym = Heteronym- { pronounciation :: Pronounciation- , definitions :: [Definition]+ { pronunciation :: Pronunciation+ , definitions :: [Definition] } deriving (Show, Eq, Ord) data Definition = Definition { definition :: Text@@ -66,6 +81,7 @@ instance FromJSON Entry where parseJSON (Object o) = do title <- o .: "title"+ references <- maybeList <$> o .:? "references" heteronyms <- catMaybes <$> o .: "heteronyms" rv <- o .:? "radical" radical <- case rv of@@ -73,8 +89,15 @@ Just letter -> Just <$> do strokeCount <- o .: "stroke_count" nonRadicalStrokeCount <- o .: "non_radical_stroke_count"+ shapeDescription <- o .:? "shape_description" return Radical{..} return Entry{..}+instance FromJSON Reference where+ parseJSON (Object o) = do+ pos <- o .:? "type"+ txt <- o .: "text"+ return $ Reference pos txt+ instance FromJSON Definition where parseJSON (Object o) = do definition <- o .: "def"@@ -86,22 +109,24 @@ synonyms <- maybeTitles <$> o .:? "synonyms" return Definition {..} where- maybeList Nothing = []- maybeList (Just xs) = xs maybeTitles Nothing = [] maybeTitles (Just xs) = Title <$> (T.splitOn "," xs)++maybeList Nothing = []+maybeList (Just xs) = xs+ instance ToJSON Definition where toJSON Definition {..} = error "NYI" instance FromJSON Heteronym where parseJSON json@(Object o) = do- pronounciation <- parseJSON json- definitions <- o .: "definitions"- return $ Heteronym { pronounciation, definitions }+ pronunciation <- parseJSON json+ definitions <- o .: "definitions"+ return $ Heteronym { pronunciation, definitions } instance ToJSON Heteronym where toJSON Heteronym {..} = object- [ ("pronounciation" .= pronounciation)- , ("definitions" .= definitions)+ [ ("pronunciation" .= pronunciation)+ , ("definitions" .= definitions) ] parseMoeDictFile :: FilePath -> IO [Entry]@@ -143,7 +168,7 @@ es' = sortBy (compare `on` title) es splitHeteronym :: Entry -> [Entry]-splitHeteronym Entry{..} = [ Entry{title, radical, heteronyms=[h]} | h <- heteronyms ]+splitHeteronym Entry{..} = [ Entry{title, radical, references, heteronyms=[h]} | h <- heteronyms ] entryHead :: Entry -> HeadWord entryHead Entry{..} = HeadWord {..}@@ -153,4 +178,4 @@ T.dropWhileEnd (== 'r') $ -- 兒化韻 T.takeWhile (/= ' ') $ T.dropWhile (> '\255') $- pinyin (pronounciation (head heteronyms))+ pinyin (pronunciation (head heteronyms))