-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1601 from spechub/1587_extracting_modules
1587 extracting modules
- Loading branch information
Showing
8 changed files
with
177 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{-# LANGUAGE DeriveDataTypeable #-} | ||
{- | | ||
Module : $Header$ | ||
Copyright : Till Mossakowski, Uni Magdeburg 2016 | ||
License : GPLv2 or higher, see LICENSE.txt | ||
Maintainer : [email protected] | ||
Stability : provisional | ||
Portability : portable | ||
OWL 2 module extraction | ||
-} | ||
|
||
module OWL2.ExtractModule where | ||
|
||
import OWL2.Sign | ||
import OWL2.MS | ||
import OWL2.ManchesterPrint | ||
import OWL2.ParseOWL | ||
import OWL2.StaticAnalysis | ||
|
||
import Common.Utils | ||
import Common.Result | ||
import Common.ResultT | ||
import Common.AS_Annotation | ||
import Common.GlobalAnnotations | ||
import qualified Common.IRI as IRI | ||
|
||
import Control.Monad.Trans | ||
import System.IO.Unsafe | ||
|
||
import Common.ExtSign | ||
|
||
extractModule :: [IRI.IRI] -> (Sign, [Named Axiom]) | ||
-> Result (Sign, [Named Axiom]) | ||
extractModule syms onto = | ||
unsafePerformIO $ runResultT $ extractModuleAux syms onto | ||
|
||
extractModuleAux :: [IRI.IRI] -> (Sign, [Named Axiom]) | ||
-> ResultT IO (Sign, [Named Axiom]) | ||
extractModuleAux syms onto = do | ||
let ontology_content = show $ printOWLBasicTheory onto | ||
inFile <- lift $ getTempFile ontology_content "in" | ||
outFile <- lift $ getTempFile "" "out" | ||
let args = [inFile, "--extract-module", "-m", "STAR"] | ||
++ map (\x -> show $ x{IRI.hasAngles = False}) syms | ||
++ ["-o", outFile] | ||
(_code,_stdout,_stderr) <- lift $ executeProcess "owltools" args "" | ||
(_imap,ontos) <- parseOWL False outFile | ||
case ontos of | ||
[modOnto] -> do | ||
(_ontodoc, ExtSign sig _, sens) <- liftR $ | ||
basicOWL2Analysis (modOnto, emptySign, emptyGlobalAnnos) | ||
lift $ return (sig, sens) | ||
_ -> error "the module should be just one ontology" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{- | | ||
Module : $Header$ | ||
Copyright : Heng Jiang, Uni Bremen 2004-2007 | ||
License : GPLv2 or higher, see LICENSE.txt | ||
Maintainer : [email protected] | ||
Stability : provisional | ||
Portability : non-portable | ||
analyse OWL files by calling the external Java parser. | ||
-} | ||
|
||
module OWL2.ParseOWL (parseOWL, convertOWL) where | ||
|
||
import OWL2.MS | ||
import OWL2.Rename | ||
|
||
import qualified Data.ByteString.Lazy as L | ||
import Data.List | ||
import Data.Maybe | ||
import qualified Data.Map as Map | ||
|
||
import Common.XmlParser | ||
import Common.ProverTools | ||
import Common.Result | ||
import Common.ResultT | ||
import Common.Utils | ||
|
||
import Control.Monad | ||
import Control.Monad.Trans | ||
|
||
import OWL2.XML | ||
|
||
import System.Directory | ||
import System.Exit | ||
import System.FilePath | ||
|
||
import Text.XML.Light hiding (QName) | ||
|
||
-- | call for owl parser (env. variable $HETS_OWL_TOOLS muss be defined) | ||
parseOWL :: Bool -- ^ Sets Option.quick | ||
-> FilePath -- ^ local filepath or uri | ||
-> ResultT IO (Map.Map String String, [OntologyDocument]) -- ^ map: uri -> OntologyFile | ||
parseOWL quick fn = do | ||
tmpFile <- lift $ getTempFile "" "owlTemp.xml" | ||
(exitCode, _, errStr) <- parseOWLAux quick fn ["-o", "xml", tmpFile] | ||
case (exitCode, errStr) of | ||
(ExitSuccess, "") -> do | ||
cont <- lift $ L.readFile tmpFile | ||
lift $ removeFile tmpFile | ||
parseProc cont | ||
_ -> fail $ "process stop! " ++ shows exitCode "\n" ++ errStr | ||
|
||
parseOWLAux :: Bool -- ^ Sets Option.quick | ||
-> FilePath -- ^ local filepath or uri | ||
-> [String] -- ^ arguments for java parser | ||
-> ResultT IO (ExitCode, String, String) | ||
parseOWLAux quick fn args = do | ||
let jar = "OWL2Parser.jar" | ||
(hasJar, toolPath) <- lift $ check4HetsOWLjar jar | ||
if hasJar | ||
then lift $ executeProcess "java" (["-jar", toolPath </> jar] | ||
++ args ++ [fn] ++ ["-qk" | quick]) "" | ||
else fail $ jar | ||
++ " not found, check your environment variable: " ++ hetsOWLenv | ||
|
||
-- | converts owl file to desired syntax using owl-api | ||
convertOWL :: FilePath -> String -> IO String | ||
convertOWL fn tp = do | ||
Result ds mRes <- runResultT | ||
$ parseOWLAux False fn ["-o-sys", tp] | ||
case mRes of | ||
Just (exitCode, content, errStr) -> case (exitCode, errStr) of | ||
(ExitSuccess, "") -> return content | ||
_ -> error $ "process stop! " ++ shows exitCode "\n" ++ errStr | ||
_ -> error $ showRelDiags 2 ds | ||
|
||
parseProc :: L.ByteString | ||
-> ResultT IO (Map.Map String String, [OntologyDocument]) | ||
parseProc str = do | ||
res <- lift $ parseXml str | ||
case res of | ||
Left err -> fail err | ||
Right el -> let | ||
es = elChildren el | ||
mis = concatMap (filterElementsName $ isSmth "Missing") es | ||
imap = Map.fromList . mapMaybe (\ e -> do | ||
imp <- findAttr (unqual "name") e | ||
ont <- findAttr (unqual "ontiri") e | ||
return (imp, ont)) $ concatMap (filterElementsName $ isSmth "Loaded") es | ||
in do | ||
unless (null mis) . liftR . justWarn () $ "Missing imports: " | ||
++ intercalate ", " (map strContent mis) | ||
return (imap, unifyDocs . map (xmlBasicSpec imap) | ||
$ concatMap (filterElementsName $ isSmth "Ontology") es) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters