2ca39b9545cad63df411619615736d9070ad7932Christian Maeder{-# LANGUAGE CPP #-}
2ca39b9545cad63df411619615736d9070ad7932Christian MaederDescription : reading Lib-Defns
2ca39b9545cad63df411619615736d9070ad7932Christian MaederCopyright : (c) C. Maeder, DFKI 2014
2ca39b9545cad63df411619615736d9070ad7932Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
2ca39b9545cad63df411619615736d9070ad7932Christian MaederMaintainer : Christian.Maeder@dfki.de
2ca39b9545cad63df411619615736d9070ad7932Christian MaederStability : provisional
2ca39b9545cad63df411619615736d9070ad7932Christian MaederPortability : non-portable(DevGraph)
2ca39b9545cad63df411619615736d9070ad7932Christian Maederreading Lib-Defns for various logics, OWL and CL return several Lib-Defns
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maedermodule Driver.ReadLibDefn (readLibDefn) where
2ca39b9545cad63df411619615736d9070ad7932Christian Maeder#ifndef NOOWLLOGIC
2ca39b9545cad63df411619615736d9070ad7932Christian Maeder#ifdef RDFLOGIC
b036d1e059b08fc4be7cf9f87703849723cf41eccmaeder-- import RDF.ParseRDFAsLibDefn -- MODULE RDF IS BROKEN AT THE MOMENT
aeabd99d28fef3b392ca208c5ac84f7892af0ddbnotanartistimport Control.Monad.Trans (MonadIO (..))
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian MaedermimeTypeMap :: [(String, InType)]
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder [ ("xml", DgXml)
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder , ("html", HtmlIn)
254f324c749726c14a3b405d148d777007557626notanartist , ("rdf", OWLIn RdfXml)
254f324c749726c14a3b405d148d777007557626notanartist , ("owl", OWLIn OwlXml)
254f324c749726c14a3b405d148d777007557626notanartist , ("obo", OWLIn OBO)
254f324c749726c14a3b405d148d777007557626notanartist , ("ttl", OWLIn Turtle)
254f324c749726c14a3b405d148d777007557626notanartist , ("turtle", OWLIn Turtle)
b036d1e059b08fc4be7cf9f87703849723cf41eccmaeder , ("omn", OWLIn Manchester)
254f324c749726c14a3b405d148d777007557626notanartist , ("dol", DOLIn)
254f324c749726c14a3b405d148d777007557626notanartist , ("clif", CommonLogicIn True)
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder , ("het", HetCASLIn)
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa , ("casl", CASLIn)
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa , ("tptp", TPTPIn)
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa , ("p", TPTPIn) ]
aeabd99d28fef3b392ca208c5ac84f7892af0ddbnotanartistowlXmlTypes :: [InType]
aeabd99d28fef3b392ca208c5ac84f7892af0ddbnotanartistowlXmlTypes = map OWLIn [OwlXml, RdfXml, Turtle]
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian MaederjoinFileTypes :: InType -> InType -> InType
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian MaederjoinFileTypes ext magic = case (ext, magic) of
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder (GuessIn, _) -> magic
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder (_, GuessIn) -> ext
aeabd99d28fef3b392ca208c5ac84f7892af0ddbnotanartist (DgXml, _) | elem magic owlXmlTypes -> magic
aeabd99d28fef3b392ca208c5ac84f7892af0ddbnotanartist (_, DgXml) | elem ext owlXmlTypes -> ext
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder (_, HtmlIn) -> magic
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder _ -> ext -- ignore contradictions
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian MaederfindFiletype :: String -> InType
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian MaederfindFiletype s =
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder maybe GuessIn snd $ find (\ (r, _) -> isInfixOf ('/' : r) s) mimeTypeMap
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian MaederguessInput :: MonadIO m => HetcatsOpts -> Maybe String -> FilePath -> String
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian MaederguessInput opts mr file input =
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder let fty1 = guess file (intype opts)
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder fty2 = maybe GuessIn findFiletype mr
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder fty = joinFileTypes fty1 fty2
aeabd99d28fef3b392ca208c5ac84f7892af0ddbnotanartist in if elem fty $ GuessIn : DgXml : owlXmlTypes then
be110dccc9f7bd9e987b35943b16ccb22922248fChristian Maeder case guessXmlContent (fty == DgXml) input of
be110dccc9f7bd9e987b35943b16ccb22922248fChristian Maeder Left ty -> fail ty
be110dccc9f7bd9e987b35943b16ccb22922248fChristian Maeder Right ty -> case ty of
be110dccc9f7bd9e987b35943b16ccb22922248fChristian Maeder DgXml -> fail "unexpected DGraph xml"
aeabd99d28fef3b392ca208c5ac84f7892af0ddbnotanartist _ -> return $ joinFileTypes fty ty
be110dccc9f7bd9e987b35943b16ccb22922248fChristian Maeder else return fty
d2db653e792249571fa437303fd5c1b152f4db9ccmaederreadLibDefn :: LogicGraph -> HetcatsOpts -> Maybe String
d2db653e792249571fa437303fd5c1b152f4db9ccmaeder -> FilePath -> FilePath -> String -> ResultT IO [LIB_DEFN]
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian MaederreadLibDefn lgraph opts mr file fileForPos input =
2ca39b9545cad63df411619615736d9070ad7932Christian Maeder if null input then fail ("empty input file: " ++ file) else
2ca39b9545cad63df411619615736d9070ad7932Christian Maeder case intype opts of
2ca39b9545cad63df411619615736d9070ad7932Christian Maeder ATermIn _ -> return [from_sml_ATermString input]
2ca39b9545cad63df411619615736d9070ad7932Christian Maeder liftIO $ fmap (: []) . readFreeCADLib file $ fileToLibName opts file
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder ty <- guessInput opts mr file input
6f70475dddc12732bdbef3e3dd116373e34cd6b9Christian Maeder HtmlIn -> fail "unexpected html input"
d2db653e792249571fa437303fd5c1b152f4db9ccmaeder CommonLogicIn _ -> parseCL_CLIF file opts
2ca39b9545cad63df411619615736d9070ad7932Christian Maeder#ifdef RDFLOGIC
8762d0e3d492aba4d1621fb0de685f0be1372864notanartist -- RDFIn -> liftIO $ parseRDF file
649fdc0d0502d62d160c150684356fef2c273484Eugen Kuksa Xmi -> return [parseXmi file input]
649fdc0d0502d62d160c150684356fef2c273484Eugen Kuksa Qvt -> liftIO $ fmap (: []) $ parseQvt file input
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa TPTPIn -> parseTPTP opts file input
2ca39b9545cad63df411619615736d9070ad7932Christian Maeder#ifndef NOOWLLOGIC
7af6ad49991a7f73b5d4233c89648a5a523f72bdTill Mossakowski OWLIn _ -> parseOWLAsLibDefn (isStructured opts) file
dc62afbf79603699b39b2387f48298634f642e67cmaeder _ -> case runParser (library lgraph { dolOnly = ty == DOLIn })
dc62afbf79603699b39b2387f48298634f642e67cmaeder (emptyAnnos ()) fileForPos input of
2ca39b9545cad63df411619615736d9070ad7932Christian Maeder Left err -> fail (showErr err)
2ca39b9545cad63df411619615736d9070ad7932Christian Maeder Right ast -> return [ast]