Morphism.hs revision 2713ec15465bd1e643f6310d7048b5a30ad55c83
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova{- |
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina SojakovaModule : $Header$
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina SojakovaDescription : OWL Morphisms
097b7fb3f8f90e87120d30bf37a1d89fe0ddfaf0Kristina SojakovaCopyright : (c) Dominik Luecke, 2008
94e2e03f6efde106de095ef4ea0ec87f74955a31Kristina SojakovaLicense : GPLv2 or higher, see LICENSE.txt
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu
211c5fb252e0a776baad9a4857ab198659289a4aKristina SojakovaMaintainer : luecke@informatik.uni-bremen.de
94e2e03f6efde106de095ef4ea0ec87f74955a31Kristina SojakovaStability : provisional
211c5fb252e0a776baad9a4857ab198659289a4aKristina SojakovaPortability : portable
211c5fb252e0a776baad9a4857ab198659289a4aKristina Sojakova
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina SojakovaMorphisms for OWL
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova-}
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakovamodule OWL2.Morphism
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ( OWLMorphism (..)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , isOWLInclusion
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , inclOWLMorphism
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova , legalMor
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , composeMor
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , cogeneratedSign
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , generatedSign
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , matchesSym
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , statSymbItems
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , statSymbMapItems
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova , inducedFromMor
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova , symMapOf
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , mapSen
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova ) where
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakovaimport OWL2.AS
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakovaimport OWL2.MS
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakovaimport OWL2.Sign
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakovaimport OWL2.ManchesterPrint()
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakovaimport OWL2.StaticAnalysis
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakovaimport OWL2.Symbols
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakovaimport Common.DocUtils
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakovaimport Common.Doc
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakovaimport Common.Result
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakovaimport Common.Lib.State (execState)
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakovaimport Common.Lib.Rel (setToMap)
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakovaimport Control.Monad
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakovaimport Data.Maybe
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakovaimport qualified Data.Map as Map
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakovaimport qualified Data.Set as Set
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakovadata OWLMorphism = OWLMorphism
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova { osource :: Sign
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova , otarget :: Sign
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova , mmaps :: Map.Map Entity IRI
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova } deriving (Show, Eq, Ord)
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina SojakovainclOWLMorphism :: Sign -> Sign -> OWLMorphism
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina SojakovainclOWLMorphism s t = OWLMorphism
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova { osource = s
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova , otarget = t
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova , mmaps = Map.empty }
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovaisOWLInclusion :: OWLMorphism -> Bool
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina SojakovaisOWLInclusion m = Map.null (mmaps m) && isSubSign (osource m) (otarget m)
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina SojakovasymMap :: Map.Map Entity IRI -> Map.Map Entity Entity
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina SojakovasymMap = Map.mapWithKey (\ (Entity ty _) -> Entity ty)
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina SojakovainducedElems :: Map.Map Entity IRI -> [Entity]
81d28e8372831ae5e6054d8d2212f0114b09b79aKristina SojakovainducedElems = Map.elems . symMap
81d28e8372831ae5e6054d8d2212f0114b09b79aKristina Sojakova
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina SojakovainducedSign :: Map.Map Entity IRI -> Sign -> Sign
81d28e8372831ae5e6054d8d2212f0114b09b79aKristina SojakovainducedSign m = execState $ do
81d28e8372831ae5e6054d8d2212f0114b09b79aKristina Sojakova mapM_ (modEntity Set.delete) $ Map.keys m
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder mapM_ (modEntity Set.insert) $ inducedElems m
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian MaederinducedFromMor :: Map.Map RawSymb RawSymb -> Sign -> Result OWLMorphism
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina SojakovainducedFromMor rm sig = do
81d28e8372831ae5e6054d8d2212f0114b09b79aKristina Sojakova let syms = symOf sig
81d28e8372831ae5e6054d8d2212f0114b09b79aKristina Sojakova mm <- foldM (\ m p -> case p of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (ASymbol s@(Entity _ v), ASymbol (Entity _ u)) ->
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova if Set.member s syms
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova then return $ if u == v then m else Map.insert s u m
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova else fail $ "unknown symbol: " ++ showDoc s "\n" ++ shows sig ""
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova (AnUri v, AnUri u) -> case filter (`Set.member` syms)
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova $ map (`Entity` v) entityTypes of
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder [] -> fail $ "unknown symbol: " ++ showDoc v "\n" ++ shows sig ""
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova l -> return $ if u == v then m else foldr (`Map.insert` u) m l
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova _ -> error "OWL2.Morphism.inducedFromMor") Map.empty $ Map.toList rm
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova return OWLMorphism
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova { osource = sig
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina Sojakova , otarget = inducedSign mm sig
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , mmaps = mm }
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovasymMapOf :: OWLMorphism -> Map.Map Entity Entity
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovasymMapOf mor = Map.union (symMap $ mmaps mor) $ setToMap $ symOf $ osource mor
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maederinstance Pretty OWLMorphism where
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder pretty m = let
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova s = osource m
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova srcD = specBraces $ space <> pretty s
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova t = otarget m
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova in if isOWLInclusion m then
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova if isSubSign t s then
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova fsep [text "identity morphism over", srcD]
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova else fsep
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova [ text "inclusion morphism of"
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova , srcD
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova , text "extended with"
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova , pretty $ Set.difference (symOf t) $ symOf s ]
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova else fsep
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova [ pretty $ mmaps m
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova , colon <+> srcD, mapsto <+> specBraces (space <> pretty t) ]
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova
12d9bff7c82145a8b68bfb8553688172655c926eKristina SojakovalegalMor :: OWLMorphism -> Bool
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovalegalMor m = let mm = mmaps m in
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova Set.isSubsetOf (Map.keysSet mm) (symOf $ osource m)
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova && Set.isSubsetOf (Set.fromList $ inducedElems mm) (symOf $ otarget m)
12d9bff7c82145a8b68bfb8553688172655c926eKristina Sojakova
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovagetIri :: EntityType -> IRI -> Map.Map Entity IRI -> IRI
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovagetIri ty u = fromMaybe u . Map.lookup (Entity ty u)
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovacomposeMor :: OWLMorphism -> OWLMorphism -> Result OWLMorphism
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovacomposeMor m1 m2 =
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova let nm = Set.fold (\ s@(Entity ty u) -> let
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova t = getIri ty u $ mmaps m1
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova r = getIri ty t $ mmaps m2
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova in if r == u then id else Map.insert s r) Map.empty
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova . symOf $ osource m1
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova in return m1
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova { otarget = otarget m2
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova , mmaps = nm }
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovacogeneratedSign :: Set.Set Entity -> Sign -> Result OWLMorphism
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovacogeneratedSign s sign =
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova let sig2 = execState (mapM_ (modEntity Set.delete) $ Set.toList s) sign
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova in if isSubSign sig2 sign then return $ inclOWLMorphism sig2 sign else
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova fail "non OWL2 subsignatures for (co)generatedSign"
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovageneratedSign :: Set.Set Entity -> Sign -> Result OWLMorphism
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovageneratedSign s sign = cogeneratedSign (Set.difference (symOf sign) s) sign
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova
12d9bff7c82145a8b68bfb8553688172655c926eKristina SojakovamatchesSym :: Entity -> RawSymb -> Bool
12d9bff7c82145a8b68bfb8553688172655c926eKristina SojakovamatchesSym e@(Entity _ u) r = case r of
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova ASymbol s -> s == e
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova AnUri s -> s == u
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovastatSymbItems :: [SymbItems] -> [RawSymb]
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovastatSymbItems = concatMap
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova $ \ (SymbItems m us) -> case m of
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova Nothing -> map AnUri us
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova Just ty -> map (ASymbol . Entity ty) us
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovastatSymbMapItems :: [SymbMapItems] -> Result (Map.Map RawSymb RawSymb)
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovastatSymbMapItems =
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova foldM (\ m (s, t) -> case Map.lookup s m of
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova Nothing -> return $ Map.insert s t m
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder Just u -> case (u, t) of
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder (AnUri su, ASymbol (Entity _ tu)) | su == tu ->
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova return $ Map.insert s t m
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova (ASymbol (Entity _ su), AnUri tu) | su == tu ->
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova return m
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova _ -> if u == t then return m else
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova fail $ "differently mapped symbol: " ++ showDoc s "\nmapped to "
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova ++ showDoc u " and " ++ showDoc t "")
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova Map.empty
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova . concatMap (\ (SymbMapItems m us) ->
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova let ps = map (\ (u, v) -> (u, fromMaybe u v)) us in
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova case m of
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova Nothing -> map (\ (s, t) -> (AnUri s, AnUri t)) ps
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova Just ty -> let mS = ASymbol . Entity ty in
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova map (\ (s, t) -> (mS s, mS t)) ps)
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovamapAnno :: Map.Map Entity IRI -> Annotation -> Annotation
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovamapAnno m annt = case annt of
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder Annotation l a e -> Annotation l (getIri AnnotationProperty a m) e
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian MaedermapAnnoList :: Map.Map Entity IRI -> Annotations -> Annotations
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovamapAnnoList m ans = map (mapAnno m) ans
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovamapSen :: OWLMorphism -> Axiom -> Result Axiom
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovamapSen m = return . mapAxiom (mmaps m)
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova
b470a3e54a4289b4189906e41f0c04578c85619dKristina SojakovamapObjExpr :: Map.Map Entity IRI -> ObjectPropertyExpression
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova -> ObjectPropertyExpression
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovamapObjExpr m ope = case ope of
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova ObjectProp u -> ObjectProp $ getIri ObjectProperty u m
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ObjectInverseOf o -> ObjectInverseOf $ mapObjExpr m o
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovamapDRange :: Map.Map Entity IRI -> DataRange -> DataRange
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovamapDRange m dr = case dr of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova DataType u l -> DataType (getIri Datatype u m) l
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina Sojakova DataJunction j l -> DataJunction j (map (mapDRange m) l)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova DataComplementOf d -> DataComplementOf $ mapDRange m d
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova DataOneOf _ -> dr
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina Sojakova
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovamapDataExpr :: Map.Map Entity IRI -> DataPropertyExpression
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -> DataPropertyExpression
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina SojakovamapDataExpr m dpe = getIri DataProperty dpe m
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovagetClassIri :: IRI -> Map.Map Entity IRI -> IRI
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovagetClassIri = getIri Class
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovagetIndIri :: IRI -> Map.Map Entity IRI -> IRI
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovagetIndIri = getIri NamedIndividual
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina Sojakova
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovamapCard :: (a -> b) -> (c -> d) -> Cardinality a c -> Cardinality b d
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovamapCard f g (Cardinality ty i a mb) =
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina Sojakova Cardinality ty i (f a) $ fmap g mb
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovamapDescr :: Map.Map Entity IRI -> ClassExpression -> ClassExpression
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovamapDescr m desc = case desc of
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder Expression u -> Expression $ getClassIri u m
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina Sojakova ObjectJunction ty ds -> ObjectJunction ty $ map (mapDescr m) ds
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ObjectComplementOf d -> ObjectComplementOf $ mapDescr m d
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder ObjectOneOf is -> ObjectOneOf $ map (`getIndIri` m) is
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ObjectValuesFrom ty o d -> ObjectValuesFrom ty (mapObjExpr m o)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova $ mapDescr m d
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ObjectHasSelf o -> ObjectHasSelf $ mapObjExpr m o
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ObjectHasValue o i -> ObjectHasValue (mapObjExpr m o) $ getIndIri i m
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina Sojakova ObjectCardinality c -> ObjectCardinality
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova $ mapCard (mapObjExpr m) (mapDescr m) c
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina Sojakova DataValuesFrom ty d ds dr -> DataValuesFrom ty (mapDataExpr m d)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (map (mapDataExpr m) ds) $ mapDRange m dr
345d3dcc9f809776009851c446916fc770aa428dKristina Sojakova DataHasValue d c -> DataHasValue (mapDataExpr m d) c
345d3dcc9f809776009851c446916fc770aa428dKristina Sojakova DataCardinality c -> DataCardinality
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova $ mapCard (mapDataExpr m) (mapDRange m) c
345d3dcc9f809776009851c446916fc770aa428dKristina Sojakova
345d3dcc9f809776009851c446916fc770aa428dKristina SojakovamapFact :: Map.Map Entity IRI -> Fact -> Fact
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovamapFact m f = case f of
a3a6b6ebe9c2d1dc3554e44779dc7361a90e7617Kristina Sojakova ObjectPropertyFact pn op i -> ObjectPropertyFact
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova pn (mapObjExpr m op) (i `getIndIri` m)
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova DataPropertyFact pn dp l -> DataPropertyFact
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova pn (mapDataExpr m dp) l
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina SojakovamapAnnList :: Map.Map Entity IRI -> (a -> a) ->
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder AnnotatedList a -> AnnotatedList a
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina SojakovamapAnnList m f (AnnotatedList anl) =
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova let ans = map fst anl
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova l = map snd anl
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova in AnnotatedList $ zip (map (mapAnnoList m) ans) (map f l)
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovamapLFB :: Map.Map Entity IRI -> ListFrameBit -> ListFrameBit
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina SojakovamapLFB m lfb = case lfb of
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova AnnotationBit a -> AnnotationBit
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova $ mapAnnList m (flip (getIri AnnotationProperty) m) a
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova ObjectBit a -> ObjectBit $ mapAnnList m (mapObjExpr m) a
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova DataBit a -> DataBit $ mapAnnList m (mapDataExpr m) a
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova IndividualSameOrDifferent a ->
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova IndividualSameOrDifferent $ mapAnnList m (`getIndIri` m) a
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova DataPropRange a -> DataPropRange $ mapAnnList m (mapDRange m) a
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova IndividualFacts a -> IndividualFacts $ mapAnnList m (mapFact m) a
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova ExpressionBit a -> ExpressionBit $ mapAnnList m (mapDescr m) a
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova ObjectCharacteristics _ -> lfb
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina SojakovamapAFB :: Map.Map Entity IRI -> AnnFrameBit -> AnnFrameBit
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian MaedermapAFB m afb = case afb of
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova DatatypeBit dr -> DatatypeBit $ mapDRange m dr
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ClassDisjointUnion ce -> ClassDisjointUnion $ map (mapDescr m) ce
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ClassHasKey op dp -> ClassHasKey (map (mapObjExpr m) op)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (map (mapDataExpr m) dp)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ObjectSubPropertyChain op -> ObjectSubPropertyChain
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (map (mapObjExpr m) op)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova _ -> afb
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovamapFB :: Map.Map Entity IRI -> FrameBit -> FrameBit
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovamapFB m fb = case fb of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ListFrameBit mr lfb -> ListFrameBit mr $ mapLFB m lfb
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova AnnFrameBit ans afb -> AnnFrameBit (mapAnnoList m ans)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova $ mapAFB m afb
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian MaedermapAxiom :: Map.Map Entity IRI -> Axiom -> Axiom
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovamapAxiom m (PlainAxiom eith fb) = case eith of
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder Right (Entity ty ent) -> PlainAxiom
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (Right $ Entity ty $ getIri ty ent m) $ mapFB m fb
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova Left ans -> PlainAxiom (Left $ mapAnnoList m ans) $ mapFB m fb
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova