AS.hs revision 63946b0fc89de113d5bf4819f9c8cc5d6adce810
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance{-# LANGUAGE DeriveDataTypeable #-}
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance{- |
5d801400993c9671010d244646936d8fd435638cChristian MaederModule : $Header$
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceCopyright : (c) C. Maeder, Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceLicense : GPLv2 or higher, see LICENSE.txt
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceMaintainer : Christian.Maeder@dfki.de
5d801400993c9671010d244646936d8fd435638cChristian MaederStability : provisional
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancePortability : portable
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
aa0ca44e856c87db27e61687cbb630f270976da1Felix Gabriel ManceOWL 2 Functional Syntax constructs
5d801400993c9671010d244646936d8fd435638cChristian Maeder
5d801400993c9671010d244646936d8fd435638cChristian MaederReferences:
5d801400993c9671010d244646936d8fd435638cChristian Maeder <http://www.w3.org/TR/2009/REC-owl2-syntax-20091027/#Functional-Style_Syntax>
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance <http://www.w3.org/TR/owl2-manchester-syntax/>
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-}
097bc9f18b722812d480df0f5c634d09cbca8e21Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mancemodule OWL2.AS where
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder
dc8c83e9922e4746c192916565f3522418534f3aFelix Gabriel Manceimport Common.Id
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceimport Common.Keywords (stringS)
feab1106bbee4f2ea2fd48bca7106dd041e4211dFelix Gabriel Mance
18ff56829e5e99383ee6106584d55bcbd8ed45e7Felix Gabriel Manceimport Common.Result
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maederimport OWL2.ColonKeywords
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Manceimport OWL2.Keywords
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceimport Data.Char (intToDigit)
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Manceimport Data.Data
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Manceimport Data.List
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Manceimport Data.Maybe
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceimport qualified Data.Map as Map
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceimport qualified Data.Set as Set
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mancedata IRIType = Full | Abbreviated | NodeID
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance deriving (Show, Eq, Ord, Typeable, Data)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance{- | full or abbreviated IRIs with a possible uri for the prefix
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance or a local part following a hash sign -}
0ec1551231bc5dfdcb3f2bd68fec7457fade7bfdFelix Gabriel Mancedata QName = QN
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance { namePrefix :: String
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
968930c7674ae3b63d308bf4fa651400aa263054Christian Maeder , localPart :: String
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance -- ^ the local part of a qualified name \"namePrefix:localPart\"
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance , iriType :: IRIType
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance , expandedIRI :: String
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance -- ^ the associated namespace uri (not printed)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance , iriPos :: Range
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance } deriving (Show, Typeable, Data)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Manceinstance Eq QName where
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance p == q = compare p q == EQ
fc7bd98aabe1bc26058660085e8c77d60a97bcecChristian Maeder
fc7bd98aabe1bc26058660085e8c77d60a97bcecChristian Maederinstance Ord QName where
fc7bd98aabe1bc26058660085e8c77d60a97bcecChristian Maeder compare (QN p1 l1 b1 n1 _) (QN p2 l2 b2 n2 _) =
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance if null n1 || null n2 then compare (b1, p1, l1) (b2, p2, l2) else
3c6b4f79cea11dd2acc2060bf1502b6ba9e905f2Felix Gabriel Mance compare n1 n2 -- compare fully expanded names only
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceqNameRange :: QName -> [Pos]
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceqNameRange q = let Range rs = iriPos q in case rs of
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder [p] -> let
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance p0 = if iriType q == Full then incSourceColumn p (-1) else p
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance in tokenRange $ Token (showQN q) $ Range [p0]
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance _ -> rs
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceinstance GetRange QName where
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance getRange = iriPos
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance rangeSpan = qNameRange
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceshowQN :: QName -> String
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceshowQN q = (if iriType q == Full then showQI else showQU) q
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance-- | show QName as abbreviated iri
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceshowQU :: QName -> String
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceshowQU (QN pre local _ _ _) =
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance if null pre then local else pre ++ ":" ++ local
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder-- | show QName in angle brackets as full iris
852bd6145634dc2832b61c44678fe539bc1682d5Christian MaedershowQI :: QName -> String
852bd6145634dc2832b61c44678fe539bc1682d5Christian MaedershowQI n = '<' : showQU n ++ ">"
ea3f858eb531d981df3ed00beeadd99cf025adecChristian Maeder
ea3f858eb531d981df3ed00beeadd99cf025adecChristian MaedernullQName :: QName
ea3f858eb531d981df3ed00beeadd99cf025adecChristian MaedernullQName = QN "" "" Abbreviated "" nullRange
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
3c6b4f79cea11dd2acc2060bf1502b6ba9e905f2Felix Gabriel ManceisNullQName :: QName -> Bool
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel ManceisNullQName qn = case qn of
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel Mance QN "" "" _ "" _ -> True
3c6b4f79cea11dd2acc2060bf1502b6ba9e905f2Felix Gabriel Mance _ -> False
3c6b4f79cea11dd2acc2060bf1502b6ba9e905f2Felix Gabriel Mance
75aaf82c430ad2a5cf159962b1c5c09255010fb4Felix Gabriel ManceunamedS :: String
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel ManceunamedS = "//www." ++ dnamedS
75aaf82c430ad2a5cf159962b1c5c09255010fb4Felix Gabriel Mance
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancednamedS :: String
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancednamedS = "dfki.de/sks/hets/ontology/unamed"
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
1b1144abf7f95a4b23405b8d5604813cfe7b036aFelix Gabriel MancedummyQName :: QName
4c684d7a2343be7350eba088f8be42888f86a495Felix Gabriel MancedummyQName = QN "http" unamedS Full ("http:" ++ unamedS) nullRange
1b1144abf7f95a4b23405b8d5604813cfe7b036aFelix Gabriel Mance
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel MancemkQName :: String -> QName
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel MancemkQName s = nullQName { localPart = s }
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel Mance
e93f944968a75becbfb496994b85263b9cc1669fFrancisc Nicolae BungiusetQRange :: Range -> QName -> QName
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel MancesetQRange r q = q { iriPos = r }
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel Mance
e93f944968a75becbfb496994b85263b9cc1669fFrancisc Nicolae BungiusetPrefix :: String -> QName -> QName
5a3ae0a9224276de25e709ef8788c1b9716cd206Christian MaedersetPrefix s q = q { namePrefix = s }
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel MancesetFull :: QName -> QName
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel MancesetFull q = q {iriType = Full}
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancetype IRI = QName
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance-- | checks if an IRI is an anonymous individual
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel ManceisAnonymous :: IRI -> Bool
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel ManceisAnonymous iri = iriType iri == NodeID || namePrefix iri == "_"
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance-- | checks if a string (bound to be localPart of an IRI) contains \":\/\/\"
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel MancecssIRI :: String -> IRIType
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel MancecssIRI iri = if isInfixOf "://" iri then Full else Abbreviated
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance-- | prefix -> localname
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancetype PrefixMap = Map.Map String String
9cb6af1a7632f12b60f592ce5eb2ac51e6bd33bbFelix Gabriel Mance
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel MancepredefPrefixes :: PrefixMap
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancepredefPrefixes = Map.fromList
968930c7674ae3b63d308bf4fa651400aa263054Christian Maeder [ ("owl", "http://www.w3.org/2002/07/owl#")
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance , ("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance , ("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance , ("xsd", "http://www.w3.org/2001/XMLSchema#")
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance , ("", showQU dummyQName ++ "#") ]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancetype LexicalForm = String
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancetype LanguageTag = String
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancetype ImportIRI = IRI
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancetype OntologyIRI = IRI
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancetype Class = IRI
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancetype Datatype = IRI
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancetype ObjectProperty = IRI
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancetype DataProperty = IRI
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancetype AnnotationProperty = IRI
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancetype Individual = IRI
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancedata EquivOrDisjoint = Equivalent | Disjoint
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance deriving (Show, Eq, Ord, Typeable, Data)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel ManceshowEquivOrDisjoint :: EquivOrDisjoint -> String
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel ManceshowEquivOrDisjoint ed = case ed of
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance Equivalent -> equivalentToC
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance Disjoint -> disjointWithC
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancedata DomainOrRange = ADomain | ARange
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance deriving (Show, Eq, Ord, Typeable, Data)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceshowDomainOrRange :: DomainOrRange -> String
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceshowDomainOrRange dr = case dr of
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance ADomain -> domainC
968930c7674ae3b63d308bf4fa651400aa263054Christian Maeder ARange -> rangeC
a921ae1da1302f673204e7b63cdce01439a9bd5eFelix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancedata SameOrDifferent = Same | Different
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance deriving (Show, Eq, Ord, Typeable, Data)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceshowSameOrDifferent :: SameOrDifferent -> String
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceshowSameOrDifferent sd = case sd of
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance Same -> sameAsC
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance Different -> differentFromC
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancedata Relation =
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance EDRelation EquivOrDisjoint
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | SubPropertyOf
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | InverseOf
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | SubClass
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | Types
097bc9f18b722812d480df0f5c634d09cbca8e21Felix Gabriel Mance | DRRelation DomainOrRange
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance | SDRelation SameOrDifferent
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance deriving (Show, Eq, Ord, Typeable, Data)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel ManceshowRelation :: Relation -> String
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel ManceshowRelation r = case r of
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance EDRelation ed -> showEquivOrDisjoint ed
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance SubPropertyOf -> subPropertyOfC
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance InverseOf -> inverseOfC
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance SubClass -> subClassOfC
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance Types -> typesC
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance DRRelation dr -> showDomainOrRange dr
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance SDRelation sd -> showSameOrDifferent sd
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancegetED :: Relation -> EquivOrDisjoint
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancegetED r = case r of
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance EDRelation ed -> ed
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance _ -> error "not domain or range"
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancegetDR :: Relation -> DomainOrRange
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancegetDR r = case r of
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance DRRelation dr -> dr
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance _ -> error "not domain or range"
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancegetSD :: Relation -> SameOrDifferent
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancegetSD s = case s of
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance SDRelation sd -> sd
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance _ -> error "not same or different"
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancedata Character =
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance Functional
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | InverseFunctional
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance | Reflexive
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance | Irreflexive
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance | Symmetric
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance | Asymmetric
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance | Antisymmetric
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance | Transitive
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance deriving (Enum, Bounded, Show, Eq, Ord, Typeable, Data)
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mancedata PositiveOrNegative = Positive | Negative
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance deriving (Show, Eq, Ord, Typeable, Data)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mancedata QuantifierType = AllValuesFrom | SomeValuesFrom
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance deriving (Show, Eq, Ord, Typeable, Data)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceshowQuantifierType :: QuantifierType -> String
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceshowQuantifierType ty = case ty of
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance AllValuesFrom -> onlyS
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance SomeValuesFrom -> someS
44985cbd4eb61dbc348617ebdd44a774e51dac07Christian Maeder
44985cbd4eb61dbc348617ebdd44a774e51dac07Christian Maeder-- * Predefined IRI checkings
44985cbd4eb61dbc348617ebdd44a774e51dac07Christian Maeder
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel MancethingMap :: PreDefMaps
44985cbd4eb61dbc348617ebdd44a774e51dac07Christian MaederthingMap = makeOWLPredefMaps predefClass
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mance
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel ManceisThing :: IRI -> Bool
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel ManceisThing = checkPredef thingMap
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mance
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel MancemakePredefObjProp :: PreDefMaps
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel MancemakePredefObjProp = makeOWLPredefMaps predefObjProp
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mance
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel ManceisPredefObjProp :: IRI -> Bool
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel ManceisPredefObjProp = checkPredef makePredefObjProp
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mance
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel MancemakePredefDataProp :: PreDefMaps
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel MancemakePredefDataProp = makeOWLPredefMaps predefDataProp
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mance
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel ManceisPredefDataProp :: IRI -> Bool
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel ManceisPredefDataProp = checkPredef makePredefDataProp
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancemakePredefRDFSAnnoProp :: PreDefMaps
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancemakePredefRDFSAnnoProp = preDefMaps predefRDFSAnnoProps "rdfs"
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceisPredefRDFSAnnoProp :: IRI -> Bool
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceisPredefRDFSAnnoProp = checkPredef makePredefRDFSAnnoProp
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancemakePredefOWLAnnoProp :: PreDefMaps
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancemakePredefOWLAnnoProp = makeOWLPredefMaps predefOWLAnnoProps
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceisPredefOWLAnnoProp :: IRI -> Bool
968930c7674ae3b63d308bf4fa651400aa263054Christian MaederisPredefOWLAnnoProp = checkPredef makePredefOWLAnnoProp
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceisPredefAnnoProp :: IRI -> Bool
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceisPredefAnnoProp iri = isPredefOWLAnnoProp iri || isPredefRDFSAnnoProp iri
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceisPredefPropOrClass :: IRI -> Bool
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceisPredefPropOrClass iri = isPredefAnnoProp iri || isPredefDataProp iri
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance || isPredefObjProp iri || isThing iri
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancepredefIRIs :: Set.Set IRI
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancepredefIRIs = Set.fromList $ map (setPrefix "xsd" . mkQName) xsdKeys
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance ++ map (setPrefix "owl" . mkQName) owlNumbers
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance ++ map (setPrefix "rdf" . mkQName) [rdfsLiteral, stringS]
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance ++ [setPrefix "rdfs" $ mkQName xmlLiteral]
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel ManceisDatatypeKey :: IRI -> Bool
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel ManceisDatatypeKey = not . null . isDatatypeKeyAux
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancexsdMap :: PreDefMaps
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancexsdMap = makeXsdMap xsdKeys
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel ManceowlNumbersMap :: PreDefMaps
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel ManceowlNumbersMap = makeOWLPredefMaps owlNumbers
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancerdfMap :: PreDefMaps
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancerdfMap = preDefMaps [xmlLiteral, stringS] "rdf"
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancerdfsMap :: PreDefMaps
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancerdfsMap = preDefMaps [rdfsLiteral] "rdfs"
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel ManceisDatatypeKeyAux :: IRI -> [(String, String)]
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel ManceisDatatypeKeyAux iri = mapMaybe (`checkPredefAux` iri)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance [ xsdMap, owlNumbersMap, rdfMap, rdfsMap ]
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mancetype PreDefMaps = ([String], String, String)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancepreDefMaps :: [String] -> String -> PreDefMaps
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancepreDefMaps sl pref = let
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance Just puri = Map.lookup pref predefPrefixes
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance Just sp = stripPrefix "http://www.w3.org/" puri
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance in (sl, pref, sp)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancecheckPredefAux :: PreDefMaps -> IRI -> Maybe (String, String)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancecheckPredefAux (sl, pref, exPref) u = case expandedIRI u of
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance "" -> Nothing
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance _ -> let lp = localPart u in case namePrefix u of
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance "http" -> case stripPrefix "//www." lp of
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance Just q -> case stripPrefix "w3.org/" q of
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance Just r -> case stripPrefix exPref r of
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance Just s | elem s sl -> Just (pref, s)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance _ -> Nothing
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance Nothing -> case stripPrefix (dnamedS ++ "#") q of
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance Just s | elem s sl -> Just (pref, s)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance _ -> Nothing
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance Nothing -> Nothing
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance pu | elem pu ["", pref] && elem lp sl -> Just (pref, lp)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance _ -> Nothing
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancecheckPredef :: PreDefMaps -> IRI -> Bool
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancecheckPredef ms = isJust . checkPredefAux ms
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancemakeOWLPredefMaps :: [String] -> PreDefMaps
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancemakeOWLPredefMaps sl = preDefMaps sl "owl"
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | sets the correct prefix for the predefined datatypes
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancesetDatatypePrefix :: IRI -> IRI
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedersetDatatypePrefix iri = case isDatatypeKeyAux iri of
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance (p, l) : _ -> setPrefix p $ mkQName l
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance _ -> error $ showQU iri ++ " is not a predefined datatype"
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder-- | checks if the IRI is part of the built-in ones and puts the correct prefix
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedersetReservedPrefix :: IRI -> IRI
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedersetReservedPrefix iri = case namePrefix iri of
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder ""
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder | isDatatypeKey iri -> setDatatypePrefix iri
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder | isThing iri || isPredefDataProp iri || isPredefOWLAnnoProp iri
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder || isPredefObjProp iri -> setPrefix "owl" iri
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder | isPredefRDFSAnnoProp iri -> setPrefix "rdfs" iri
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder _ -> iri
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederstripReservedPrefix :: IRI -> IRI
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederstripReservedPrefix = mkQName . getPredefName
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder{- | returns the name of the predefined IRI (e.g <xsd:string> returns "string"
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder or <http://www.w3.org/2002/07/owl#real> returns "real") -}
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedergetPredefName :: IRI -> String
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedergetPredefName iri =
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder if namePrefix iri `elem` ["", "xsd", "rdf", "rdfs", "owl"]
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder then localPart iri
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder else case mapMaybe (`stripPrefix` showQU iri)
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder $ Map.elems predefPrefixes of
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder [s] -> s
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder _ -> showQN iri
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder-- | Extracts Token from IRI
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederuriToTok :: IRI -> Token
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederuriToTok urI = mkSimpleId $ getPredefName urI
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder-- | Extracts Id from IRI
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederuriToId :: IRI -> Id
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederuriToId = simpleIdToId . uriToTok
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder-- | Extracts Id from Entities
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederentityToId :: Entity -> Id
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederentityToId = uriToId . cutIRI
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederprintDatatype :: IRI -> String
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederprintDatatype dt = showQU $
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder if isDatatypeKey dt then stripReservedPrefix dt else dt
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maederdata DatatypeCat = OWL2Number | OWL2String | OWL2Bool | Other
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedergetDatatypeCat :: IRI -> DatatypeCat
cbb0a924599bcaea230e7dcd2892cc91c49319aeChristian MaedergetDatatypeCat iri = case isDatatypeKey iri of
cbb0a924599bcaea230e7dcd2892cc91c49319aeChristian Maeder True
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder | checkPredef xsdBooleanMap iri -> OWL2Bool
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder | checkPredef xsdNumbersMap iri || checkPredef owlNumbersMap iri
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder -> OWL2Number
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder | checkPredef xsdStringsMap iri -> OWL2String
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder | otherwise -> Other
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder False -> Other
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedermakeXsdMap :: [String] -> PreDefMaps
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedermakeXsdMap sl = preDefMaps sl "xsd"
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederxsdBooleanMap :: PreDefMaps
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederxsdBooleanMap = makeXsdMap [booleanS]
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederxsdNumbersMap :: PreDefMaps
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederxsdNumbersMap = makeXsdMap xsdNumbers
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederxsdStringsMap :: PreDefMaps
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederxsdStringsMap = makeXsdMap xsdStrings
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederfacetToIRI :: DatatypeFacet -> ConstrainingFacet
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederfacetToIRI = setPrefix "xsd" . mkQName . showFacet
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder-- * Cardinalities
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maederdata CardinalityType = MinCardinality | MaxCardinality | ExactCardinality
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedershowCardinalityType :: CardinalityType -> String
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedershowCardinalityType ty = case ty of
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mance MinCardinality -> minS
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mance MaxCardinality -> maxS
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mance ExactCardinality -> exactlyS
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mance
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mancedata Cardinality a b = Cardinality CardinalityType Int a (Maybe b)
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mance deriving (Show, Eq, Ord, Typeable, Data)
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mance
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mancedata JunctionType = UnionOf | IntersectionOf
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mance deriving (Show, Eq, Ord, Typeable, Data)
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mance
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mancetype ConstrainingFacet = IRI
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mancetype RestrictionValue = Literal
a4a1b0cfce938fc38d5924b8fb6a7e140602ec5cFelix Gabriel Mance
cbb0a924599bcaea230e7dcd2892cc91c49319aeChristian Maeder-- * ENTITIES
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel Mance
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel Mancedata Entity = Entity
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel Mance { label :: Maybe String
a4a1b0cfce938fc38d5924b8fb6a7e140602ec5cFelix Gabriel Mance , entityKind :: EntityType
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance , cutIRI :: IRI }
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance deriving (Show, Typeable, Data)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancemkEntity :: EntityType -> IRI -> Entity
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancemkEntity = Entity Nothing
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancemkEntityLbl :: String -> EntityType -> IRI -> Entity
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancemkEntityLbl = Entity . Just
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Manceinstance Ord Entity where
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance compare (Entity _ ek1 ir1) (Entity _ ek2 ir2) = compare (ek1, ir1) (ek2, ir2)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Manceinstance Eq Entity where
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance e1 == e2 = compare e1 e2 == EQ
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
962c83276bc80dd04f4a83e47eb81524d5294a4fChristian Maederinstance GetRange Entity where
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance getRange = iriPos . cutIRI
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance rangeSpan = qNameRange . cutIRI
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mancedata EntityType =
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance Datatype
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance | Class
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance | ObjectProperty
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance | DataProperty
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance | AnnotationProperty
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance | NamedIndividual
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance deriving (Enum, Bounded, Show, Read, Eq, Ord, Typeable, Data)
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel ManceshowEntityType :: EntityType -> String
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel ManceshowEntityType e = case e of
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance Datatype -> datatypeC
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance Class -> classC
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance ObjectProperty -> objectPropertyC
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance DataProperty -> dataPropertyC
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance AnnotationProperty -> annotationPropertyC
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance NamedIndividual -> individualC
968930c7674ae3b63d308bf4fa651400aa263054Christian Maeder
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceentityTypes :: [EntityType]
1435782fda52a2898ea74e99088351d4f5b450dcChristian MaederentityTypes = [minBound .. maxBound]
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel MancepairSymbols :: Entity -> Entity -> Result Entity -- TODO: improve!
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancepairSymbols (Entity lb1 k1 i1) (Entity lb2 k2 i2) =
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance if k1 /= k2 then
962c83276bc80dd04f4a83e47eb81524d5294a4fChristian Maeder error "can't pair symbols of different kind"
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance else do
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance let rest x = drop 1 $ dropWhile (/= '#') x
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance pairLables lbl1 lbl2 = case (lbl1, lbl2) of
(Nothing, _) -> pairLables lbl2 lbl1
(Just l1, Just l2) | l1 /= l2 -> Just $ l1 ++ ", " ++ l2
_ -> lbl1
pairIRIs (QN p1 l1 t1 _e1 r1)
(QN _p2 l2 _t2 _e2 _r2) =
QN
{ namePrefix = p1
, localPart = if rest l1 == rest l2 then l1 else l1 ++ "_" ++ rest l2
, iriType = t1
, expandedIRI = ""
, iriPos = r1
}
return $ Entity (pairLables lb1 lb2) k1 $ pairIRIs i1 i2
-- * LITERALS
data TypedOrUntyped = Typed Datatype | Untyped (Maybe LanguageTag)
deriving (Show, Eq, Ord, Typeable, Data)
data Literal = Literal LexicalForm TypedOrUntyped | NumberLit FloatLit
deriving (Show, Eq, Ord, Typeable, Data)
-- | non-negative integers given by the sequence of digits
data NNInt = NNInt [Int] deriving (Eq, Ord, Typeable, Data)
instance Show NNInt where
show (NNInt l) = map intToDigit l
zeroNNInt :: NNInt
zeroNNInt = NNInt []
isZeroNNInt :: NNInt -> Bool
isZeroNNInt (NNInt l) = null l
data IntLit = IntLit
{ absInt :: NNInt
, isNegInt :: Bool }
deriving (Eq, Ord, Typeable, Data)
instance Show IntLit where
show (IntLit n b) = (if b then ('-' :) else id) $ show n
zeroInt :: IntLit
zeroInt = IntLit zeroNNInt False
isZeroInt :: IntLit -> Bool
isZeroInt (IntLit n _) = isZeroNNInt n
negNNInt :: Bool -> NNInt -> IntLit
negNNInt b n = IntLit n b
negInt :: IntLit -> IntLit
negInt (IntLit n b) = IntLit n $ not b
data DecLit = DecLit
{ truncDec :: IntLit
, fracDec :: NNInt }
deriving (Eq, Ord, Typeable, Data)
instance Show DecLit where
show (DecLit t f) = show t
++ if isZeroNNInt f then "" else
'.' : show f
isDecInt :: DecLit -> Bool
isDecInt = isZeroNNInt . fracDec
negDec :: Bool -> DecLit -> DecLit
negDec b (DecLit t f) = DecLit (if b then negInt t else t) f
data FloatLit = FloatLit
{ floatBase :: DecLit
, floatExp :: IntLit }
deriving (Eq, Ord, Typeable, Data)
instance Show FloatLit where
show (FloatLit b e) = show b
++ if isZeroInt e then "" else
'E' : show e ++ "F"
isFloatDec :: FloatLit -> Bool
isFloatDec = isZeroInt . floatExp
isFloatInt :: FloatLit -> Bool
isFloatInt f = isFloatDec f && isDecInt (floatBase f)
floatToInt :: FloatLit -> IntLit
floatToInt = truncDec . floatBase
intToDec :: IntLit -> DecLit
intToDec i = DecLit i zeroNNInt
decToFloat :: DecLit -> FloatLit
decToFloat d = FloatLit d zeroInt
intToFloat :: IntLit -> FloatLit
intToFloat = decToFloat . intToDec
abInt :: IntLit -> IntLit
abInt int = int {isNegInt = False}
abDec :: DecLit -> DecLit
abDec dec = dec {truncDec = abInt $ truncDec dec}
abFloat :: FloatLit -> FloatLit
abFloat f = f {floatBase = abDec $ floatBase f}
isNegDec :: DecLit -> Bool
isNegDec d = isNegInt $ truncDec d
numberName :: FloatLit -> String
numberName f
| isFloatInt f = integerS
| isFloatDec f = decimalS
| otherwise = floatS
cTypeS :: String
cTypeS = "^^"
-- * PROPERTY EXPRESSIONS
type InverseObjectProperty = ObjectPropertyExpression
data ObjectPropertyExpression = ObjectProp ObjectProperty
| ObjectInverseOf InverseObjectProperty
deriving (Show, Eq, Ord, Typeable, Data)
objPropToIRI :: ObjectPropertyExpression -> Individual
objPropToIRI opExp = case opExp of
ObjectProp u -> u
ObjectInverseOf objProp -> objPropToIRI objProp
type DataPropertyExpression = DataProperty
-- * DATA RANGES
data DataRange =
DataType Datatype [(ConstrainingFacet, RestrictionValue)]
| DataJunction JunctionType [DataRange]
| DataComplementOf DataRange
| DataOneOf [Literal]
deriving (Show, Eq, Ord, Typeable, Data)
-- * CLASS EXPERSSIONS
data ClassExpression =
Expression Class
| ObjectJunction JunctionType [ClassExpression]
| ObjectComplementOf ClassExpression
| ObjectOneOf [Individual]
| ObjectValuesFrom QuantifierType ObjectPropertyExpression ClassExpression
| ObjectHasValue ObjectPropertyExpression Individual
| ObjectHasSelf ObjectPropertyExpression
| ObjectCardinality (Cardinality ObjectPropertyExpression ClassExpression)
| DataValuesFrom QuantifierType DataPropertyExpression DataRange
| DataHasValue DataPropertyExpression Literal
| DataCardinality (Cardinality DataPropertyExpression DataRange)
deriving (Show, Eq, Ord, Typeable, Data)
-- * ANNOTATIONS
data Annotation = Annotation [Annotation] AnnotationProperty AnnotationValue
deriving (Show, Eq, Ord, Typeable, Data)
data AnnotationValue = AnnValue IRI | AnnValLit Literal
deriving (Show, Eq, Ord, Typeable, Data)