AS.hs revision 80875f917d741946a39d0ec0b5721e46ba609823
c797f343be2f3619bb1f5569753166ec49d27bdbChristian Maeder{-# LANGUAGE DeriveDataTypeable #-}
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederCopyright : (c) C. Maeder, Felix Gabriel Mance
c797f343be2f3619bb1f5569753166ec49d27bdbChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
c797f343be2f3619bb1f5569753166ec49d27bdbChristian MaederMaintainer : Alexander.Koslowski@st.ovgu.de
c797f343be2f3619bb1f5569753166ec49d27bdbChristian MaederStability : provisional
f3a94a197960e548ecd6520bb768cb0d547457bbChristian MaederPortability : portable
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian 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/>
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maederimport Data.Char (intToDigit)
8b9fda012e5ee53b7b2320c0638896a0ff6e99f3Christian Maederimport qualified Data.Map as Map
8b9fda012e5ee53b7b2320c0638896a0ff6e99f3Christian Maederimport qualified Data.Set as Set
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian Maeder-- | checks if an IRI is an anonymous individual
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaederisAnonymous :: IRI -> Bool
04dada28736b4a237745e92063d8bdd49a362debChristian MaederisAnonymous i = prefixName i == "_" && isBlankNode i
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian Maeder-- | prefix -> localname
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype PrefixMap = Map.Map String String
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederpredefPrefixes :: PrefixMap
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian MaederpredefPrefixes = Map.fromList
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder [ ("owl", "http://www.w3.org/2002/07/owl#")
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder , ("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder , ("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder , ("xsd", "http://www.w3.org/2001/XMLSchema#")
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder , ("", showIRICompact dummyIRI ++ "#") ]
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype LexicalForm = String
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype LanguageTag = String
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype ImportIRI = IRI
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype OntologyIRI = IRI
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype Class = IRI
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype Datatype = IRI
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype ObjectProperty = IRI
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maedertype DataProperty = IRI
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maedertype AnnotationProperty = IRI
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maedertype Individual = IRI
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maederdata EquivOrDisjoint = Equivalent | Disjoint
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedershowEquivOrDisjoint :: EquivOrDisjoint -> String
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian MaedershowEquivOrDisjoint ed = case ed of
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder Equivalent -> equivalentToC
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder Disjoint -> disjointWithC
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maederdata DomainOrRange = ADomain | ARange
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedershowDomainOrRange :: DomainOrRange -> String
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedershowDomainOrRange dr = case dr of
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder ADomain -> domainC
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder ARange -> rangeC
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maederdata SameOrDifferent = Same | Different
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedershowSameOrDifferent :: SameOrDifferent -> String
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedershowSameOrDifferent sd = case sd of
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder Same -> sameAsC
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder Different -> differentFromC
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maederdata Relation =
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder EDRelation EquivOrDisjoint
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder | SubPropertyOf
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder | DRRelation DomainOrRange
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder | SDRelation SameOrDifferent
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder deriving (Show, Eq, Ord, Typeable, Data)
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedershowRelation :: Relation -> String
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedershowRelation r = case r of
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder EDRelation ed -> showEquivOrDisjoint ed
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder SubPropertyOf -> subPropertyOfC
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder InverseOf -> inverseOfC
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder SubClass -> subClassOfC
15bb922b665fcd44c6230a1202785d0c7890e90cChristian Maeder Types -> typesC
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder DRRelation dr -> showDomainOrRange dr
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder SDRelation sd -> showSameOrDifferent sd
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian MaedergetED :: Relation -> EquivOrDisjoint
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedergetED r = case r of
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder EDRelation ed -> ed
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder _ -> error "not domain or range"
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedergetDR :: Relation -> DomainOrRange
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedergetDR r = case r of
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder DRRelation dr -> dr
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder _ -> error "not domain or range"
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedergetSD :: Relation -> SameOrDifferent
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedergetSD s = case s of
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder SDRelation sd -> sd
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder _ -> error "not same or different"
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maederdata Character =
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder | InverseFunctional
04dada28736b4a237745e92063d8bdd49a362debChristian Maeder | Irreflexive
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder | Antisymmetric
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder deriving (Enum, Bounded, Show, Eq, Ord, Typeable, Data)
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maederdata PositiveOrNegative = Positive | Negative
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maederdata QuantifierType = AllValuesFrom | SomeValuesFrom
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedershowQuantifierType :: QuantifierType -> String
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedershowQuantifierType ty = case ty of
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder AllValuesFrom -> onlyS
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder SomeValuesFrom -> someS
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder-- * Predefined IRI checkings
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederthingMap :: PreDefMaps
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaederthingMap = makeOWLPredefMaps predefClass
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederisThing :: IRI -> Bool
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederisThing = checkPredef thingMap
15bb922b665fcd44c6230a1202785d0c7890e90cChristian MaedermakePredefObjProp :: PreDefMaps
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedermakePredefObjProp = makeOWLPredefMaps predefObjProp
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaederisPredefObjProp :: IRI -> Bool
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaederisPredefObjProp = checkPredef makePredefObjProp
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedermakePredefDataProp :: PreDefMaps
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedermakePredefDataProp = makeOWLPredefMaps predefDataProp
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaederisPredefDataProp :: IRI -> Bool
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederisPredefDataProp = checkPredef makePredefDataProp
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaedermakePredefRDFSAnnoProp :: PreDefMaps
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaedermakePredefRDFSAnnoProp = preDefMaps predefRDFSAnnoProps "rdfs"
e76e6a43f51438215737d6fc176c89da05bb86daChristian MaederisPredefRDFSAnnoProp :: IRI -> Bool
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaederisPredefRDFSAnnoProp = checkPredef makePredefRDFSAnnoProp
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaedermakePredefOWLAnnoProp :: PreDefMaps
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaedermakePredefOWLAnnoProp = makeOWLPredefMaps predefOWLAnnoProps
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederisPredefOWLAnnoProp :: IRI -> Bool
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaederisPredefOWLAnnoProp = checkPredef makePredefOWLAnnoProp
962d5c684e2b86d1f9c556c096b426e10cc74026Christian MaederisPredefAnnoProp :: IRI -> Bool
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederisPredefAnnoProp i = isPredefOWLAnnoProp i || isPredefRDFSAnnoProp i
962d5c684e2b86d1f9c556c096b426e10cc74026Christian MaederisPredefPropOrClass :: IRI -> Bool
962d5c684e2b86d1f9c556c096b426e10cc74026Christian MaederisPredefPropOrClass i = isPredefAnnoProp i || isPredefDataProp i
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder || isPredefObjProp i || isThing i
962d5c684e2b86d1f9c556c096b426e10cc74026Christian MaederpredefIRIs :: Set.Set IRI
962d5c684e2b86d1f9c556c096b426e10cc74026Christian MaederpredefIRIs = Set.fromList $ map (setPrefix "xsd" . mkIRI) xsdKeys
962d5c684e2b86d1f9c556c096b426e10cc74026Christian Maeder ++ map (setPrefix "owl" . mkIRI) owlNumbers
962d5c684e2b86d1f9c556c096b426e10cc74026Christian Maeder ++ map (setPrefix "rdf" . mkIRI) [rdfsLiteral, stringS]
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder ++ [setPrefix "rdfs" $ mkIRI xmlLiteral]
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaederisDatatypeKey :: IRI -> Bool
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaederisDatatypeKey = not . null . isDatatypeKeyAux
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederxsdMap :: PreDefMaps
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederxsdMap = makeXsdMap xsdKeys
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederowlNumbersMap :: PreDefMaps
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederowlNumbersMap = makeOWLPredefMaps owlNumbers
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederrdfMap :: PreDefMaps
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederrdfMap = preDefMaps [xmlLiteral, stringS] "rdf"
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaederrdfsMap :: PreDefMaps
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaederrdfsMap = preDefMaps [rdfsLiteral] "rdfs"
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaederisDatatypeKeyAux :: IRI -> [(String, String)]
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaederisDatatypeKeyAux i = mapMaybe (`checkPredefAux` i)
c797f343be2f3619bb1f5569753166ec49d27bdbChristian Maeder [ xsdMap, owlNumbersMap, rdfMap, rdfsMap ]
15bb922b665fcd44c6230a1202785d0c7890e90cChristian Maedertype PreDefMaps = ([String], String, String)
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian MaederpreDefMaps :: [String] -> String -> PreDefMaps
Just puri = Map.lookup pref predefPrefixes
Just sp = stripPrefix "http://www.w3.org/" puri
Just q -> case stripPrefix "w3.org/" q of
case stripPrefix "http://www." ex of
Just r | r == "w3.org/" ++ exPref ++ lp -- || r == lp
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