Commit 3665ccda authored by mzheng's avatar mzheng

fix, using .:? instead of .: for more flexibility

parent 3a7d039e
......@@ -43,7 +43,7 @@ instance FromJSON Corpus where
_corpus_source <- o .:? "source_s"
_corpus_authors_names <- o .: "authFullName_s" <|> return []
idsNames <- o .: "structIdName_fs" :: Parser [Text] --unsparsed (contains a _FacetSep_)
idsNames <- o .:? "structIdName_fs" :: Parser (Maybe [Text]) --unsparsed (contains a _FacetSep_)
let structIdname = getStructIdsNames idsNames
......@@ -64,11 +64,12 @@ instance FromJSON Corpus where
-- > StructId_FacetSep_StructName
--
-- returns [(StructId, StructName)]
getStructIdsNames :: [T.Text] -> [(Int, T.Text)]
getStructIdsNames idsNames = map (\tab -> (P.read (T.unpack (P.head tab)) :: Int, P.last tab)) $ splitInstitutes idsNames
getStructIdsNames :: Maybe [T.Text] -> [(Int, T.Text)]
getStructIdsNames (Just idsNames) = map (\tab -> (P.read (T.unpack (P.head tab)) :: Int, P.last tab)) $ splitInstitutes idsNames
where
splitInstitutes :: [T.Text] -> [[T.Text]]
splitInstitutes = P.map (T.splitOn (T.pack "_FacetSep_"))
getStructIdsNames Nothing = []
instance ToHttpApiData Corpus where
toUrlPiece _ = "docid,title_s,en_abstract_s,fr_abstract_s,submittedDate_s,source_s,authFullName_s,structId_i,structIdName_fs"
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