AS.hs revision 7852de3551fc797566ee71165bafe05b6d81728c
275f2a1080c2089e14a1455dbbbb3bc992d8e593cmaeder{-# LANGUAGE DeriveDataTypeable #-}
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : $Header$
e83ed59502a681713982f25c559aae77a4145734Christian MaederCopyright : (c) C. Maeder, Felix Gabriel Mance
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederMaintainer : Christian.Maeder@dfki.de
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederStability : provisional
90255d8098793fec454acbf2c67d4911dd5a7e83Christian MaederPortability : portable
90255d8098793fec454acbf2c67d4911dd5a7e83Christian MaederOWL 2 Functional Syntax constructs
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/>
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederimport Data.Char (intToDigit)
1600a2e47d5ed599df94d20411f0767fb6d68587Christian Maederimport qualified Data.Map as Map
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederimport qualified Data.Set as Set
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederdata IRIType = Full | Abbreviated | NodeID
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
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)
77a28e0c97ba4a6f4ad5c7d66c31a2e35aab019dChristian Maederinstance Eq QName where
77a28e0c97ba4a6f4ad5c7d66c31a2e35aab019dChristian Maeder p == q = compare p q == EQ
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
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederqNameRange :: QName -> [Pos]
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian MaederqNameRange q = let Range rs = iriPos q in case rs of
90255d8098793fec454acbf2c67d4911dd5a7e83Christian Maeder p0 = if iriType q == Full then incSourceColumn p (-1) else p
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder in tokenRange $ Token (showQN q) $ Range [p0]
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian Maederinstance GetRange QName where
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian Maeder getRange = iriPos
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian Maeder rangeSpan = qNameRange
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian MaedershowQN :: QName -> String
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian MaedershowQN q = (if iriType q == Full then showQI else showQU) q
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
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder-- | show QName in angle brackets as full iris
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaedershowQI :: QName -> String
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedershowQI n = '<' : showQU n ++ ">"
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian MaedernullQName :: QName
158196f73dca970c3541c1f31680ac50a28a6ec9Christian MaedernullQName = QN "" "" Abbreviated "" nullRange
158196f73dca970c3541c1f31680ac50a28a6ec9Christian MaederisNullQName :: QName -> Bool
158196f73dca970c3541c1f31680ac50a28a6ec9Christian MaederisNullQName qn = case qn of
158196f73dca970c3541c1f31680ac50a28a6ec9Christian Maeder QN "" "" _ "" _ -> True
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederunamedS :: String
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian MaederunamedS = "//www." ++ dnamedS
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaederdnamedS :: String
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaederdnamedS = "dfki.de/sks/hets/ontology/unamed"
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaederdummyQName :: QName
ec2db3a0102875c71d3fccb5531dd21410890976Christian MaederdummyQName = QN "http" unamedS Full ("http:" ++ unamedS) nullRange
90255d8098793fec454acbf2c67d4911dd5a7e83Christian MaedermkQName :: String -> QName
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedermkQName s = nullQName { localPart = s }
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedersetQRange :: Range -> QName -> QName
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedersetQRange r q = q { iriPos = r }
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedersetPrefix :: String -> QName -> QName
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedersetPrefix s q = q { namePrefix = s }
aa83d02e62b7e9f4b87a454f553a75fdbd061412Christian MaedersetFull :: QName -> QName
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedersetFull q = q {iriType = Full}
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maedertype IRI = QName
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder-- | checks if an IRI is an anonymous individual
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederisAnonymous :: IRI -> Bool
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederisAnonymous iri = iriType iri == NodeID || namePrefix iri == "_"
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-- | prefix -> localname
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maedertype PrefixMap = Map.Map String String
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 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
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maederdata EquivOrDisjoint = Equivalent | Disjoint
81394dea09f1589f67989c4a9c9b0183c9c9a085Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaedershowEquivOrDisjoint :: EquivOrDisjoint -> String
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaedershowEquivOrDisjoint ed = case ed of
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian Maeder Equivalent -> equivalentToC
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder Disjoint -> disjointWithC
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederdata DomainOrRange = ADomain | ARange
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedershowDomainOrRange :: DomainOrRange -> String
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaedershowDomainOrRange dr = case dr of
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder ADomain -> domainC
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder ARange -> rangeC
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maederdata SameOrDifferent = Same | Different
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedershowSameOrDifferent :: SameOrDifferent -> String
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedershowSameOrDifferent sd = case sd of
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder Same -> sameAsC
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder Different -> differentFromC
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederdata Relation =
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian Maeder EDRelation EquivOrDisjoint
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder | SubPropertyOf
e510c0b71a70d5c1e05e8132b438d8ee889a7dadChristian Maeder | DRRelation DomainOrRange
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian Maeder | SDRelation SameOrDifferent
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
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
6d49b450d2fbb6bf7a647894abad8ea17f63e14aEwaryst SchulzgetED :: Relation -> EquivOrDisjoint
6d49b450d2fbb6bf7a647894abad8ea17f63e14aEwaryst SchulzgetED r = case r of
6d49b450d2fbb6bf7a647894abad8ea17f63e14aEwaryst Schulz EDRelation ed -> ed
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder _ -> error "not domain or range"
e64aab3e57d843884cd489cc3aa130120a400b05Christian MaedergetDR :: Relation -> DomainOrRange
e64aab3e57d843884cd489cc3aa130120a400b05Christian MaedergetDR r = case r of
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder DRRelation dr -> dr
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder _ -> error "not domain or range"
017f1c7ef7027a0bc0d221b31e8877e09a790172Christian MaedergetSD :: Relation -> SameOrDifferent
017f1c7ef7027a0bc0d221b31e8877e09a790172Christian MaedergetSD s = case s of
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz SDRelation sd -> sd
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz _ -> error "not same or different"
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulzdata Character =
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz | InverseFunctional
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz | Irreflexive
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz | Antisymmetric
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulz deriving (Enum, Bounded, Show, Eq, Ord, Typeable, Data)
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulzdata PositiveOrNegative = Positive | Negative
017f1c7ef7027a0bc0d221b31e8877e09a790172Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
e54b5a26d985615b60b797701325f24b870f15d7Ewaryst Schulzdata QuantifierType = AllValuesFrom | SomeValuesFrom
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedershowQuantifierType :: QuantifierType -> String
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian MaedershowQuantifierType ty = case ty of
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian Maeder AllValuesFrom -> onlyS
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian Maeder SomeValuesFrom -> someS
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian Maeder-- * Predefined IRI checkings
6e6ba3ab90205840b9c0ea408befaed7d1d7b80bChristian MaederthingMap :: PreDefMaps
9aca2bcd1f6778d4db433096e77011a4dc450b58Christian MaederthingMap = makeOWLPredefMaps predefClass
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian MaederisThing :: IRI -> Bool
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederisThing = checkPredef thingMap
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaedermakePredefObjProp :: PreDefMaps
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedermakePredefObjProp = makeOWLPredefMaps predefObjProp
77a28e0c97ba4a6f4ad5c7d66c31a2e35aab019dChristian MaederisPredefObjProp :: IRI -> Bool
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian MaederisPredefObjProp = checkPredef makePredefObjProp
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaedermakePredefDataProp :: PreDefMaps
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian MaedermakePredefDataProp = makeOWLPredefMaps predefDataProp
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian MaederisPredefDataProp :: IRI -> Bool
0cb5f9c8582ad87ceef1c16b5d92347ae0878019Christian MaederisPredefDataProp = checkPredef makePredefDataProp
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedermakePredefRDFSAnnoProp :: PreDefMaps
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaedermakePredefRDFSAnnoProp = preDefMaps predefRDFSAnnoProps "rdfs"
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian MaederisPredefRDFSAnnoProp :: IRI -> Bool
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian MaederisPredefRDFSAnnoProp = checkPredef makePredefRDFSAnnoProp
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian MaedermakePredefOWLAnnoProp :: PreDefMaps
97279257021fd703f25019ae8869d86f455d1ea1Christian MaedermakePredefOWLAnnoProp = makeOWLPredefMaps predefOWLAnnoProps
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian MaederisPredefOWLAnnoProp :: IRI -> Bool
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederisPredefOWLAnnoProp = checkPredef makePredefOWLAnnoProp
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederisPredefAnnoProp :: IRI -> Bool
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederisPredefAnnoProp iri = isPredefOWLAnnoProp iri || isPredefRDFSAnnoProp iri
bc00171a749cbc4af91f867f11d10e64c2e161acChristian MaederisPredefPropOrClass :: IRI -> Bool
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederisPredefPropOrClass iri = isPredefAnnoProp iri || isPredefDataProp iri
1600a2e47d5ed599df94d20411f0767fb6d68587Christian Maeder || isPredefObjProp iri || isThing iri
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]
0913f44c14e3fefffbacb8d2280b1da46e27fc5aChristian MaederisDatatypeKey :: IRI -> Bool
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederisDatatypeKey = not . null . isDatatypeKeyAux
e64aab3e57d843884cd489cc3aa130120a400b05Christian MaederxsdMap :: PreDefMaps
f88169d190b8bdafb6d368216948feb5c8ecf871Christian MaederxsdMap = makeXsdMap xsdKeys
90255d8098793fec454acbf2c67d4911dd5a7e83Christian MaederowlNumbersMap :: PreDefMaps
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederowlNumbersMap = makeOWLPredefMaps owlNumbers
203822057b82d4515f57aabba92e3e1e0abb1c2cChristian MaederrdfMap :: PreDefMaps
1600a2e47d5ed599df94d20411f0767fb6d68587Christian MaederrdfMap = preDefMaps [xmlLiteral, stringS] "rdf"
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederrdfsMap :: PreDefMaps
90255d8098793fec454acbf2c67d4911dd5a7e83Christian MaederrdfsMap = preDefMaps [rdfsLiteral] "rdfs"
7fc94f7c677e280e09b834c5bfcf0411aed1f842Christian MaederisDatatypeKeyAux :: IRI -> [(String, String)]
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederisDatatypeKeyAux iri = mapMaybe (`checkPredefAux` iri)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder [ xsdMap, owlNumbersMap, rdfMap, rdfsMap ]
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maedertype PreDefMaps = ([String], String, String)
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)
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)
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maeder Nothing -> case stripPrefix (dnamedS ++ "#") q of
5fed4a7944dcbb9cd5c49af5924945b4994a9ea4Christian Maeder Just s | elem s sl -> Just (pref, s)
ec2db3a0102875c71d3fccb5531dd21410890976Christian Maeder Nothing -> Nothing
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder pu | elem pu ["", pref] && elem lp sl -> Just (pref, lp)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedercheckPredef :: PreDefMaps -> IRI -> Bool
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedercheckPredef ms = isJust . checkPredefAux ms
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedermakeOWLPredefMaps :: [String] -> PreDefMaps
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedermakeOWLPredefMaps sl = preDefMaps sl "owl"
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"
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 MaederstripReservedPrefix :: IRI -> IRI
28273e1ca9e369682007479ba6ca56ac6167f279Christian MaederstripReservedPrefix = mkQName . getPredefName
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"]
$ Map.elems predefPrefixes of