import
Common.Doc hiding (sepBySemis, sepByCommas)
sepBySemis :: [Doc] -> Doc
sepBySemis = vcat . punctuate (text " ;")
ppWithSemis :: Pretty a => [a] -> Doc
ppWithSemis = sepBySemis . map pretty
sepByCommas :: [Doc] -> Doc
sepByCommas = vcat . punctuate (text " ,")
ppWithCommas :: Pretty a => [a] -> Doc
ppWithCommas = sepByCommas . map pretty
instance Pretty Predicate where
printPredicate :: Predicate -> Doc
printPredicate (Predicate iri) = pretty iri
instance Pretty RDFLiteral where
RDFLiteral b lexi ty -> text (if not b
else "\"\"\"" ++ lexi ++ "\"\"\"") <> case ty of
Typed u -> keyword cTypeS <> pretty u
Untyped tag -> if isNothing tag then empty
else let Just tag2 = tag in text "@" <> text tag2
RDFNumberLit f -> text (show f)
instance Pretty PredicateObjectList where
pretty = printPredObjList
printPredObjList :: PredicateObjectList -> Doc
printPredObjList (PredicateObjectList p ol) = pretty p <+> ppWithCommas ol
instance Pretty Subject where
printSubject :: Subject -> Doc
printSubject subj = case subj of
Subject iri -> pretty iri
SubjectList ls -> brackets $ ppWithSemis ls
SubjectCollection c -> parens $ (hsep . map pretty) c
instance Pretty Object where
printObject :: Object -> Doc
printObject obj = case obj of
ObjectLiteral l -> pretty l
instance Pretty Triples where
printTriples :: Triples -> Doc
printTriples (Triples s ls) = pretty s <+> ppWithSemis ls <+> dot
instance Pretty Statement where
printStatement :: Statement -> Doc
printStatement s = case s of
PrefixStatement (PrefixR p iri)
-> text "@prefix" <+> pretty p <> colon <+> pretty iri <+> dot
BaseStatement (Base iri) -> text "@base" <+> pretty iri <+> dot
instance Pretty TurtleDocument where
printDocument :: TurtleDocument -> Doc
printDocument doc = (vcat . map pretty) (statements doc)
printExpandedIRI :: IRI -> Doc
if (not $ hasFullIRI iri) || (isBlankNode iri) then
text $ showIRICompact iri
else text "<" <> text (showIRIFull iri) <> text ">"
instance Pretty Term where
SubjectTerm iri -> printExpandedIRI iri
PredicateTerm iri -> printExpandedIRI iri
ObjectTerm obj -> case obj of
Left iri -> printExpandedIRI iri
instance Pretty Axiom where
printAxiom :: Axiom -> Doc
printAxiom (Axiom sub pre obj) = pretty sub <+> pretty pre <+> pretty obj
printAxioms :: [Axiom] -> Doc
printAxioms = vcat . map pretty
-- | RDF signature printing
printRDFBasicTheory :: (Sign, [Named Axiom]) -> Doc
printRDFBasicTheory (_, l) = vsep (map (pretty . sentence) l)
instance Pretty Sign where
printNodes :: String ->
Set.Set Term -> Doc
printNodes s terms = text "#" <+> text s $+$
vcat (map ((text "#\t\t" <+>) . pretty) (
Set.toList terms))
printSign s = printNodes "subjects:" (subjects s)
$+$ printNodes "predicates:" (predicates s)
$+$ printNodes "objects:" (objects s)
instance Pretty RDFEntityType where
pretty ety = text $ show ety
instance Pretty RDFEntity where
pretty (RDFEntity ty ent) = pretty ty <+> pretty ent
instance Pretty SymbItems where
pretty (SymbItems m us) = pretty m <+> ppWithCommas us
instance Pretty SymbMapItems where
pretty (SymbMapItems m us) = pretty m
Just t -> mapsto <+> pretty t]) us)
instance Pretty RawSymb where