Commit 0426c9f1 authored by Alfredo Di Napoli's avatar Alfredo Di Napoli Committed by Alfredo Di Napoli

Rewrite buildForest in terms of graphs (and strongly-connected

components)

This commit rewrites the logic behind `buildForest` to build first a
graph, discovering loops in there (via the strongly-connected components
machinery) and finally converting the DAG (freshly-made so) into a
Forest.
parent 4739268a
Pipeline #7945 failed with stages
in 43 minutes and 33 seconds
This diff is collapsed.
......@@ -198,7 +198,7 @@ data BuildForestError
= -- We found a loop, something that shouldn't normally happen if the calling
-- code is correct by construction, but if that does happen, the value will
-- contain the full path to the cycle.
BFE_loop_detected !(Set VisitedNode)
BFE_loop_detected !(Set VisitedNode)
deriving (Show, Eq)
instance ToHumanFriendlyError BuildForestError where
......
......@@ -235,7 +235,7 @@ testFlat05 = do
testForestSearchProp :: Property
testForestSearchProp = forAll arbitrary $ \(AcyclicTableMap ngramsTable el) -> do
case searchTableNgrams (Versioned 0 ngramsTable) (searchQuery el) of
Left (BFE_loop_detected err) -> fail (T.unpack $ renderLoop err)
Left (BFE_loop_detected err) -> fail (T.unpack $ renderLoop err)
Right res -> res ^. vc_data `shouldSatisfy` (any (containsTerm (_ne_ngrams el)) . getNgramsTable)
where
searchQuery term = NgramsSearchQuery {
......
......@@ -315,8 +315,8 @@ testLoopBreaker_02 =
let t1 = Map.fromList [ ( "foo", mkMapTerm "foo" & ne_children .~ mSetFromList ["bar"])
, ( "bar", mkMapTerm "bar" & ne_children .~ mSetFromList ["foo"])
]
in (buildForestOrBreakLoop t1) `compareForestVisually` [r|
foo
in (pruneForest $ buildForestOrBreakLoop t1) `compareForestVisually` [r|
bar
|
`- bar
`- foo
|]
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