2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell{- |
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellModule : ./CASL/Taxonomy.hs
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellDescription : converters for theories to MMiSSOntology
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell (subsorting and concept taxonomies)
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellCopyright : (c) Klaus Luettich, Uni Bremen 2002-2004
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellLicense : GPLv2 or higher, see LICENSE.txt
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellMaintainer : luecke@informatik.uni-bremen.de
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellStability : provisional
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellPortability : portable
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellConverters for theories to MMiSSOntology (subsorting and concept taxonomies)
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellthe functions showOntClass, showRelationName and showRelation may be used
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellfor printing out MMiSS Ontologies in LaTeX to Stdout
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell(see commets marked with --printOut).
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellPlease do not remove them without reason!!
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell-}
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnellmodule CASL.Taxonomy
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnell ( -- * Conversion
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnell convTaxo
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnell -- * Printing of MMiSS ontologies in LaTeX
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnell , showOntClass, showRelationName, showRelation) where
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnell
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnellimport CASL.AS_Basic_CASL
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnellimport CASL.Sign
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnellimport Taxonomy.MMiSSOntology
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellimport Common.Taxonomy
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellimport Common.Result
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnellimport Common.Id ()
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnellimport Common.AS_Annotation
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnellimport qualified Common.Lib.MapSet as MapSet
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnellimport qualified Common.Lib.Rel as Rel
fb63998ce7684bddab24e10c0b593809df1b7bffCraig McDonnell
3cb6a584a87fa8fec140b0bb20dd91731d13e751Diego Colantoniimport qualified Data.Map as Map
3cb6a584a87fa8fec140b0bb20dd91731d13e751Diego Colantoniimport qualified Data.Set as Set
3cb6a584a87fa8fec140b0bb20dd91731d13e751Diego Colantoni
3cb6a584a87fa8fec140b0bb20dd91731d13e751Diego Colantoni{- | convert a generic CASL signature into the MMiSS ontology
3cb6a584a87fa8fec140b0bb20dd91731d13e751Diego Colantonidatastructure for display as taxonomy graph -}
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnellconvTaxo :: TaxoGraphKind -> MMiSSOntology
-> Sign f e
-> [Named (FORMULA f)] -> Result MMiSSOntology
convTaxo kind onto sign sens =
fromWithError $
case kind of
KSubsort -> convSign KSubsort onto sign
KConcept -> foldl convSen (convSign KConcept onto sign) sens
convSign :: TaxoGraphKind
-> MMiSSOntology -> Sign f e -> WithError MMiSSOntology
convSign KConcept o s =
case convSign KSubsort o s of
wOnto -> weither (const wOnto) (convPred s) wOnto
convSign KSubsort onto sign =
Set.fold addSor (hasValue onto) $ sortSet sign
-- start with top sorts (maybe use Rel.mostRight?)
where relMap = Rel.toMap $ Rel.intransKernel $ sortRel sign
addSor sort weOnto =
let sortStr = show sort
in weither (const weOnto)
(\ on -> insClass on sortStr
(maybe [] toStrL $
Map.lookup sort relMap))
weOnto
insClass o nm supL =
insertClass o nm nm supL (Just SubSort)
toStrL = map show . Set.toList
convPred :: Sign f e -> MMiSSOntology -> WithError MMiSSOntology
convPred s o =
-- first only binary preds; later also unary preds
Map.foldWithKey addPred (hasValue o) $ MapSet.toMap $ predMap s
where addPred pn tSet wOnto =
weither (const wOnto) insBinaryPred wOnto
where insBinaryPred on =
let binT = Set.filter isBinPredType tSet
in if Set.null binT
then hasValue on
else Set.fold insType (insName on) binT
insName on = insertBaseRelation on (show pn) (show pn)
Nothing Nothing
insType t wOn =
weither (const wOn)
(\ ont ->
let [a1, a2] = predArgs t
src = show a1
tar = show a2
in insertRelationType ont (show pn)
src tar)
wOn
convSen :: WithError MMiSSOntology
-> Named (FORMULA f) -> WithError MMiSSOntology
convSen weOnto _nSen = weither (const weOnto) hasValue weOnto
-- implemented but not used by now
showOntClass :: String -> [String] -> String
showOntClass cln =
foldl (\ res sup -> res ++ ontClass sup) ""
where ontClass s = "\\Class{" ++ cln ++ "}{" ++ cln ++ "}{" ++ s ++ "}"
showRelationName :: String -> String
showRelationName rn = "\\RelationName{" ++ rn ++ "}{" ++ rn ++ "}"
showRelation :: String -> String -> String -> String
showRelation rn s t = "\\Relation{" ++ rn ++ "}{" ++ s ++ "}{" ++ t ++ "}{}"