Commit 14fa1393 authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Add ToExpr to Phylo

parent be58a6ac
...@@ -616,6 +616,7 @@ library ...@@ -616,6 +616,7 @@ library
, timezone-series ^>= 0.1.13 , timezone-series ^>= 0.1.13
, transformers ^>= 0.5.6.2 , transformers ^>= 0.5.6.2
, transformers-base ^>= 0.4.6 , transformers-base ^>= 0.4.6
, tree-diff
, tomland >= 1.3.3.2 , tomland >= 1.3.3.2
, tuple ^>= 0.3.0.2 , tuple ^>= 0.3.0.2
, unordered-containers ^>= 0.2.16.0 , unordered-containers ^>= 0.2.16.0
......
...@@ -33,6 +33,7 @@ import Data.Aeson.TH (deriveJSON) ...@@ -33,6 +33,7 @@ import Data.Aeson.TH (deriveJSON)
import Data.Swagger import Data.Swagger
import Data.Text (pack) import Data.Text (pack)
import Data.Text.Lazy qualified as TextLazy import Data.Text.Lazy qualified as TextLazy
import Data.TreeDiff
import Data.Vector (Vector) import Data.Vector (Vector)
import Gargantext.Core.Utils.Prefix (unPrefix) import Gargantext.Core.Utils.Prefix (unPrefix)
import Gargantext.Core.Utils.Prefix (unPrefixSwagger) import Gargantext.Core.Utils.Prefix (unPrefixSwagger)
...@@ -48,13 +49,13 @@ data CorpusParser = ...@@ -48,13 +49,13 @@ data CorpusParser =
Wos {_wos_limit :: Int} Wos {_wos_limit :: Int}
| Csv {_csv_limit :: Int} | Csv {_csv_limit :: Int}
| Csv' {_csv'_limit :: Int} | Csv' {_csv'_limit :: Int}
deriving (Show,Generic,Eq) deriving (Show,Generic,Eq, ToExpr)
instance ToSchema CorpusParser where instance ToSchema CorpusParser where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_")
data ListParser = V3 | V4 deriving (Show,Generic,Eq) data ListParser = V3 | V4 deriving (Show,Generic,Eq,ToExpr)
instance ToSchema ListParser instance ToSchema ListParser
...@@ -66,7 +67,7 @@ data SeaElevation = ...@@ -66,7 +67,7 @@ data SeaElevation =
{ _adap_steps :: Double } { _adap_steps :: Double }
| Evolving | Evolving
{ _evol_neighborhood :: Bool } { _evol_neighborhood :: Bool }
deriving (Show,Generic,Eq) deriving (Show,Generic,Eq,ToExpr)
instance ToSchema SeaElevation instance ToSchema SeaElevation
...@@ -81,17 +82,17 @@ data PhyloSimilarity = ...@@ -81,17 +82,17 @@ data PhyloSimilarity =
{ _hmg_sensibility :: Double { _hmg_sensibility :: Double
, _hmg_minSharedNgrams :: Int} , _hmg_minSharedNgrams :: Int}
deriving (Show,Generic,Eq) deriving (Show,Generic,Eq,ToExpr)
instance ToSchema PhyloSimilarity where instance ToSchema PhyloSimilarity where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "")
data SynchronyScope = SingleBranch | SiblingBranches | AllBranches data SynchronyScope = SingleBranch | SiblingBranches | AllBranches
deriving (Show,Generic,Eq, ToSchema) deriving (Show,Generic,Eq, ToSchema, ToExpr)
data SynchronyStrategy = MergeRegularGroups | MergeAllGroups data SynchronyStrategy = MergeRegularGroups | MergeAllGroups
deriving (Show,Generic,Eq) deriving (Show,Generic,Eq,ToExpr)
instance ToSchema SynchronyStrategy where instance ToSchema SynchronyStrategy where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "")
...@@ -106,7 +107,7 @@ data Synchrony = ...@@ -106,7 +107,7 @@ data Synchrony =
| ByProximityDistribution | ByProximityDistribution
{ _bpd_sensibility :: Double { _bpd_sensibility :: Double
, _bpd_strategy :: SynchronyStrategy } , _bpd_strategy :: SynchronyStrategy }
deriving (Show,Generic,Eq) deriving (Show,Generic,Eq,ToExpr)
instance ToSchema Synchrony where instance ToSchema Synchrony where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_")
...@@ -134,13 +135,13 @@ data TimeUnit = ...@@ -134,13 +135,13 @@ data TimeUnit =
{ _day_period :: Int { _day_period :: Int
, _day_step :: Int , _day_step :: Int
, _day_matchingFrame :: Int } , _day_matchingFrame :: Int }
deriving (Show,Generic,Eq,NFData) deriving (Show,Generic,Eq,NFData,ToExpr)
instance ToSchema TimeUnit where instance ToSchema TimeUnit where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "")
data MaxCliqueFilter = ByThreshold | ByNeighbours deriving (Show,Generic,Eq) data MaxCliqueFilter = ByThreshold | ByNeighbours deriving (Show,Generic,Eq,ToExpr)
instance ToSchema MaxCliqueFilter where instance ToSchema MaxCliqueFilter where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "")
...@@ -155,7 +156,7 @@ data Cluster = ...@@ -155,7 +156,7 @@ data Cluster =
{ _mcl_size :: Int { _mcl_size :: Int
, _mcl_threshold :: Double , _mcl_threshold :: Double
, _mcl_filter :: MaxCliqueFilter } , _mcl_filter :: MaxCliqueFilter }
deriving (Show,Generic,Eq) deriving (Show,Generic,Eq,ToExpr)
instance ToSchema Cluster where instance ToSchema Cluster where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "")
...@@ -164,7 +165,7 @@ instance ToSchema Cluster where ...@@ -164,7 +165,7 @@ instance ToSchema Cluster where
data Quality = data Quality =
Quality { _qua_granularity :: Double Quality { _qua_granularity :: Double
, _qua_minBranch :: Int } , _qua_minBranch :: Int }
deriving (Show,Generic,Eq) deriving (Show,Generic,Eq,ToExpr)
instance ToSchema Quality where instance ToSchema Quality where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_qua_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_qua_")
...@@ -189,7 +190,7 @@ data PhyloConfig = ...@@ -189,7 +190,7 @@ data PhyloConfig =
, exportLabel :: [PhyloLabel] , exportLabel :: [PhyloLabel]
, exportSort :: Sort , exportSort :: Sort
, exportFilter :: [Filter] , exportFilter :: [Filter]
} deriving (Show,Generic,Eq) } deriving (Show,Generic,Eq,ToExpr)
-------------------------------- --------------------------------
-- | SubConfig API & 1Click | -- -- | SubConfig API & 1Click | --
...@@ -306,7 +307,7 @@ instance ToJSON Quality ...@@ -306,7 +307,7 @@ instance ToJSON Quality
data Software = data Software =
Software { _software_name :: Text Software { _software_name :: Text
, _software_version :: Text , _software_version :: Text
} deriving (Generic, Show, Eq) } deriving (Generic, Show, Eq, ToExpr)
instance ToSchema Software where instance ToSchema Software where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_software_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_software_")
...@@ -324,7 +325,7 @@ data PhyloParam = ...@@ -324,7 +325,7 @@ data PhyloParam =
PhyloParam { _phyloParam_version :: Text PhyloParam { _phyloParam_version :: Text
, _phyloParam_software :: Software , _phyloParam_software :: Software
, _phyloParam_config :: PhyloConfig , _phyloParam_config :: PhyloConfig
} deriving (Generic, Show, Eq) } deriving (Generic, Show, Eq, ToExpr)
instance ToSchema PhyloParam where instance ToSchema PhyloParam where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phyloParam_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phyloParam_")
...@@ -373,7 +374,7 @@ data Document = Document ...@@ -373,7 +374,7 @@ data Document = Document
data PhyloFoundations = PhyloFoundations data PhyloFoundations = PhyloFoundations
{ _foundations_roots :: (Vector Ngrams) { _foundations_roots :: (Vector Ngrams)
, _foundations_rootsInGroups :: Map Int [PhyloGroupId] -- map of roots associated to groups , _foundations_rootsInGroups :: Map Int [PhyloGroupId] -- map of roots associated to groups
} deriving (Generic, Show, Eq) } deriving (Generic, Show, Eq, ToExpr)
data PhyloCounts = PhyloCounts data PhyloCounts = PhyloCounts
{ coocByDate :: !(Map Date Cooc) { coocByDate :: !(Map Date Cooc)
...@@ -382,10 +383,10 @@ data PhyloCounts = PhyloCounts ...@@ -382,10 +383,10 @@ data PhyloCounts = PhyloCounts
, rootsCount :: !(Map Int Double) , rootsCount :: !(Map Int Double)
, rootsFreq :: !(Map Int Double) , rootsFreq :: !(Map Int Double)
, lastRootsFreq :: !(Map Int Double) , lastRootsFreq :: !(Map Int Double)
} deriving (Generic, Show, Eq) } deriving (Generic, Show, Eq, ToExpr)
data PhyloSources = PhyloSources data PhyloSources = PhyloSources
{ _sources :: !(Vector Text) } deriving (Generic, Show, Eq) { _sources :: !(Vector Text) } deriving (Generic, Show, Eq, ToExpr)
instance ToSchema PhyloFoundations where instance ToSchema PhyloFoundations where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_foundations_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_foundations_")
...@@ -432,7 +433,7 @@ data Phylo = ...@@ -432,7 +433,7 @@ data Phylo =
, _phylo_quality :: Double , _phylo_quality :: Double
, _phylo_level :: Double , _phylo_level :: Double
} }
deriving (Generic, Show, Eq) deriving (Generic, Show, Eq, ToExpr)
instance ToSchema Phylo where instance ToSchema Phylo where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_")
...@@ -449,7 +450,7 @@ data PhyloPeriod = ...@@ -449,7 +450,7 @@ data PhyloPeriod =
PhyloPeriod { _phylo_periodPeriod :: Period PhyloPeriod { _phylo_periodPeriod :: Period
, _phylo_periodPeriodStr :: PeriodStr , _phylo_periodPeriodStr :: PeriodStr
, _phylo_periodScales :: Map PhyloScaleId PhyloScale , _phylo_periodScales :: Map PhyloScaleId PhyloScale
} deriving (Generic, Show, Eq) } deriving (Generic, Show, Eq, ToExpr)
instance ToSchema PhyloPeriod where instance ToSchema PhyloPeriod where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_")
...@@ -471,7 +472,7 @@ data PhyloScale = ...@@ -471,7 +472,7 @@ data PhyloScale =
, _phylo_scaleScale :: Scale , _phylo_scaleScale :: Scale
, _phylo_scaleGroups :: Map PhyloGroupId PhyloGroup , _phylo_scaleGroups :: Map PhyloGroupId PhyloGroup
} }
deriving (Generic, Show, Eq) deriving (Generic, Show, Eq, ToExpr)
instance ToSchema PhyloScale where instance ToSchema PhyloScale where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_")
...@@ -506,7 +507,7 @@ data PhyloGroup = ...@@ -506,7 +507,7 @@ data PhyloGroup =
, _phylo_groupPeriodMemoryParents :: [Pointer'] , _phylo_groupPeriodMemoryParents :: [Pointer']
, _phylo_groupPeriodMemoryChilds :: [Pointer'] , _phylo_groupPeriodMemoryChilds :: [Pointer']
} }
deriving (Generic, Show, Eq, NFData, Ord) deriving (Generic, Show, Eq, NFData, Ord, ToExpr)
instance ToSchema PhyloGroup where instance ToSchema PhyloGroup where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_")
...@@ -547,19 +548,19 @@ data Clustering = Clustering ...@@ -547,19 +548,19 @@ data Clustering = Clustering
type DotId = TextLazy.Text type DotId = TextLazy.Text
data EdgeType = GroupToGroup | GroupToGroupMemory | BranchToGroup | BranchToBranch | GroupToAncestor | PeriodToPeriod deriving (Show,Generic,Eq) data EdgeType = GroupToGroup | GroupToGroupMemory | BranchToGroup | BranchToBranch | GroupToAncestor | PeriodToPeriod deriving (Show,Generic,Eq,ToExpr)
data Filter = ByBranchSize { _branch_size :: Double } deriving (Show,Generic,Eq) data Filter = ByBranchSize { _branch_size :: Double } deriving (Show,Generic,Eq,ToExpr)
instance ToSchema Filter where instance ToSchema Filter where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "")
data Order = Asc | Desc deriving (Show,Generic,Eq, ToSchema) data Order = Asc | Desc deriving (Show,Generic,Eq, ToSchema, ToExpr)
data Sort = ByBirthDate { _sort_order :: Order } | ByHierarchy {_sort_order :: Order } deriving (Show,Generic,Eq) data Sort = ByBirthDate { _sort_order :: Order } | ByHierarchy {_sort_order :: Order } deriving (Show,Generic,Eq,ToExpr)
instance ToSchema Sort where instance ToSchema Sort where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_sort_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_sort_")
data Tagger = MostInclusive | MostEmergentInclusive | MostEmergentTfIdf deriving (Show,Generic,Eq) data Tagger = MostInclusive | MostEmergentInclusive | MostEmergentTfIdf deriving (Show,Generic,Eq,ToExpr)
instance ToSchema Tagger where instance ToSchema Tagger where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "")
...@@ -570,7 +571,7 @@ data PhyloLabel = ...@@ -570,7 +571,7 @@ data PhyloLabel =
| GroupLabel | GroupLabel
{ _group_labelTagger :: Tagger { _group_labelTagger :: Tagger
, _group_labelSize :: Int } , _group_labelSize :: Int }
deriving (Show,Generic,Eq) deriving (Show,Generic,Eq,ToExpr)
instance ToSchema PhyloLabel where instance ToSchema PhyloLabel where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_")
......
...@@ -5,23 +5,25 @@ ...@@ -5,23 +5,25 @@
module Test.Offline.Phylo (tests) where module Test.Offline.Phylo (tests) where
import Common
import Data.Aeson import Data.Aeson
import Data.GraphViz.Attributes.Complete qualified as Graphviz import Data.GraphViz.Attributes.Complete qualified as Graphviz
import Data.Text.Lazy as TL import Data.Text.Lazy as TL
import Data.TreeDiff
import Data.Vector qualified as V import Data.Vector qualified as V
import Gargantext.Core.Viz.Phylo import Gargantext.Core.Viz.Phylo
import Gargantext.Core.Viz.Phylo.API.Tools (readPhylo, writePhylo) import Gargantext.Core.Viz.Phylo.API.Tools (readPhylo, writePhylo)
import Gargantext.Core.Viz.Phylo.PhyloExport import Gargantext.Core.Viz.Phylo.PhyloExport
import Gargantext.Core.Viz.Phylo.PhyloMaker (toPhylo, toPhyloWithoutLink) import Gargantext.Core.Viz.Phylo.PhyloMaker (toPhylo, toPhyloWithoutLink)
import Gargantext.Core.Viz.Phylo.PhyloTools import Gargantext.Core.Viz.Phylo.PhyloTools
import Paths_gargantext
import Prelude import Prelude
import Test.QuickCheck
import Test.QuickCheck.Monadic
import Test.Tasty import Test.Tasty
import Test.Tasty.HUnit import Test.Tasty.HUnit
import Test.Tasty.QuickCheck import Test.Tasty.QuickCheck
import Common
import Paths_gargantext
phyloConfig :: PhyloConfig phyloConfig :: PhyloConfig
phyloConfig = PhyloConfig { phyloConfig = PhyloConfig {
corpusPath = "corpus.csv" corpusPath = "corpus.csv"
...@@ -53,39 +55,39 @@ tests = testGroup "Phylo" [ ...@@ -53,39 +55,39 @@ tests = testGroup "Phylo" [
, testCase "ngramsToLabel is rendered correctly in CustomAttribute" test_ngramsToLabel_02 , testCase "ngramsToLabel is rendered correctly in CustomAttribute" test_ngramsToLabel_02
] ]
, testGroup "toPhyloWithoutLink" [ , testGroup "toPhyloWithoutLink" [
testCase "returns expected data" testSmallPhyloWithoutLinkExpectedOutput testProperty "returns expected data" testSmallPhyloWithoutLinkExpectedOutput
] ]
, testGroup "toPhylo" [ , testGroup "toPhylo" [
testCase "returns expected data" testSmallPhyloExpectedOutput testProperty "returns expected data" testSmallPhyloExpectedOutput
] ]
, testGroup "relatedComponents" [ , testGroup "relatedComponents" [
testCase "finds simple connection" testRelComp_Connected testCase "finds simple connection" testRelComp_Connected
] ]
] ]
testSmallPhyloWithoutLinkExpectedOutput :: Assertion testSmallPhyloWithoutLinkExpectedOutput :: Property
testSmallPhyloWithoutLinkExpectedOutput = do testSmallPhyloWithoutLinkExpectedOutput = monadicIO $ do
bpaConfig <- getDataFileName "bench-data/phylo/bpa-config.json" bpaConfig <- run $ getDataFileName "bench-data/phylo/bpa-config.json"
corpusPath' <- getDataFileName "test-data/phylo/small_phylo_docslist.csv" corpusPath' <- run $ getDataFileName "test-data/phylo/small_phylo_docslist.csv"
listPath' <- getDataFileName "test-data/phylo/small_phylo_ngramslist.csv" listPath' <- run $ getDataFileName "test-data/phylo/small_phylo_ngramslist.csv"
(Right config) <- fmap (\pcfg -> pcfg { corpusPath = corpusPath' (Right config) <- fmap (\pcfg -> pcfg { corpusPath = corpusPath'
, listPath = listPath' , listPath = listPath'
}) <$> (eitherDecodeFileStrict' bpaConfig) }) <$> (run $ eitherDecodeFileStrict' bpaConfig)
mapList <- fileToList (listParser config) (listPath config) mapList <- run $ fileToList (listParser config) (listPath config)
corpus <- fileToDocsDefault (corpusParser config) corpus <- run $ fileToDocsDefault (corpusParser config)
(corpusPath config) (corpusPath config)
[Year 3 1 5,Month 3 1 5,Week 4 2 5] [Year 3 1 5,Month 3 1 5,Week 4 2 5]
mapList mapList
actual <- pure $ toPhyloWithoutLink corpus config actual <- pure $ toPhyloWithoutLink corpus config
expected <- readPhylo =<< getDataFileName "test-data/phylo/small-phylo.golden.json" expected <- run $ readPhylo =<< getDataFileName "test-data/phylo/small-phylo.golden.json"
expected @?= actual pure $ counterexample (show $ ansiWlEditExpr $ ediff' expected actual) (expected === actual)
testSmallPhyloExpectedOutput :: Assertion testSmallPhyloExpectedOutput :: Property
testSmallPhyloExpectedOutput = do testSmallPhyloExpectedOutput = monadicIO $ do
issue290PhyloSmall <- setConfig phyloConfig <$> (readPhylo =<< getDataFileName "bench-data/phylo/issue-290-small.json") issue290PhyloSmall <- run $ setConfig phyloConfig <$> (readPhylo =<< getDataFileName "bench-data/phylo/issue-290-small.json")
expected <- readPhylo =<< getDataFileName "test-data/phylo/issue-290-small.golden.json" expected <- run $ readPhylo =<< getDataFileName "test-data/phylo/issue-290-small.golden.json"
let actual = toPhylo issue290PhyloSmall let actual = toPhylo issue290PhyloSmall
expected @?= actual pure $ counterexample (show $ ansiWlEditExpr $ ediff' expected actual) (expected === actual)
test_ngramsToLabel_01 :: Assertion test_ngramsToLabel_01 :: Assertion
test_ngramsToLabel_01 = test_ngramsToLabel_01 =
......
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