AS.hs revision 1a38107941725211e7c3f051f7a8f5e12199f03a
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder{-# LANGUAGE DeriveDataTypeable #-}
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder{- |
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederModule : $Header$
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian MaederCopyright : (c) C. Maeder, Felix Gabriel Mance
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederMaintainer : Christian.Maeder@dfki.de
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian MaederStability : provisional
413db961f13e112716509b6d61d7a7bbf50c98b2Christian MaederPortability : portable
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder
f3a94a197960e548ecd6520bb768cb0d547457bbChristian MaederOWL 2 Functional Syntax constructs
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederReferences:
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maeder <http://www.w3.org/TR/2009/REC-owl2-syntax-20091027/#Functional-Style_Syntax>
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder <http://www.w3.org/TR/owl2-manchester-syntax/>
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maeder-}
d48085f765fca838c1d972d2123601997174583dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maedermodule OWL2.AS where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maederimport Common.Id
0df692ce8b9293499b2e1768458613a63e7b5cd0Christian Maederimport Common.Keywords (stringS)
d48085f765fca838c1d972d2123601997174583dChristian Maeder
47d6bc7bc9a708427f96be8d805f712697ad3d9eChristian Maederimport Common.Result
23a00c966f2aa8da525d7a7c51933c99964426c0Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport OWL2.ColonKeywords
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maederimport OWL2.Keywords
72909c6c1cfe9702f5910d0a135c8b55729c7917Christian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maederimport Data.Char (intToDigit)
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maederimport Data.Data
3c5cc698b0c061209ff83eb8de027daef5ae922aChristian Maederimport Data.List
3c5cc698b0c061209ff83eb8de027daef5ae922aChristian Maederimport Data.Maybe
3c5cc698b0c061209ff83eb8de027daef5ae922aChristian Maederimport qualified Data.Map as Map
3c5cc698b0c061209ff83eb8de027daef5ae922aChristian Maederimport qualified Data.Set as Set
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maederdata IRIType = Full | Abbreviated | NodeID
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder{- | full or abbreviated IRIs with a possible uri for the prefix
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder or a local part following a hash sign -}
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata QName = QN
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder { namePrefix :: String
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian Maeder -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , localPart :: String
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder -- ^ the local part of a qualified name \"namePrefix:localPart\"
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , iriType :: IRIType
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , expandedIRI :: String
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- ^ the associated namespace uri (not printed)
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maeder , iriPos :: Range
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder } deriving (Show, Typeable, Data)
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maederinstance Eq QName where
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder p == q = compare p q == EQ
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Ord QName where
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder compare (QN p1 l1 b1 n1 _) (QN p2 l2 b2 n2 _) =
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder if null n1 || null n2 then compare (b1, p1, l1) (b2, p2, l2) else
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder compare n1 n2 -- compare fully expanded names only
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederqNameRange :: QName -> [Pos]
df33a9af92444f63ad545da6bb326aac9284318eChristian MaederqNameRange q = let Range rs = iriPos q in case rs of
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder [p] -> let
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder p0 = if iriType q == Full then incSourceColumn p (-1) else p
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder in tokenRange $ Token (showQN q) $ Range [p0]
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder _ -> rs
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder
df33a9af92444f63ad545da6bb326aac9284318eChristian Maederinstance GetRange QName where
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder getRange = iriPos
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder rangeSpan = qNameRange
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder
df33a9af92444f63ad545da6bb326aac9284318eChristian MaedershowQN :: QName -> String
df33a9af92444f63ad545da6bb326aac9284318eChristian MaedershowQN q = (if iriType q == Full then showQI else showQU) q
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder-- | show QName as abbreviated iri
ce3928e71520030ad0275b72050a8f4377f9313cChristian MaedershowQU :: QName -> String
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedershowQU (QN pre local _ _ _) =
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder if null pre then local else pre ++ ":" ++ local
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder-- | show QName in angle brackets as full iris
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedershowQI :: QName -> String
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaedershowQI n = '<' : showQU n ++ ">"
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaedernullQName :: QName
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaedernullQName = QN "" "" Abbreviated "" nullRange
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
92aa1b88f02d2a413da60dba78acd34312e6f29aChristian MaederisNullQName :: QName -> Bool
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederisNullQName qn = case qn of
6b1153c560b677f9f5da2a60ee8a10de75ff90c5Christian Maeder QN "" "" _ "" _ -> True
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder _ -> False
81946e2b3f6dde6167f48769bd02c7a634736856Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederunamedS :: String
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederunamedS = "//www." ++ dnamedS
6cb518d88084543c13aa7e56db767c14ee97ab77Christian Maeder
6cb518d88084543c13aa7e56db767c14ee97ab77Christian MaederdnamedS :: String
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaederdnamedS = "dfki.de/sks/hets/ontology/unamed"
024621f43239cfe9629e35d35a8669fad7acbba2Christian Maeder
99f16a0f9ca757410960ff51a79b034503384fe2Christian MaederdummyQName :: QName
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaederdummyQName = QN "http" unamedS Full ("http:" ++ unamedS) nullRange
d48085f765fca838c1d972d2123601997174583dChristian Maeder
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaedermkQName :: String -> QName
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaedermkQName s = nullQName { localPart = s }
d48085f765fca838c1d972d2123601997174583dChristian Maeder
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaedersetQRange :: Range -> QName -> QName
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaedersetQRange r q = q { iriPos = r }
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaedersetPrefix :: String -> QName -> QName
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaedersetPrefix s q = q { namePrefix = s }
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaedersetFull :: QName -> QName
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaedersetFull q = q {iriType = Full}
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maedertype IRI = QName
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder-- | checks if an IRI is an anonymous individual
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaederisAnonymous :: IRI -> Bool
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaederisAnonymous iri = iriType iri == NodeID || namePrefix iri == "_"
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder-- | checks if a string (bound to be localPart of an IRI) contains \":\/\/\"
df33a9af92444f63ad545da6bb326aac9284318eChristian MaedercssIRI :: String -> IRIType
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaedercssIRI iri = if isInfixOf "://" iri then Full else Abbreviated
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder-- | prefix -> localname
04a1ed0b360858b85de6f449b84df4eab81b3fc9Christian Maedertype PrefixMap = Map.Map String String
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaederpredefPrefixes :: PrefixMap
932f71e6f6f404ac139399c3d6a2b906ba055cbdChristian MaederpredefPrefixes = Map.fromList
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder [ ("owl", "http://www.w3.org/2002/07/owl#")
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder , ("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
72909c6c1cfe9702f5910d0a135c8b55729c7917Christian Maeder , ("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
72909c6c1cfe9702f5910d0a135c8b55729c7917Christian Maeder , ("xsd", "http://www.w3.org/2001/XMLSchema#")
72909c6c1cfe9702f5910d0a135c8b55729c7917Christian Maeder , ("", showQU dummyQName ++ "#") ]
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maedertype LexicalForm = String
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maedertype LanguageTag = String
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maedertype ImportIRI = IRI
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maedertype OntologyIRI = IRI
932f71e6f6f404ac139399c3d6a2b906ba055cbdChristian Maedertype Class = IRI
932f71e6f6f404ac139399c3d6a2b906ba055cbdChristian Maedertype Datatype = IRI
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maedertype ObjectProperty = IRI
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maedertype DataProperty = IRI
99f16a0f9ca757410960ff51a79b034503384fe2Christian Maedertype AnnotationProperty = IRI
99f16a0f9ca757410960ff51a79b034503384fe2Christian Maedertype Individual = IRI
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maederdata EquivOrDisjoint = Equivalent | Disjoint
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
932f71e6f6f404ac139399c3d6a2b906ba055cbdChristian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaedershowEquivOrDisjoint :: EquivOrDisjoint -> String
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaedershowEquivOrDisjoint ed = case ed of
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder Equivalent -> equivalentToC
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder Disjoint -> disjointWithC
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maederdata DomainOrRange = ADomain | ARange
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaedershowDomainOrRange :: DomainOrRange -> String
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaedershowDomainOrRange dr = case dr of
932f71e6f6f404ac139399c3d6a2b906ba055cbdChristian Maeder ADomain -> domainC
35cd0c10843c2cdbbe29f00a2a5d7e5e4f2d0064Christian Maeder ARange -> rangeC
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maederdata SameOrDifferent = Same | Different
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
e997f1724fcc2c5bb49f44e9f45e8354e0f3a2d6Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedershowSameOrDifferent :: SameOrDifferent -> String
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaedershowSameOrDifferent sd = case sd of
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder Same -> sameAsC
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder Different -> differentFromC
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maederdata Relation =
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder EDRelation EquivOrDisjoint
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder | SubPropertyOf
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder | InverseOf
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder | SubClass
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | Types
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder | DRRelation DomainOrRange
48c4688439e0aade4faeebf25ca8b16d661e47afChristian Maeder | SDRelation SameOrDifferent
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
37354e3ed68875fb527338105a610df481f98cb0Christian MaedershowRelation :: Relation -> String
413db961f13e112716509b6d61d7a7bbf50c98b2Christian MaedershowRelation r = case r of
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder EDRelation ed -> showEquivOrDisjoint ed
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder SubPropertyOf -> subPropertyOfC
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder InverseOf -> inverseOfC
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder SubClass -> subClassOfC
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Types -> typesC
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder DRRelation dr -> showDomainOrRange dr
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder SDRelation sd -> showSameOrDifferent sd
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedergetED :: Relation -> EquivOrDisjoint
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedergetED r = case r of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder EDRelation ed -> ed
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> error "not domain or range"
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedergetDR :: Relation -> DomainOrRange
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedergetDR r = case r of
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder DRRelation dr -> dr
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> error "not domain or range"
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedergetSD :: Relation -> SameOrDifferent
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedergetSD s = case s of
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian Maeder SDRelation sd -> sd
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder _ -> error "not same or different"
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata Character =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Functional
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | InverseFunctional
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian Maeder | Reflexive
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | Irreflexive
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder | Symmetric
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder | Asymmetric
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder | Antisymmetric
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder | Transitive
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian Maeder deriving (Enum, Bounded, Show, Eq, Ord, Typeable, Data)
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maederdata PositiveOrNegative = Positive | Negative
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maederdata QuantifierType = AllValuesFrom | SomeValuesFrom
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaedershowQuantifierType :: QuantifierType -> String
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaedershowQuantifierType ty = case ty of
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder AllValuesFrom -> onlyS
79bf169bcae16ce390683c698bae248c1ed6ab13Christian Maeder SomeValuesFrom -> someS
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder-- * Predefined IRI checkings
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaederthingMap :: PreDefMaps
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaederthingMap = makeOWLPredefMaps predefClass
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaederisThing :: IRI -> Bool
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaederisThing = checkPredef thingMap
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaedermakePredefObjProp :: PreDefMaps
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaedermakePredefObjProp = makeOWLPredefMaps predefObjProp
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaederisPredefObjProp :: IRI -> Bool
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaederisPredefObjProp = checkPredef makePredefObjProp
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaedermakePredefDataProp :: PreDefMaps
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaedermakePredefDataProp = makeOWLPredefMaps predefDataProp
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder
d50ea352472823a62196db3cf11fae2af6866ab6Christian MaederisPredefDataProp :: IRI -> Bool
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian MaederisPredefDataProp = checkPredef makePredefDataProp
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaedermakePredefRDFSAnnoProp :: PreDefMaps
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian MaedermakePredefRDFSAnnoProp = preDefMaps predefRDFSAnnoProps "rdfs"
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederisPredefRDFSAnnoProp :: IRI -> Bool
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian MaederisPredefRDFSAnnoProp = checkPredef makePredefRDFSAnnoProp
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedermakePredefOWLAnnoProp :: PreDefMaps
ce3928e71520030ad0275b72050a8f4377f9313cChristian MaedermakePredefOWLAnnoProp = makeOWLPredefMaps predefOWLAnnoProps
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederisPredefOWLAnnoProp :: IRI -> Bool
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian MaederisPredefOWLAnnoProp = checkPredef makePredefOWLAnnoProp
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian Maeder
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian MaederisPredefAnnoProp :: IRI -> Bool
b06572b54fcf9d6976cfff57da22672f996b4748Christian MaederisPredefAnnoProp iri = isPredefOWLAnnoProp iri || isPredefRDFSAnnoProp iri
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederisPredefPropOrClass :: IRI -> Bool
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederisPredefPropOrClass iri = isPredefAnnoProp iri || isPredefDataProp iri
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder || isPredefObjProp iri || isThing iri
b06572b54fcf9d6976cfff57da22672f996b4748Christian Maeder
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederpredefIRIs :: Set.Set IRI
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederpredefIRIs = Set.fromList $ map (setPrefix "xsd" . mkQName) xsdKeys
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder ++ map (setPrefix "owl" . mkQName) owlNumbers
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder ++ map (setPrefix "rdf" . mkQName) [rdfsLiteral, stringS]
b06572b54fcf9d6976cfff57da22672f996b4748Christian Maeder ++ [setPrefix "rdfs" $ mkQName xmlLiteral]
b06572b54fcf9d6976cfff57da22672f996b4748Christian Maeder
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederisDatatypeKey :: IRI -> Bool
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederisDatatypeKey = not . null . isDatatypeKeyAux
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederxsdMap :: PreDefMaps
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederxsdMap = makeXsdMap xsdKeys
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder
84e7cfca5b97aef300acdaa8cf63a3572f9151c0Christian MaederowlNumbersMap :: PreDefMaps
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederowlNumbersMap = makeOWLPredefMaps owlNumbers
84e7cfca5b97aef300acdaa8cf63a3572f9151c0Christian Maeder
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederrdfMap :: PreDefMaps
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian MaederrdfMap = preDefMaps [xmlLiteral, stringS] "rdf"
d50ea352472823a62196db3cf11fae2af6866ab6Christian Maeder
ce3928e71520030ad0275b72050a8f4377f9313cChristian MaederrdfsMap :: PreDefMaps
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederrdfsMap = preDefMaps [rdfsLiteral] "rdfs"
38d7048d3410a9c3d0883a00c6c589e7b84e470fChristian Maeder
30e50372105eacc129a413e390e06036735b69b2Christian MaederisDatatypeKeyAux :: IRI -> [(String, String)]
30e50372105eacc129a413e390e06036735b69b2Christian MaederisDatatypeKeyAux iri = mapMaybe (`checkPredefAux` iri)
30e50372105eacc129a413e390e06036735b69b2Christian Maeder [ xsdMap, owlNumbersMap, rdfMap, rdfsMap ]
95a732a847b41efa43b43608fcfcbac3b18dbb4fChristian Maeder
30e50372105eacc129a413e390e06036735b69b2Christian Maedertype PreDefMaps = ([String], String, String)
95a732a847b41efa43b43608fcfcbac3b18dbb4fChristian Maeder
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian MaederpreDefMaps :: [String] -> String -> PreDefMaps
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian MaederpreDefMaps sl pref = let
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder Just puri = Map.lookup pref predefPrefixes
f7663514e02f6095198371a64e574c50e6ec857aChristian Maeder Just sp = stripPrefix "http://www.w3.org/" puri
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder in (sl, pref, sp)
f7663514e02f6095198371a64e574c50e6ec857aChristian Maeder
f7663514e02f6095198371a64e574c50e6ec857aChristian MaedercheckPredefAux :: PreDefMaps -> IRI -> Maybe (String, String)
f7663514e02f6095198371a64e574c50e6ec857aChristian MaedercheckPredefAux (sl, pref, exPref) u = let lp = localPart u in
f7663514e02f6095198371a64e574c50e6ec857aChristian Maeder case namePrefix u of
f7663514e02f6095198371a64e574c50e6ec857aChristian Maeder "http" -> case stripPrefix "//www." lp of
f7663514e02f6095198371a64e574c50e6ec857aChristian Maeder Just q -> case stripPrefix "w3.org/" q of
f7663514e02f6095198371a64e574c50e6ec857aChristian Maeder Just r -> case stripPrefix exPref r of
f7663514e02f6095198371a64e574c50e6ec857aChristian Maeder Just s | elem s sl -> Just (pref, s)
f7663514e02f6095198371a64e574c50e6ec857aChristian Maeder _ -> Nothing
f7663514e02f6095198371a64e574c50e6ec857aChristian Maeder Nothing -> case stripPrefix (dnamedS ++ "#") q of
f7663514e02f6095198371a64e574c50e6ec857aChristian Maeder Just s | elem s sl -> Just (pref, s)
f7663514e02f6095198371a64e574c50e6ec857aChristian Maeder _ -> Nothing
f7663514e02f6095198371a64e574c50e6ec857aChristian Maeder Nothing -> Nothing
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder pu | elem pu ["", pref] && elem lp sl -> Just (pref, lp)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> Nothing
99edc5256de959957a8c27b05ae4ad4f0572233dChristian Maeder
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian MaedercheckPredef :: PreDefMaps -> IRI -> Bool
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedercheckPredef ms = isJust . checkPredefAux ms
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedermakeOWLPredefMaps :: [String] -> PreDefMaps
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedermakeOWLPredefMaps sl = preDefMaps sl "owl"
5581c4644d91dcb9b7e2e7f6052f7cbf5f97b6deChristian Maeder
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder-- | sets the correct prefix for the predefined datatypes
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedersetDatatypePrefix :: IRI -> IRI
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedersetDatatypePrefix iri = case isDatatypeKeyAux iri of
966e627a1c06b302a06d59d08b8ab45905f3509cChristian Maeder (p, l) : _ -> setPrefix p $ mkQName l
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder _ -> error $ showQU iri ++ " is not a predefined datatype"
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder-- | checks if the IRI is part of the built-in ones and puts the correct prefix
ce3928e71520030ad0275b72050a8f4377f9313cChristian MaedersetReservedPrefix :: IRI -> IRI
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaedersetReservedPrefix iri
f7663514e02f6095198371a64e574c50e6ec857aChristian Maeder | isDatatypeKey iri && null (namePrefix iri) = setDatatypePrefix iri
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder | (isThing iri || isPredefDataProp iri || isPredefOWLAnnoProp iri
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder || isPredefObjProp iri) && null (namePrefix iri) = setPrefix "owl" iri
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | isPredefRDFSAnnoProp iri = setPrefix "rdfs" iri
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | otherwise = iri
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederstripReservedPrefix :: IRI -> IRI
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederstripReservedPrefix = mkQName . getPredefName
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian Maeder
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian Maeder{- | returns the name of the predefined IRI (e.g <xsd:string> returns "string"
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian Maeder or <http://www.w3.org/2002/07/owl#real> returns "real") -}
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian MaedergetPredefName :: IRI -> String
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian MaedergetPredefName iri =
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian Maeder if namePrefix iri `elem` ["", "xsd", "rdf", "rdfs", "owl"]
5b2a749acd03ab4f09585251cf38b89bb012dbdcChristian Maeder then localPart iri
5b2a749acd03ab4f09585251cf38b89bb012dbdcChristian Maeder else case mapMaybe (`stripPrefix` showQU iri)
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian Maeder $ Map.elems predefPrefixes of
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian Maeder [s] -> s
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> showQN iri
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | Extracts Token from IRI
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederuriToTok :: IRI -> Token
028f19cdb09d52bb2fd207399b6fa874540d1670Christian MaederuriToTok urI = mkSimpleId $ getPredefName urI
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder-- | Extracts Id from IRI
028f19cdb09d52bb2fd207399b6fa874540d1670Christian MaederuriToId :: IRI -> Id
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederuriToId = simpleIdToId . uriToTok
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian Maeder-- | Extracts Id from Entities
028f19cdb09d52bb2fd207399b6fa874540d1670Christian MaederentityToId :: Entity -> Id
028f19cdb09d52bb2fd207399b6fa874540d1670Christian MaederentityToId = uriToId . cutIRI
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder
028f19cdb09d52bb2fd207399b6fa874540d1670Christian MaederprintDatatype :: IRI -> String
028f19cdb09d52bb2fd207399b6fa874540d1670Christian MaederprintDatatype dt = showQU $
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder if isDatatypeKey dt then stripReservedPrefix dt else dt
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maederdata DatatypeCat = OWL2Number | OWL2String | OWL2Bool | Other
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaedergetDatatypeCat :: IRI -> DatatypeCat
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaedergetDatatypeCat iri = case isDatatypeKey iri of
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder True
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder | checkPredef xsdBooleanMap iri -> OWL2Bool
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder | checkPredef xsdNumbersMap iri || checkPredef owlNumbersMap iri
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder -> OWL2Number
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder | checkPredef xsdStringsMap iri -> OWL2String
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder | otherwise -> Other
aaf68b27b802d3b9bf39202fa781478dcab8fde5Christian Maeder False -> Other
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian MaedermakeXsdMap :: [String] -> PreDefMaps
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaedermakeXsdMap sl = preDefMaps sl "xsd"
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederxsdBooleanMap :: PreDefMaps
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederxsdBooleanMap = makeXsdMap [booleanS]
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder
6cb518d88084543c13aa7e56db767c14ee97ab77Christian MaederxsdNumbersMap :: PreDefMaps
6cb518d88084543c13aa7e56db767c14ee97ab77Christian MaederxsdNumbersMap = makeXsdMap xsdNumbers
6cb518d88084543c13aa7e56db767c14ee97ab77Christian Maeder
6cb518d88084543c13aa7e56db767c14ee97ab77Christian MaederxsdStringsMap :: PreDefMaps
6cb518d88084543c13aa7e56db767c14ee97ab77Christian MaederxsdStringsMap = makeXsdMap xsdStrings
6cb518d88084543c13aa7e56db767c14ee97ab77Christian Maeder
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian MaederfacetToIRI :: DatatypeFacet -> ConstrainingFacet
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian MaederfacetToIRI = setPrefix "xsd" . mkQName . showFacet
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder-- * Cardinalities
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maederdata CardinalityType = MinCardinality | MaxCardinality | ExactCardinality
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian MaedershowCardinalityType :: CardinalityType -> String
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaedershowCardinalityType ty = case ty of
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder MinCardinality -> minS
de2f13b8310de00ca228385b1530660e036054c2Christian Maeder MaxCardinality -> maxS
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder ExactCardinality -> exactlyS
6cb518d88084543c13aa7e56db767c14ee97ab77Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maederdata Cardinality a b = Cardinality CardinalityType Int a (Maybe b)
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
6cb518d88084543c13aa7e56db767c14ee97ab77Christian Maeder
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maederdata JunctionType = UnionOf | IntersectionOf
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maedertype ConstrainingFacet = IRI
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maedertype RestrictionValue = Literal
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- * ENTITIES
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
6cb518d88084543c13aa7e56db767c14ee97ab77Christian Maederdata Entity = Entity
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder { entityKind :: EntityType
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder , cutIRI :: IRI }
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
d92635f998347112e5d5803301c2abfe7832ab65Christian Maeder
9c5b1136299d9052e4e995614a3a36a051a2682fChristian Maederinstance GetRange Entity where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder getRange = iriPos . cutIRI
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder rangeSpan = qNameRange . cutIRI
da245da15da78363c896e44ea97a14ab1f83eb50Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata EntityType =
32a2f5f00ff72c095b39629101043db4407974f9Christian Maeder Datatype
32a2f5f00ff72c095b39629101043db4407974f9Christian Maeder | Class
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | ObjectProperty
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | DataProperty
1090553a9231ceb536cb8007219c08be0c8c313dChristian Maeder | AnnotationProperty
1090553a9231ceb536cb8007219c08be0c8c313dChristian Maeder | NamedIndividual
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder deriving (Enum, Bounded, Show, Read, Eq, Ord, Typeable, Data)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedershowEntityType :: EntityType -> String
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedershowEntityType e = case e of
75a89d93ae4550e5ed844a999ab3ce2ed40db9bcChristian Maeder Datatype -> datatypeC
75a89d93ae4550e5ed844a999ab3ce2ed40db9bcChristian Maeder Class -> classC
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maeder ObjectProperty -> objectPropertyC
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder DataProperty -> dataPropertyC
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maeder AnnotationProperty -> annotationPropertyC
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maeder NamedIndividual -> individualC
011b7807145efa2af0c7470414a96e0133c26dbcChristian Maeder
011b7807145efa2af0c7470414a96e0133c26dbcChristian MaederentityTypes :: [EntityType]
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaederentityTypes = [minBound .. maxBound]
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaederpairSymbols :: Entity -> Entity -> Result Entity -- TODO: improve!
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaederpairSymbols (Entity k1 i1) (Entity k2 i2) =
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder if k1 /= k2 then
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder error "can't pair symbols of different kind"
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder else do
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder let
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder rest x = drop 1 $ dropWhile (/= '#') x
75a89d93ae4550e5ed844a999ab3ce2ed40db9bcChristian Maeder pairIRIs (QN p1 l1 t1 _e1 r1)
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder (QN _p2 l2 _t2 _e2 _r2) =
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder QN
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder { namePrefix = p1
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder , localPart = if rest l1 == rest l2 then l1 else l1 ++ "_" ++ rest l2
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder , iriType = t1
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder , expandedIRI = ""
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder , iriPos = r1
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder }
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder return $ Entity k1 $ pairIRIs i1 i2
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder-- * LITERALS
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maederdata TypedOrUntyped = Typed Datatype | Untyped (Maybe LanguageTag)
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maederdata Literal = Literal LexicalForm TypedOrUntyped | NumberLit FloatLit
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder-- | non-negative integers given by the sequence of digits
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata NNInt = NNInt [Int] deriving (Eq, Ord, Typeable, Data)
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maederinstance Show NNInt where
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder show (NNInt l) = map intToDigit l
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaederzeroNNInt :: NNInt
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaederzeroNNInt = NNInt []
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederisZeroNNInt :: NNInt -> Bool
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederisZeroNNInt (NNInt l) = null l
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata IntLit = IntLit
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder { absInt :: NNInt
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , isNegInt :: Bool }
fe021e3e6c51b77d25c48a4c246f73571de1c04dChristian Maeder deriving (Eq, Ord, Typeable, Data)
fe021e3e6c51b77d25c48a4c246f73571de1c04dChristian Maeder
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maederinstance Show IntLit where
62fb92b09f732b770317b46a793b60b960d5f481Christian Maeder show (IntLit n b) = (if b then ('-' :) else id) $ show n
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian MaederzeroInt :: IntLit
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian MaederzeroInt = IntLit zeroNNInt False
43a582fe35884e2c6f455e7bfa34f0f4ef8dfe2eChristian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederisZeroInt :: IntLit -> Bool
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederisZeroInt (IntLit n _) = isZeroNNInt n
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maeder
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian MaedernegNNInt :: Bool -> NNInt -> IntLit
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian MaedernegNNInt b n = IntLit n b
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian MaedernegInt :: IntLit -> IntLit
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian MaedernegInt (IntLit n b) = IntLit n $ not b
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maederdata DecLit = DecLit
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder { truncDec :: IntLit
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder , fracDec :: NNInt }
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder deriving (Eq, Ord, Typeable, Data)
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maederinstance Show DecLit where
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder show (DecLit t f) = show t
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder ++ if isZeroNNInt f then "" else
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder '.' : show f
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaederisDecInt :: DecLit -> Bool
2f6227e9ec96ca827cc40078916f18d54a075136Christian MaederisDecInt = isZeroNNInt . fracDec
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian MaedernegDec :: Bool -> DecLit -> DecLit
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaedernegDec b (DecLit t f) = DecLit (if b then negInt t else t) f
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maederdata FloatLit = FloatLit
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder { floatBase :: DecLit
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder , floatExp :: IntLit }
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder deriving (Eq, Ord, Typeable, Data)
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maederinstance Show FloatLit where
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder show (FloatLit b e) = show b
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder ++ if isZeroInt e then "" else
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder 'E' : show e ++ "F"
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian MaederisFloatDec :: FloatLit -> Bool
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian MaederisFloatDec = isZeroInt . floatExp
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian MaederisFloatInt :: FloatLit -> Bool
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian MaederisFloatInt f = isFloatDec f && isDecInt (floatBase f)
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian Maeder
24f79601ad5e42ce74f4152a36aad257d7c4d7b5Christian MaederfloatToInt :: FloatLit -> IntLit
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaederfloatToInt = truncDec . floatBase
48c4688439e0aade4faeebf25ca8b16d661e47afChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederintToDec :: IntLit -> DecLit
bf4263f9dab040818efc7a67172aab8f32218061Christian MaederintToDec i = DecLit i zeroNNInt
32a2f5f00ff72c095b39629101043db4407974f9Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederdecToFloat :: DecLit -> FloatLit
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederdecToFloat d = FloatLit d zeroInt
df33a9af92444f63ad545da6bb326aac9284318eChristian Maeder
749074bf849727439f584139415f6a985a8aa875Christian MaederintToFloat :: IntLit -> FloatLit
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederintToFloat = decToFloat . intToDec
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederabInt :: IntLit -> IntLit
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederabInt int = int {isNegInt = False}
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederabDec :: DecLit -> DecLit
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederabDec dec = dec {truncDec = abInt $ truncDec dec}
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
6cb518d88084543c13aa7e56db767c14ee97ab77Christian MaederabFloat :: FloatLit -> FloatLit
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederabFloat f = f {floatBase = abDec $ floatBase f}
f8a1ab8012a1f36060d6ce9b63399fa4a8a2981cChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederisNegDec :: DecLit -> Bool
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian MaederisNegDec d = isNegInt $ truncDec d
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian MaedernumberName :: FloatLit -> String
99edc5256de959957a8c27b05ae4ad4f0572233dChristian MaedernumberName f
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder | isFloatInt f = integerS
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder | isFloatDec f = decimalS
120efeede54a5f7650cda8e91363bd6832eac9a9Christian Maeder | otherwise = floatS
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
48c4688439e0aade4faeebf25ca8b16d661e47afChristian MaedercTypeS :: String
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian MaedercTypeS = "^^"
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder-- * PROPERTY EXPRESSIONS
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maedertype InverseObjectProperty = ObjectPropertyExpression
43a582fe35884e2c6f455e7bfa34f0f4ef8dfe2eChristian Maeder
43a582fe35884e2c6f455e7bfa34f0f4ef8dfe2eChristian Maederdata ObjectPropertyExpression = ObjectProp ObjectProperty
43a582fe35884e2c6f455e7bfa34f0f4ef8dfe2eChristian Maeder | ObjectInverseOf InverseObjectProperty
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaederobjPropToIRI :: ObjectPropertyExpression -> Individual
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaederobjPropToIRI opExp = case opExp of
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder ObjectProp u -> u
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder ObjectInverseOf objProp -> objPropToIRI objProp
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maedertype DataPropertyExpression = DataProperty
43a582fe35884e2c6f455e7bfa34f0f4ef8dfe2eChristian Maeder
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder-- * DATA RANGES
2f6227e9ec96ca827cc40078916f18d54a075136Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata DataRange =
9e0472be46104307b974fe5079bf5cc9e94a1a96Christian Maeder DataType Datatype [(ConstrainingFacet, RestrictionValue)]
9e0472be46104307b974fe5079bf5cc9e94a1a96Christian Maeder | DataJunction JunctionType [DataRange]
9e0472be46104307b974fe5079bf5cc9e94a1a96Christian Maeder | DataComplementOf DataRange
9e0472be46104307b974fe5079bf5cc9e94a1a96Christian Maeder | DataOneOf [Literal]
9e0472be46104307b974fe5079bf5cc9e94a1a96Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
9e0472be46104307b974fe5079bf5cc9e94a1a96Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- * CLASS EXPERSSIONS
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
48c4688439e0aade4faeebf25ca8b16d661e47afChristian Maederdata ClassExpression =
48c4688439e0aade4faeebf25ca8b16d661e47afChristian Maeder Expression Class
48c4688439e0aade4faeebf25ca8b16d661e47afChristian Maeder | ObjectJunction JunctionType [ClassExpression]
aae7a026a323021c5364aef85a0e03d586e5a5c3Christian Maeder | ObjectComplementOf ClassExpression
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | ObjectOneOf [Individual]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | ObjectValuesFrom QuantifierType ObjectPropertyExpression ClassExpression
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | ObjectHasValue ObjectPropertyExpression Individual
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | ObjectHasSelf ObjectPropertyExpression
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | ObjectCardinality (Cardinality ObjectPropertyExpression ClassExpression)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | DataValuesFrom QuantifierType DataPropertyExpression DataRange
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder | DataHasValue DataPropertyExpression Literal
6cb518d88084543c13aa7e56db767c14ee97ab77Christian Maeder | DataCardinality (Cardinality DataPropertyExpression DataRange)
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
54b698a84a1686b828c99d839fc671942b817534Christian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder-- * ANNOTATIONS
54b698a84a1686b828c99d839fc671942b817534Christian Maeder
d92635f998347112e5d5803301c2abfe7832ab65Christian Maederdata Annotation = Annotation [Annotation] AnnotationProperty AnnotationValue
aae7a026a323021c5364aef85a0e03d586e5a5c3Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata AnnotationValue = AnnValue IRI | AnnValLit Literal
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder