AS.hs revision 7852de3551fc797566ee71165bafe05b6d81728c
275f2a1080c2089e14a1455dbbbb3bc992d8e593cmaeder{-# LANGUAGE DeriveDataTypeable #-}
90255d8098793fec454acbf2c67d4911dd5a7e83Christian Maeder{- |
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : $Header$
e83ed59502a681713982f25c559aae77a4145734Christian MaederCopyright : (c) C. Maeder, Felix Gabriel Mance
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederMaintainer : Christian.Maeder@dfki.de
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederStability : provisional
90255d8098793fec454acbf2c67d4911dd5a7e83Christian MaederPortability : portable
90255d8098793fec454acbf2c67d4911dd5a7e83Christian Maeder
90255d8098793fec454acbf2c67d4911dd5a7e83Christian MaederOWL 2 Functional Syntax constructs
e6d40133bc9f858308654afb1262b8b483ec5922Till Mossakowski
dd62ef8d300d66a3ff2895c20cdf311ae3f8fd58Christian MaederReferences:
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder <http://www.w3.org/TR/2009/REC-owl2-syntax-20091027/#Functional-Style_Syntax>
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder <http://www.w3.org/TR/owl2-manchester-syntax/>
2eb84fc82d3ffa9116bc471fda3742bd9e5a24bbChristian Maeder-}
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maedermodule OWL2.AS where
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maeder
35db0960aa2e2a13652381c756fae5fb2b27213bChristian Maederimport Common.Id
35db0960aa2e2a13652381c756fae5fb2b27213bChristian Maederimport Common.Keywords (stringS)
97279257021fd703f25019ae8869d86f455d1ea1Christian Maeder
97279257021fd703f25019ae8869d86f455d1ea1Christian Maederimport Common.Result
77a28e0c97ba4a6f4ad5c7d66c31a2e35aab019dChristian Maeder
77a28e0c97ba4a6f4ad5c7d66c31a2e35aab019dChristian Maederimport OWL2.ColonKeywords
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian Maederimport OWL2.Keywords
35db0960aa2e2a13652381c756fae5fb2b27213bChristian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederimport Data.Char (intToDigit)
1600a2e47d5ed599df94d20411f0767fb6d68587Christian Maederimport Data.Data
1600a2e47d5ed599df94d20411f0767fb6d68587Christian Maederimport Data.List
1600a2e47d5ed599df94d20411f0767fb6d68587Christian Maederimport Data.Maybe
1600a2e47d5ed599df94d20411f0767fb6d68587Christian Maederimport qualified Data.Map as Map
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederimport qualified Data.Set as Set
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederdata IRIType = Full | Abbreviated | NodeID
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maeder{- | full or abbreviated IRIs with a possible uri for the prefix
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder or a local part following a hash sign -}
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maederdata QName = QN
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maeder { namePrefix :: String
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maeder -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder , localPart :: String
1600a2e47d5ed599df94d20411f0767fb6d68587Christian Maeder -- ^ the local part of a qualified name \"namePrefix:localPart\"
e14842b97369d292f0c18e08c4f8bd025764d4b1Christian Maeder , iriType :: IRIType
1600a2e47d5ed599df94d20411f0767fb6d68587Christian Maeder , expandedIRI :: String
e14842b97369d292f0c18e08c4f8bd025764d4b1Christian Maeder -- ^ the associated namespace uri (not printed)
e14842b97369d292f0c18e08c4f8bd025764d4b1Christian Maeder , iriPos :: Range
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder } deriving (Show, Typeable, Data)
017f1c7ef7027a0bc0d221b31e8877e09a790172Christian Maeder
77a28e0c97ba4a6f4ad5c7d66c31a2e35aab019dChristian Maederinstance Eq QName where
77a28e0c97ba4a6f4ad5c7d66c31a2e35aab019dChristian Maeder p == q = compare p q == EQ
77a28e0c97ba4a6f4ad5c7d66c31a2e35aab019dChristian Maeder
77a28e0c97ba4a6f4ad5c7d66c31a2e35aab019dChristian Maederinstance Ord QName where
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder compare (QN p1 l1 b1 n1 _) (QN p2 l2 b2 n2 _) =
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder if null n1 || null n2 then compare (b1, p1, l1) (b2, p2, l2) else
e14842b97369d292f0c18e08c4f8bd025764d4b1Christian Maeder compare n1 n2 -- compare fully expanded names only
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederqNameRange :: QName -> [Pos]
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian MaederqNameRange q = let Range rs = iriPos q in case rs of
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder [p] -> let
90255d8098793fec454acbf2c67d4911dd5a7e83Christian Maeder p0 = if iriType q == Full then incSourceColumn p (-1) else p
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder in tokenRange $ Token (showQN q) $ Range [p0]
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian Maeder _ -> rs
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian Maeder
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian Maederinstance GetRange QName where
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian Maeder getRange = iriPos
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian Maeder rangeSpan = qNameRange
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian Maeder
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian MaedershowQN :: QName -> String
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian MaedershowQN q = (if iriType q == Full then showQI else showQU) q
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maeder
e83ed59502a681713982f25c559aae77a4145734Christian Maeder-- | show QName as abbreviated iri
e83ed59502a681713982f25c559aae77a4145734Christian MaedershowQU :: QName -> String
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaedershowQU (QN pre local _ _ _) =
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian Maeder if null pre then local else pre ++ ":" ++ local
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder-- | show QName in angle brackets as full iris
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaedershowQI :: QName -> String
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedershowQI n = '<' : showQU n ++ ">"
158196f73dca970c3541c1f31680ac50a28a6ec9Christian Maeder
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian MaedernullQName :: QName
158196f73dca970c3541c1f31680ac50a28a6ec9Christian MaedernullQName = QN "" "" Abbreviated "" nullRange
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder
158196f73dca970c3541c1f31680ac50a28a6ec9Christian MaederisNullQName :: QName -> Bool
158196f73dca970c3541c1f31680ac50a28a6ec9Christian MaederisNullQName qn = case qn of
158196f73dca970c3541c1f31680ac50a28a6ec9Christian Maeder QN "" "" _ "" _ -> True
158196f73dca970c3541c1f31680ac50a28a6ec9Christian Maeder _ -> False
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederunamedS :: String
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian MaederunamedS = "//www." ++ dnamedS
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaederdnamedS :: String
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaederdnamedS = "dfki.de/sks/hets/ontology/unamed"
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaederdummyQName :: QName
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaederdummyQName = QN "http" unamedS Full ("http:" ++ unamedS) nullRange
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
90255d8098793fec454acbf2c67d4911dd5a7e83Christian MaedermkQName :: String -> QName
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedermkQName s = nullQName { localPart = s }
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedersetQRange :: Range -> QName -> QName
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedersetQRange r q = q { iriPos = r }
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedersetPrefix :: String -> QName -> QName
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedersetPrefix s q = q { namePrefix = s }
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
aa83d02e62b7e9f4b87a454f553a75fdbd061412Christian MaedersetFull :: QName -> QName
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedersetFull q = q {iriType = Full}
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maedertype IRI = QName
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder-- | checks if an IRI is an anonymous individual
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederisAnonymous :: IRI -> Bool
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederisAnonymous iri = iriType iri == NodeID || namePrefix iri == "_"
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
aa83d02e62b7e9f4b87a454f553a75fdbd061412Christian Maeder-- | checks if a string (bound to be localPart of an IRI) contains \":\/\/\"
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedercssIRI :: String -> IRIType
90255d8098793fec454acbf2c67d4911dd5a7e83Christian MaedercssIRI iri = if isInfixOf "://" iri then Full else Abbreviated
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder-- | prefix -> localname
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maedertype PrefixMap = Map.Map String String
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederpredefPrefixes :: PrefixMap
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian MaederpredefPrefixes = Map.fromList
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maeder [ ("owl", "http://www.w3.org/2002/07/owl#")
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maeder , ("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maeder , ("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maeder , ("xsd", "http://www.w3.org/2001/XMLSchema#")
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maeder , ("", showQU dummyQName ++ "#") ]
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maeder
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maedertype LexicalForm = String
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maedertype LanguageTag = String
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maedertype ImportIRI = IRI
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maedertype OntologyIRI = IRI
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maedertype Class = IRI
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maedertype Datatype = IRI
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maedertype ObjectProperty = IRI
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maedertype DataProperty = IRI
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maedertype AnnotationProperty = IRI
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maedertype Individual = IRI
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maederdata EquivOrDisjoint = Equivalent | Disjoint
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaedershowEquivOrDisjoint :: EquivOrDisjoint -> String
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaedershowEquivOrDisjoint ed = case ed of
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian Maeder Equivalent -> equivalentToC
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder Disjoint -> disjointWithC
90255d8098793fec454acbf2c67d4911dd5a7e83Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederdata DomainOrRange = ADomain | ARange
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
9029484754c7b2037321e7cbd077580866845265Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedershowDomainOrRange :: DomainOrRange -> String
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaedershowDomainOrRange dr = case dr of
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder ADomain -> domainC
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder ARange -> rangeC
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maederdata SameOrDifferent = Same | Different
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedershowSameOrDifferent :: SameOrDifferent -> String
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedershowSameOrDifferent sd = case sd of
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder Same -> sameAsC
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder Different -> differentFromC
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederdata Relation =
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian Maeder EDRelation EquivOrDisjoint
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder | SubPropertyOf
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian Maeder | InverseOf
017f1c7ef7027a0bc0d221b31e8877e09a790172Christian Maeder | SubClass
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian Maeder | Types
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian Maeder | DRRelation DomainOrRange
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian Maeder | SDRelation SameOrDifferent
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
017f1c7ef7027a0bc0d221b31e8877e09a790172Christian Maeder
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian MaedershowRelation :: Relation -> String
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian MaedershowRelation r = case r of
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder EDRelation ed -> showEquivOrDisjoint ed
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder SubPropertyOf -> subPropertyOfC
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian Maeder InverseOf -> inverseOfC
90255d8098793fec454acbf2c67d4911dd5a7e83Christian Maeder SubClass -> subClassOfC
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder Types -> typesC
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder DRRelation dr -> showDomainOrRange dr
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder SDRelation sd -> showSameOrDifferent sd
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
6d49b450d2fbb6bf7a647894abad8ea17f63e14aEwaryst SchulzgetED :: Relation -> EquivOrDisjoint
6d49b450d2fbb6bf7a647894abad8ea17f63e14aEwaryst SchulzgetED r = case r of
6d49b450d2fbb6bf7a647894abad8ea17f63e14aEwaryst Schulz EDRelation ed -> ed
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder _ -> error "not domain or range"
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder
e64aab3e57d843884cd489cc3aa130120a400b05Christian MaedergetDR :: Relation -> DomainOrRange
e64aab3e57d843884cd489cc3aa130120a400b05Christian MaedergetDR r = case r of
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder DRRelation dr -> dr
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder _ -> error "not domain or range"
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz
017f1c7ef7027a0bc0d221b31e8877e09a790172Christian MaedergetSD :: Relation -> SameOrDifferent
017f1c7ef7027a0bc0d221b31e8877e09a790172Christian MaedergetSD s = case s of
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz SDRelation sd -> sd
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz _ -> error "not same or different"
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulzdata Character =
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz Functional
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz | InverseFunctional
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz | Reflexive
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz | Irreflexive
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz | Symmetric
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz | Asymmetric
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz | Antisymmetric
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz | Transitive
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz deriving (Enum, Bounded, Show, Eq, Ord, Typeable, Data)
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulzdata PositiveOrNegative = Positive | Negative
017f1c7ef7027a0bc0d221b31e8877e09a790172Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulzdata QuantifierType = AllValuesFrom | SomeValuesFrom
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedershowQuantifierType :: QuantifierType -> String
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian MaedershowQuantifierType ty = case ty of
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder AllValuesFrom -> onlyS
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder SomeValuesFrom -> someS
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian Maeder-- * Predefined IRI checkings
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian Maeder
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian MaederthingMap :: PreDefMaps
9aca2bcd1f6778d4db433096e77011a4dc450b58Christian MaederthingMap = makeOWLPredefMaps predefClass
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian Maeder
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian MaederisThing :: IRI -> Bool
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederisThing = checkPredef thingMap
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaedermakePredefObjProp :: PreDefMaps
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedermakePredefObjProp = makeOWLPredefMaps predefObjProp
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
77a28e0c97ba4a6f4ad5c7d66c31a2e35aab019dChristian MaederisPredefObjProp :: IRI -> Bool
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian MaederisPredefObjProp = checkPredef makePredefObjProp
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian Maeder
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaedermakePredefDataProp :: PreDefMaps
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian MaedermakePredefDataProp = makeOWLPredefMaps predefDataProp
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian Maeder
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian MaederisPredefDataProp :: IRI -> Bool
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian MaederisPredefDataProp = checkPredef makePredefDataProp
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedermakePredefRDFSAnnoProp :: PreDefMaps
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaedermakePredefRDFSAnnoProp = preDefMaps predefRDFSAnnoProps "rdfs"
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian MaederisPredefRDFSAnnoProp :: IRI -> Bool
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian MaederisPredefRDFSAnnoProp = checkPredef makePredefRDFSAnnoProp
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian MaedermakePredefOWLAnnoProp :: PreDefMaps
97279257021fd703f25019ae8869d86f455d1ea1Christian MaedermakePredefOWLAnnoProp = makeOWLPredefMaps predefOWLAnnoProps
97279257021fd703f25019ae8869d86f455d1ea1Christian Maeder
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian MaederisPredefOWLAnnoProp :: IRI -> Bool
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederisPredefOWLAnnoProp = checkPredef makePredefOWLAnnoProp
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederisPredefAnnoProp :: IRI -> Bool
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederisPredefAnnoProp iri = isPredefOWLAnnoProp iri || isPredefRDFSAnnoProp iri
97279257021fd703f25019ae8869d86f455d1ea1Christian Maeder
bc00171a749cbc4af91f867f11d10e64c2e161acChristian MaederisPredefPropOrClass :: IRI -> Bool
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederisPredefPropOrClass iri = isPredefAnnoProp iri || isPredefDataProp iri
1600a2e47d5ed599df94d20411f0767fb6d68587Christian Maeder || isPredefObjProp iri || isThing iri
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
90255d8098793fec454acbf2c67d4911dd5a7e83Christian MaederpredefIRIs :: Set.Set IRI
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederpredefIRIs = Set.fromList $ map (setPrefix "xsd" . mkQName) xsdKeys
0913f44c14e3fefffbacb8d2280b1da46e27fc5aChristian Maeder ++ map (setPrefix "owl" . mkQName) owlNumbers
0913f44c14e3fefffbacb8d2280b1da46e27fc5aChristian Maeder ++ map (setPrefix "rdf" . mkQName) [rdfsLiteral, stringS]
0913f44c14e3fefffbacb8d2280b1da46e27fc5aChristian Maeder ++ [setPrefix "rdfs" $ mkQName xmlLiteral]
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
0913f44c14e3fefffbacb8d2280b1da46e27fc5aChristian MaederisDatatypeKey :: IRI -> Bool
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederisDatatypeKey = not . null . isDatatypeKeyAux
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
e64aab3e57d843884cd489cc3aa130120a400b05Christian MaederxsdMap :: PreDefMaps
f88169d190b8bdafb6d368216948feb5c8ecf871Christian MaederxsdMap = makeXsdMap xsdKeys
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
90255d8098793fec454acbf2c67d4911dd5a7e83Christian MaederowlNumbersMap :: PreDefMaps
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederowlNumbersMap = makeOWLPredefMaps owlNumbers
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian MaederrdfMap :: PreDefMaps
1600a2e47d5ed599df94d20411f0767fb6d68587Christian MaederrdfMap = preDefMaps [xmlLiteral, stringS] "rdf"
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederrdfsMap :: PreDefMaps
90255d8098793fec454acbf2c67d4911dd5a7e83Christian MaederrdfsMap = preDefMaps [rdfsLiteral] "rdfs"
90255d8098793fec454acbf2c67d4911dd5a7e83Christian Maeder
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederisDatatypeKeyAux :: IRI -> [(String, String)]
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederisDatatypeKeyAux iri = mapMaybe (`checkPredefAux` iri)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder [ xsdMap, owlNumbersMap, rdfMap, rdfsMap ]
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maedertype PreDefMaps = ([String], String, String)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaederpreDefMaps :: [String] -> String -> PreDefMaps
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaederpreDefMaps sl pref = let
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder Just puri = Map.lookup pref predefPrefixes
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder Just sp = stripPrefix "http://www.w3.org/" puri
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder in (sl, pref, sp)
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaedercheckPredefAux :: PreDefMaps -> IRI -> Maybe (String, String)
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaedercheckPredefAux (sl, pref, exPref) u = let lp = localPart u in
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder case namePrefix u of
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder "http" -> case stripPrefix "//www." lp of
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder Just q -> case stripPrefix "w3.org/" q of
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder Just r -> case stripPrefix exPref r of
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder Just s | elem s sl -> Just (pref, s)
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder _ -> Nothing
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maeder Nothing -> case stripPrefix (dnamedS ++ "#") q of
5fed4a7944dcbb9cd5c49af5924945b4994a9ea4Christian Maeder Just s | elem s sl -> Just (pref, s)
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder _ -> Nothing
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder Nothing -> Nothing
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder pu | elem pu ["", pref] && elem lp sl -> Just (pref, lp)
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder _ -> Nothing
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedercheckPredef :: PreDefMaps -> IRI -> Bool
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedercheckPredef ms = isJust . checkPredefAux ms
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedermakeOWLPredefMaps :: [String] -> PreDefMaps
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedermakeOWLPredefMaps sl = preDefMaps sl "owl"
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa-- | sets the correct prefix for the predefined datatypes
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksasetDatatypePrefix :: IRI -> IRI
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksasetDatatypePrefix iri = case isDatatypeKeyAux iri of
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa (p, l) : _ -> setPrefix p $ mkQName l
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa _ -> error $ showQU iri ++ " is not a predefined datatype"
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder-- | checks if the IRI is part of the built-in ones and puts the correct prefix
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedersetReservedPrefix :: IRI -> IRI
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaedersetReservedPrefix iri
57c51f0673511217c416090de812b779612e7551Christian Maeder | isDatatypeKey iri && null (namePrefix iri) = setDatatypePrefix iri
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder | (isThing iri || isPredefDataProp iri || isPredefOWLAnnoProp iri
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder || isPredefObjProp iri) && null (namePrefix iri) = setPrefix "owl" iri
6e581fca2ae28c6fce9e6ee5805c69682cdac5bbChristian Maeder | isPredefRDFSAnnoProp iri = setPrefix "rdfs" iri
28273e1ca9e369682007479ba6ca56ac6167f279Christian Maeder | otherwise = iri
017f1c7ef7027a0bc0d221b31e8877e09a790172Christian Maeder
017f1c7ef7027a0bc0d221b31e8877e09a790172Christian MaederstripReservedPrefix :: IRI -> IRI
28273e1ca9e369682007479ba6ca56ac6167f279Christian MaederstripReservedPrefix = mkQName . getPredefName
28273e1ca9e369682007479ba6ca56ac6167f279Christian Maeder
28273e1ca9e369682007479ba6ca56ac6167f279Christian Maeder{- | returns the name of the predefined IRI (e.g <xsd:string> returns "string"
97279257021fd703f25019ae8869d86f455d1ea1Christian Maeder or <http://www.w3.org/2002/07/owl#real> returns "real") -}
97279257021fd703f25019ae8869d86f455d1ea1Christian MaedergetPredefName :: IRI -> String
017f1c7ef7027a0bc0d221b31e8877e09a790172Christian MaedergetPredefName iri =
017f1c7ef7027a0bc0d221b31e8877e09a790172Christian Maeder 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 = lbl1 -- TODO implement!
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)