AS.hs revision 0c3badd7ad83eb89f64ef5ed1122c4fa856fb45d
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceModule : $Header$
81ec673ac5ab1493568d9ef7798b752ab8ee0e61Felix Gabriel ManceCopyright : (c) C. Maeder, Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceLicense : GPLv2 or higher, see LICENSE.txt
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceMaintainer : Christian.Maeder@dfki.de
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceStability : provisional
5d801400993c9671010d244646936d8fd435638cChristian MaederPortability : portable
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel ManceOWL 2 Functional Syntax constructs
5d801400993c9671010d244646936d8fd435638cChristian Maeder <http://www.w3.org/TR/2009/REC-owl2-syntax-20091027/#Functional-Style_Syntax>
5d801400993c9671010d244646936d8fd435638cChristian Maeder <http://www.w3.org/TR/owl2-manchester-syntax/>
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maederimport Data.Char (intToDigit)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceimport qualified Data.Map as Map
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mancedata IRIType = Full | Abbreviated | NodeID
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance deriving (Show, Eq, Ord)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance{- | full or abbreviated IRIs with a possible uri for the prefix
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance or a local part following a hash sign -}
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mancedata QName = QN
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance { namePrefix :: String
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance , localPart :: String
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance -- ^ the local part of a qualified name \"namePrefix:localPart\"
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance , iriType :: IRIType
0ec1551231bc5dfdcb3f2bd68fec7457fade7bfdFelix Gabriel Mance , expandedIRI :: String
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance -- ^ the associated namespace uri (not printed)
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder , iriPos :: Range
968930c7674ae3b63d308bf4fa651400aa263054Christian Maeder } deriving Show
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Manceinstance Eq QName where
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance p == q = compare p q == EQ
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Manceinstance Ord QName where
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance compare (QN p1 l1 b1 n1 _) (QN p2 l2 b2 n2 _) =
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance if null n1 || null n2 then compare (b1, p1, l1) (b2, p2, l2) else
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance compare n1 n2 -- compare fully expanded names only
fc7bd98aabe1bc26058660085e8c77d60a97bcecChristian Maederinstance GetRange QName where
fc7bd98aabe1bc26058660085e8c77d60a97bcecChristian Maeder getRange = iriPos
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceshowQN :: QName -> String
3c6b4f79cea11dd2acc2060bf1502b6ba9e905f2Felix Gabriel ManceshowQN q = (if iriType q /= Abbreviated then showQI else showQU) q
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- | show QName as abbreviated iri
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceshowQU :: QName -> String
852bd6145634dc2832b61c44678fe539bc1682d5Christian MaedershowQU (QN pre local _ _ _) =
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance if null pre then local else pre ++ ":" ++ local
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- | show QName in ankle brackets as full iris
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceshowQI :: QName -> String
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceshowQI = ('<' :) . (++ ">") . showQU
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancenullQName :: QName
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel MancenullQName = QN "" "" Abbreviated "" nullRange
544989bc1f6ed4bc0813334ffd934db0fb0010eaFelix Gabriel ManceisNullQName :: QName -> Bool
544989bc1f6ed4bc0813334ffd934db0fb0010eaFelix Gabriel ManceisNullQName qn = case qn of
544989bc1f6ed4bc0813334ffd934db0fb0010eaFelix Gabriel Mance QN "" "" _ "" _ -> True
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancedummyQName :: QName
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance QN "http" "//www.dfki.de/sks/hets/ontology/unamed" Full "" nullRange
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancemkQName :: String -> QName
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancemkQName s = nullQName { localPart = s }
852bd6145634dc2832b61c44678fe539bc1682d5Christian MaedersetQRange :: Range -> QName -> QName
852bd6145634dc2832b61c44678fe539bc1682d5Christian MaedersetQRange r q = q { iriPos = r }
ea3f858eb531d981df3ed00beeadd99cf025adecChristian MaedersetPrefix :: String -> QName -> QName
ea3f858eb531d981df3ed00beeadd99cf025adecChristian MaedersetPrefix s q = q { namePrefix = s }
75aaf82c430ad2a5cf159962b1c5c09255010fb4Felix Gabriel MancesetFull :: QName -> QName
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel MancesetFull q = q {iriType = Full}
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancetype IRI = QName
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance-- | checks if an IRI is an anonymous individual
1b1144abf7f95a4b23405b8d5604813cfe7b036aFelix Gabriel ManceisAnonymous :: IRI -> Bool
19e01e1a7e319063434bd86c8ecbc5f241ef9993Felix Gabriel ManceisAnonymous iri = iriType iri == NodeID
5a3ae0a9224276de25e709ef8788c1b9716cd206Christian Maeder-- | checks if a string (bound to be localPart of an IRI) contains \":\/\/\"
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel MancecssIRI :: String -> IRIType
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel MancecssIRI iri = if isInfixOf "://" iri then Full else Abbreviated
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- | prefix -> localname
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancetype PrefixMap = Map.Map String String
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel MancepredefPrefixes :: PrefixMap
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel Mance [ ("owl", "http://www.w3.org/2002/07/owl#")
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel Mance , ("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel Mance , ("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel Mance , ("xsd", "http://www.w3.org/2001/XMLSchema#")
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel Mance , ("", showQU dummyQName ++ "#") ]
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancetype LexicalForm = String
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancetype LanguageTag = String
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancetype ImportIRI = IRI
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancetype OntologyIRI = IRI
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancetype Class = IRI
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancetype Datatype = IRI
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancetype ObjectProperty = IRI
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancetype DataProperty = IRI
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancetype AnnotationProperty = IRI
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancetype NamedIndividual = IRI
9cb6af1a7632f12b60f592ce5eb2ac51e6bd33bbFelix Gabriel Mancetype Individual = IRI
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancedata EquivOrDisjoint = Equivalent | Disjoint
968930c7674ae3b63d308bf4fa651400aa263054Christian Maeder deriving (Show, Eq, Ord)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceshowEquivOrDisjoint :: EquivOrDisjoint -> String
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceshowEquivOrDisjoint ed = case ed of
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance Equivalent -> equivalentToC
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance Disjoint -> disjointWithC
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancedata DomainOrRange = ADomain | ARange
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance deriving (Show, Eq, Ord)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceshowDomainOrRange :: DomainOrRange -> String
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceshowDomainOrRange dr = case dr of
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance ADomain -> domainC
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance ARange -> rangeC
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancedata SameOrDifferent = Same | Different
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance deriving (Show, Eq, Ord)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel ManceshowSameOrDifferent :: SameOrDifferent -> String
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel ManceshowSameOrDifferent sd = case sd of
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance Same -> sameAsC
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance Different -> differentFromC
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancedata Relation =
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance EDRelation EquivOrDisjoint
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | SubPropertyOf
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | DRRelation DomainOrRange
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | SDRelation SameOrDifferent
968930c7674ae3b63d308bf4fa651400aa263054Christian Maeder deriving (Show, Eq, Ord)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceshowRelation :: Relation -> String
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix 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
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance Types -> typesC
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance DRRelation dr -> showDomainOrRange dr
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance SDRelation sd -> showSameOrDifferent sd
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"
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancegetDR :: Relation -> DomainOrRange
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancegetDR r = case r of
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance DRRelation dr -> dr
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance _ -> error "not domain or range"
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancegetSD :: Relation -> SameOrDifferent
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancegetSD s = case s of
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance SDRelation sd -> sd
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance _ -> error "not same or different"
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancedata Character =
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | InverseFunctional
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | Antisymmetric
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance deriving (Enum, Bounded, Show, Eq, Ord)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancedata PositiveOrNegative = Positive | Negative
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance deriving (Show, Eq, Ord)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancedata QuantifierType = AllValuesFrom | SomeValuesFrom
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance deriving (Show, Eq, Ord)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceshowQuantifierType :: QuantifierType -> String
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceshowQuantifierType ty = case ty of
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance AllValuesFrom -> onlyS
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance SomeValuesFrom -> someS
083b2687afdb676237f926bdb643b24027291d05Felix Gabriel Mance-- * Predefined IRI checkings
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel ManceisThing :: IRI -> Bool
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel ManceisThing = isOWLPredef predefClass
0c3badd7ad83eb89f64ef5ed1122c4fa856fb45dFelix Gabriel ManceisPredefObjProp :: IRI -> Bool
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel ManceisPredefObjProp = isOWLPredef predefObjProp
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel ManceisPredefDataProp :: IRI -> Bool
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel ManceisPredefDataProp = isOWLPredef predefDataProp
d850dba73b02f345f64a3546d0f0299c292f88d6Felix Gabriel ManceisPredefRDFSAnnoProp :: IRI -> Bool
0c3badd7ad83eb89f64ef5ed1122c4fa856fb45dFelix Gabriel ManceisPredefRDFSAnnoProp = checkPredef predefRDFSAnnoProps "rdfs"
d850dba73b02f345f64a3546d0f0299c292f88d6Felix Gabriel ManceisPredefOWLAnnoProp :: IRI -> Bool
0c3badd7ad83eb89f64ef5ed1122c4fa856fb45dFelix Gabriel ManceisPredefOWLAnnoProp = isOWLPredef predefOWLAnnoProps
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel ManceisPredefAnnoProp :: IRI -> Bool
d850dba73b02f345f64a3546d0f0299c292f88d6Felix Gabriel ManceisPredefAnnoProp iri = isPredefOWLAnnoProp iri || isPredefRDFSAnnoProp iri
6504b297e21d071d8fada2f732cabb6d8f7d38a2Felix Gabriel ManceisPredefPropOrClass :: IRI -> Bool
6504b297e21d071d8fada2f732cabb6d8f7d38a2Felix Gabriel ManceisPredefPropOrClass iri = isPredefAnnoProp iri || isPredefDataProp iri
6504b297e21d071d8fada2f732cabb6d8f7d38a2Felix Gabriel Mance || isPredefObjProp iri || isThing iri
4b7c9b9fec53befb553f2c9b11e30a4fe2235e03Felix Gabriel MancepredefIRIs :: [IRI]
4b7c9b9fec53befb553f2c9b11e30a4fe2235e03Felix Gabriel MancepredefIRIs = map (setPrefix "xsd" . mkQName) xsdKeys
4b7c9b9fec53befb553f2c9b11e30a4fe2235e03Felix Gabriel Mance ++ map (setPrefix "owl" . mkQName) owlNumbers
0c3badd7ad83eb89f64ef5ed1122c4fa856fb45dFelix Gabriel Mance ++ [setPrefix "rdf" (mkQName rdfsLiteral),
4b7c9b9fec53befb553f2c9b11e30a4fe2235e03Felix Gabriel Mance setPrefix "rdfs" $ mkQName xmlLiteral]
44985cbd4eb61dbc348617ebdd44a774e51dac07Christian MaederisDatatypeKey :: IRI -> Bool
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel ManceisDatatypeKey iri = any (\ (l, p) -> checkPredef l p iri) [(xsdKeys, "xsd"),
1b90322eaf59ded3de24fc891bd67bbd73ec2bfaFelix Gabriel Mance (owlNumbers, "owl"), ([xmlLiteral], "rdf"), ([rdfsLiteral], "rdfs")]
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel MancecheckPredef :: [String] -> String -> IRI -> Bool
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel MancecheckPredef sl pref u =
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance localPart u `elem` sl && elem (namePrefix u) ["", pref]
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance || showQU u `elem` map (Map.findWithDefault
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance (error $ "not predefined prefix: " ++ show pref)
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance pref (predefPrefixes `Map.difference`
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance Map.fromList [("", showQU dummyQName ++ "#")]) ++) sl
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel ManceisOWLPredef :: [String] -> IRI -> Bool
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel ManceisOWLPredef sl = checkPredef sl "owl"
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance-- | sets the correct prefix for the predefined datatypes
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel MancesetDatatypePrefix :: IRI -> IRI
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel MancesetDatatypePrefix iri = let lp = localPart iri in
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance if lp `elem` xsdKeys
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance then setPrefix "xsd" iri
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance else if lp `elem` owlNumbers
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance then setPrefix "owl" iri
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance else case lp of
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance "XMLLiteral" -> setPrefix "rdf" iri
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance "Literal" -> setPrefix "rdfs" iri
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance _ -> error $ showQU iri ++ " is not a predefined datatype"
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance-- | checks if the IRI is part of the built-in ones and puts the correct prefix
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel MancesetReservedPrefix :: IRI -> IRI
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel MancesetReservedPrefix iri
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance | isDatatypeKey iri && null (namePrefix iri) = setDatatypePrefix iri
d850dba73b02f345f64a3546d0f0299c292f88d6Felix Gabriel Mance | (isThing iri || isPredefDataProp iri || isPredefOWLAnnoProp iri
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance || isPredefObjProp iri) && null (namePrefix iri) = setPrefix "owl" iri
d850dba73b02f345f64a3546d0f0299c292f88d6Felix Gabriel Mance | isPredefRDFSAnnoProp iri = setPrefix "rdfs" iri
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance | otherwise = iri
4b7c9b9fec53befb553f2c9b11e30a4fe2235e03Felix Gabriel MancestripReservedPrefix :: IRI -> IRI
4b7c9b9fec53befb553f2c9b11e30a4fe2235e03Felix Gabriel MancestripReservedPrefix = mkQName . getPredefName
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance{- | returns the name of the predefined IRI (e.g <xsd:string> returns "string"
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance or <http://www.w3.org/2002/07/owl#real> returns "real") -}
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel MancegetPredefName :: IRI -> String
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel MancegetPredefName iri =
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance if namePrefix iri `elem` ["", "xsd", "rdf", "rdfs", "owl"]
0c3badd7ad83eb89f64ef5ed1122c4fa856fb45dFelix Gabriel Mance then localPart iri
771c32080c77497c6c023a3b1c422f7daf3773f7Felix Gabriel Mance else case mapMaybe (flip stripPrefix $ showQU iri)
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance $ Map.elems predefPrefixes of
3980dee81f793b601da33adea1b55753bab868a9Felix Gabriel Mance _ -> error $ showQU iri ++ " is not a predefined IRI"
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maederdata DatatypeCat = OWL2Number | OWL2String | OWL2Bool | Other
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maeder deriving (Show, Eq, Ord)
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian MaedergetDatatypeCat :: IRI -> DatatypeCat
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian MaedergetDatatypeCat iri = case isDatatypeKey iri of
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maeder | hasPrefXSD [booleanS] iri -> OWL2Bool
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maeder | hasPrefXSD xsdNumbers iri || checkPredef owlNumbers "owl" iri
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maeder -> OWL2Number
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maeder | hasPrefXSD xsdStrings iri -> OWL2String
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maeder | otherwise -> Other
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maeder False -> Other
a03c109eabfe250e4b57bdf44f37f53751a65df4Felix Gabriel MancehasPrefXSD :: [String] -> IRI -> Bool
a03c109eabfe250e4b57bdf44f37f53751a65df4Felix Gabriel MancehasPrefXSD sl = checkPredef sl "xsd"
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel MancefacetToIRI :: DatatypeFacet -> ConstrainingFacet
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel MancefacetToIRI = setPrefix "xsd" . mkQName . showFacet
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance-- * Cardinalities
fa544036407a8ec4be203ebd5e3bff225175e664Felix Gabriel Mancedata CardinalityType = MinCardinality | MaxCardinality | ExactCardinality
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance deriving (Show, Eq, Ord)
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel ManceshowCardinalityType :: CardinalityType -> String
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel ManceshowCardinalityType ty = case ty of
fa544036407a8ec4be203ebd5e3bff225175e664Felix Gabriel Mance MinCardinality -> minS
fa544036407a8ec4be203ebd5e3bff225175e664Felix Gabriel Mance MaxCardinality -> maxS
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mance ExactCardinality -> exactlyS
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mancedata Cardinality a b = Cardinality CardinalityType Int a (Maybe b)
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mance deriving (Show, Eq, Ord)
4b7c9b9fec53befb553f2c9b11e30a4fe2235e03Felix Gabriel Mancedata JunctionType = UnionOf | IntersectionOf
4b7c9b9fec53befb553f2c9b11e30a4fe2235e03Felix Gabriel Mance deriving (Show, Eq, Ord)
863fa65ac095659c6da1cde7fe7b839f1e7f60f9Felix Gabriel Mancetype ConstrainingFacet = IRI
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mancetype RestrictionValue = Literal
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mancedata Entity = Entity EntityType IRI deriving (Show, Eq, Ord)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Manceinstance GetRange Entity where
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance getRange (Entity _ iri) = iriPos iri
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mancedata EntityType =
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance | ObjectProperty
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance | DataProperty
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance | AnnotationProperty
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance | NamedIndividual
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance deriving (Enum, Bounded, Show, Read, Eq, Ord)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel ManceshowEntityType :: EntityType -> String
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel ManceshowEntityType e = case e of
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance Datatype -> datatypeC
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance Class -> classC
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance ObjectProperty -> objectPropertyC
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance DataProperty -> dataPropertyC
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance AnnotationProperty -> annotationPropertyC
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance NamedIndividual -> individualC
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel ManceentityTypes :: [EntityType]
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel ManceentityTypes = [minBound .. maxBound]
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancecutIRI :: Entity -> IRI
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancecutIRI (Entity _ iri) = iri
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mancedata TypedOrUntyped = Typed Datatype | Untyped (Maybe LanguageTag)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance deriving (Show, Eq, Ord)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mancedata Literal = Literal LexicalForm TypedOrUntyped | NumberLit FloatLit
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance deriving (Show, Eq, Ord)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance-- | non-negative integers given by the sequence of digits
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mancedata NNInt = NNInt [Int] deriving (Eq, Ord)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Manceinstance Show NNInt where
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance show (NNInt l) = map intToDigit l
431571057e88a650a974adec93ea4bb5173b6213Felix Gabriel MancezeroNNInt :: NNInt
431571057e88a650a974adec93ea4bb5173b6213Felix Gabriel MancezeroNNInt = NNInt []
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceisZeroNNInt :: NNInt -> Bool
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceisZeroNNInt (NNInt l) = null l
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancedata IntLit = IntLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder { absInt :: NNInt
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance , isNegInt :: Bool }
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance deriving (Eq, Ord)
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maederinstance Show IntLit where
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder show (IntLit n b) = (if b then ('-' :) else id) $ show n
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederzeroInt :: IntLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederzeroInt = IntLit zeroNNInt False
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederisZeroInt :: IntLit -> Bool
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederisZeroInt (IntLit n _) = isZeroNNInt n
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedernegNNInt :: Bool -> NNInt -> IntLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedernegNNInt b n = IntLit n b
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedernegInt :: IntLit -> IntLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedernegInt (IntLit n b) = IntLit n $ not b
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maederdata DecLit = DecLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder { truncDec :: IntLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder , fracDec :: NNInt }
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder deriving (Eq, Ord)
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maederinstance Show DecLit where
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder show (DecLit t f) = show t
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder ++ if isZeroNNInt f then "" else
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederisDecInt :: DecLit -> Bool
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederisDecInt = isZeroNNInt . fracDec
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedernegDec :: Bool -> DecLit -> DecLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedernegDec b (DecLit t f) = DecLit (if b then negInt t else t) f
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maederdata FloatLit = FloatLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder { floatBase :: DecLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder , floatExp :: IntLit }
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder deriving (Eq, Ord)
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maederinstance Show FloatLit where
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder show (FloatLit b e) = show b
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder ++ if isZeroInt e then "" else
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder 'E' : show e ++ "F"
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederisFloatDec :: FloatLit -> Bool
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederisFloatDec = isZeroInt . floatExp
cbb0a924599bcaea230e7dcd2892cc91c49319aeChristian MaederisFloatInt :: FloatLit -> Bool
d66846429fcdd6882e62c7e5b911f98b3812ff09Felix Gabriel ManceisFloatInt f = isFloatDec f && isDecInt (floatBase f)
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederfloatToInt :: FloatLit -> IntLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederfloatToInt = truncDec . floatBase
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederintToDec :: IntLit -> DecLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederintToDec i = DecLit i zeroNNInt
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederdecToFloat :: DecLit -> FloatLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederdecToFloat d = FloatLit d zeroInt
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederintToFloat :: IntLit -> FloatLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederintToFloat = decToFloat . intToDec
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederabInt :: IntLit -> IntLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederabInt int = int {isNegInt = False}
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederabDec :: DecLit -> DecLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederabDec dec = dec {truncDec = abInt $ truncDec dec}
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederabFloat :: FloatLit -> FloatLit
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederabFloat f = f {floatBase = abDec $ floatBase f}
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederisNegDec :: DecLit -> Bool
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederisNegDec d = isNegInt $ truncDec d
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaedernumberName :: FloatLit -> String
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder | isFloatInt f = integerS
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian Maeder | isFloatDec f = decimalS
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mance | otherwise = floatS
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel MancecTypeS :: String
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mance-- * PROPERTY EXPRESSIONS
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mancetype InverseObjectProperty = ObjectPropertyExpression
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mancedata ObjectPropertyExpression = ObjectProp ObjectProperty
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mance | ObjectInverseOf InverseObjectProperty
c704da29ad5d9d00c07e75f9109442d178dd990bFelix Gabriel Mance deriving (Show, Eq, Ord)
cbb0a924599bcaea230e7dcd2892cc91c49319aeChristian Maedertype DataPropertyExpression = DataProperty
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel Mance-- * DATA RANGES
a4a1b0cfce938fc38d5924b8fb6a7e140602ec5cFelix Gabriel Mancedata DataRange =
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance DataType Datatype [(ConstrainingFacet, RestrictionValue)]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | DataJunction JunctionType [DataRange]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | DataComplementOf DataRange
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | DataOneOf [Literal]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance deriving (Show, Eq, Ord)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- * CLASS EXPERSSIONS
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancedata ClassExpression =
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance Expression Class
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | ObjectJunction JunctionType [ClassExpression]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | ObjectComplementOf ClassExpression
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | ObjectOneOf [Individual]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | ObjectValuesFrom QuantifierType ObjectPropertyExpression ClassExpression
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance | ObjectHasValue ObjectPropertyExpression Individual
fa544036407a8ec4be203ebd5e3bff225175e664Felix Gabriel Mance | ObjectHasSelf ObjectPropertyExpression
fa544036407a8ec4be203ebd5e3bff225175e664Felix Gabriel Mance | ObjectCardinality (Cardinality ObjectPropertyExpression ClassExpression)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance | DataValuesFrom QuantifierType DataPropertyExpression DataRange
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance | DataHasValue DataPropertyExpression Literal
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance | DataCardinality (Cardinality DataPropertyExpression DataRange)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance deriving (Show, Eq, Ord)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance-- * ANNOTATIONS
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancedata Annotation = Annotation [Annotation] AnnotationProperty AnnotationValue
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance deriving (Show, Eq, Ord)
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancedata AnnotationValue =
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance | AnnValLit Literal
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance deriving (Show, Eq, Ord)