AS.hs revision 1b90322eaf59ded3de24fc891bd67bbd73ec2bfa
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederModule : $Header$
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederCopyright : (c) C. Maeder
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederMaintainer : Christian.Maeder@dfki.de
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederStability : provisional
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederPortability : portable
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederOWL 2 Functional Syntax constructs
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder <http://www.w3.org/TR/2009/REC-owl2-syntax-20091027/#Functional-Style_Syntax>
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder <http://www.w3.org/TR/owl2-manchester-syntax/>
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederimport Data.Char (intToDigit)
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederimport Data.Maybe (fromJust)
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederimport qualified Data.Map as Map
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederdata IRIType = Full | Abbreviated | NodeID
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder deriving (Show, Eq, Ord)
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder{- | full or abbreviated IRIs with a possible uri for the prefix
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder or a local part following a hash sign -}
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederdata QName = QN
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder { namePrefix :: String
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder , localPart :: String
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder -- ^ the local part of a qualified name \"namePrefix:localPart\"
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder , iriType :: IRIType
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder , expandedIRI :: String
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder -- ^ the associated namespace uri (not printed)
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder , iriPos :: Range
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder } deriving Show
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederinstance Eq QName where
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder p == q = compare p q == EQ
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederinstance Ord QName where
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder compare (QN p1 l1 b1 n1 _) (QN p2 l2 b2 n2 _) =
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder if null n1 || null n2 then compare (b1, p1, l1) (b2, p2, l2) else
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder compare n1 n2 -- compare fully expanded names only
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederinstance GetRange QName where
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder getRange = iriPos
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedershowQN :: QName -> String
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedershowQN q = (if iriType q /= Abbreviated then showQI else showQU) q
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder-- | show QName as abbreviated iri
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedershowQU :: QName -> String
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedershowQU (QN pre local _ _ _) =
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder if null pre then local else pre ++ ":" ++ local
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder-- | show QName in ankle brackets as full iris
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedershowQI :: QName -> String
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedershowQI = ('<' :) . (++ ">") . showQU
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedernullQName :: QName
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedernullQName = QN "" "" Abbreviated "" nullRange
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederdummyQName :: QName
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder QN "http" "//www.dfki.de/sks/hets/ontology/unamed" Full "" nullRange
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedermkQName :: String -> QName
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedermkQName s = nullQName { localPart = s }
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedersetQRange :: Range -> QName -> QName
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedersetQRange r q = q { iriPos = r }
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedersetPrefix :: String -> QName -> QName
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedersetPrefix s q = q { namePrefix = s }
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedersetDatatypePrefix :: QName -> QName
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedersetDatatypePrefix iri = let lp = localPart iri in
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder if lp `elem` xsdKeys
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder then setPrefix "xsd" iri
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder else if lp `elem` owlNumbers
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder then setPrefix "owl" iri
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder else case lp of
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder "XMLLiteral" -> setPrefix "rdf" iri
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder "Literal" -> setPrefix "rdfs" iri
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder _ -> error $ showQU iri ++ " is not a predefined datatype"
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedersetReservedPrefix :: QName -> QName
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedersetReservedPrefix iri
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder | isDatatypeKey iri && null (namePrefix iri) = setDatatypePrefix iri
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder | isThing iri && null (namePrefix iri) = setPrefix "owl" iri
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder | otherwise = iri
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedersetFull :: QName -> QName
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedersetFull q = q {iriType = Full}
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maedertype IRI = QName
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder-- | checks if an IRI is an anonymous individual
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederisAnonymous :: IRI -> Bool
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederisAnonymous iri = iriType iri == NodeID
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder-- | checks if a string (bound to be localPart of an IRI) contains \":\/\/\"
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedercssIRI :: String -> IRIType
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedercssIRI iri = if isInfixOf "://" iri then Full else Abbreviated
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder-- | prefix -> localname
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maedertype PrefixMap = Map.Map String String
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederpredefPrefixes :: PrefixMap
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederpredefPrefixes = Map.fromList
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder [ ("owl", "http://www.w3.org/2002/07/owl#")
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder , ("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder , ("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder , ("xsd", "http://www.w3.org/2001/XMLSchema#")
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder , ("", showQU dummyQName ++ "#") ]
|| showQU u `elem` map (Map.findWithDefault
"http://www.w3.org/2001/XMLSchema#" $ showQU dt