AS.hs revision 863fa65ac095659c6da1cde7fe7b839f1e7f60f9
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederModule : $Header$
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerCopyright : (c) C. Maeder
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>
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder <http://www.w3.org/TR/owl2-manchester-syntax/>
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport Data.Char (intToDigit)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport qualified Data.Map as Map
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederdata IRIType = Full | Abbreviated | NodeID
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder deriving (Show, Eq, Ord)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder{- | full or abbreviated IRIs with a possible uri for the prefix
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder or a local part following a hash sign -}
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederdata QName = QN
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder { namePrefix :: String
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder , localPart :: String
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder -- ^ the local part of a qualified name \"namePrefix:localPart\"
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder , iriType :: IRIType
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder , expandedIRI :: String
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder -- ^ the associated namespace uri (not printed)
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder , iriPos :: Range
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder } deriving Show
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Eq QName where
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder p == q = compare p q == EQ
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Ord QName where
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder compare (QN p1 l1 b1 n1 _) (QN p2 l2 b2 n2 _) =
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder if null n1 || null n2 then compare (b1, p1, l1) (b2, p2, l2) else
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder compare n1 n2 -- compare fully expanded names only
1a38107941725211e7c3f051f7a8f5e12199f03acmaederinstance GetRange QName where
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder getRange = iriPos
1a38107941725211e7c3f051f7a8f5e12199f03acmaedershowQN :: QName -> String
3b48e17c1da54ee669e70b626d9fbc32ce495b2cChristian MaedershowQN q = (if iriType q /= Abbreviated then showQI else showQU) q
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder-- | show QName as abbreviated iri
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaedershowQU :: QName -> String
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaedershowQU (QN pre local _ _ _) =
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder if null pre then local else pre ++ ":" ++ local
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder-- | show QName in ankle brackets as full iris
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaedershowQI :: QName -> String
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaedershowQI = ('<' :) . (++ ">") . showQU
3b48e17c1da54ee669e70b626d9fbc32ce495b2cChristian MaedernullQName :: QName
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedernullQName = QN "" "" Abbreviated "" nullRange
9f93b2a8b552789cd939d599504d39732672dc84Christian MaederdummyQName :: QName
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder QN "http" "//www.dfki.de/sks/hets/ontology/unamed" Full "" nullRange
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedermkQName :: String -> QName
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedermkQName s = nullQName { localPart = s }
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian MaedersetQRange :: Range -> QName -> QName
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedersetQRange r q = q { iriPos = r }
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedersetPrefix :: String -> QName -> QName
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian MaedersetPrefix s q = q { namePrefix = s }
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedersetFull :: QName -> QName
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian MaedersetFull q = q {iriType = Full}
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype IRI = QName
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder-- | checks if an IRI is an anonymous individual
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederisAnonymous :: IRI -> Bool
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederisAnonymous iri = iriType iri == NodeID
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder-- | checks if a string (bound to be localPart of an IRI) contains \":\/\/\"
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercssIRI :: String -> IRIType
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedercssIRI iri = if isInfixOf "://" iri then Full else Abbreviated
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder-- | prefix -> localname
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maedertype PrefixMap = Map.Map String String
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederpredefPrefixes :: PrefixMap
66ea26416f702f5e00759ffc767f0f785cc86058Christian 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#")
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder , ("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder , ("xsd", "http://www.w3.org/2001/XMLSchema#")
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder , ("", showQU dummyQName ++ "#") ]
d3f192025f2836285d9705a959542350e057f281Christian Maedertype LexicalForm = String
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maedertype LanguageTag = String
499b6cb3ab95a336a324545123e18f387ee4d2a3Christian Maedertype ImportIRI = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype OntologyIRI = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype Class = IRI
d3f192025f2836285d9705a959542350e057f281Christian Maedertype Datatype = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype ObjectProperty = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype DataProperty = IRI
d3f192025f2836285d9705a959542350e057f281Christian Maedertype AnnotationProperty = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype NamedIndividual = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype Individual = IRI
d3f192025f2836285d9705a959542350e057f281Christian Maederdata EquivOrDisjoint = Equivalent | Disjoint
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder deriving (Show, Eq, Ord)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedershowEquivOrDisjoint :: EquivOrDisjoint -> String
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedershowEquivOrDisjoint ed = case ed of
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder Equivalent -> equivalentToC
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder Disjoint -> disjointWithC
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederdata DomainOrRange = ADomain | ARange
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder deriving (Show, Eq, Ord)
d3f192025f2836285d9705a959542350e057f281Christian MaedershowDomainOrRange :: DomainOrRange -> String
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedershowDomainOrRange dr = case dr of
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder ADomain -> domainC
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder ARange -> rangeC
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederdata SameOrDifferent = Same | Different
d3f192025f2836285d9705a959542350e057f281Christian Maeder deriving (Show, Eq, Ord)
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedershowSameOrDifferent :: SameOrDifferent -> String
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedershowSameOrDifferent sd = case sd of
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder Same -> sameAsC
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder Different -> differentFromC
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederdata Relation =
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder EDRelation EquivOrDisjoint
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder | SubPropertyOf
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder | DRRelation DomainOrRange
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder | SDRelation SameOrDifferent
|| showQU u `elem` map (Map.findWithDefault
pref (predefPrefixes `Map.difference`
Map.fromList [("", showQU dummyQName ++ "#")]) ++) sl
{- | 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