AS.hs revision 437db42248d4e92184bf34417043a8fe891c751b
ca010363454de207082dfaa4b753531ce2a34551Christian Maeder{-# LANGUAGE DeriveDataTypeable #-}
ca010363454de207082dfaa4b753531ce2a34551Christian Maeder{- |
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederModule : $Header$
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaederCopyright : (c) C. Maeder, Felix Gabriel Mance
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuLicense : 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
d27877901128f04518461d25b96d2d93a13f01e4Christian Maederimport Common.Keywords (stringS)
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maeder
ca010363454de207082dfaa4b753531ce2a34551Christian Maederimport Common.Result
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maeder
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maederimport OWL2.ColonKeywords
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maederimport OWL2.Keywords
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maeder
53301de22afd7190981b363b57c48df86fcb50f7Christian Maederimport Data.Char (intToDigit)
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maederimport Data.Data
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maederimport Data.List
23f8d286586ff38a9e73052b2c7c04c62c5c638fChristian Maederimport Data.Maybe
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maederimport qualified Data.Map as Map
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maederimport qualified Data.Set as Set
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maeder
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maederdata IRIType = Full | Abbreviated | NodeID
e68f45f355ed9d4026ee9baff5aa75aa7c911cc2Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder
fc8c6570c7b4ee13f375eb607bed2290438573bfChristian Maeder{- | full or abbreviated IRIs with a possible uri for the prefix
83cc27e4ca7cf1a4bb5f4a8df17d3e6d44e6f1eaChristian Maeder or a local part following a hash sign -}
53301de22afd7190981b363b57c48df86fcb50f7Christian Maederdata QName = QN
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder { namePrefix :: String
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
83cc27e4ca7cf1a4bb5f4a8df17d3e6d44e6f1eaChristian Maeder , localPart :: String
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder -- ^ the local part of a qualified name \"namePrefix:localPart\"
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder , iriType :: IRIType
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder , expandedIRI :: String
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder -- ^ the associated namespace uri (not printed)
fc8c6570c7b4ee13f375eb607bed2290438573bfChristian Maeder , iriPos :: Range
83cc27e4ca7cf1a4bb5f4a8df17d3e6d44e6f1eaChristian Maeder } deriving (Show, Typeable, Data)
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maederinstance Eq QName where
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder p == q = compare p q == EQ
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maederinstance Ord QName where
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder compare (QN p1 l1 b1 n1 _) (QN p2 l2 b2 n2 _) =
53301de22afd7190981b363b57c48df86fcb50f7Christian 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
da2b959c50c95309d8eb8b24174249c2847e74b5Christian Maeder
0a39036fa485579a7b7c81cdd44a412392571927Christian MaederqNameRange :: QName -> [Pos]
9c07aad044613547d61ab235665c08adcef03a1cChristian MaederqNameRange q = let Range rs = iriPos q in case rs of
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder [p] -> let
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder p0 = if iriType q == Full then incSourceColumn p (-1) else p
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder in tokenRange $ Token (showQN q) $ Range [p0]
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder _ -> rs
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maederinstance GetRange QName where
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder getRange = iriPos
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder rangeSpan = qNameRange
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian 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
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowQU :: QName -> String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowQU (QN pre local _ _ _) =
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder if null pre then local else pre ++ ":" ++ local
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder-- | show QName in angle brackets as full iris
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian MaedershowQI :: QName -> String
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedershowQI n = '<' : showQU n ++ ">"
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedernullQName :: QName
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedernullQName = QN "" "" Abbreviated "" nullRange
c2c1ca07d7f3c2228b66599a7fb37b90fe6fb3bcChristian Maeder
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian MaederisNullQName :: QName -> Bool
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian MaederisNullQName qn = case qn of
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder QN "" "" _ "" _ -> True
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder _ -> False
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaederunamedS :: String
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaederunamedS = "//www." ++ dnamedS
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian MaederdnamedS :: String
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederdnamedS = "dfki.de/sks/hets/ontology/unamed"
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian MaederdummyQName :: QName
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaederdummyQName = QN "http" unamedS Full ("http:" ++ unamedS) nullRange
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedermkQName :: String -> QName
c4d4df505f3ca488978629c65f4fd15a3ba2833aChristian MaedermkQName s = nullQName { localPart = s }
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaedersetQRange :: Range -> QName -> QName
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaedersetQRange r q = q { iriPos = r }
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian MaedersetPrefix :: String -> QName -> QName
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedersetPrefix s q = q { namePrefix = s }
6fc65e097da8013f5f4f96c8b343b9b48cd3d9e1Christian Maeder
6fc65e097da8013f5f4f96c8b343b9b48cd3d9e1Christian MaedersetFull :: QName -> QName
6fc65e097da8013f5f4f96c8b343b9b48cd3d9e1Christian MaedersetFull q = q {iriType = Full}
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
6fc65e097da8013f5f4f96c8b343b9b48cd3d9e1Christian Maedertype IRI = QName
add9c81ed5250ba046a8581ff75b2284bd69e219Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder-- | checks if an IRI is an anonymous individual
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian 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#")
9c07aad044613547d61ab235665c08adcef03a1cChristian Maeder , ("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
9c07aad044613547d61ab235665c08adcef03a1cChristian Maeder , ("xsd", "http://www.w3.org/2001/XMLSchema#")
9c07aad044613547d61ab235665c08adcef03a1cChristian Maeder , ("", showQU dummyQName ++ "#") ]
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype LexicalForm = String
9c07aad044613547d61ab235665c08adcef03a1cChristian Maedertype LanguageTag = String
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maedertype ImportIRI = IRI
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maedertype OntologyIRI = IRI
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maedertype Class = IRI
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maedertype Datatype = IRI
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maedertype ObjectProperty = IRI
9c07aad044613547d61ab235665c08adcef03a1cChristian Maedertype DataProperty = IRI
9c07aad044613547d61ab235665c08adcef03a1cChristian Maedertype AnnotationProperty = IRI
9c07aad044613547d61ab235665c08adcef03a1cChristian Maedertype Individual = IRI
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maederdata EquivOrDisjoint = Equivalent | Disjoint
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedershowEquivOrDisjoint :: EquivOrDisjoint -> String
9c07aad044613547d61ab235665c08adcef03a1cChristian MaedershowEquivOrDisjoint ed = case ed of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Equivalent -> equivalentToC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Disjoint -> disjointWithC
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maederdata DomainOrRange = ADomain | ARange
adfdcfa67b7f12df6df7292e238c3f9a4b637980Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian Maeder
6e2c88c65d50b2e44f7afa165e6a5fac0724f08cChristian MaedershowDomainOrRange :: DomainOrRange -> String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowDomainOrRange dr = case dr of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder ADomain -> domainC
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maeder ARange -> rangeC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maederdata SameOrDifferent = Same | Different
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
d27877901128f04518461d25b96d2d93a13f01e4Christian MaedershowSameOrDifferent :: SameOrDifferent -> String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowSameOrDifferent sd = case sd of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Same -> sameAsC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Different -> differentFromC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maederdata Relation =
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder EDRelation EquivOrDisjoint
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder | SubPropertyOf
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | InverseOf
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maeder | SubClass
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maeder | Types
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder | DRRelation DomainOrRange
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | SDRelation SameOrDifferent
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowRelation :: Relation -> String
72b9099aeec0762bae4546db3bc4b48721027bf4Christian 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
d27877901128f04518461d25b96d2d93a13f01e4Christian MaedergetED :: Relation -> EquivOrDisjoint
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaedergetED r = case r of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder EDRelation ed -> ed
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder _ -> error "not domain or range"
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaedergetDR :: Relation -> DomainOrRange
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetDR r = case r of
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder DRRelation dr -> dr
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder _ -> error "not domain or range"
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maeder
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian MaedergetSD :: Relation -> SameOrDifferent
d27877901128f04518461d25b96d2d93a13f01e4Christian MaedergetSD s = case s of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder SDRelation sd -> sd
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder _ -> error "not same or different"
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maederdata Character =
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Functional
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | InverseFunctional
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Reflexive
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maeder | Irreflexive
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Symmetric
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Asymmetric
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Antisymmetric
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Transitive
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder deriving (Enum, Bounded, Show, Eq, Ord, Typeable, Data)
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maeder
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maederdata PositiveOrNegative = Positive | Negative
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maederdata QuantifierType = AllValuesFrom | SomeValuesFrom
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedershowQuantifierType :: QuantifierType -> String
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedershowQuantifierType ty = case ty of
669e21946b6f90785fc3cb44e7cf4f38c3f6493dChristian Maeder AllValuesFrom -> onlyS
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maeder SomeValuesFrom -> someS
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder-- * Predefined IRI checkings
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
d27877901128f04518461d25b96d2d93a13f01e4Christian MaederthingMap :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederthingMap = makeOWLPredefMaps predefClass
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian MaederisThing :: IRI -> Bool
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian MaederisThing = checkPredef thingMap
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefObjProp :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefObjProp = makeOWLPredefMaps predefObjProp
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian MaederisPredefObjProp :: IRI -> Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisPredefObjProp = checkPredef makePredefObjProp
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefDataProp :: PreDefMaps
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian MaedermakePredefDataProp = makeOWLPredefMaps predefDataProp
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder
669e21946b6f90785fc3cb44e7cf4f38c3f6493dChristian MaederisPredefDataProp :: IRI -> Bool
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill MossakowskiisPredefDataProp = checkPredef makePredefDataProp
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefRDFSAnnoProp :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefRDFSAnnoProp = preDefMaps predefRDFSAnnoProps "rdfs"
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederisPredefRDFSAnnoProp :: IRI -> Bool
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederisPredefRDFSAnnoProp = checkPredef makePredefRDFSAnnoProp
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaedermakePredefOWLAnnoProp :: PreDefMaps
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaedermakePredefOWLAnnoProp = makeOWLPredefMaps predefOWLAnnoProps
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederisPredefOWLAnnoProp :: IRI -> Bool
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederisPredefOWLAnnoProp = checkPredef makePredefOWLAnnoProp
add9c81ed5250ba046a8581ff75b2284bd69e219Christian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaederisPredefAnnoProp :: IRI -> Bool
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaederisPredefAnnoProp iri = isPredefOWLAnnoProp iri || isPredefRDFSAnnoProp iri
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder
9c07aad044613547d61ab235665c08adcef03a1cChristian MaederisPredefPropOrClass :: IRI -> Bool
72b9099aeec0762bae4546db3bc4b48721027bf4Christian MaederisPredefPropOrClass iri = isPredefAnnoProp iri || isPredefDataProp iri
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder || isPredefObjProp iri || isThing iri
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederpredefIRIs :: Set.Set IRI
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederpredefIRIs = Set.fromList $ map (setPrefix "xsd" . mkQName) xsdKeys
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder ++ map (setPrefix "owl" . mkQName) owlNumbers
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder ++ map (setPrefix "rdf" . mkQName) [rdfsLiteral, stringS]
add9c81ed5250ba046a8581ff75b2284bd69e219Christian Maeder ++ [setPrefix "rdfs" $ mkQName xmlLiteral]
fcfed328fae6266214ee61ee7a16fd263fd3cb70Christian Maeder
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederisDatatypeKey :: IRI -> Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisDatatypeKey = not . null . isDatatypeKeyAux
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder
46d766efdf8beaaadf3f34d99c305738064e9216Christian MaederxsdMap :: PreDefMaps
7946f81bdc77b0790ac47ccaf2912a1d55c8336dChristian MaederxsdMap = makeXsdMap xsdKeys
d27877901128f04518461d25b96d2d93a13f01e4Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederowlNumbersMap :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederowlNumbersMap = makeOWLPredefMaps owlNumbers
b734b51e16ca659814c11205dfb0e97d13bf7ef6Christian Maeder
b734b51e16ca659814c11205dfb0e97d13bf7ef6Christian MaederrdfMap :: PreDefMaps
b734b51e16ca659814c11205dfb0e97d13bf7ef6Christian MaederrdfMap = preDefMaps [xmlLiteral, stringS] "rdf"
b734b51e16ca659814c11205dfb0e97d13bf7ef6Christian Maeder
b734b51e16ca659814c11205dfb0e97d13bf7ef6Christian MaederrdfsMap :: PreDefMaps
6fc65e097da8013f5f4f96c8b343b9b48cd3d9e1Christian MaederrdfsMap = preDefMaps [rdfsLiteral] "rdfs"
b734b51e16ca659814c11205dfb0e97d13bf7ef6Christian Maeder
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisDatatypeKeyAux :: IRI -> [(String, String)]
add9c81ed5250ba046a8581ff75b2284bd69e219Christian MaederisDatatypeKeyAux iri = mapMaybe (`checkPredefAux` iri)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder [ xsdMap, owlNumbersMap, rdfMap, rdfsMap ]
d27877901128f04518461d25b96d2d93a13f01e4Christian Maeder
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maedertype PreDefMaps = ([String], String, String)
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder
ad187062b0009820118c1b773a232e29b879a2faChristian 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
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder in (sl, pref, sp)
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaedercheckPredefAux :: PreDefMaps -> IRI -> Maybe (String, String)
13b24998210d193b38cae06485da6f06c61d7f62Christian MaedercheckPredefAux (sl, pref, exPref) u =
13b24998210d193b38cae06485da6f06c61d7f62Christian Maeder let lp = localPart u
13b24998210d193b38cae06485da6f06c61d7f62Christian Maeder nn = dnamedS ++ "#"
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder res = Just (pref, lp)
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder in case namePrefix u of
9c07aad044613547d61ab235665c08adcef03a1cChristian Maeder "http" -> case stripPrefix "//www." lp of
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder Just q -> case stripPrefix "w3.org/" q of
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder Just r -> case stripPrefix exPref r of
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder Just s | elem s sl -> Just (pref, s)
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder _ -> Nothing
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder Nothing -> case stripPrefix nn q of
9c07aad044613547d61ab235665c08adcef03a1cChristian Maeder Just s | elem s sl -> Just (pref, s)
9c07aad044613547d61ab235665c08adcef03a1cChristian Maeder _ -> Nothing
9c07aad044613547d61ab235665c08adcef03a1cChristian Maeder Nothing -> Nothing
9c07aad044613547d61ab235665c08adcef03a1cChristian Maeder pu | elem lp sl -> case pu of
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder "" -> let ex = expandedIRI u in
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder case stripPrefix "http://www." ex of
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder Just r | r == "w3.org/" ++ exPref ++ lp || r == nn ++ lp
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder -> res
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder _ | null ex -> res
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder _ -> Nothing
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder _ | pu == pref -> Just (pref, lp)
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder _ -> Nothing
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder _ -> Nothing
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaedercheckPredef :: PreDefMaps -> IRI -> Bool
ac142c1b088711f911018d8108a64be80b2f2a58Christian MaedercheckPredef ms = isJust . checkPredefAux ms
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder
ac142c1b088711f911018d8108a64be80b2f2a58Christian MaedermakeOWLPredefMaps :: [String] -> PreDefMaps
f1ef1c750f805c1732b01001f2b157c0077b808eChristian MaedermakeOWLPredefMaps sl = preDefMaps sl "owl"
-- | sets the correct prefix for the predefined datatypes
setDatatypePrefix :: IRI -> IRI
setDatatypePrefix iri = case isDatatypeKeyAux iri of
(p, l) : _ -> setPrefix p $ mkQName l
_ -> error $ showQU iri ++ " is not a predefined datatype"
-- | checks if the IRI is part of the built-in ones and puts the correct prefix
setReservedPrefix :: IRI -> IRI
setReservedPrefix iri = case namePrefix iri of
""
| isDatatypeKey iri -> setDatatypePrefix iri
| isThing iri || isPredefDataProp iri || isPredefOWLAnnoProp iri
|| isPredefObjProp iri -> setPrefix "owl" iri
| isPredefRDFSAnnoProp iri -> setPrefix "rdfs" iri
_ -> iri
stripReservedPrefix :: IRI -> IRI
stripReservedPrefix = mkQName . getPredefName
{- | returns the name of the predefined IRI (e.g <xsd:string> returns "string"
or <http://www.w3.org/2002/07/owl#real> returns "real") -}
getPredefName :: IRI -> String
getPredefName iri =
if namePrefix iri `elem` ["", "xsd", "rdf", "rdfs", "owl"]
then localPart iri
else case mapMaybe (`stripPrefix` showQU iri)
$ Map.elems predefPrefixes of
[s] -> s
_ -> showQN iri
-- | Extracts Token from IRI
uriToTok :: IRI -> Token
uriToTok urI = mkSimpleId $ getPredefName urI
-- | Extracts Id from IRI
uriToId :: IRI -> Id
uriToId = simpleIdToId . uriToTok
-- | Extracts Id from Entities
entityToId :: Entity -> Id
entityToId = uriToId . cutIRI
printDatatype :: IRI -> String
printDatatype dt = showQU $
if isDatatypeKey dt then stripReservedPrefix dt else dt
data DatatypeCat = OWL2Number | OWL2String | OWL2Bool | Other
deriving (Show, Eq, Ord, Typeable, Data)
getDatatypeCat :: IRI -> DatatypeCat
getDatatypeCat iri = case isDatatypeKey iri of
True
| checkPredef xsdBooleanMap iri -> OWL2Bool
| checkPredef xsdNumbersMap iri || checkPredef owlNumbersMap iri
-> OWL2Number
| checkPredef xsdStringsMap iri -> OWL2String
| otherwise -> Other
False -> Other
makeXsdMap :: [String] -> PreDefMaps
makeXsdMap sl = preDefMaps sl "xsd"
xsdBooleanMap :: PreDefMaps
xsdBooleanMap = 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)