Print.hs revision d9d4fb44ea56316e0a54e129d8a49a75eff66994
66267bcb678a9c341272c323b299337bcfdb7cc5Christian Maeder{- |
81d182b21020b815887e9057959228546cf61b6bChristian MaederModule : $Header$
81d182b21020b815887e9057959228546cf61b6bChristian MaederCopyright : (c) Heng Jiang, Uni Bremen 2005-2006
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
66267bcb678a9c341272c323b299337bcfdb7cc5Christian Maeder
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederMaintainer : Christian.Maeder@dfki.de
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederStability : provisional
ffd01020a4f35f434b912844ad6e0d6918fadffdChristian MaederPortability : portable
66267bcb678a9c341272c323b299337bcfdb7cc5Christian Maeder
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederPretty printing for OWL 2 DL theories - common Functional and Manchester Syntax.
fb69cd512eab767747f109e40322df7cae2f7bdfChristian Maeder-}
fb69cd512eab767747f109e40322df7cae2f7bdfChristian Maeder
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maedermodule OWL2.Print where
fb69cd512eab767747f109e40322df7cae2f7bdfChristian Maeder
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport Common.Doc
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport Common.DocUtils
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport Common.Id
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport Common.Keywords
05e2a3161e4589a717c6fe5c7306820273a473c5Christian Maeder
05e2a3161e4589a717c6fe5c7306820273a473c5Christian Maederimport OWL2.AS
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport OWL2.Symbols
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maederimport OWL.Keywords
ad270004874ce1d0697fb30d7309f180553bb315Christian Maederimport OWL.ColonKeywords
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport qualified Data.Set as Set
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty QName where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty = printURIreference
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintURIreference :: QName -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintURIreference q =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder (if localPart q == "Thing" && elem (namePrefix q) ["", "owl"]
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian Maeder then keyword else text) $ showQN q
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian Maeder
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian Maederinstance Pretty SymbItems where
05e2a3161e4589a717c6fe5c7306820273a473c5Christian Maeder pretty (SymbItems m us) = maybe empty (keyword . show) m
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder <+> ppWithCommas us
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
024621f43239cfe9629e35d35a8669fad7acbba2Christian Maederinstance Pretty SymbMapItems where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty (SymbMapItems m us) = maybe empty (keyword . show) m
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder <+> sepByCommas
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder (map (\ (s, ms) -> sep
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder [ pretty s
27912d626bf179b82fcb337077e5cd9653bb71cfChristian Maeder , case ms of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Nothing -> empty
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Just t -> mapsto <+> pretty t]) us)
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maeder
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maederinstance GetRange RawSymb -- no position by default
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maeder
8c81b727b788d90ff3b8cbda7b0900c9009243bbChristian Maederinstance Pretty RawSymb where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty rs = case rs of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ASymbol e -> pretty e
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder AnUri u -> pretty u
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty Entity where
07b1bf56f3a486f26d69514d05b73100abb25a0eChristian Maeder pretty (Entity ty e) = keyword (show ty) <+> pretty e
05e2a3161e4589a717c6fe5c7306820273a473c5Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedercardinalityType :: CardinalityType -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedercardinalityType = keyword . showCardinalityType
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederquantifierType :: QuantifierType -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederquantifierType = keyword . showQuantifierType
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintIndividual :: Individual -> Doc
c438c79d00fc438f99627e612498744bdc0d0c89Christian MaederprintIndividual = pretty
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty ClassExpression where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty desc = case desc of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Expression ocUri -> printURIreference ocUri
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ObjectJunction ty ds -> let
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder (k, p) = case ty of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder UnionOf -> (orS, pretty)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder IntersectionOf -> (andS, printPrimary)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder in fsep $ prepPunctuate (keyword k <> space) $ map p ds
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ObjectComplementOf d -> keyword notS <+> printNegatedPrimary d
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ObjectOneOf indUriList -> specBraces $ ppWithCommas indUriList
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ObjectValuesFrom ty opExp d ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder printObjPropExp opExp <+> quantifierType ty <+> printNegatedPrimary d
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ObjectHasSelf opExp ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder printObjPropExp opExp <+> keyword selfS
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ObjectHasValue opExp indUri ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty opExp <+> keyword valueS <+> pretty indUri
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder ObjectCardinality (Cardinality ty card opExp maybeDesc) ->
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder printObjPropExp opExp <+> cardinalityType ty
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder <+> text (show card)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder <+> maybe (keyword "owl:Thing") printPrimary maybeDesc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder DataValuesFrom ty dpExp dpExpList dRange ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder printURIreference dpExp <+> quantifierType ty
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder <+> (if null dpExpList then empty
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder else specBraces $ ppWithCommas dpExpList) <+> pretty dRange
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder DataHasValue dpExp cons -> pretty dpExp <+> keyword valueS <+> pretty cons
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder DataCardinality (Cardinality ty card dpExp maybeRange) ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty dpExp <+> cardinalityType ty <+> text (show card)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder <+> maybe empty pretty maybeRange
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintPrimary :: ClassExpression -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintPrimary d = let dd = pretty d in case d of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ObjectJunction _ _ -> parens dd
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> dd
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintNegatedPrimary :: ClassExpression -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintNegatedPrimary d = let r = parens $ pretty d in case d of
81d182b21020b815887e9057959228546cf61b6bChristian Maeder ObjectComplementOf _ -> r
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maeder ObjectValuesFrom _ _ _ -> r
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maeder DataValuesFrom _ _ _ _ -> r
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ObjectHasValue _ _ -> r
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder DataHasValue _ _ -> r
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> printPrimary d
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty ObjectPropertyExpression where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty = printObjPropExp
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintObjPropExp :: ObjectPropertyExpression -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintObjPropExp obExp =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder case obExp of
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder ObjectProp ou -> pretty ou
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder ObjectInverseOf iopExp -> keyword inverseS <+> printObjPropExp iopExp
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maederinstance Pretty DataRange where
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder pretty = printDataRange
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maeder
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian MaederprintDataRange :: DataRange -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintDataRange dr = case dr of
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder DataType du -> pretty du
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder DataComplementOf drange -> keyword notS <+> pretty drange
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder DataOneOf constList -> specBraces $ ppWithCommas constList
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder DatatypeRestriction dtype l -> pretty dtype <+>
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder if null l then empty else brackets $ sepByCommas $ map printFV l
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder DataJunction ty drlist -> let
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder k = case ty of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder UnionOf -> orS
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder IntersectionOf -> andS
61091743da1a9ed6dfd5e077fdcc972553358962Christian Maeder in fsep $ prepPunctuate (keyword k <> space) $ map pretty drlist
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintFV ::(ConstrainingFacet, RestrictionValue) -> Doc
08b724e8dcbba5820d80f0974b9a5385140815baChristian MaederprintFV (facet, restValue) = pretty facet <+> pretty restValue
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maederinstance Pretty DatatypeFacet where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty = keyword . showFacet
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maederinstance Pretty Literal where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty (Literal lexi ty) =
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maeder text (case lexi of
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maeder '"' : _ -> lexi
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> show lexi) <> case ty of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Typed u -> keyword cTypeS <> pretty u
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Untyped tag -> if tag == Nothing then empty else
2e9985cd67e4f2414becb670ef33b8f16513e41dChristian Maeder let Just tag2 = tag in text asP <> text tag2
2e9985cd67e4f2414becb670ef33b8f16513e41dChristian Maeder
2e9985cd67e4f2414becb670ef33b8f16513e41dChristian MaederprintEquivOrDisjoint :: EquivOrDisjoint -> Doc
2e9985cd67e4f2414becb670ef33b8f16513e41dChristian MaederprintEquivOrDisjoint = keyword . showEquivOrDisjoint
2e9985cd67e4f2414becb670ef33b8f16513e41dChristian Maeder
2e9985cd67e4f2414becb670ef33b8f16513e41dChristian MaederprintObjDomainOrRange :: ObjDomainOrRange -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintObjDomainOrRange = keyword . showObjDomainOrRange
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder
717686b54b9650402e2ebfbaadf433eab8ba5171Christian MaederprintDataDomainOrRange :: DataDomainOrRange -> Doc
405b95208385572f491e1e0207d8d14e31022fa6Christian MaederprintDataDomainOrRange dr = case dr of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder DataDomain d -> keyword domainC <+> pretty d
8c81b727b788d90ff3b8cbda7b0900c9009243bbChristian Maeder DataRange d -> keyword rangeC <+> pretty d
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintSameOrDifferent :: SameOrDifferent -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederprintSameOrDifferent = keyword . showSameOrDifferent
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederclassStart :: Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederclassStart = keyword classC
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederopStart :: Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederopStart = keyword objectPropertyC
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederdpStart :: Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederdpStart = keyword dataPropertyC
05e2a3161e4589a717c6fe5c7306820273a473c5Christian Maeder
05e2a3161e4589a717c6fe5c7306820273a473c5Christian MaederindStart :: Doc
76647324ed70f33b95a881b536d883daccf9568dChristian MaederindStart = keyword individualC
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty SubObjectPropertyExpression where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty sopExp =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder case sopExp of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder OPExpression opExp -> pretty opExp
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder SubObjectPropertyChain opExpList ->
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder fsep $ prepPunctuate (keyword oS <> space) $ map pretty opExpList
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedersetToDocs :: Pretty a => Set.Set a -> [Doc]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedersetToDocs = punctuate comma . map pretty . Set.toList
setToDocV :: (Pretty a) => Set.Set a -> Doc
setToDocV = vcat . setToDocs