AS.hs revision 6470a08d94430381c14ed30c3a3a8e433401352b
ca010363454de207082dfaa4b753531ce2a34551Christian Maeder{-# LANGUAGE DeriveDataTypeable #-}
ca010363454de207082dfaa4b753531ce2a34551Christian Maeder{- |
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederModule : $Header$
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaederCopyright : (c) C. Maeder, Felix Gabriel Mance
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
ca010363454de207082dfaa4b753531ce2a34551Christian Maeder
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederMaintainer : Christian.Maeder@dfki.de
ca010363454de207082dfaa4b753531ce2a34551Christian MaederStability : provisional
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaederPortability : portable
ca010363454de207082dfaa4b753531ce2a34551Christian Maeder
79d11c2e3ad242ebb241f5d4a5e98a674c0b986fChristian MaederOWL 2 Functional Syntax constructs
ca010363454de207082dfaa4b753531ce2a34551Christian Maeder
ca010363454de207082dfaa4b753531ce2a34551Christian MaederReferences:
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maeder <http://www.w3.org/TR/2009/REC-owl2-syntax-20091027/#Functional-Style_Syntax>
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maeder <http://www.w3.org/TR/owl2-manchester-syntax/>
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder-}
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maeder
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maedermodule OWL2.AS where
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maeder
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maederimport Common.Id
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maederimport Common.Keywords (stringS)
ca010363454de207082dfaa4b753531ce2a34551Christian Maeder
ca010363454de207082dfaa4b753531ce2a34551Christian Maederimport Common.Result
ca010363454de207082dfaa4b753531ce2a34551Christian Maeder
ca010363454de207082dfaa4b753531ce2a34551Christian Maederimport OWL2.ColonKeywords
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maederimport OWL2.Keywords
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maederimport Data.Char (intToDigit)
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maederimport Data.Data
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maederimport Data.List
23f8d286586ff38a9e73052b2c7c04c62c5c638fChristian Maederimport Data.Maybe
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maederimport qualified Data.Map as Map
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maederimport qualified Data.Set as Set
e68f45f355ed9d4026ee9baff5aa75aa7c911cc2Christian Maeder
ad270004874ce1d0697fb30d7309f180553bb315Christian Maederdata IRIType = Full | Abbreviated | NodeID
fc8c6570c7b4ee13f375eb607bed2290438573bfChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
83cc27e4ca7cf1a4bb5f4a8df17d3e6d44e6f1eaChristian Maeder
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder{- | full or abbreviated IRIs with a possible uri for the prefix
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder or a local part following a hash sign -}
975642b989852fc24119c59cf40bc1af653608ffChristian Maederdata QName = QN
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder { namePrefix :: String
83cc27e4ca7cf1a4bb5f4a8df17d3e6d44e6f1eaChristian Maeder -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder , localPart :: String
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder -- ^ the local part of a qualified name \"namePrefix:localPart\"
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder , iriType :: IRIType
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder , expandedIRI :: String
fc8c6570c7b4ee13f375eb607bed2290438573bfChristian Maeder -- ^ the associated namespace uri (not printed)
83cc27e4ca7cf1a4bb5f4a8df17d3e6d44e6f1eaChristian Maeder , iriPos :: Range
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder } deriving (Show, Typeable, Data)
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder
53301de22afd7190981b363b57c48df86fcb50f7Christian Maederinstance Eq QName where
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder p == q = compare p q == EQ
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder
53301de22afd7190981b363b57c48df86fcb50f7Christian Maederinstance Ord QName where
0a39036fa485579a7b7c81cdd44a412392571927Christian Maeder compare (QN p1 l1 b1 n1 _) (QN p2 l2 b2 n2 _) =
da2b959c50c95309d8eb8b24174249c2847e74b5Christian Maeder if null n1 || null n2 then compare (b1, p1, l1) (b2, p2, l2) else
0a39036fa485579a7b7c81cdd44a412392571927Christian Maeder compare n1 n2 -- compare fully expanded names only
0a39036fa485579a7b7c81cdd44a412392571927Christian Maeder
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederqNameRange :: QName -> [Pos]
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederqNameRange q = let Range rs = iriPos q in case rs of
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder [p] -> let
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder p0 = if iriType q == Full then incSourceColumn p (-1) else p
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder in tokenRange $ Token (showQN q) $ Range [p0]
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder _ -> rs
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maederinstance GetRange QName where
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder getRange = iriPos
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder rangeSpan = qNameRange
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowQN :: QName -> String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowQN q = (if iriType q == Full then showQI else showQU) q
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder-- | show QName as abbreviated iri
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaedershowQU :: QName -> String
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedershowQU (QN pre local _ _ _) =
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder if null pre then local else pre ++ ":" ++ local
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder-- | show QName in angle brackets as full iris
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedershowQI :: QName -> String
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedershowQI n = '<' : showQU n ++ ">"
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedernullQName :: QName
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedernullQName = QN "" "" Abbreviated "" nullRange
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederisNullQName :: QName -> Bool
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederisNullQName qn = case qn of
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder QN "" "" _ "" _ -> True
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder _ -> False
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederunamedS :: String
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederunamedS = "//www." ++ dnamedS
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederdnamedS :: String
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederdnamedS = "dfki.de/sks/hets/ontology/unamed"
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederdummyQName :: QName
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederdummyQName = QN "http" unamedS Full ("http:" ++ unamedS) nullRange
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedermkQName :: String -> QName
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedermkQName s = nullQName { localPart = s }
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedersetQRange :: Range -> QName -> QName
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedersetQRange r q = q { iriPos = r }
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedersetPrefix :: String -> QName -> QName
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedersetPrefix s q = q { namePrefix = s }
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedersetFull :: QName -> QName
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedersetFull q = q {iriType = Full}
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maedertype IRI = QName
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
da2b959c50c95309d8eb8b24174249c2847e74b5Christian Maeder-- | checks if an IRI is an anonymous individual
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederisAnonymous :: IRI -> Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisAnonymous iri = iriType iri == NodeID || namePrefix iri == "_"
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder-- | checks if a string (bound to be localPart of an IRI) contains \":\/\/\"
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedercssIRI :: String -> IRIType
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedercssIRI iri = if isInfixOf "://" iri then Full else Abbreviated
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder-- | prefix -> localname
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype PrefixMap = Map.Map String String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederpredefPrefixes :: PrefixMap
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederpredefPrefixes = Map.fromList
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder [ ("owl", "http://www.w3.org/2002/07/owl#")
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder , ("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder , ("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder , ("xsd", "http://www.w3.org/2001/XMLSchema#")
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder , ("", showQU dummyQName ++ "#") ]
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype LexicalForm = String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype LanguageTag = String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype ImportIRI = IRI
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype OntologyIRI = IRI
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype Class = IRI
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype Datatype = IRI
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype ObjectProperty = IRI
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maedertype DataProperty = IRI
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maedertype AnnotationProperty = IRI
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maedertype Individual = IRI
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maeder
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maederdata EquivOrDisjoint = Equivalent | Disjoint
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedershowEquivOrDisjoint :: EquivOrDisjoint -> String
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedershowEquivOrDisjoint ed = case ed of
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder Equivalent -> equivalentToC
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder Disjoint -> disjointWithC
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maederdata DomainOrRange = ADomain | ARange
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowDomainOrRange :: DomainOrRange -> String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowDomainOrRange dr = case dr of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder ADomain -> domainC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder ARange -> rangeC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maederdata SameOrDifferent = Same | Different
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowSameOrDifferent :: SameOrDifferent -> String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowSameOrDifferent sd = case sd of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Same -> sameAsC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Different -> differentFromC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maederdata Relation =
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder EDRelation EquivOrDisjoint
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | SubPropertyOf
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | InverseOf
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | SubClass
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Types
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | DRRelation DomainOrRange
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | SDRelation SameOrDifferent
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowRelation :: Relation -> String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowRelation r = case r of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder EDRelation ed -> showEquivOrDisjoint ed
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder SubPropertyOf -> subPropertyOfC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder InverseOf -> inverseOfC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder SubClass -> subClassOfC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Types -> typesC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder DRRelation dr -> showDomainOrRange dr
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder SDRelation sd -> showSameOrDifferent sd
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetED :: Relation -> EquivOrDisjoint
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetED r = case r of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder EDRelation ed -> ed
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder _ -> error "not domain or range"
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetDR :: Relation -> DomainOrRange
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetDR r = case r of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder DRRelation dr -> dr
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder _ -> error "not domain or range"
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetSD :: Relation -> SameOrDifferent
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetSD s = case s of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder SDRelation sd -> sd
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder _ -> error "not same or different"
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maederdata Character =
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Functional
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | InverseFunctional
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Reflexive
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Irreflexive
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Symmetric
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Asymmetric
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Antisymmetric
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Transitive
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder deriving (Enum, Bounded, Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maederdata PositiveOrNegative = Positive | Negative
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maederdata QuantifierType = AllValuesFrom | SomeValuesFrom
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowQuantifierType :: QuantifierType -> String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowQuantifierType ty = case ty of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder AllValuesFrom -> onlyS
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder SomeValuesFrom -> someS
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder-- * Predefined IRI checkings
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaederthingMap :: PreDefMaps
669e21946b6f90785fc3cb44e7cf4f38c3f6493dChristian MaederthingMap = makeOWLPredefMaps predefClass
669e21946b6f90785fc3cb44e7cf4f38c3f6493dChristian Maeder
669e21946b6f90785fc3cb44e7cf4f38c3f6493dChristian MaederisThing :: IRI -> Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisThing = checkPredef thingMap
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefObjProp :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefObjProp = makeOWLPredefMaps predefObjProp
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisPredefObjProp :: IRI -> Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisPredefObjProp = checkPredef makePredefObjProp
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefDataProp :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefDataProp = makeOWLPredefMaps predefDataProp
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisPredefDataProp :: IRI -> Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisPredefDataProp = checkPredef makePredefDataProp
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefRDFSAnnoProp :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefRDFSAnnoProp = preDefMaps predefRDFSAnnoProps "rdfs"
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaederisPredefRDFSAnnoProp :: IRI -> Bool
669e21946b6f90785fc3cb44e7cf4f38c3f6493dChristian MaederisPredefRDFSAnnoProp = checkPredef makePredefRDFSAnnoProp
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefOWLAnnoProp :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefOWLAnnoProp = makeOWLPredefMaps predefOWLAnnoProps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
53301de22afd7190981b363b57c48df86fcb50f7Christian MaederisPredefOWLAnnoProp :: IRI -> Bool
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederisPredefOWLAnnoProp = checkPredef makePredefOWLAnnoProp
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederisPredefAnnoProp :: IRI -> Bool
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederisPredefAnnoProp iri = isPredefOWLAnnoProp iri || isPredefRDFSAnnoProp iri
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederisPredefPropOrClass :: IRI -> Bool
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederisPredefPropOrClass iri = isPredefAnnoProp iri || isPredefDataProp iri
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder || isPredefObjProp iri || isThing iri
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederpredefIRIs :: Set.Set IRI
53301de22afd7190981b363b57c48df86fcb50f7Christian MaederpredefIRIs = Set.fromList $ map (setPrefix "xsd" . mkQName) xsdKeys
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder ++ map (setPrefix "owl" . mkQName) owlNumbers
909ce57d58a9cec1d214f0ecbdb1dadddad2e6d9Christian Maeder ++ map (setPrefix "rdf" . mkQName) [rdfsLiteral, stringS]
f8a03685d9184046e88e1d76aabdab4f714db440Christian Maeder ++ [setPrefix "rdfs" $ mkQName xmlLiteral]
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisDatatypeKey :: IRI -> Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisDatatypeKey = not . null . isDatatypeKeyAux
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederxsdMap :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederxsdMap = makeXsdMap xsdKeys
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederowlNumbersMap :: PreDefMaps
fcfed328fae6266214ee61ee7a16fd263fd3cb70Christian MaederowlNumbersMap = makeOWLPredefMaps owlNumbers
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederrdfMap :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederrdfMap = preDefMaps [xmlLiteral, stringS] "rdf"
46d766efdf8beaaadf3f34d99c305738064e9216Christian Maeder
975642b989852fc24119c59cf40bc1af653608ffChristian MaederrdfsMap :: PreDefMaps
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederrdfsMap = preDefMaps [rdfsLiteral] "rdfs"
13b24998210d193b38cae06485da6f06c61d7f62Christian Maeder
13b24998210d193b38cae06485da6f06c61d7f62Christian MaederisDatatypeKeyAux :: IRI -> [(String, String)]
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederisDatatypeKeyAux iri = mapMaybe (`checkPredefAux` iri)
13b24998210d193b38cae06485da6f06c61d7f62Christian Maeder [ xsdMap, owlNumbersMap, rdfMap, rdfsMap ]
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype PreDefMaps = ([String], String, String)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederpreDefMaps :: [String] -> String -> PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederpreDefMaps sl pref = let
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Just puri = Map.lookup pref predefPrefixes
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Just sp = stripPrefix "http://www.w3.org/" puri
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder in (sl, pref, sp)
e68f45f355ed9d4026ee9baff5aa75aa7c911cc2Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedercheckPredefAux :: PreDefMaps -> IRI -> Maybe (String, String)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedercheckPredefAux (sl, pref, exPref) u =
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder let lp = localPart u in case namePrefix u of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder "http" -> case stripPrefix "//www." lp of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Just q -> case stripPrefix "w3.org/" q of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Just r -> case stripPrefix exPref r of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Just s | elem s sl -> Just (pref, s)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder _ -> Nothing
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder Nothing -> case stripPrefix (dnamedS ++ "#") q of
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder Just s | elem s sl -> Just (pref, s)
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder _ -> Nothing
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Nothing -> Nothing
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder pu | (null (expandedIRI u) && null pu || pu == pref) && elem lp sl
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder -> Just (pref, lp)
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder _ -> Nothing
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaedercheckPredef :: PreDefMaps -> IRI -> Bool
13b24998210d193b38cae06485da6f06c61d7f62Christian MaedercheckPredef ms = isJust . checkPredefAux ms
13b24998210d193b38cae06485da6f06c61d7f62Christian Maeder
13b24998210d193b38cae06485da6f06c61d7f62Christian MaedermakeOWLPredefMaps :: [String] -> PreDefMaps
53301de22afd7190981b363b57c48df86fcb50f7Christian MaedermakeOWLPredefMaps sl = preDefMaps sl "owl"
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder-- | sets the correct prefix for the predefined datatypes
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaedersetDatatypePrefix :: IRI -> IRI
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaedersetDatatypePrefix iri = case isDatatypeKeyAux iri of
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder (p, l) : _ -> setPrefix p $ mkQName l
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder _ -> error $ showQU iri ++ " is not a predefined datatype"
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder-- | checks if the IRI is part of the built-in ones and puts the correct prefix
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaedersetReservedPrefix :: IRI -> IRI
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaedersetReservedPrefix iri = case namePrefix iri of
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder ""
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder | isDatatypeKey iri -> setDatatypePrefix iri
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder | isThing iri || isPredefDataProp iri || isPredefOWLAnnoProp iri
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder || isPredefObjProp iri -> setPrefix "owl" iri
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder | isPredefRDFSAnnoProp iri -> setPrefix "rdfs" iri
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder _ -> iri
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaederstripReservedPrefix :: IRI -> IRI
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaederstripReservedPrefix = mkQName . getPredefName
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder{- | returns the name of the predefined IRI (e.g <xsd:string> returns "string"
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder or <http://www.w3.org/2002/07/owl#real> returns "real") -}
ac142c1b088711f911018d8108a64be80b2f2a58Christian MaedergetPredefName :: IRI -> String
f1ef1c750f805c1732b01001f2b157c0077b808eChristian MaedergetPredefName iri =
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maeder if namePrefix iri `elem` ["", "xsd", "rdf", "rdfs", "owl"]
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder then localPart iri
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder else case mapMaybe (`stripPrefix` showQU iri)
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder $ Map.elems predefPrefixes of
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder [s] -> s
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder _ -> showQN iri
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder-- | Extracts Token from IRI
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederuriToTok :: IRI -> Token
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederuriToTok urI = mkSimpleId $ getPredefName urI
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder-- | Extracts Id from IRI
ab0f35d8b9012e459417e086773049ce33dda2a0Christian MaederuriToId :: IRI -> Id
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederuriToId = simpleIdToId . uriToTok
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder-- | Extracts Id from Entities
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederentityToId :: Entity -> Id
975642b989852fc24119c59cf40bc1af653608ffChristian MaederentityToId = uriToId . cutIRI
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederprintDatatype :: IRI -> String
975642b989852fc24119c59cf40bc1af653608ffChristian MaederprintDatatype dt = showQU $
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder if isDatatypeKey dt then stripReservedPrefix dt else dt
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder
975642b989852fc24119c59cf40bc1af653608ffChristian Maederdata DatatypeCat = OWL2Number | OWL2String | OWL2Bool | Other
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetDatatypeCat :: IRI -> DatatypeCat
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetDatatypeCat iri = case isDatatypeKey iri of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder True
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | checkPredef xsdBooleanMap iri -> OWL2Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | checkPredef xsdNumbersMap iri || checkPredef owlNumbersMap iri
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder -> OWL2Number
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder | checkPredef xsdStringsMap iri -> OWL2String
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder | otherwise -> Other
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder False -> Other
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaedermakeXsdMap :: [String] -> PreDefMaps
975642b989852fc24119c59cf40bc1af653608ffChristian MaedermakeXsdMap sl = preDefMaps sl "xsd"
ab0f35d8b9012e459417e086773049ce33dda2a0Christian Maeder
975642b989852fc24119c59cf40bc1af653608ffChristian MaederxsdBooleanMap :: PreDefMaps
975642b989852fc24119c59cf40bc1af653608ffChristian MaederxsdBooleanMap = makeXsdMap [booleanS]
xsdNumbersMap :: PreDefMaps
xsdNumbersMap = makeXsdMap xsdNumbers
xsdStringsMap :: PreDefMaps
xsdStringsMap = makeXsdMap xsdStrings
facetToIRI :: DatatypeFacet -> ConstrainingFacet
facetToIRI = setPrefix "xsd" . mkQName . showFacet
-- * Cardinalities
data CardinalityType = MinCardinality | MaxCardinality | ExactCardinality
deriving (Show, Eq, Ord, Typeable, Data)
showCardinalityType :: CardinalityType -> String
showCardinalityType ty = case ty of
MinCardinality -> minS
MaxCardinality -> maxS
ExactCardinality -> exactlyS
data Cardinality a b = Cardinality CardinalityType Int a (Maybe b)
deriving (Show, Eq, Ord, Typeable, Data)
data JunctionType = UnionOf | IntersectionOf
deriving (Show, Eq, Ord, Typeable, Data)
type ConstrainingFacet = IRI
type RestrictionValue = Literal
-- * ENTITIES
data Entity = Entity
{ label :: Maybe String
, entityKind :: EntityType
, cutIRI :: IRI }
deriving (Show, Typeable, Data)
mkEntity :: EntityType -> IRI -> Entity
mkEntity = Entity Nothing
mkEntityLbl :: String -> EntityType -> IRI -> Entity
mkEntityLbl = Entity . Just
instance Ord Entity where
compare (Entity _ ek1 ir1) (Entity _ ek2 ir2) = compare (ek1, ir1) (ek2, ir2)
instance Eq Entity where
e1 == e2 = compare e1 e2 == EQ
instance GetRange Entity where
getRange = iriPos . cutIRI
rangeSpan = qNameRange . cutIRI
data EntityType =
Datatype
| Class
| ObjectProperty
| DataProperty
| AnnotationProperty
| NamedIndividual
deriving (Enum, Bounded, Show, Read, Eq, Ord, Typeable, Data)
showEntityType :: EntityType -> String
showEntityType e = case e of
Datatype -> datatypeC
Class -> classC
ObjectProperty -> objectPropertyC
DataProperty -> dataPropertyC
AnnotationProperty -> annotationPropertyC
NamedIndividual -> individualC
entityTypes :: [EntityType]
entityTypes = [minBound .. maxBound]
pairSymbols :: Entity -> Entity -> Result Entity -- TODO: improve!
pairSymbols (Entity lb1 k1 i1) (Entity lb2 k2 i2) =
if k1 /= k2 then
error "can't pair symbols of different kind"
else do
let rest x = drop 1 $ dropWhile (/= '#') x
pairLables lbl1 lbl2 = case (lbl1, lbl2) of
(Nothing, _) -> pairLables lbl2 lbl1
(Just l1, Just l2) | l1 /= l2 -> Just $ l1 ++ ", " ++ l2
_ -> lbl1
pairIRIs (QN p1 l1 t1 _e1 r1)
(QN _p2 l2 _t2 _e2 _r2) =
QN
{ namePrefix = p1
, localPart = if rest l1 == rest l2 then l1 else l1 ++ "_" ++ rest l2
, iriType = t1
, expandedIRI = ""
, iriPos = r1
}
return $ Entity (pairLables lb1 lb2) k1 $ pairIRIs i1 i2
-- * LITERALS
data TypedOrUntyped = Typed Datatype | Untyped (Maybe LanguageTag)
deriving (Show, Eq, Ord, Typeable, Data)
data Literal = Literal LexicalForm TypedOrUntyped | NumberLit FloatLit
deriving (Show, Eq, Ord, Typeable, Data)
-- | non-negative integers given by the sequence of digits
data NNInt = NNInt [Int] deriving (Eq, Ord, Typeable, Data)
instance Show NNInt where
show (NNInt l) = map intToDigit l
zeroNNInt :: NNInt
zeroNNInt = NNInt []
isZeroNNInt :: NNInt -> Bool
isZeroNNInt (NNInt l) = null l
data IntLit = IntLit
{ absInt :: NNInt
, isNegInt :: Bool }
deriving (Eq, Ord, Typeable, Data)
instance Show IntLit where
show (IntLit n b) = (if b then ('-' :) else id) $ show n
zeroInt :: IntLit
zeroInt = IntLit zeroNNInt False
isZeroInt :: IntLit -> Bool
isZeroInt (IntLit n _) = isZeroNNInt n
negNNInt :: Bool -> NNInt -> IntLit
negNNInt b n = IntLit n b
negInt :: IntLit -> IntLit
negInt (IntLit n b) = IntLit n $ not b
data DecLit = DecLit
{ truncDec :: IntLit
, fracDec :: NNInt }
deriving (Eq, Ord, Typeable, Data)
instance Show DecLit where
show (DecLit t f) = show t
++ if isZeroNNInt f then "" else
'.' : show f
isDecInt :: DecLit -> Bool
isDecInt = isZeroNNInt . fracDec
negDec :: Bool -> DecLit -> DecLit
negDec b (DecLit t f) = DecLit (if b then negInt t else t) f
data FloatLit = FloatLit
{ floatBase :: DecLit
, floatExp :: IntLit }
deriving (Eq, Ord, Typeable, Data)
instance Show FloatLit where
show (FloatLit b e) = show b
++ if isZeroInt e then "" else
'E' : show e ++ "F"
isFloatDec :: FloatLit -> Bool
isFloatDec = isZeroInt . floatExp
isFloatInt :: FloatLit -> Bool
isFloatInt f = isFloatDec f && isDecInt (floatBase f)
floatToInt :: FloatLit -> IntLit
floatToInt = truncDec . floatBase
intToDec :: IntLit -> DecLit
intToDec i = DecLit i zeroNNInt
decToFloat :: DecLit -> FloatLit
decToFloat d = FloatLit d zeroInt
intToFloat :: IntLit -> FloatLit
intToFloat = decToFloat . intToDec
abInt :: IntLit -> IntLit
abInt int = int {isNegInt = False}
abDec :: DecLit -> DecLit
abDec dec = dec {truncDec = abInt $ truncDec dec}
abFloat :: FloatLit -> FloatLit
abFloat f = f {floatBase = abDec $ floatBase f}
isNegDec :: DecLit -> Bool
isNegDec d = isNegInt $ truncDec d
numberName :: FloatLit -> String
numberName f
| isFloatInt f = integerS
| isFloatDec f = decimalS
| otherwise = floatS
cTypeS :: String
cTypeS = "^^"
-- * PROPERTY EXPRESSIONS
type InverseObjectProperty = ObjectPropertyExpression
data ObjectPropertyExpression = ObjectProp ObjectProperty
| ObjectInverseOf InverseObjectProperty
deriving (Show, Eq, Ord, Typeable, Data)
objPropToIRI :: ObjectPropertyExpression -> Individual
objPropToIRI opExp = case opExp of
ObjectProp u -> u
ObjectInverseOf objProp -> objPropToIRI objProp
type DataPropertyExpression = DataProperty
-- * DATA RANGES
data DataRange =
DataType Datatype [(ConstrainingFacet, RestrictionValue)]
| DataJunction JunctionType [DataRange]
| DataComplementOf DataRange
| DataOneOf [Literal]
deriving (Show, Eq, Ord, Typeable, Data)
-- * CLASS EXPERSSIONS
data ClassExpression =
Expression Class
| ObjectJunction JunctionType [ClassExpression]
| ObjectComplementOf ClassExpression
| ObjectOneOf [Individual]
| ObjectValuesFrom QuantifierType ObjectPropertyExpression ClassExpression
| ObjectHasValue ObjectPropertyExpression Individual
| ObjectHasSelf ObjectPropertyExpression
| ObjectCardinality (Cardinality ObjectPropertyExpression ClassExpression)
| DataValuesFrom QuantifierType DataPropertyExpression DataRange
| DataHasValue DataPropertyExpression Literal
| DataCardinality (Cardinality DataPropertyExpression DataRange)
deriving (Show, Eq, Ord, Typeable, Data)
-- * ANNOTATIONS
data Annotation = Annotation [Annotation] AnnotationProperty AnnotationValue
deriving (Show, Eq, Ord, Typeable, Data)
data AnnotationValue = AnnValue IRI | AnnValLit Literal
deriving (Show, Eq, Ord, Typeable, Data)