Taxonomy.hs revision ad4da9d870c666f00992431e3badbbe9cc4f19aa
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz{- |
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : $Header$
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst SchulzDescription : converters for theories to MMiSSOntology
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz (subsorting and concept taxonomies)
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuCopyright : (c) Klaus Luettich, Uni Bremen 2002-2004
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst SchulzLicense : GPLv2 or higher, see LICENSE.txt
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst SchulzMaintainer : luecke@informatik.uni-bremen.de
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst SchulzStability : provisional
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst SchulzPortability : portable
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst SchulzConverters for theories to MMiSSOntology (subsorting and concept taxonomies)
4cbba4634ba267c438f75fa7a5009f6249d3dda1Christian Maeder
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulzthe functions showOntClass, showRelationName and showRelation may be used
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulzfor printing out MMiSS Ontologies in LaTeX to Stdout
de8eee2014437ec4020be15cd363257f87e79943Christian Maeder(see commets marked with --printOut).
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst SchulzPlease do not remove them without reason!!
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder-}
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maedermodule CASL.Taxonomy
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulz ( -- * Conversion
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder convTaxo
1f7d5e06c0b9d99d257bdee9e8fb7bc000ec1d78Ewaryst Schulz -- * Printing of MMiSS ontologies in LaTeX
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulz , showOntClass, showRelationName, showRelation) where
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulzimport qualified Data.Map as Map
91b3147021cbeebb0590f4a577acba73142785c5Christian Maederimport qualified Common.Lib.Rel as Rel
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maederimport qualified Data.Set as Set
ad3327fb03d73436ee6f61c7ad2e51186137f46bChristian Maeder
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulzimport CASL.AS_Basic_CASL
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulzimport CASL.Sign
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulz
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulzimport Taxonomy.MMiSSOntology
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulz
1f0bfa2fbeea34f9ab8af45efcf50647c85c0ae5Ewaryst Schulzimport Common.Taxonomy
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulzimport Common.Result
c7f1a9b3811f1ed427c57559d9af26a75a309ff1Ewaryst Schulzimport Common.Id ()
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maederimport Common.AS_Annotation
01ddc4cad68fa84b4e9dd41089ad876329bae5b0Christian Maeder
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder{- | convert a generic CASL signature into the MMiSS ontology
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maederdatastructure for display as taxonomy graph -}
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederconvTaxo :: TaxoGraphKind -> MMiSSOntology
01ddc4cad68fa84b4e9dd41089ad876329bae5b0Christian Maeder -> Sign f e
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder -> [Named (FORMULA f)] -> Result MMiSSOntology
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaederconvTaxo kind onto sign sens =
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder fromWithError $
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder case kind of
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder KSubsort -> convSign KSubsort onto sign
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder KConcept -> foldl convSen (convSign KConcept onto sign) sens
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederconvSign :: TaxoGraphKind
de8eee2014437ec4020be15cd363257f87e79943Christian Maeder -> MMiSSOntology -> Sign f e -> WithError MMiSSOntology
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederconvSign KConcept o s =
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder case convSign KSubsort o s of
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder wOnto -> weither (const wOnto) (convPred s) wOnto
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederconvSign KSubsort onto sign =
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder Set.fold addSor (hasValue onto) $ sortSet sign
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder-- Ausgehend von den Top-Sorten -- Rel.mostRight
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder where str = show
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder relMap = Rel.toMap $ Rel.intransKernel $ sortRel sign
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder addSor sort weOnto =
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder let sortStr = str sort
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder in weither (const weOnto)
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder (\ on -> insClass on sortStr
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder (maybe [] toStrL $
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder Map.lookup sort relMap))
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder weOnto
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder insClass o nm supL =
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maeder insertClass o nm nm supL (Just SubSort)
6c244f12ab0dc7ba1baf1413266093886a570e13Christian Maeder toStrL = Set.fold ((:) . str) []
8a3ab31caff2bc2ad9355680186a7dd4da5f73b5Christian Maeder
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaederconvPred :: Sign f e -> MMiSSOntology -> WithError MMiSSOntology
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederconvPred s o =
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder -- first only binary preds; later also unary preds
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maeder Map.foldWithKey addPred (hasValue o) $ predMap s
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maeder where addPred pn tSet wOnto =
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maeder weither (const wOnto) insBinaryPred wOnto
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder where insBinaryPred on =
6c244f12ab0dc7ba1baf1413266093886a570e13Christian Maeder let binT = Set.filter ((== 2) . length . predArgs) tSet
3fea26a73b8fa69b22dfd2653d8f7bdacb45b9c9Christian Maeder in if Set.null binT
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder then hasValue on
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder else Set.fold insType (insName on) binT
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder insName on = insertBaseRelation on (show pn) (show pn)
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder Nothing Nothing
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder insType t wOn =
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder weither (const wOn)
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder (\ ont ->
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder let [a1, a2] = predArgs t
5b68f1141555736e0b7ddbe14218bcabcc44636fChristian Maeder src = show a1
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder tar = show a2
5b68f1141555736e0b7ddbe14218bcabcc44636fChristian Maeder in insertRelationType ont (show pn)
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder src tar)
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder wOn
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
1fd936f22c745583ff70fd7ff6e3397f6bcf3fd9Marcel ZirbelconvSen :: WithError MMiSSOntology
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder -> Named (FORMULA f) -> WithError MMiSSOntology
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaederconvSen weOnto _nSen = weither (const weOnto) hasValue weOnto
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder-- implemented but not used by now
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaedershowOntClass :: String -> [String] -> String
dc62afbf79603699b39b2387f48298634f642e67cmaedershowOntClass cln =
e24ccbc27ab90aa0bdb7064fd42e3bb0e0da6174Christian Maeder foldl (\ res sup -> res ++ ontClass sup) ""
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian Maeder where ontClass s = "\\Class{" ++ cln ++ "}{" ++ cln ++ "}{" ++ s ++ "}"
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaedershowRelationName :: String -> String
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian MaedershowRelationName rn = "\\RelationName{" ++ rn ++ "}{" ++ rn ++ "}"
9aec0bc9d57df2669c8095fb1b4bd954d80b5537Christian Maeder
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaedershowRelation :: String -> String -> String -> String
86c1b41a968fde92972d40753dbbd13e0b25d85bChristian MaedershowRelation rn s t = "\\Relation{" ++ rn ++ "}{" ++ s ++ "}{" ++ t ++ "}{}"
5664bc775d5d61bbd5f71cf05f5c6dd5c63340ffChristian Maeder