Rename.hs revision 1341e758a8a0785dd7063b93aed3989f13b36f2a
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederimport qualified Data.Map as Map
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederimport qualified Data.Set as Set
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederimport qualified Common.AS_Annotation as Common.Annotation
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederimport Data.List (find, nub)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederimport Data.Char (isDigit)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maedertype TranslationMap = Map.Map String String
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederclass PrefixClass a where
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder mv :: TranslationMap -> a -> a
329c739bc05b8ce8d54f81071d0826ff771d1f78Christian MaedermaybeRename :: (PrefixClass a) => TranslationMap -> Maybe a -> Maybe a
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian MaedermaybeRename tMap = fmap $ mv tMap
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederinstance PrefixClass PrefixMap where
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder mv tMap oldPs =
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder foldl (\ ns (pre, ouri) ->
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder Map.insert (Map.findWithDefault pre pre tMap) ouri ns)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederinstance PrefixClass QName where
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder mv tMap old = let pre = namePrefix old in
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder old { namePrefix = Map.findWithDefault pre pre tMap }
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederinstance PrefixClass Sign where
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder mv tMap (Sign p1 p2 p3 p4 p5 p6 p7) =
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder Sign (Set.map (mv tMap) p1)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder (Set.map (mv tMap) p2)
ac4396c9f44a76c5c97925954ee49b4a91d8dd88Christian Maeder (Set.map (mv tMap) p3)
ac4396c9f44a76c5c97925954ee49b4a91d8dd88Christian Maeder (Set.map (mv tMap) p4)
ac4396c9f44a76c5c97925954ee49b4a91d8dd88Christian Maeder (Set.map (mv tMap) p5)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder (Set.map (mv tMap) p6)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederinstance PrefixClass (DomainOrRangeOrFunc a) where
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder mv tMap dor = case dor of
a38f3d84e592184830fa308c5dab3f7c71e4464fChristian Maeder DomainOrRange ty des -> DomainOrRange ty $ mv tMap des
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder RDRange dr -> RDRange $ mv tMap dr
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederinstance PrefixClass SignAxiom where
329c739bc05b8ce8d54f81071d0826ff771d1f78Christian Maeder mv tMap signAxiom =
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder case signAxiom of
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder Subconcept cId1 cId2 ->
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder Subconcept (mv tMap cId1)
a208edf329751a734895216ad5b0e334a9ac6a44Christian Maeder (mv tMap cId2)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder Role rdr id1 ->
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder Role (mv tMap rdr) (mv tMap id1)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder Data rdr id1 ->
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder Data (mv tMap rdr) (mv tMap id1)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder Conceptmembership iId des ->
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder Conceptmembership (mv tMap iId)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder (mv tMap des)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederinstance PrefixClass (Common.Annotation.Named Axiom) where
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder mv tMap sent = sent {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederinstance PrefixClass Entity where
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder mv tMap (Entity ty euri) = Entity ty $ mv tMap euri
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederinstance PrefixClass Literal where
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder mv tMap lit = case lit of
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder Literal l (Typed curi) ->
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder Literal l $ Typed $ mv tMap curi
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederinstance PrefixClass ObjectPropertyExpression where
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder mv tMap opExp = case opExp of
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder ObjectProp opuri -> ObjectProp (mv tMap opuri)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder ObjectInverseOf invOp -> ObjectInverseOf (mv tMap invOp)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederinstance PrefixClass DataRange where
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder let rnRest (facet, value) = (facet, mv tMap value)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder in case dr of
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder DataType druri restrList ->
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder DataType (mv tMap druri) (map rnRest restrList)
testAndInteg (pre, oiri) (old, tm) = case Map.lookup pre old of
Nothing -> (Map.insert pre oiri old, tm)
in fromJust $ find (not . flip Map.member nameMap)
if Map.null tm then return (addSign s1 s2) {prefixMap = pm}