{- |
Module      :  ./OWL2/ManchesterPrint.hs
Copyright   :  (c) Felix Gabriel Mance
License     :  GPLv2 or higher, see LICENSE.txt

Maintainer  :  f.mance@jacobs-university.de
Stability   :  provisional
Portability :  portable

Pretty printing for the Manchester Syntax of OWL 2
-}

module OWL2.ManchesterPrint where

import Common.Doc
import Common.DocUtils
import Common.AS_Annotation as Anno
import Common.IRI

import qualified OWL2.AS as AS
import OWL2.Extract
import OWL2.MS
import OWL2.Sign
import OWL2.Theorem
import OWL2.Print
import OWL2.Keywords
import OWL2.ColonKeywords

import Data.List
import qualified Data.Map as Map
import qualified Data.Set as Set

import OWL2.Pretty()

-- | OWL2 signature printing


printOWLBasicTheory :: (Sign, [Named AS.Axiom]) -> Doc
printOWLBasicTheory :: (Sign, [Named Axiom]) -> Doc
printOWLBasicTheory = (Sign, [Named Axiom]) -> Doc
printBasicTheory ((Sign, [Named Axiom]) -> Doc)
-> ((Sign, [Named Axiom]) -> (Sign, [Named Axiom]))
-> (Sign, [Named Axiom])
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sign, [Named Axiom]) -> (Sign, [Named Axiom])
prepareBasicTheory

prepareBasicTheory :: (Sign, [Named AS.Axiom]) -> (Sign, [Named AS.Axiom])
prepareBasicTheory :: (Sign, [Named Axiom]) -> (Sign, [Named Axiom])
prepareBasicTheory (s :: Sign
s, l :: [Named Axiom]
l) =
  (Sign
s { prefixMap :: PrefixMap
prefixMap = PrefixMap -> PrefixMap -> PrefixMap
forall k a. Ord k => Map k a -> Map k a -> Map k a
Map.union (Sign -> PrefixMap
prefixMap Sign
s) PrefixMap
AS.predefPrefixes }, [Named Axiom]
l)

printBasicTheory :: (Sign, [Named AS.Axiom]) -> Doc
printBasicTheory :: (Sign, [Named Axiom]) -> Doc
printBasicTheory = OntologyDocument -> Doc
forall a. Pretty a => a -> Doc
pretty (OntologyDocument -> Doc)
-> ((Sign, [Named Axiom]) -> OntologyDocument)
-> (Sign, [Named Axiom])
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sign, [Named Axiom]) -> OntologyDocument
convertBasicTheory

convertBasicTheory :: (Sign, [Named AS.Axiom]) -> AS.OntologyDocument
convertBasicTheory :: (Sign, [Named Axiom]) -> OntologyDocument
convertBasicTheory (sig :: Sign
sig, l :: [Named Axiom]
l) = let
  (axs :: [Named Axiom]
axs, ths :: [Named Axiom]
ths) = (Named Axiom -> Bool)
-> [Named Axiom] -> ([Named Axiom], [Named Axiom])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition Named Axiom -> Bool
forall s a. SenAttr s a -> Bool
Anno.isAxiom [Named Axiom]
l
  cnvrt :: (a -> b) -> [SenAttr a a] -> [b]
cnvrt f :: a -> b
f = (a -> b) -> [a] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map a -> b
f ([a] -> [b]) -> ([SenAttr a a] -> [a]) -> [SenAttr a a] -> [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SenAttr a a -> a) -> [SenAttr a a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map SenAttr a a -> a
forall s a. SenAttr s a -> s
Anno.sentence
  in (Sign, [Axiom]) -> OntologyDocument
convertBasicTheory' (Sign
sig, (Axiom -> Axiom) -> [Named Axiom] -> [Axiom]
forall a b a. (a -> b) -> [SenAttr a a] -> [b]
cnvrt Axiom -> Axiom
rmImplied [Named Axiom]
axs [Axiom] -> [Axiom] -> [Axiom]
forall a. [a] -> [a] -> [a]
++ (Axiom -> Axiom) -> [Named Axiom] -> [Axiom]
forall a b a. (a -> b) -> [SenAttr a a] -> [b]
cnvrt Axiom -> Axiom
addImplied [Named Axiom]
ths)

convertBasicTheory' :: (Sign, [AS.Axiom]) -> AS.OntologyDocument
convertBasicTheory' :: (Sign, [Axiom]) -> OntologyDocument
convertBasicTheory' (sig :: Sign
sig, axs :: [Axiom]
axs) = OntologyDocument
AS.emptyOntologyDoc {
        prefixDeclaration :: PrefixMap
AS.prefixDeclaration = PrefixMap -> PrefixMap
AS.changePrefixMapTypeToGA (PrefixMap -> PrefixMap) -> PrefixMap -> PrefixMap
forall a b. (a -> b) -> a -> b
$ Sign -> PrefixMap
prefixMap Sign
sig,
        ontology :: Ontology
AS.ontology = Ontology
AS.emptyOntology {
            axioms :: [Axiom]
AS.axioms = Sign -> [Axiom]
toDecl Sign
sig [Axiom] -> [Axiom] -> [Axiom]
forall a. [a] -> [a] -> [a]
++ [Axiom]
axs
        }
    }

instance Pretty Sign where
    pretty :: Sign -> Doc
pretty = Sign -> Doc
printSign

printSignElem :: Pretty a => Sign -> String -> (Sign -> Set.Set a) -> Doc
printSignElem :: Sign -> String -> (Sign -> Set a) -> Doc
printSignElem s :: Sign
s ty :: String
ty f :: Sign -> Set a
f = [Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (a -> Doc) -> [a] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (\ t :: a
t -> String -> Doc
keyword String
ty Doc -> Doc -> Doc
<+> a -> Doc
forall a. Pretty a => a -> Doc
pretty a
t)
    ([a] -> [Doc]) -> [a] -> [Doc]
forall a b. (a -> b) -> a -> b
$ Set a -> [a]
forall a. Set a -> [a]
Set.toList (Set a -> [a]) -> Set a -> [a]
forall a b. (a -> b) -> a -> b
$ Sign -> Set a
f Sign
s

printSign :: Sign -> Doc
printSign :: Sign -> Doc
printSign s :: Sign
s = [Doc] -> Doc
vcat
    (((String, String) -> Doc) -> [(String, String)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (\ (c :: String
c, l :: String
l) -> [Doc] -> Doc
hsep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map String -> Doc
text [String
prefixC, String
c String -> String -> String
forall a. [a] -> [a] -> [a]
++ ":", String
l])
    ([(String, String)] -> [Doc]) -> [(String, String)] -> [Doc]
forall a b. (a -> b) -> a -> b
$ PrefixMap -> [(String, String)]
forall k a. Map k a -> [(k, a)]
Map.toList (PrefixMap -> [(String, String)])
-> PrefixMap -> [(String, String)]
forall a b. (a -> b) -> a -> b
$ Sign -> PrefixMap
prefixMap Sign
s)
        Doc -> Doc -> Doc
$++$ (Doc -> Doc -> Doc) -> [Doc] -> Doc
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 Doc -> Doc -> Doc
($++$) (((String, Sign -> Set Datatype) -> Doc)
-> [(String, Sign -> Set Datatype)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ((String -> (Sign -> Set Datatype) -> Doc)
-> (String, Sign -> Set Datatype) -> Doc
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((String -> (Sign -> Set Datatype) -> Doc)
 -> (String, Sign -> Set Datatype) -> Doc)
-> (String -> (Sign -> Set Datatype) -> Doc)
-> (String, Sign -> Set Datatype)
-> Doc
forall a b. (a -> b) -> a -> b
$ Sign -> String -> (Sign -> Set Datatype) -> Doc
forall a. Pretty a => Sign -> String -> (Sign -> Set a) -> Doc
printSignElem Sign
s)
                [ (String
datatypeC, Sign -> Set Datatype
datatypes)
                , (String
classC, Sign -> Set Datatype
concepts)
                , (String
objectPropertyC, Sign -> Set Datatype
objectProperties)
                , (String
dataPropertyC, Sign -> Set Datatype
dataProperties)
                , (String
individualC, Sign -> Set Datatype
individuals)
                , (String
annotationPropertyC, Sign -> Set Datatype
annotationRoles) ])

instance Pretty Fact where
    pretty :: Fact -> Doc
pretty = Fact -> Doc
printFact

printFact :: Fact -> Doc
printFact :: Fact -> Doc
printFact pf :: Fact
pf = case Fact
pf of
    ObjectPropertyFact pn :: PositiveOrNegative
pn op :: ObjectPropertyExpression
op i :: Datatype
i -> PositiveOrNegative -> Doc
printPositiveOrNegative PositiveOrNegative
pn
           Doc -> Doc -> Doc
<+> ObjectPropertyExpression -> Doc
forall a. Pretty a => a -> Doc
pretty ObjectPropertyExpression
op Doc -> Doc -> Doc
<+> Datatype -> Doc
forall a. Pretty a => a -> Doc
pretty Datatype
i
    DataPropertyFact pn :: PositiveOrNegative
pn dp :: Datatype
dp l :: Literal
l -> PositiveOrNegative -> Doc
printPositiveOrNegative PositiveOrNegative
pn
           Doc -> Doc -> Doc
<+> Datatype -> Doc
forall a. Pretty a => a -> Doc
pretty Datatype
dp Doc -> Doc -> Doc
<+> Literal -> Doc
forall a. Pretty a => a -> Doc
pretty Literal
l

instance Pretty ListFrameBit where
    pretty :: ListFrameBit -> Doc
pretty = ListFrameBit -> Doc
printListFrameBit

-- | ListFrameBits only with relations
printListFrameBit :: ListFrameBit -> Doc
printListFrameBit :: ListFrameBit -> Doc
printListFrameBit lfb :: ListFrameBit
lfb = case ListFrameBit
lfb of
    AnnotationBit a :: AnnotatedList Datatype
a -> AnnotatedList Datatype -> Doc
forall a. Pretty a => AnnotatedList a -> Doc
printAnnotatedList AnnotatedList Datatype
a
    ExpressionBit a :: AnnotatedList ClassExpression
a -> AnnotatedList ClassExpression -> Doc
forall a. Pretty a => AnnotatedList a -> Doc
printAnnotatedList AnnotatedList ClassExpression
a
    ObjectBit a :: AnnotatedList ObjectPropertyExpression
a -> AnnotatedList ObjectPropertyExpression -> Doc
forall a. Pretty a => AnnotatedList a -> Doc
printAnnotatedList AnnotatedList ObjectPropertyExpression
a
    DataBit a :: AnnotatedList Datatype
a -> AnnotatedList Datatype -> Doc
forall a. Pretty a => AnnotatedList a -> Doc
printAnnotatedList AnnotatedList Datatype
a
    IndividualSameOrDifferent a :: AnnotatedList Datatype
a -> AnnotatedList Datatype -> Doc
forall a. Pretty a => AnnotatedList a -> Doc
printAnnotatedList AnnotatedList Datatype
a
    _ -> Doc
empty

printMisc :: Pretty a => Annotations -> (b -> Doc) -> b -> AnnotatedList a
    -> Doc
printMisc :: Annotations -> (b -> Doc) -> b -> AnnotatedList a -> Doc
printMisc a :: Annotations
a f :: b -> Doc
f r :: b
r anl :: AnnotatedList a
anl = b -> Doc
f b
r Doc -> Doc -> Doc
<+> (Annotations -> Doc
printAnnotations Annotations
a Doc -> Doc -> Doc
$+$ AnnotatedList a -> Doc
forall a. Pretty a => AnnotatedList a -> Doc
printAnnotatedList AnnotatedList a
anl)

-- | Misc ListFrameBits
printMiscBit :: AS.Relation -> Annotations -> ListFrameBit -> Doc
printMiscBit :: Relation -> Annotations -> ListFrameBit -> Doc
printMiscBit r :: Relation
r a :: Annotations
a lfb :: ListFrameBit
lfb = case ListFrameBit
lfb of
    ExpressionBit anl :: AnnotatedList ClassExpression
anl -> Annotations
-> (EquivOrDisjoint -> Doc)
-> EquivOrDisjoint
-> AnnotatedList ClassExpression
-> Doc
forall a b.
Pretty a =>
Annotations -> (b -> Doc) -> b -> AnnotatedList a -> Doc
printMisc Annotations
a EquivOrDisjoint -> Doc
printEquivOrDisjointClasses (Relation -> EquivOrDisjoint
AS.getED Relation
r) AnnotatedList ClassExpression
anl
    ObjectBit anl :: AnnotatedList ObjectPropertyExpression
anl -> Annotations
-> (EquivOrDisjoint -> Doc)
-> EquivOrDisjoint
-> AnnotatedList ObjectPropertyExpression
-> Doc
forall a b.
Pretty a =>
Annotations -> (b -> Doc) -> b -> AnnotatedList a -> Doc
printMisc Annotations
a EquivOrDisjoint -> Doc
printEquivOrDisjointProp (Relation -> EquivOrDisjoint
AS.getED Relation
r) AnnotatedList ObjectPropertyExpression
anl
    DataBit anl :: AnnotatedList Datatype
anl -> Annotations
-> (EquivOrDisjoint -> Doc)
-> EquivOrDisjoint
-> AnnotatedList Datatype
-> Doc
forall a b.
Pretty a =>
Annotations -> (b -> Doc) -> b -> AnnotatedList a -> Doc
printMisc Annotations
a EquivOrDisjoint -> Doc
printEquivOrDisjointProp (Relation -> EquivOrDisjoint
AS.getED Relation
r) AnnotatedList Datatype
anl
    IndividualSameOrDifferent anl :: AnnotatedList Datatype
anl ->
        Annotations
-> (SameOrDifferent -> Doc)
-> SameOrDifferent
-> AnnotatedList Datatype
-> Doc
forall a b.
Pretty a =>
Annotations -> (b -> Doc) -> b -> AnnotatedList a -> Doc
printMisc Annotations
a SameOrDifferent -> Doc
printSameOrDifferentInd (Relation -> SameOrDifferent
AS.getSD Relation
r) AnnotatedList Datatype
anl
    _ -> Doc
empty

printAnnFrameBit :: Annotations -> AnnFrameBit -> Doc
printAnnFrameBit :: Annotations -> AnnFrameBit -> Doc
printAnnFrameBit a :: Annotations
a afb :: AnnFrameBit
afb = case AnnFrameBit
afb of
    AnnotationFrameBit _ -> Annotations -> Doc
printAnnotations Annotations
a
    DatatypeBit x :: DataRange
x -> Annotations -> Doc
printAnnotations Annotations
a
          Doc -> Doc -> Doc
$+$ String -> Doc
keyword String
equivalentToC Doc -> Doc -> Doc
<+> DataRange -> Doc
forall a. Pretty a => a -> Doc
pretty DataRange
x
    ClassDisjointUnion x :: [ClassExpression]
x -> String -> Doc
keyword String
disjointUnionOfC
      Doc -> Doc -> Doc
<+> (Annotations -> Doc
printAnnotations Annotations
a
          Doc -> Doc -> Doc
$+$ [Doc] -> Doc
vcat (Doc -> [Doc] -> [Doc]
punctuate Doc
comma ( (ClassExpression -> Doc) -> [ClassExpression] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ClassExpression -> Doc
forall a. Pretty a => a -> Doc
pretty [ClassExpression]
x )))
    ClassHasKey op :: [ObjectPropertyExpression]
op dp :: [Datatype]
dp -> String -> Doc
keyword String
hasKeyC Doc -> Doc -> Doc
<+> (Annotations -> Doc
printAnnotations Annotations
a
      Doc -> Doc -> Doc
$+$ [Doc] -> Doc
vcat (Doc -> [Doc] -> [Doc]
punctuate Doc
comma ([Doc] -> [Doc]) -> [Doc] -> [Doc]
forall a b. (a -> b) -> a -> b
$ (ObjectPropertyExpression -> Doc)
-> [ObjectPropertyExpression] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ObjectPropertyExpression -> Doc
forall a. Pretty a => a -> Doc
pretty [ObjectPropertyExpression]
op [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ (Datatype -> Doc) -> [Datatype] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Datatype -> Doc
forall a. Pretty a => a -> Doc
pretty [Datatype]
dp))
    ObjectSubPropertyChain opl :: [ObjectPropertyExpression]
opl -> String -> Doc
keyword String
subPropertyChainC
      Doc -> Doc -> Doc
<+> (Annotations -> Doc
printAnnotations Annotations
a Doc -> Doc -> Doc
$+$ [Doc] -> Doc
fsep (Doc -> [Doc] -> [Doc]
prepPunctuate (String -> Doc
keyword String
oS Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
space)
          ([Doc] -> [Doc]) -> [Doc] -> [Doc]
forall a b. (a -> b) -> a -> b
$ (ObjectPropertyExpression -> Doc)
-> [ObjectPropertyExpression] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ObjectPropertyExpression -> Doc
forall a. Pretty a => a -> Doc
pretty [ObjectPropertyExpression]
opl))
    DataFunctional -> String -> Doc
keyword String
characteristicsC Doc -> Doc -> Doc
<+>
          (Annotations -> Doc
printAnnotations Annotations
a Doc -> Doc -> Doc
$+$ String -> Doc
printCharact String
functionalS)

instance Pretty FrameBit where
    pretty :: FrameBit -> Doc
pretty = FrameBit -> Doc
printFrameBit

printFrameBit :: FrameBit -> Doc
printFrameBit :: FrameBit -> Doc
printFrameBit fb :: FrameBit
fb = case FrameBit
fb of
    ListFrameBit r :: Maybe Relation
r lfb :: ListFrameBit
lfb -> case Maybe Relation
r of
        Just rel :: Relation
rel -> Relation -> Doc
printRelation Relation
rel Doc -> Doc -> Doc
<+> ListFrameBit -> Doc
forall a. Pretty a => a -> Doc
pretty ListFrameBit
lfb
        Nothing -> case ListFrameBit
lfb of
            ObjectCharacteristics x :: AnnotatedList Character
x -> String -> Doc
keyword String
characteristicsC
                Doc -> Doc -> Doc
<+> AnnotatedList Character -> Doc
forall a. Pretty a => AnnotatedList a -> Doc
printAnnotatedList AnnotatedList Character
x
            DataPropRange x :: AnnotatedList DataRange
x -> String -> Doc
keyword String
rangeC Doc -> Doc -> Doc
<+> AnnotatedList DataRange -> Doc
forall a. Pretty a => AnnotatedList a -> Doc
printAnnotatedList AnnotatedList DataRange
x
            IndividualFacts x :: AnnotatedList Fact
x -> String -> Doc
keyword String
factsC Doc -> Doc -> Doc
<+> AnnotatedList Fact -> Doc
forall a. Pretty a => AnnotatedList a -> Doc
printAnnotatedList AnnotatedList Fact
x
            _ -> Doc
empty
    AnnFrameBit a :: Annotations
a afb :: AnnFrameBit
afb -> Annotations -> AnnFrameBit -> Doc
printAnnFrameBit Annotations
a AnnFrameBit
afb

instance Pretty Frame where
    pretty :: Frame -> Doc
pretty = Frame -> Doc
printFrame

printFrame :: Frame -> Doc
printFrame :: Frame -> Doc
printFrame (Frame eith :: Extended
eith bl :: [FrameBit]
bl) = case Extended
eith of
    SimpleEntity (AS.Entity _ e :: EntityType
e uri :: Datatype
uri) -> String -> Doc
keyword (EntityType -> String
AS.showEntityType EntityType
e) Doc -> Doc -> Doc
<+>
            [Doc] -> Doc
fsep [Datatype -> Doc
forall a. Pretty a => a -> Doc
pretty Datatype
uri Doc -> Doc -> Doc
$+$ [Doc] -> Doc
vcat ((FrameBit -> Doc) -> [FrameBit] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map FrameBit -> Doc
forall a. Pretty a => a -> Doc
pretty [FrameBit]
bl)]
    ObjectEntity ope :: ObjectPropertyExpression
ope -> String -> Doc
keyword String
objectPropertyC Doc -> Doc -> Doc
<+>
            (ObjectPropertyExpression -> Doc
forall a. Pretty a => a -> Doc
pretty ObjectPropertyExpression
ope Doc -> Doc -> Doc
$+$ [Doc] -> Doc
fsep [[Doc] -> Doc
vcat ((FrameBit -> Doc) -> [FrameBit] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map FrameBit -> Doc
forall a. Pretty a => a -> Doc
pretty [FrameBit]
bl)])
    ClassEntity ce :: ClassExpression
ce -> String -> Doc
keyword String
classC Doc -> Doc -> Doc
<+>
            (ClassExpression -> Doc
forall a. Pretty a => a -> Doc
pretty ClassExpression
ce Doc -> Doc -> Doc
$+$ [Doc] -> Doc
fsep [[Doc] -> Doc
vcat ((FrameBit -> Doc) -> [FrameBit] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map FrameBit -> Doc
forall a. Pretty a => a -> Doc
pretty [FrameBit]
bl)])
    Misc a :: Annotations
a -> case [FrameBit]
bl of
        [ListFrameBit (Just r :: Relation
r) lfb :: ListFrameBit
lfb] -> Relation -> Annotations -> ListFrameBit -> Doc
printMiscBit Relation
r Annotations
a ListFrameBit
lfb
        [AnnFrameBit ans :: Annotations
ans (AnnotationFrameBit Assertion)] ->
            let [AS.Annotation _ iri :: Datatype
iri _] = Annotations
a
            in String -> Doc
keyword String
individualC Doc -> Doc -> Doc
<+> (Datatype -> Doc
forall a. Pretty a => a -> Doc
pretty Datatype
iri Doc -> Doc -> Doc
$+$ Annotations -> Doc
printAnnotations Annotations
ans)
        h :: FrameBit
h : r :: [FrameBit]
r -> Frame -> Doc
printFrame (Extended -> [FrameBit] -> Frame
Frame Extended
eith [FrameBit
h])
          Doc -> Doc -> Doc
$+$ Frame -> Doc
printFrame (Extended -> [FrameBit] -> Frame
Frame Extended
eith [FrameBit]
r)
        [] -> Doc
empty

instance Pretty Axiom where
    pretty :: Axiom -> Doc
pretty = Axiom -> Doc
printAxiom

printAxiom :: Axiom -> Doc
printAxiom :: Axiom -> Doc
printAxiom (PlainAxiom e :: Extended
e fb :: FrameBit
fb) = Frame -> Doc
printFrame (Extended -> [FrameBit] -> Frame
Frame Extended
e [FrameBit
fb])

printImport :: AS.ImportIRI -> Doc
printImport :: Datatype -> Doc
printImport x :: Datatype
x = String -> Doc
keyword String
importC Doc -> Doc -> Doc
<+> Datatype -> Doc
forall a. Pretty a => a -> Doc
pretty Datatype
x

printPrefixes :: AS.PrefixMap -> Doc
printPrefixes :: PrefixMap -> Doc
printPrefixes x :: PrefixMap
x = [Doc] -> Doc
vcat (((String, String) -> Doc) -> [(String, String)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (\ (a :: String
a, b :: String
b) ->
       (String -> Doc
text "Prefix:" Doc -> Doc -> Doc
<+> String -> Doc
text String
a Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
colon Doc -> Doc -> Doc
<+> String -> Doc
text ('<' Char -> String -> String
forall a. a -> [a] -> [a]
: String
b String -> String -> String
forall a. [a] -> [a] -> [a]
++ ">")))
          (PrefixMap -> [(String, String)]
forall k a. Map k a -> [(k, a)]
Map.toList PrefixMap
x))

-- | Printing the ontology
instance Pretty Ontology where
    pretty :: Ontology -> Doc
pretty = Ontology -> Doc
printOntology

printOntology :: Ontology -> Doc
printOntology :: Ontology -> Doc
printOntology Ontology {name :: Ontology -> Datatype
name = Datatype
a, imports :: Ontology -> [Datatype]
imports = [Datatype]
b, ann :: Ontology -> [Annotations]
ann = [Annotations]
c, ontFrames :: Ontology -> [Frame]
ontFrames = [Frame]
d} =
    (if Datatype
nullIRI Datatype -> Datatype -> Bool
forall a. Eq a => a -> a -> Bool
== Datatype
a then Doc
empty else String -> Doc
keyword String
ontologyC Doc -> Doc -> Doc
<+> Datatype -> Doc
forall a. Pretty a => a -> Doc
pretty Datatype
a)
    Doc -> Doc -> Doc
$++$ [Doc] -> Doc
vcat ((Datatype -> Doc) -> [Datatype] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Datatype -> Doc
printImport [Datatype]
b)
    Doc -> Doc -> Doc
$++$ [Doc] -> Doc
vcat ((Annotations -> Doc) -> [Annotations] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Annotations -> Doc
printAnnotations [Annotations]
c) Doc -> Doc -> Doc
$+$ [Doc] -> Doc
vcat ((Frame -> Doc) -> [Frame] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Frame -> Doc
forall a. Pretty a => a -> Doc
pretty [Frame]
d)

printOntologyDocument :: OntologyDocument -> Doc
printOntologyDocument :: OntologyDocument -> Doc
printOntologyDocument OntologyDocument {prefixDeclaration :: OntologyDocument -> PrefixMap
prefixDeclaration = PrefixMap
a, ontology :: OntologyDocument -> Ontology
ontology = Ontology
b} =
    PrefixMap -> Doc
printPrefixes PrefixMap
a Doc -> Doc -> Doc
$++$ Ontology -> Doc
forall a. Pretty a => a -> Doc
pretty Ontology
b

instance Pretty OntologyDocument where
    pretty :: OntologyDocument -> Doc
pretty = OntologyDocument -> Doc
printOntologyDocument