Translate.hs revision c505f62dff03727dc14a1f08be48208540d78d4a
{- |
Module : $Header$
Description : translate string to OWL2 valid names
Copyright : (c) C. Maeder, DFKI GmbH 2012
License : GPLv2 or higher, see LICENSE.txt
Maintainer : Christian.Maeder@dfki.de
Stability : provisional
Portability : portable
-}
module OWL2.Translate where
import Common.Id
import Common.ProofUtils
import Data.Char
import OWL2.AS
idToIRI :: Id -> QName
idToIRI = idToAnonIRI False
idToAnonIRI :: Bool -> Id -> QName
idToAnonIRI b i = nullQName
{ localPart = (if b then ('_' :) else id) . transString $ show i
, iriPos = rangeOfId i }
-- | translate to a valid OWL string
transString :: String -> String
transString str = let
x = 'X'
replaceChar1 d | d == x = [x, x] -- code out existing x!
| isAlphaNum d = [d]
| otherwise = x : replaceChar d
in case str of
"" -> [x]
c : s -> let l = replaceChar1 c in
(if isDigit c then [x, c]
else l) ++ concatMap replaceChar1 s
-- | injective replacement of special characters
replaceChar :: Char -> String
replaceChar c = if isAlphaNum c then [c] else lookupCharMap c