AS.hs revision 47589c2d80dabefc0cd8e2ee5e7331e3db677c68
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian Maeder{-# LANGUAGE DeriveDataTypeable #-}
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederModule : $Header$
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederCopyright : (c) C. Maeder, Felix Gabriel Mance
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederMaintainer : Christian.Maeder@dfki.de
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederStability : provisional
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederPortability : portable
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederOWL 2 Functional Syntax constructs
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder <http://www.w3.org/TR/2009/REC-owl2-syntax-20091027/#Functional-Style_Syntax>
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder <http://www.w3.org/TR/owl2-manchester-syntax/>
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport Data.Char (intToDigit)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport qualified Data.Map as Map
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport qualified Data.Set as Set
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederdata IRIType = Full | Abbreviated | NodeID
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder{- | full or abbreviated IRIs with a possible uri for the prefix
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder or a local part following a hash sign -}
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederdata QName = QN
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder { namePrefix :: String
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder , localPart :: String
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder -- ^ the local part of a qualified name \"namePrefix:localPart\"
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder , iriType :: IRIType
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder , expandedIRI :: String
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder -- ^ the associated namespace uri (not printed)
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder , iriPos :: Range
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder } deriving (Show, Typeable, Data)
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Eq QName where
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder p == q = compare p q == EQ
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Ord QName where
3b48e17c1da54ee669e70b626d9fbc32ce495b2cChristian Maeder compare (QN p1 l1 b1 n1 _) (QN p2 l2 b2 n2 _) =
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder if null n1 || null n2 then compare (b1, p1, l1) (b2, p2, l2) else
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder compare n1 n2 -- compare fully expanded names only
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaederqNameRange :: QName -> [Pos]
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaederqNameRange q = let Range rs = iriPos q in case rs of
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder p0 = if iriType q == Full then incSourceColumn p (-1) else p
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder in tokenRange $ Token (showQN q) $ Range [p0]
3b48e17c1da54ee669e70b626d9fbc32ce495b2cChristian Maederinstance GetRange QName where
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder getRange = iriPos
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder rangeSpan = qNameRange
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedershowQN :: QName -> String
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedershowQN q = (if iriType q == Full then showQI else showQU) q
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder-- | show QName as abbreviated iri
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedershowQU :: QName -> String
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian MaedershowQU (QN pre local _ _ _) =
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder if null pre then local else pre ++ ":" ++ local
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder-- | show QName in angle brackets as full iris
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedershowQI :: QName -> String
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian MaedershowQI n = '<' : showQU n ++ ">"
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedernullQName :: QName
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian MaedernullQName = QN "" "" Abbreviated "" nullRange
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederisNullQName :: QName -> Bool
d3f192025f2836285d9705a959542350e057f281Christian MaederisNullQName qn = case qn of
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder QN "" "" _ "" _ -> True
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederunamedS :: String
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederunamedS = "//www." ++ dnamedS
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederdnamedS :: String
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederdnamedS = "dfki.de/sks/hets/ontology/unamed"
d3f192025f2836285d9705a959542350e057f281Christian MaederdummyQName :: QName
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederdummyQName = QN "http" unamedS Full ("http:" ++ unamedS) nullRange
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedermkQName :: String -> QName
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedermkQName s = nullQName { localPart = s }
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedersetQRange :: Range -> QName -> QName
d3f192025f2836285d9705a959542350e057f281Christian MaedersetQRange r q = q { iriPos = r }
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedersetPrefix :: String -> QName -> QName
d3f192025f2836285d9705a959542350e057f281Christian MaedersetPrefix s q = q { namePrefix = s }
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedersetFull :: QName -> QName
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedersetFull q = q {iriType = Full}
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maedertype IRI = QName
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | checks if an IRI is an anonymous individual
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederisAnonymous :: IRI -> Bool
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederisAnonymous iri = iriType iri == NodeID || namePrefix iri == "_"
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | checks if a string (bound to be localPart of an IRI) contains \":\/\/\"
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedercssIRI :: String -> IRIType
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercssIRI iri = if isInfixOf "://" iri then Full else Abbreviated
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder-- | prefix -> localname
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maedertype PrefixMap = Map.Map String String
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederpredefPrefixes :: PrefixMap
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederpredefPrefixes = Map.fromList
d3f192025f2836285d9705a959542350e057f281Christian Maeder [ ("owl", "http://www.w3.org/2002/07/owl#")
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder , ("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
d3f192025f2836285d9705a959542350e057f281Christian Maeder , ("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder , ("xsd", "http://www.w3.org/2001/XMLSchema#")
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder , ("", showQU dummyQName ++ "#") ]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype LexicalForm = String
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype LanguageTag = String
d3f192025f2836285d9705a959542350e057f281Christian Maedertype ImportIRI = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype OntologyIRI = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype Class = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype Datatype = IRI
d3f192025f2836285d9705a959542350e057f281Christian Maedertype ObjectProperty = IRI
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maedertype DataProperty = IRI
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maedertype AnnotationProperty = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype Individual = IRI
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maederdata EquivOrDisjoint = Equivalent | Disjoint
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedershowEquivOrDisjoint :: EquivOrDisjoint -> String
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedershowEquivOrDisjoint ed = case ed of
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder Equivalent -> equivalentToC
d3f192025f2836285d9705a959542350e057f281Christian Maeder Disjoint -> disjointWithC
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederdata DomainOrRange = ADomain | ARange
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedershowDomainOrRange :: DomainOrRange -> String
d3f192025f2836285d9705a959542350e057f281Christian MaedershowDomainOrRange dr = case dr of
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder ADomain -> domainC
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder ARange -> rangeC
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maederdata SameOrDifferent = Same | Different
d3f192025f2836285d9705a959542350e057f281Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedershowSameOrDifferent :: SameOrDifferent -> String
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedershowSameOrDifferent sd = case sd of
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder Same -> sameAsC
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder Different -> differentFromC
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maederdata Relation =
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder EDRelation EquivOrDisjoint
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder | SubPropertyOf
predefIRIs :: Set.Set IRI
predefIRIs = Set.fromList $ map (setPrefix "xsd" . mkQName) xsdKeys
Just puri = Map.lookup pref predefPrefixes
Just sp = stripPrefix "http://www.w3.org/" puri
Just q -> case stripPrefix "w3.org/" q of
{- | returns the name of the predefined IRI (e.g <xsd:string> returns "string"
or <http://www.w3.org/2002/07/owl#real> returns "real") -}
$ Map.elems predefPrefixes of