AS.hs revision 6470a08d94430381c14ed30c3a3a8e433401352b
ca010363454de207082dfaa4b753531ce2a34551Christian Maeder{-# LANGUAGE DeriveDataTypeable #-}
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederModule : $Header$
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaederCopyright : (c) C. Maeder, Felix Gabriel Mance
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederMaintainer : Christian.Maeder@dfki.de
ca010363454de207082dfaa4b753531ce2a34551Christian MaederStability : provisional
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaederPortability : portable
79d11c2e3ad242ebb241f5d4a5e98a674c0b986fChristian MaederOWL 2 Functional Syntax constructs
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/>
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maederimport Data.Char (intToDigit)
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maederimport qualified Data.Map as Map
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maederimport qualified Data.Set as Set
ad270004874ce1d0697fb30d7309f180553bb315Christian Maederdata IRIType = Full | Abbreviated | NodeID
fc8c6570c7b4ee13f375eb607bed2290438573bfChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder{- | full or abbreviated IRIs with a possible uri for the prefix
028f19cdb09d52bb2fd207399b6fa874540d1670Christian Maeder or a local part following a hash sign -}
975642b989852fc24119c59cf40bc1af653608ffChristian Maederdata QName = QN
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder { namePrefix :: String
83cc27e4ca7cf1a4bb5f4a8df17d3e6d44e6f1eaChristian Maeder -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder , localPart :: String
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder -- ^ the local part of a qualified name \"namePrefix:localPart\"
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder , iriType :: IRIType
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder , expandedIRI :: String
fc8c6570c7b4ee13f375eb607bed2290438573bfChristian Maeder -- ^ the associated namespace uri (not printed)
83cc27e4ca7cf1a4bb5f4a8df17d3e6d44e6f1eaChristian Maeder , iriPos :: Range
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder } deriving (Show, Typeable, Data)
53301de22afd7190981b363b57c48df86fcb50f7Christian Maederinstance Eq QName where
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder p == q = compare p q == EQ
53301de22afd7190981b363b57c48df86fcb50f7Christian Maederinstance Ord QName where
0a39036fa485579a7b7c81cdd44a412392571927Christian Maeder compare (QN p1 l1 b1 n1 _) (QN p2 l2 b2 n2 _) =
da2b959c50c95309d8eb8b24174249c2847e74b5Christian Maeder if null n1 || null n2 then compare (b1, p1, l1) (b2, p2, l2) else
0a39036fa485579a7b7c81cdd44a412392571927Christian Maeder compare n1 n2 -- compare fully expanded names only
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederqNameRange :: QName -> [Pos]
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederqNameRange q = let Range rs = iriPos q in case rs of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder p0 = if iriType q == Full then incSourceColumn p (-1) else p
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder in tokenRange $ Token (showQN q) $ Range [p0]
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maederinstance GetRange QName where
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder getRange = iriPos
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder rangeSpan = qNameRange
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowQN :: QName -> String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowQN q = (if iriType q == Full then showQI else showQU) q
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder-- | show QName as abbreviated iri
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaedershowQU :: QName -> String
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedershowQU (QN pre local _ _ _) =
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder if null pre then local else pre ++ ":" ++ local
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder-- | show QName in angle brackets as full iris
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedershowQI :: QName -> String
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedershowQI n = '<' : showQU n ++ ">"
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedernullQName :: QName
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedernullQName = QN "" "" Abbreviated "" nullRange
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederisNullQName :: QName -> Bool
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederisNullQName qn = case qn of
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder QN "" "" _ "" _ -> True
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederunamedS :: String
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederunamedS = "//www." ++ dnamedS
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederdnamedS :: String
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederdnamedS = "dfki.de/sks/hets/ontology/unamed"
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederdummyQName :: QName
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederdummyQName = QN "http" unamedS Full ("http:" ++ unamedS) nullRange
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedermkQName :: String -> QName
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedermkQName s = nullQName { localPart = s }
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedersetQRange :: Range -> QName -> QName
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedersetQRange r q = q { iriPos = r }
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedersetPrefix :: String -> QName -> QName
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedersetPrefix s q = q { namePrefix = s }
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedersetFull :: QName -> QName
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedersetFull q = q {iriType = Full}
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maedertype IRI = QName
da2b959c50c95309d8eb8b24174249c2847e74b5Christian Maeder-- | checks if an IRI is an anonymous individual
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederisAnonymous :: IRI -> Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisAnonymous iri = iriType iri == NodeID || namePrefix iri == "_"
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-- | prefix -> localname
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype PrefixMap = Map.Map String String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederpredefPrefixes :: PrefixMap
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederpredefPrefixes = Map.fromList
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder [ ("owl", "http://www.w3.org/2002/07/owl#")
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder , ("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder , ("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder , ("xsd", "http://www.w3.org/2001/XMLSchema#")
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder , ("", showQU dummyQName ++ "#") ]
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype LexicalForm = String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype LanguageTag = String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype ImportIRI = IRI
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype OntologyIRI = IRI
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype Class = IRI
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype Datatype = IRI
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype ObjectProperty = IRI
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maedertype DataProperty = IRI
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maedertype AnnotationProperty = IRI
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maedertype Individual = IRI
639732746d7c3a586790043b452a4cbdd29a3fc3Christian Maederdata EquivOrDisjoint = Equivalent | Disjoint
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedershowEquivOrDisjoint :: EquivOrDisjoint -> String
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaedershowEquivOrDisjoint ed = case ed of
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder Equivalent -> equivalentToC
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder Disjoint -> disjointWithC
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maederdata DomainOrRange = ADomain | ARange
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowDomainOrRange :: DomainOrRange -> String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowDomainOrRange dr = case dr of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder ADomain -> domainC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder ARange -> rangeC
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maederdata SameOrDifferent = Same | Different
d591a82b32594f0992b27477cacb00b97226c9c8Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowSameOrDifferent :: SameOrDifferent -> String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowSameOrDifferent sd = case sd of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Same -> sameAsC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Different -> differentFromC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maederdata Relation =
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder EDRelation EquivOrDisjoint
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | SubPropertyOf
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | DRRelation DomainOrRange
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | SDRelation SameOrDifferent
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowRelation :: Relation -> String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowRelation r = case r of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder EDRelation ed -> showEquivOrDisjoint ed
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder SubPropertyOf -> subPropertyOfC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder InverseOf -> inverseOfC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder SubClass -> subClassOfC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Types -> typesC
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder DRRelation dr -> showDomainOrRange dr
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder SDRelation sd -> showSameOrDifferent sd
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetED :: Relation -> EquivOrDisjoint
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetED r = case r of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder EDRelation ed -> ed
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder _ -> error "not domain or range"
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetDR :: Relation -> DomainOrRange
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetDR r = case r of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder DRRelation dr -> dr
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder _ -> error "not domain or range"
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetSD :: Relation -> SameOrDifferent
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetSD s = case s of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder SDRelation sd -> sd
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder _ -> error "not same or different"
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maederdata Character =
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | InverseFunctional
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Irreflexive
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | Antisymmetric
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder deriving (Enum, Bounded, Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maederdata PositiveOrNegative = Positive | Negative
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maederdata QuantifierType = AllValuesFrom | SomeValuesFrom
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowQuantifierType :: QuantifierType -> String
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedershowQuantifierType ty = case ty of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder AllValuesFrom -> onlyS
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder SomeValuesFrom -> someS
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder-- * Predefined IRI checkings
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaederthingMap :: PreDefMaps
669e21946b6f90785fc3cb44e7cf4f38c3f6493dChristian MaederthingMap = makeOWLPredefMaps predefClass
669e21946b6f90785fc3cb44e7cf4f38c3f6493dChristian MaederisThing :: IRI -> Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisThing = checkPredef thingMap
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefObjProp :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefObjProp = makeOWLPredefMaps predefObjProp
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisPredefObjProp :: IRI -> Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisPredefObjProp = checkPredef makePredefObjProp
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefDataProp :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefDataProp = makeOWLPredefMaps predefDataProp
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisPredefDataProp :: IRI -> Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisPredefDataProp = checkPredef makePredefDataProp
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefRDFSAnnoProp :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefRDFSAnnoProp = preDefMaps predefRDFSAnnoProps "rdfs"
d591a82b32594f0992b27477cacb00b97226c9c8Christian MaederisPredefRDFSAnnoProp :: IRI -> Bool
669e21946b6f90785fc3cb44e7cf4f38c3f6493dChristian MaederisPredefRDFSAnnoProp = checkPredef makePredefRDFSAnnoProp
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefOWLAnnoProp :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedermakePredefOWLAnnoProp = makeOWLPredefMaps predefOWLAnnoProps
53301de22afd7190981b363b57c48df86fcb50f7Christian MaederisPredefOWLAnnoProp :: IRI -> Bool
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederisPredefOWLAnnoProp = checkPredef makePredefOWLAnnoProp
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederisPredefAnnoProp :: IRI -> Bool
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederisPredefAnnoProp iri = isPredefOWLAnnoProp iri || isPredefRDFSAnnoProp iri
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederisPredefPropOrClass :: IRI -> Bool
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederisPredefPropOrClass iri = isPredefAnnoProp iri || isPredefDataProp iri
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder || isPredefObjProp iri || isThing iri
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederpredefIRIs :: Set.Set IRI
53301de22afd7190981b363b57c48df86fcb50f7Christian MaederpredefIRIs = Set.fromList $ map (setPrefix "xsd" . mkQName) xsdKeys
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder ++ map (setPrefix "owl" . mkQName) owlNumbers
909ce57d58a9cec1d214f0ecbdb1dadddad2e6d9Christian Maeder ++ map (setPrefix "rdf" . mkQName) [rdfsLiteral, stringS]
f8a03685d9184046e88e1d76aabdab4f714db440Christian Maeder ++ [setPrefix "rdfs" $ mkQName xmlLiteral]
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisDatatypeKey :: IRI -> Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederisDatatypeKey = not . null . isDatatypeKeyAux
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederxsdMap :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederxsdMap = makeXsdMap xsdKeys
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederowlNumbersMap :: PreDefMaps
fcfed328fae6266214ee61ee7a16fd263fd3cb70Christian MaederowlNumbersMap = makeOWLPredefMaps owlNumbers
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederrdfMap :: PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederrdfMap = preDefMaps [xmlLiteral, stringS] "rdf"
975642b989852fc24119c59cf40bc1af653608ffChristian MaederrdfsMap :: PreDefMaps
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederrdfsMap = preDefMaps [rdfsLiteral] "rdfs"
13b24998210d193b38cae06485da6f06c61d7f62Christian MaederisDatatypeKeyAux :: IRI -> [(String, String)]
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederisDatatypeKeyAux iri = mapMaybe (`checkPredefAux` iri)
13b24998210d193b38cae06485da6f06c61d7f62Christian Maeder [ xsdMap, owlNumbersMap, rdfMap, rdfsMap ]
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maedertype PreDefMaps = ([String], String, String)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederpreDefMaps :: [String] -> String -> PreDefMaps
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederpreDefMaps sl pref = let
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Just puri = Map.lookup pref predefPrefixes
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Just sp = stripPrefix "http://www.w3.org/" puri
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder in (sl, pref, sp)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedercheckPredefAux :: PreDefMaps -> IRI -> Maybe (String, String)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedercheckPredefAux (sl, pref, exPref) u =
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder let lp = localPart u in case namePrefix u of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder "http" -> case stripPrefix "//www." lp of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Just q -> case stripPrefix "w3.org/" q of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Just r -> case stripPrefix exPref r of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Just s | elem s sl -> Just (pref, s)
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder Nothing -> case stripPrefix (dnamedS ++ "#") q of
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder Just s | elem s sl -> Just (pref, s)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder Nothing -> Nothing
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder pu | (null (expandedIRI u) && null pu || pu == pref) && elem lp sl
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder -> Just (pref, lp)
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaedercheckPredef :: PreDefMaps -> IRI -> Bool
13b24998210d193b38cae06485da6f06c61d7f62Christian MaedercheckPredef ms = isJust . checkPredefAux ms
13b24998210d193b38cae06485da6f06c61d7f62Christian MaedermakeOWLPredefMaps :: [String] -> PreDefMaps
53301de22afd7190981b363b57c48df86fcb50f7Christian MaedermakeOWLPredefMaps sl = preDefMaps sl "owl"
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder-- | sets the correct prefix for the predefined datatypes
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaedersetDatatypePrefix :: IRI -> IRI
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaedersetDatatypePrefix iri = case isDatatypeKeyAux iri of
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder (p, l) : _ -> setPrefix p $ mkQName l
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder _ -> error $ showQU iri ++ " is not a predefined datatype"
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder-- | checks if the IRI is part of the built-in ones and puts the correct prefix
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaedersetReservedPrefix :: IRI -> IRI
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaedersetReservedPrefix iri = case namePrefix iri of
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder | isDatatypeKey iri -> setDatatypePrefix iri
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder | isThing iri || isPredefDataProp iri || isPredefOWLAnnoProp iri
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder || isPredefObjProp iri -> setPrefix "owl" iri
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder | isPredefRDFSAnnoProp iri -> setPrefix "rdfs" iri
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaederstripReservedPrefix :: IRI -> IRI
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaederstripReservedPrefix = mkQName . getPredefName
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder{- | returns the name of the predefined IRI (e.g <xsd:string> returns "string"
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder or <http://www.w3.org/2002/07/owl#real> returns "real") -}
ac142c1b088711f911018d8108a64be80b2f2a58Christian MaedergetPredefName :: IRI -> String
f1ef1c750f805c1732b01001f2b157c0077b808eChristian MaedergetPredefName iri =
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maeder if namePrefix iri `elem` ["", "xsd", "rdf", "rdfs", "owl"]
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder then localPart iri
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder else case mapMaybe (`stripPrefix` showQU iri)
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder $ Map.elems predefPrefixes of
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder _ -> showQN iri
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder-- | Extracts Token from IRI
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaederuriToTok :: IRI -> Token
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederuriToTok urI = mkSimpleId $ getPredefName urI
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder-- | Extracts Id from IRI
ab0f35d8b9012e459417e086773049ce33dda2a0Christian MaederuriToId :: IRI -> Id
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederuriToId = simpleIdToId . uriToTok
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder-- | Extracts Id from Entities
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederentityToId :: Entity -> Id
975642b989852fc24119c59cf40bc1af653608ffChristian MaederentityToId = uriToId . cutIRI
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederprintDatatype :: IRI -> String
975642b989852fc24119c59cf40bc1af653608ffChristian MaederprintDatatype dt = showQU $
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder if isDatatypeKey dt then stripReservedPrefix dt else dt
975642b989852fc24119c59cf40bc1af653608ffChristian Maederdata DatatypeCat = OWL2Number | OWL2String | OWL2Bool | Other
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetDatatypeCat :: IRI -> DatatypeCat
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian MaedergetDatatypeCat iri = case isDatatypeKey iri of
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | checkPredef xsdBooleanMap iri -> OWL2Bool
4b8e74c68d62fc4e5a1739b11f8df09beaecbee8Christian Maeder | checkPredef xsdNumbersMap iri || checkPredef owlNumbersMap iri
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder -> OWL2Number
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder | checkPredef xsdStringsMap iri -> OWL2String
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder | otherwise -> Other
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder False -> Other
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaedermakeXsdMap :: [String] -> PreDefMaps
975642b989852fc24119c59cf40bc1af653608ffChristian MaedermakeXsdMap sl = preDefMaps sl "xsd"
975642b989852fc24119c59cf40bc1af653608ffChristian MaederxsdBooleanMap :: PreDefMaps
975642b989852fc24119c59cf40bc1af653608ffChristian MaederxsdBooleanMap = makeXsdMap [booleanS]