ManchesterPrint.hs revision f07079faf4e99014e900c7c99adb5ff7fa106b61
ce5ff829db5f0bb4f16ad4de150eed4401d6acd5Christian MaederModule : $Header$
ce5ff829db5f0bb4f16ad4de150eed4401d6acd5Christian MaederCopyright : (c) Felix Gabriel Mance
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
eca29a7be76eb73944ec19b06eda3d6a9e6e543dChristian MaederMaintainer : f.mance@jacobs-university.de
ce5ff829db5f0bb4f16ad4de150eed4401d6acd5Christian MaederStability : provisional
ce5ff829db5f0bb4f16ad4de150eed4401d6acd5Christian MaederPortability : portable
f3a94a197960e548ecd6520bb768cb0d547457bbChristian MaederContains : Pretty printing for the Manchester Syntax of OWL 2
3f63b98c111e5e2bb2cf13795cf6e084a78b0a8dChristian Maederimport qualified Data.Map as Map
fc7df539e6d41b050161ed8f9ae6e444b1b5ab14Christian MaederprintCharact :: String -> Doc
3f63b98c111e5e2bb2cf13795cf6e084a78b0a8dChristian MaederprintCharact charact = text charact
2b9022bd5dfb351d1d80f61680336effeccfa23eChristian Maederinstance Pretty Character where
2b9022bd5dfb351d1d80f61680336effeccfa23eChristian Maeder pretty = printCharact . show
2b9022bd5dfb351d1d80f61680336effeccfa23eChristian Maederinstance Pretty AnnotationValue where
f9a73de15ef09dbd6b391c7b1f695c79b4446fe2Christian Maeder pretty x = case x of
d3bca27d616c5741d0b18776c8a0848ec31c87f4Christian Maeder AnnValue iri -> pretty iri
f9a73de15ef09dbd6b391c7b1f695c79b4446fe2Christian Maeder AnnValLit lit -> pretty lit
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maederinstance Pretty Annotation where
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder pretty = printAnnotation
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian MaederprintAnnotation :: Annotation -> Doc
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian MaederprintAnnotation (Annotation ans ap av) =
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder sep [printAnnotations ans, sep [pretty ap, pretty av]]
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian MaederprintAnnotations :: Annotations -> Doc
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian MaederprintAnnotations l = case l of
0df692ce8b9293499b2e1768458613a63e7b5cd0Christian Maeder _ -> keyword annotationsC <+>
cc8b603388a7deb7fb8045db0341f550f8be5844Christian Maeder vcat (punctuate comma (map ( \(Annotation ans ap av) -> printAnnotations ans $+$ pretty (Annotation [] ap av)) l) )
0df692ce8b9293499b2e1768458613a63e7b5cd0Christian Maederinstance Pretty a => Pretty (AnnotatedList a) where
0df692ce8b9293499b2e1768458613a63e7b5cd0Christian Maeder pretty = printAnnotatedList
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian MaederprintAnnotatedList :: Pretty a => AnnotatedList a -> Doc
04dada28736b4a237745e92063d8bdd49a362debChristian MaederprintAnnotatedList (AnnotatedList l) =
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder vcat $ punctuate comma $ map
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder ( \ (ans, a) -> printAnnotations ans $+$ pretty a) l
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maederinstance Pretty FrameBit where
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder pretty = printFrameBit
ce5ff829db5f0bb4f16ad4de150eed4401d6acd5Christian MaederprintFrameBit :: FrameBit -> Doc
cf5149eb4d0faef6272231879c04aa740f5abc2bChristian MaederprintFrameBit fb = case fb of
cf5149eb4d0faef6272231879c04aa740f5abc2bChristian Maeder AnnotationFrameBit x -> printAnnotations x
cf5149eb4d0faef6272231879c04aa740f5abc2bChristian Maeder AnnotationBit ed l -> printRelation ed <+> pretty l
cf5149eb4d0faef6272231879c04aa740f5abc2bChristian Maeder DatatypeBit ans a -> printAnnotations ans $+$ keyword equivalentToC <+> pretty a
cf5149eb4d0faef6272231879c04aa740f5abc2bChristian Maeder ExpressionBit x y -> printRelation x <+> pretty y
cf5149eb4d0faef6272231879c04aa740f5abc2bChristian Maeder ClassDisjointUnion a x -> keyword disjointUnionOfC
cf5149eb4d0faef6272231879c04aa740f5abc2bChristian Maeder <+> (printAnnotations a $+$ vcat(punctuate comma ( map (\p -> pretty p) x )))
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder ClassHasKey a op dp -> keyword hasKeyC <+> (printAnnotations a
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder $+$ vcat (punctuate comma $ map pretty op ++ map pretty dp))
2b9022bd5dfb351d1d80f61680336effeccfa23eChristian Maeder ObjectBit dr x -> printRelation dr <+> pretty x
2b9022bd5dfb351d1d80f61680336effeccfa23eChristian Maeder ObjectCharacteristics x -> keyword characteristicsC <+> pretty x
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder ObjectSubPropertyChain a opl -> keyword subPropertyChainC
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder <+> (printAnnotations a $+$ fsep (prepPunctuate (keyword oS <> space) $ map pretty opl))
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder DataBit dr x -> printRelation dr <+> pretty x
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder DataPropRange x -> keyword rangeC <+> pretty x
04dada28736b4a237745e92063d8bdd49a362debChristian Maeder DataFunctional x -> keyword characteristicsC <+> (printAnnotations x $+$ printCharact functionalS)
ce5ff829db5f0bb4f16ad4de150eed4401d6acd5Christian Maeder IndividualFacts x -> keyword factsC <+> pretty x
7dec34aee2b609b9535c48d060e0f7baf3536457Christian Maeder IndividualSameOrDifferent s x -> printSameOrDifferent s <+> pretty x
ccf3de3d66b521a260e5c22d335c64a48e3f0195Christian Maederinstance Pretty Fact where
ccf3de3d66b521a260e5c22d335c64a48e3f0195Christian Maeder pretty = printFact
ccf3de3d66b521a260e5c22d335c64a48e3f0195Christian MaederprintFact :: Fact -> Doc
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian MaederprintFact pf = case pf of
2dba752dedea77b7664117a46312d4a5ced6c979Christian Maeder ObjectPropertyFact pn op i -> printPositiveOrNegative pn <+> pretty op <+> pretty i
2b9022bd5dfb351d1d80f61680336effeccfa23eChristian Maeder DataPropertyFact pn dp l -> printPositiveOrNegative pn <+> pretty dp <+> pretty l
2dba752dedea77b7664117a46312d4a5ced6c979Christian MaederprintPositiveOrNegative :: PositiveOrNegative -> Doc
2dba752dedea77b7664117a46312d4a5ced6c979Christian MaederprintPositiveOrNegative x = case x of
7dec34aee2b609b9535c48d060e0f7baf3536457Christian Maeder Positive -> empty
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder Negative -> keyword notS
04dada28736b4a237745e92063d8bdd49a362debChristian Maederinstance Pretty Frame where
bf8221af2a4e579e1a616e3d472e9e8533cd8f8cChristian Maeder pretty = printFrame
bf8221af2a4e579e1a616e3d472e9e8533cd8f8cChristian MaederprintFrame :: Frame -> Doc
7dec34aee2b609b9535c48d060e0f7baf3536457Christian MaederprintFrame f = case f of
bf8221af2a4e579e1a616e3d472e9e8533cd8f8cChristian Maeder Frame (Entity e uri) bl -> pretty (showEntityType e) <+> fsep [pretty uri, vcat (map pretty bl)]
e76e6a43f51438215737d6fc176c89da05bb86daChristian Maeder MiscFrame e a misc -> case misc of
7dec34aee2b609b9535c48d060e0f7baf3536457Christian Maeder MiscEquivOrDisjointClasses c -> printEquivOrDisjointClasses e <+> (printAnnotations a $+$ vcat (punctuate comma (map pretty c) ))
bf8221af2a4e579e1a616e3d472e9e8533cd8f8cChristian Maeder MiscEquivOrDisjointObjProp c -> printEquivOrDisjointProp e <+> (printAnnotations a $+$ vcat ( punctuate comma (map pretty c) ))
7dec34aee2b609b9535c48d060e0f7baf3536457Christian Maeder MiscEquivOrDisjointDataProp c -> printEquivOrDisjointProp e <+> (printAnnotations a $+$ vcat ( punctuate comma (map pretty c) ))
7dec34aee2b609b9535c48d060e0f7baf3536457Christian Maeder MiscSameOrDifferent s a c -> printSameOrDifferentInd s <+> (printAnnotations a $+$ vcat( punctuate comma (map pretty c) ))
e76e6a43f51438215737d6fc176c89da05bb86daChristian Maederinstance Pretty MOntology where
3f63b98c111e5e2bb2cf13795cf6e084a78b0a8dChristian Maeder pretty = printOntology
0df692ce8b9293499b2e1768458613a63e7b5cd0Christian MaederprintImport :: ImportIRI -> Doc
0df692ce8b9293499b2e1768458613a63e7b5cd0Christian MaederprintImport x = keyword importC <+> pretty x
f626b1acbe874a48143a6f8d6246bf9d7a055ffbChristian MaederprintEquivOrDisjointProp :: EquivOrDisjoint -> Doc
15c12a3ac049a4528da05b1017b78145f308aeb0Christian MaederprintEquivOrDisjointProp e = case e of
15c12a3ac049a4528da05b1017b78145f308aeb0Christian Maeder Disjoint -> text "DisjointProperties:"
cc8b603388a7deb7fb8045db0341f550f8be5844Christian Maeder Equivalent -> text "EquivalentProperties:"
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian MaederprintPrefixes :: PrefixMap -> Doc
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian MaederprintPrefixes x = vcat (map (\(a, b) ->
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder (text "Prefix:" <+> text a <> colon <+> text ('<' : b ++ ">"))) (Map.toList x))
15c12a3ac049a4528da05b1017b78145f308aeb0Christian MaederprintOntology :: MOntology -> Doc
15c12a3ac049a4528da05b1017b78145f308aeb0Christian MaederprintOntology MOntology {muri = a, imports = b, ann = c, ontologyFrame = d} = keyword ontologyC
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder <+> pretty a $++$ vcat (map printImport b) $++$ vcat (map printAnnotations c) $+$ vcat(map pretty d)
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian MaederprintOntologyDocument :: OntologyDocument -> Doc
cc8b603388a7deb7fb8045db0341f550f8be5844Christian MaederprintOntologyDocument OntologyDocument {prefixDeclaration = a, mOntology = b} = printPrefixes a $++$ pretty b
15c12a3ac049a4528da05b1017b78145f308aeb0Christian Maederinstance Pretty OntologyDocument where
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder pretty = printOntologyDocument