factors :: [Term] -> MLN -> Map (Set Predicate) FOL
factors ts (MLN m) = fs
  where
    -- All groundings mapped to their original formula
    gs = Set.foldr' (\k a -> Set.foldr' (`Map.insert` k) a (FOL.groundings ts k)) Map.empty (Map.keysSet m)
    -- Separate the formula in sets of predicates:
    fs = Map.foldrWithKey (\k v a -> Map.insert (F.atoms k) v a) Map.empty gs

-- | All possible assignments to the predicates in the network.
factors :: [Term] -> MLN -> Map (Set Predicate) FOL
factors ts (MLN m) = fs
  where
    -- All groundings mapped to their original formula
    gs = Set.foldr' (\k a -> Set.foldr' (`Map.insert` k) a (FOL.groundings ts k)) Map.empty (Map.keysSet m)
    -- Separate the formula in sets of predicates:
    fs = Map.foldrWithKey (\k v a -> Map.insert (F.atoms k) v a) Map.empty gs

-- | All possible assignments to the predicates in the network.
factors ts (MLN m) = fs
  where
    -- All groundings mapped to their original formula
    gs = Set.foldr' (\k a -> Set.foldr' (`Map.insert` k) a (FOL.groundings ts k)) Map.empty (Map.keysSet m)
    -- Separate the formula in sets of predicates:
    fs = Map.foldrWithKey (\k v a -> Map.insert (F.atoms k) v a) Map.empty gs

-- | All possible assignments to the predicates in the network.