Print.hs revision 39bb489dcaaa867e065e4b33ec658ac915ef9ea6
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo WiedemeyerModule : $Header$
6b26240dca29e026900a83d51c75ca230a072a16Thiemo WiedemeyerCopyright : (c) Heng Jiang, Uni Bremen 2005-2006
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo WiedemeyerLicense : GPLv2 or higher, see LICENSE.txt
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo WiedemeyerMaintainer : Christian.Maeder@dfki.de
2eeec5240b424984e3ee26296da1eeab6c6d739eChristian MaederStability : provisional
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo WiedemeyerPortability : portable
7520452bb30b5abbd471f82352fc4c1c937e02c5Till MossakowskiPretty printing for the Manchester Syntax of OWL 2.
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyerinstance Pretty Character where
b0adcc203b4267d5535b430372935a5f36726db1Simon Ulbricht pretty = printCharact . show
83263d411f611d9902ef4d98c93be6ad9361c833Christian MaederprintCharact :: String -> Doc
abea93ed557b22ea833e1524ee5ca11afc12208aSimon UlbrichtprintCharact = text
9a9860760c6f30558e5e60049692b6fc63904590Markus Grossinstance Pretty QName where
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer pretty = printIRI
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo WiedemeyerprintIRI :: QName -> Doc
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer | (isPredefPropOrClass q && namePrefix q `elem` ["owl", "rdfs"]) ||
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer isDatatypeKey q = keyword $ localPart q
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer | otherwise = text $ showQN q
1a389234e68da7c3d087b038307ed8c66fc6dc32Thiemo Wiedemeyer-- | Symbols printing
1c039dc13801bb9c90ad6a1bac0e56af19fd2fbfMihai Codescuinstance Pretty ExtEntityType where
38122cbf09ad3dcc31a826cc4093f630515a5cfcChristian Maeder pretty ety = case ety of
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer AnyEntity -> empty
f7b9d64160c23654b7288a3b0ee3e2b95af3e752Thiemo Wiedemeyer EntityType ty -> keyword $ show ty
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer Prefix -> keyword "Prefix"
3a6decfd748f532d5cb03fbcb7a42fa37b0faab3Christian Maederinstance Pretty SymbItems where
f7b9d64160c23654b7288a3b0ee3e2b95af3e752Thiemo Wiedemeyer pretty (SymbItems m us) = pretty m
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer <+> ppWithCommas us
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyerinstance Pretty SymbMapItems where
c208973c890b8f993297720fd0247bc7481d4304Christian Maeder pretty (SymbMapItems m us) = pretty m
b6a59f004903ac7bc96323ee3ef09c01fd221157Christian Maeder <+> sepByCommas
f7b9d64160c23654b7288a3b0ee3e2b95af3e752Thiemo Wiedemeyer (map (\ (s, ms) -> sep
ec25781c1180ea07f66b48c34f93cf5634e9277cChristian Maeder Nothing -> empty
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer Just t -> mapsto <+> pretty t]) us)
f7b9d64160c23654b7288a3b0ee3e2b95af3e752Thiemo Wiedemeyerinstance GetRange RawSymb -- no position by default
239991d3955da0cfb760af4d506069446e1676b7Christian Maederinstance Pretty RawSymb where
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer pretty rs = case rs of
66fd8f017efdb8a6c862c3f1856dfaef90865dd5Thiemo Wiedemeyer ASymbol e -> pretty e
d1066b8fb69179973dcab47154858d77e72760a7Thiemo Wiedemeyer AnUri u -> pretty u
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer APrefix p -> pretty p
f7b9d64160c23654b7288a3b0ee3e2b95af3e752Thiemo WiedemeyercardinalityType :: CardinalityType -> Doc
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo WiedemeyercardinalityType = keyword . showCardinalityType
a7e5c17a679fa2dae5998cd04c7e9e06c05c8164Christian MaederquantifierType :: QuantifierType -> Doc
f9e0b18852b238ddb649d341194e05d7200d1bbeChristian MaederquantifierType = keyword . showQuantifierType
1e3aca4178372af672efb237d16087c603fe5564Christian MaederprintRelation :: Relation -> Doc
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo WiedemeyerprintRelation = keyword . showRelation
f456529a89bfb620d39e5fd5b0a53b24643db96dDominik LueckeprintEquivOrDisjointClasses :: EquivOrDisjoint -> Doc
a79266feb130561fa1a95ae0429d0574f625f6ceChristian MaederprintEquivOrDisjointClasses x = case x of
f7b9d64160c23654b7288a3b0ee3e2b95af3e752Thiemo Wiedemeyer Equivalent -> text "EquivalentClasses:"
f7b9d64160c23654b7288a3b0ee3e2b95af3e752Thiemo Wiedemeyer Disjoint -> text "DisjointClasses:"
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo WiedemeyerprintEquivOrDisjointProp :: EquivOrDisjoint -> Doc
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo WiedemeyerprintEquivOrDisjointProp e = case e of
f7b9d64160c23654b7288a3b0ee3e2b95af3e752Thiemo Wiedemeyer Disjoint -> text "DisjointProperties:"
0d0278c34a374b29c2d6c58b39b8b56e283d48e8Christian Maeder Equivalent -> text "EquivalentProperties:"
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo WiedemeyerprintPositiveOrNegative :: PositiveOrNegative -> Doc
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo WiedemeyerprintPositiveOrNegative x = case x of
16e45483b5ce48f0b92d01c817242a8c9b8bae02Christian Maeder Positive -> empty
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer Negative -> keyword notS
28ca54b0d63d1d26a991711c8c7e85c474994715Christian MaederprintSameOrDifferentInd :: SameOrDifferent -> Doc
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan PascanuprintSameOrDifferentInd x = case x of
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan Pascanu Same -> keyword sameIndividualC
02a84229da51532505a93fc2abfca1ccf81b4446Razvan Pascanu Different -> keyword differentIndividualsC
66fd8f017efdb8a6c862c3f1856dfaef90865dd5Thiemo Wiedemeyerinstance Pretty Entity where
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer pretty (Entity ty e) = keyword (show ty) <+> pretty e
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyerinstance Pretty Literal where
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer pretty lit = case lit of
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer Literal lexi ty -> text ('"' : lexi ++ "\"") <> case ty of
32d98ca5e560cf6c1062a0463be4c350af32bed5Thiemo Wiedemeyer Typed u -> keyword cTypeS <> pretty u
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer Untyped tag -> if tag == Nothing then empty
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer else let Just tag2 = tag in text asP <> text tag2
32d98ca5e560cf6c1062a0463be4c350af32bed5Thiemo Wiedemeyer NumberLit f -> text (show f)
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyerinstance Pretty ObjectPropertyExpression where
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer pretty = printObjPropExp
d71a37fb09bce02af6c98e7a5ab0aa5639058e4fThiemo WiedemeyerprintObjPropExp :: ObjectPropertyExpression -> Doc
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan PascanuprintObjPropExp obExp = case obExp of
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer ObjectProp ou -> pretty ou
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer ObjectInverseOf iopExp -> keyword inverseS <+> printObjPropExp iopExp
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo WiedemeyerprintFV :: (ConstrainingFacet, RestrictionValue) -> Doc
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo WiedemeyerprintFV (facet, restValue) = pretty (fromCF facet) <+> pretty restValue
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo WiedemeyerfromCF :: ConstrainingFacet -> String
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer | iriType f == Full = showQU f \\ "http://www.w3.org/2001/XMLSchema#"
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer | otherwise = localPart f
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maederinstance Pretty DatatypeFacet where
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer pretty = keyword . showFacet
0b8b26a22f136a9b2a8e99d655f6fe6b0b96008cThiemo Wiedemeyer-- | Printing the DataRange
0b8b26a22f136a9b2a8e99d655f6fe6b0b96008cThiemo Wiedemeyerinstance Pretty DataRange where
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer pretty = printDataRange
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo WiedemeyerprintDataRange :: DataRange -> Doc
788bd3c33ec5aaeb90a1932c341ff837116410cfThiemo WiedemeyerprintDataRange dr = case dr of
788bd3c33ec5aaeb90a1932c341ff837116410cfThiemo Wiedemeyer DataType dtype l -> pretty dtype <+>
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder if null l then empty else brackets $ sepByCommas $ map printFV l
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer DataComplementOf drange -> keyword notS <+> pretty drange
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer DataOneOf constList -> specBraces $ ppWithCommas constList
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer DataJunction ty drlist -> let
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo Wiedemeyer k = case ty of
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer UnionOf -> orS
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer IntersectionOf -> andS
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer in fsep $ prepPunctuate (keyword k <> space) $ map pretty drlist
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer-- | Printing the ClassExpression
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyerinstance Pretty ClassExpression where
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer pretty desc = case desc of
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer Expression ocUri -> printIRI ocUri
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer ObjectJunction ty ds -> let
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer (k, p) = case ty of
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer UnionOf -> (orS, pretty)
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer IntersectionOf -> (andS, printPrimary)
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer in fsep $ prepPunctuate (keyword k <> space) $ map p ds
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer ObjectComplementOf d -> keyword notS <+> printNegatedPrimary d
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer ObjectOneOf indUriList -> specBraces $ ppWithCommas indUriList
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder ObjectValuesFrom ty opExp d ->
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder printObjPropExp opExp <+> quantifierType ty <+> printNegatedPrimary d
0b8b26a22f136a9b2a8e99d655f6fe6b0b96008cThiemo Wiedemeyer ObjectHasSelf opExp ->
66fd8f017efdb8a6c862c3f1856dfaef90865dd5Thiemo Wiedemeyer printObjPropExp opExp <+> keyword selfS
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer ObjectHasValue opExp indUri ->
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer pretty opExp <+> keyword valueS <+> pretty indUri
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer ObjectCardinality (Cardinality ty card opExp maybeDesc) ->
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer printObjPropExp opExp <+> cardinalityType ty
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer <+> text (show card)
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer <+> maybe (keyword "Thing") printPrimary maybeDesc
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer DataValuesFrom ty dpExp dRange ->
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer printIRI dpExp <+> quantifierType ty
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer <+> pretty dRange
d71a37fb09bce02af6c98e7a5ab0aa5639058e4fThiemo Wiedemeyer DataHasValue dpExp cons -> pretty dpExp <+> keyword valueS <+> pretty cons
d71a37fb09bce02af6c98e7a5ab0aa5639058e4fThiemo Wiedemeyer DataCardinality (Cardinality ty card dpExp maybeRange) ->
788bd3c33ec5aaeb90a1932c341ff837116410cfThiemo Wiedemeyer pretty dpExp <+> cardinalityType ty <+> text (show card)
d71a37fb09bce02af6c98e7a5ab0aa5639058e4fThiemo Wiedemeyer <+> maybe empty pretty maybeRange
39a2520d13a7d43f0c0fa71b94255c3f7c500005Christian MaederprintPrimary :: ClassExpression -> Doc
39a2520d13a7d43f0c0fa71b94255c3f7c500005Christian MaederprintPrimary d = let dd = pretty d in case d of
788bd3c33ec5aaeb90a1932c341ff837116410cfThiemo Wiedemeyer ObjectJunction _ _ -> parens dd
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo WiedemeyerprintNegatedPrimary :: ClassExpression -> Doc
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo WiedemeyerprintNegatedPrimary d = let r = parens $ pretty d in case d of
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo Wiedemeyer ObjectComplementOf _ -> r
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo Wiedemeyer ObjectValuesFrom _ _ _ -> r
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo Wiedemeyer DataValuesFrom _ _ _ -> r
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo Wiedemeyer ObjectHasValue _ _ -> r
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo Wiedemeyer DataHasValue _ _ -> r
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer _ -> printPrimary d
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo Wiedemeyer-- | annotations printing
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo Wiedemeyerinstance Pretty AnnotationValue where
92e96be605537638d75e9d3023ab698bd89cf889Thiemo Wiedemeyer pretty x = case x of
92e96be605537638d75e9d3023ab698bd89cf889Thiemo Wiedemeyer AnnValue iri -> pretty iri
fa1bf658051ac503f27ff1b59edb093398eed6edThiemo Wiedemeyer AnnValLit lit -> pretty lit
fa1bf658051ac503f27ff1b59edb093398eed6edThiemo Wiedemeyerinstance Pretty OWL2.AS.Annotation where
d24317c8197e565e60c8f41309de246249c1e57eChristian Maeder pretty = printAnnotation
92e96be605537638d75e9d3023ab698bd89cf889Thiemo WiedemeyerprintAnnotation :: OWL2.AS.Annotation -> Doc
92e96be605537638d75e9d3023ab698bd89cf889Thiemo WiedemeyerprintAnnotation (Annotation ans ap av) =
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder sep [printAnnotations ans, sep [pretty ap, pretty av]]
92e96be605537638d75e9d3023ab698bd89cf889Thiemo WiedemeyerprintAnnotations :: Annotations -> Doc
92e96be605537638d75e9d3023ab698bd89cf889Thiemo WiedemeyerprintAnnotations l = case l of
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo Wiedemeyer _ -> keyword annotationsC <+>
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo Wiedemeyer vcat (punctuate comma (map (\ (Annotation ans ap av) ->
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo Wiedemeyer printAnnotations ans $+$ pretty (Annotation [] ap av)) l) )
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo WiedemeyerprintAnnotatedList :: Pretty a => AnnotatedList a -> Doc
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo WiedemeyerprintAnnotatedList l =
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo Wiedemeyer vcat $ punctuate comma $ map
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer ( \ (ans, a) -> printAnnotations ans $+$ pretty a) l