80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit{- |
80802511792d4e59a4ac67ad19677009d332b37dBruno LavitModule : ./OWL2/ColimSign.hs
80802511792d4e59a4ac67ad19677009d332b37dBruno LavitDescription : OWL signatures colimits
80802511792d4e59a4ac67ad19677009d332b37dBruno LavitCopyright : (c) Mihai Codescu, and Uni Bremen 2009
0d29d2c9c206eb1652fa951dd55bcc0cfa4b48feNeil MaddenLicense : GPLv2 or higher, see LICENSE.txt
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit
80802511792d4e59a4ac67ad19677009d332b37dBruno LavitMaintainer : mcodescu@informatik.uni-bremen.de
80802511792d4e59a4ac67ad19677009d332b37dBruno LavitStability : provisional
0d29d2c9c206eb1652fa951dd55bcc0cfa4b48feNeil MaddenPortability : non-portable
0d29d2c9c206eb1652fa951dd55bcc0cfa4b48feNeil Madden
0d29d2c9c206eb1652fa951dd55bcc0cfa4b48feNeil MaddenOWL2 signature colimits, computed component-wise.
0d29d2c9c206eb1652fa951dd55bcc0cfa4b48feNeil Madden
0d29d2c9c206eb1652fa951dd55bcc0cfa4b48feNeil Madden-}
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit
0d29d2c9c206eb1652fa951dd55bcc0cfa4b48feNeil Maddenmodule OWL2.ColimSign where
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavitimport OWL2.Sign
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavitimport OWL2.Morphism
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavitimport OWL2.AS
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavitimport Common.IRI
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavitimport Common.SetColimit
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavitimport Common.Lib.Graph
4f39fae2f8671f7389a26412a6203c455b80f06dDavid Luna
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavitimport Data.Graph.Inductive.Graph as Graph
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavitimport qualified Data.Map as Map
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit
80802511792d4e59a4ac67ad19677009d332b37dBruno LavitsignColimit :: Gr Sign (Int, OWLMorphism) ->
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit (Sign, Map.Map Int OWLMorphism)
80802511792d4e59a4ac67ad19677009d332b37dBruno LavitsignColimit graph = let
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit conGraph = emap (getEntityTypeMap Class) $ nmap concepts graph
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit dataGraph = emap (getEntityTypeMap Datatype) $ nmap datatypes graph
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit indGraph = emap (getEntityTypeMap NamedIndividual) $ nmap individuals graph
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit objGraph = emap (getEntityTypeMap ObjectProperty) $
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit nmap objectProperties graph
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit dataPropGraph = emap (getEntityTypeMap DataProperty) $
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit nmap dataProperties graph
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit annPropGraph = emap (getEntityTypeMap AnnotationProperty) $
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit nmap annotationRoles graph
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit _prefixGraph = emap getPrefixMap
80802511792d4e59a4ac67ad19677009d332b37dBruno Lavit $ nmap (Map.keysSet . toQName . prefixMap) graph
(con, funC) = addIntToSymbols $ computeColimitSet conGraph
(dat, funD) = addIntToSymbols $ computeColimitSet dataGraph
(ind, funI) = addIntToSymbols $ computeColimitSet indGraph
(obj, funO) = addIntToSymbols $ computeColimitSet objGraph
(dp, funDP) = addIntToSymbols $ computeColimitSet dataPropGraph
(ap, funAP) = addIntToSymbols $ computeColimitSet annPropGraph
-- (pf, funP) = addIntToSymbols $ computeColimitSet prefixGraph
morFun i = foldl Map.union Map.empty
[ setEntityTypeMap Class $
Map.findWithDefault (error "maps") i funC,
setEntityTypeMap Datatype $
Map.findWithDefault (error "maps") i funD,
setEntityTypeMap NamedIndividual $
Map.findWithDefault (error "maps") i funI,
setEntityTypeMap ObjectProperty $
Map.findWithDefault (error "maps") i funO,
setEntityTypeMap DataProperty $
Map.findWithDefault (error "maps") i funDP,
setEntityTypeMap AnnotationProperty $
Map.findWithDefault (error "maps") i funAP
]
morMaps = Map.fromAscList $
map (\ x -> (x, morFun x)) $ nodes graph
nameMap = foldl Map.union Map.empty $
map (\ (_, l) -> prefixMap l) $ labNodes graph
colimSign = emptySign {
concepts = con,
datatypes = dat,
objectProperties = obj,
dataProperties = dp,
individuals = ind,
annotationRoles = ap,
prefixMap = nameMap
}
colimMor = Map.fromAscList $
map (\ (i, ssig) -> let
mm = Map.findWithDefault (error "mor") i morMaps
om = OWLMorphism {
osource = ssig,
otarget = colimSign,
mmaps = mm,
pmap = Map.empty
}
in (i, om)
) $ labNodes graph
in (colimSign, colimMor)
getEntityTypeMap :: EntityType -> (Int, OWLMorphism)
-> (Int, Map.Map IRI IRI)
getEntityTypeMap e (i, phi) = let
f = Map.filterWithKey
(\ (Entity _ x _) _ -> x == e) $ mmaps phi
in (i, Map.fromList $
map (\ (Entity _ _ x, y) -> (x, y)) $
Map.toAscList f)
setEntityTypeMap :: EntityType -> Map.Map IRI IRI
-> Map.Map Entity IRI
setEntityTypeMap = Map.mapKeys . mkEntity
getPrefixMap :: (Int, OWLMorphism) -> (Int, Map.Map IRI IRI)
getPrefixMap (i, phi) = let
f = pmap phi
in (i, Map.fromList $
map (\ (x, y) -> (mkIRI x, mkIRI y)) $
Map.toAscList f)
toQName :: PrefixMap -> Map.Map IRI String
toQName pm = Map.fromList $ map (\ (p, s) -> (mkIRI p, s)) $ Map.toList pm