Commit d54812d5 authored by mzheng's avatar mzheng

adding institutes tree

parent 1dbd9392
......@@ -6,7 +6,7 @@ import Data.Aeson ( FromJSON )
import Data.LanguageCodes (ISO639_1(..))
import Data.Text qualified as T
import HAL.Client ( SortField(Asc), search, structure, searchCursor )
import HAL.Doc.Document ( Document )
import HAL.Doc.Document ( Document(..) )
import HAL.Doc.Struct ( Struct )
import HAL.Types (Response(..))
import HAL.Utils (langAbstractS, toText)
......@@ -231,7 +231,8 @@ baseFields = [ "docid"
, "source_s"
, "authFullName_s"
, "authOrganism_s"
, "structIdName_fs" ]
, "structIdName_fs"
, "instStructIsChildOf_fs" ]
structFields :: Text
structFields = "docid,label_s,parentDocid_i"
......
......@@ -26,13 +26,14 @@ data Document = Document
, _document_source :: Maybe Text
, _document_authors_names :: [Text]
, _document_authors_affiliations :: [Text]
, _document_institutes_tree :: Map Text Text
, _document_struct_id :: [Int]
, _document_original :: Object
} deriving (Show, Generic)
L.makeLenses ''Document
instance Default Document where
def = Document "default Id" def def def def def def def def mempty
def = Document "default Id" def def def def def def def def def mempty
instance FromJSON Document where
parseJSON = withObject "Document" $ \o -> do
......@@ -50,6 +51,10 @@ instance FromJSON Document where
let _document_struct_id = map fst structIdname
let _document_authors_affiliations = map snd structIdname
structChild <- o .:? "instStructIsChildOf_fs" :: Parser (Maybe [Text])
let _document_institutes_tree = Map.fromList $ getStructParentChild structChild
abstracts <-
mapM (\lang -> do
ma <- o .:? fromString (T.unpack $ langAbstractS lang)
......@@ -71,5 +76,25 @@ getStructIdsNames (Just idsNames) = map (\tab -> (P.read (T.unpack (P.head tab))
splitInstitutes = P.map (T.splitOn (T.pack "_FacetSep_"))
getStructIdsNames Nothing = []
getStructParentChild :: Maybe [T.Text] -> [(T.Text, T.Text)]
getStructParentChild (Just struct) = map (\tab -> (formatParent $ P.last tab, formatChild $ P.head tab)) $ splitStruct struct
where
splitStruct :: [T.Text] -> [[T.Text]]
splitStruct = P.map (T.splitOn (T.pack "_JoinSep_"))
formatChild c = name <> " | " <> id
where
name = P.last splited
id = P.head splited
splited = T.splitOn "_" c
formatParent p = name <> " | " <> id
where
name = P.last splited
id = P.head splited
splited = T.splitOn "_FacetSep_" p
getStructParentChild Nothing = []
instance ToHttpApiData Document 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