ask
  :: MLN -- ^ A Markov logic network.
  -> [T.Text] -- ^ A list of constants to ground the Markov logic network.
  -> String -- ^ A query to be parsed by 'Sphinx.Parser.parseCondQuery' or 'Sphinx.Parser.parseJointQuery'.
  -> Maybe Double -- ^ Either a double in [0.0, 1.0] or Nothing if the parsers fail.
ask mln terms query = pq <|> pj
  where
    ts = map Constant terms
    pq = case parseCondQuery query of
      Left _ -> Nothing; Right (q, c) -> Just $ conditional mln ts q c
    pj = case parseJointQuery query of
      Left _ -> Nothing; Right q -> Just $ joint mln ts q

-- | Direct method of computing joint probabilities for Markov logic (does not
-- scale!).
ask
  :: MLN -- ^ A Markov logic network.
  -> [T.Text] -- ^ A list of constants to ground the Markov logic network.
  -> String -- ^ A query to be parsed by 'Sphinx.Parser.parseCondQuery' or 'Sphinx.Parser.parseJointQuery'.
  -> Maybe Double
ask mln terms query = pq <|> pj
  where
    ts = map Constant terms
    pq = case parseCondQuery query of
      Left _ -> Nothing; Right (q, c) -> Just $ conditional mln ts q c
    pj = case parseJointQuery query of
      Left _ -> Nothing; Right q -> Just $ joint mln ts q

-- | Direct method of computing joint probabilities for Markov logic (does not
-- scale!).
ask mln terms query = pq <|> pj
  where
    ts = map Constant terms
    pq = case parseCondQuery query of
      Left _ -> Nothing; Right (q, c) -> Just $ conditional mln ts q c
    pj = case parseJointQuery query of
      Left _ -> Nothing; Right q -> Just $ joint mln ts q

-- | Direct method of computing joint probabilities for Markov logic (does not
-- scale!).