AS.hs revision d850dba73b02f345f64a3546d0f0299c292f88d6
c797f343be2f3619bb1f5569753166ec49d27bdbChristian MaederModule : $Header$
c797f343be2f3619bb1f5569753166ec49d27bdbChristian MaederCopyright : (c) C. Maeder, Felix Gabriel Mance
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
b4fbc96e05117839ca409f5f20f97b3ac872d1edTill MossakowskiMaintainer : Christian.Maeder@dfki.de
c797f343be2f3619bb1f5569753166ec49d27bdbChristian MaederStability : provisional
c797f343be2f3619bb1f5569753166ec49d27bdbChristian MaederPortability : portable
f3a94a197960e548ecd6520bb768cb0d547457bbChristian MaederOWL 2 Functional Syntax constructs
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder <http://www.w3.org/TR/2009/REC-owl2-syntax-20091027/#Functional-Style_Syntax>
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder <http://www.w3.org/TR/owl2-manchester-syntax/>
04dada28736b4a237745e92063d8bdd49a362debChristian Maederimport Data.Char (intToDigit)
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maederimport qualified Data.Map as Map
89054b2b95a3f92e78324dc852f3d34704e2ca49Christian Maederdata IRIType = Full | Abbreviated | NodeID
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder deriving (Show, Eq, Ord)
8b9fda012e5ee53b7b2320c0638896a0ff6e99f3Christian Maeder{- | full or abbreviated IRIs with a possible uri for the prefix
8b9fda012e5ee53b7b2320c0638896a0ff6e99f3Christian Maeder or a local part following a hash sign -}
8b9fda012e5ee53b7b2320c0638896a0ff6e99f3Christian Maederdata QName = QN
8b9fda012e5ee53b7b2320c0638896a0ff6e99f3Christian Maeder { namePrefix :: String
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian Maeder -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian Maeder , localPart :: String
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder -- ^ the local part of a qualified name \"namePrefix:localPart\"
04dada28736b4a237745e92063d8bdd49a362debChristian Maeder , iriType :: IRIType
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian Maeder , expandedIRI :: String
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian Maeder -- ^ the associated namespace uri (not printed)
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder , iriPos :: Range
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder } deriving Show
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian Maederinstance Eq QName where
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder p == q = compare p q == EQ
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maederinstance Ord QName where
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder compare (QN p1 l1 b1 n1 _) (QN p2 l2 b2 n2 _) =
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder if null n1 || null n2 then compare (b1, p1, l1) (b2, p2, l2) else
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder compare n1 n2 -- compare fully expanded names only
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maederinstance GetRange QName where
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder getRange = iriPos
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedershowQN :: QName -> String
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedershowQN q = (if iriType q /= Abbreviated then showQI else showQU) q
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder-- | show QName as abbreviated iri
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian MaedershowQU :: QName -> String
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian MaedershowQU (QN pre local _ _ _) =
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder if null pre then local else pre ++ ":" ++ local
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder-- | show QName in ankle brackets as full iris
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedershowQI :: QName -> String
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedershowQI = ('<' :) . (++ ">") . showQU
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian MaedernullQName :: QName
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedernullQName = QN "" "" Abbreviated "" nullRange
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian MaederisNullQName :: QName -> Bool
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaederisNullQName qn = case qn of
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder QN "" "" _ "" _ -> True
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian MaederdummyQName :: QName
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder QN "http" "//www.dfki.de/sks/hets/ontology/unamed" Full "" nullRange
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian MaedermkQName :: String -> QName
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian MaedermkQName s = nullQName { localPart = s }
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedersetQRange :: Range -> QName -> QName
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedersetQRange r q = q { iriPos = r }
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedersetPrefix :: String -> QName -> QName
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedersetPrefix s q = q { namePrefix = s }
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedersetFull :: QName -> QName
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedersetFull q = q {iriType = Full}
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype IRI = QName
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder-- | checks if an IRI is an anonymous individual
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederisAnonymous :: IRI -> Bool
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederisAnonymous iri = iriType iri == NodeID
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder-- | checks if a string (bound to be localPart of an IRI) contains \":\/\/\"
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedercssIRI :: String -> IRIType
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedercssIRI iri = if isInfixOf "://" iri then Full else Abbreviated
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder-- | prefix -> localname
15bb922b665fcd44c6230a1202785d0c7890e90cChristian Maedertype PrefixMap = Map.Map String String
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederpredefPrefixes :: PrefixMap
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian MaederpredefPrefixes = Map.fromList
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder [ ("owl", "http://www.w3.org/2002/07/owl#")
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder , ("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder , ("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder , ("xsd", "http://www.w3.org/2001/XMLSchema#")
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder , ("", showQU dummyQName ++ "#") ]
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maedertype LexicalForm = String
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype LanguageTag = String
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype ImportIRI = IRI
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maedertype OntologyIRI = IRI
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maedertype Class = IRI
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maedertype Datatype = IRI
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype ObjectProperty = IRI
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maedertype DataProperty = IRI
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype AnnotationProperty = IRI
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype NamedIndividual = IRI
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maedertype Individual = IRI
04dada28736b4a237745e92063d8bdd49a362debChristian Maederdata EquivOrDisjoint = Equivalent | Disjoint
04dada28736b4a237745e92063d8bdd49a362debChristian Maeder deriving (Show, Eq, Ord)
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedershowEquivOrDisjoint :: EquivOrDisjoint -> String
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedershowEquivOrDisjoint ed = case ed of
04dada28736b4a237745e92063d8bdd49a362debChristian Maeder Equivalent -> equivalentToC
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder Disjoint -> disjointWithC
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maederdata DomainOrRange = ADomain | ARange
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder deriving (Show, Eq, Ord)
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaedershowDomainOrRange :: DomainOrRange -> String
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaedershowDomainOrRange dr = case dr of
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder ADomain -> domainC
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder ARange -> rangeC
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maederdata SameOrDifferent = Same | Different
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder deriving (Show, Eq, Ord)
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaedershowSameOrDifferent :: SameOrDifferent -> String
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaedershowSameOrDifferent sd = case sd of
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder Same -> sameAsC
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder Different -> differentFromC
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maederdata Relation =
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder EDRelation EquivOrDisjoint
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder | SubPropertyOf
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder | DRRelation DomainOrRange
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder | SDRelation SameOrDifferent
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder deriving (Show, Eq, Ord)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedershowRelation :: Relation -> String
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedershowRelation r = case r of
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder EDRelation ed -> showEquivOrDisjoint ed
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder SubPropertyOf -> subPropertyOfC
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder InverseOf -> inverseOfC
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder SubClass -> subClassOfC
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder Types -> typesC
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder DRRelation dr -> showDomainOrRange dr
e76e6a43f51438215737d6fc176c89da05bb86daChristian Maeder SDRelation sd -> showSameOrDifferent sd
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaedergetED :: Relation -> EquivOrDisjoint
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaedergetED r = case r of
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder EDRelation ed -> ed
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder _ -> error "not domain or range"
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaedergetDR :: Relation -> DomainOrRange
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaedergetDR r = case r of
962d5c684e2b86d1f9c556c096b426e10cc74026Christian Maeder DRRelation dr -> dr
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder _ -> error "not domain or range"
962d5c684e2b86d1f9c556c096b426e10cc74026Christian MaedergetSD :: Relation -> SameOrDifferent
962d5c684e2b86d1f9c556c096b426e10cc74026Christian MaedergetSD s = case s of
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder SDRelation sd -> sd
962d5c684e2b86d1f9c556c096b426e10cc74026Christian Maeder _ -> error "not same or different"
962d5c684e2b86d1f9c556c096b426e10cc74026Christian Maederdata Character =
962d5c684e2b86d1f9c556c096b426e10cc74026Christian Maeder | InverseFunctional
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder | Irreflexive
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder | Antisymmetric
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder deriving (Enum, Bounded, Show, Eq, Ord)
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maederdata PositiveOrNegative = Positive | Negative
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder deriving (Show, Eq, Ord)
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maederdata QuantifierType = AllValuesFrom | SomeValuesFrom
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder deriving (Show, Eq, Ord)
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedershowQuantifierType :: QuantifierType -> String
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaedershowQuantifierType ty = case ty of
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder AllValuesFrom -> onlyS
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder SomeValuesFrom -> someS
c797f343be2f3619bb1f5569753166ec49d27bdbChristian Maeder-- * Predefined IRI checkings
15bb922b665fcd44c6230a1202785d0c7890e90cChristian MaederisThing :: IRI -> Bool
15bb922b665fcd44c6230a1202785d0c7890e90cChristian MaederisThing = isOWLPredef predefClass
|| 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