Changeset 12726

Show
Ignore:
Timestamp:
26.10.2009 16:00:16 (4 weeks ago)
Author:
mcodescu
Message:

made an algorithm generic to reuse it for OWL

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/CASL/ColimSign.hs

    r12314 r12726  
    1515-} 
    1616 
    17 module CASL.ColimSign(signColimit, extCASLColimit, renameSorts) where 
     17module CASL.ColimSign(signColimit, extCASLColimit) where 
    1818 
    1919import CASL.Sign 
     
    5757   sortGraph = emap getSortMap $ nmap sortSet graph 
    5858   (setSort0, funSort0) = computeColimitSet sortGraph 
    59    (setSort, funSort) = renameSorts (setSort0, funSort0) 
     59   (setSort, funSort) = addIntToSymbols (setSort0, funSort0) 
    6060   sigmaSort = (emptySign $ error "err"){sortSet=setSort} 
    6161   phiSort = Map.fromList 
     
    8080     phiAssoc 
    8181   in (sigmaExt, phiExt) 
    82  
    83 -- method for adding the number as suffix of the id it pairs 
    84 addSuffixToId :: (Id, Node) -> Id 
    85 addSuffixToId (idN, n) = appendNumber idN n 
    86  
    87 --method for applying the renaming to the colimit of sorts 
    88 renameSorts :: (Set.Set (Id, Node), Map.Map Node (Map.Map Id (Id, Node))) -> 
    89                (Set.Set Id, Map.Map Node (EndoMap Id)) 
    90 renameSorts (set, fun) = let 
    91   fstEqual (x1,_) (x2,_) = x1 == x2 
    92   partList pairSet = leqClasses fstEqual pairSet 
    93   namePartitions elemList f0 s1 f1 = case elemList of 
    94    [] -> (s1, f1) 
    95    p:ps -> if length p == 1 then 
    96      -- a single element with this name,it can be kept 
    97     let s2 = Set.insert (fst $ head p) s1 
    98         updateF node = Map.union (Map.findWithDefault (error "f1") node f1) $ 
    99                        Map.fromList $ map (\x -> (x, fst $ head p)) $ 
    100                        filter (\x -> Map.findWithDefault (error "fo(node)") x 
    101                                       (Map.findWithDefault (error "f0") node f0) 
    102                                      == head p) $ 
    103                        Map.keys $ Map.findWithDefault (error "f0") 
    104                                    node f0 
    105         f2 = Map.fromList $ zip (Map.keys f0) $ map updateF $ Map.keys f0 
    106     in namePartitions ps f0 s2 f2 
    107                 else 
    108      --several elements with same name, the number is added at the end 
    109     let s2 = Set.union s1 $ Set.fromList $ map addSuffixToId p 
    110         updateF node = Map.union (Map.findWithDefault (error "f1") node f1) $ 
    111              Map.fromList $ 
    112              map ( \x -> (x, addSuffixToId $ 
    113                                   Map.findWithDefault (error "addSuffixToId") x 
    114                                   (Map.findWithDefault (error "f0") node f0))) $ 
    115              filter (\x -> (Map.findWithDefault (error "fo(node)") x 
    116                            (Map.findWithDefault (error "f0") node f0)) 
    117                            `elem` p) $ 
    118              Map.keys $ Map.findWithDefault (error "f0") node f0 
    119         f2 = Map.fromList $ zip (Map.keys f0) $ map updateF $ Map.keys f0 
    120     in namePartitions ps f0 s2 f2 
    121  in namePartitions (partList set) fun (Set.empty) $ 
    122     Map.fromList $ zip (Map.keys fun) (repeat Map.empty) 
    12382 
    12483-- computing subsorts in the colimit 
  • trunk/Common/SetColimit.hs

    r11854 r12726  
    1818 
    1919module Common.SetColimit( 
    20     computeColimitSet 
     20    computeColimitSet, 
     21    addIntToSymbols 
    2122  ) 
    2223 where 
     
    2728import qualified Data.Set as Set 
    2829import Data.List 
     30import CASL.Overload(leqClasses) 
     31import Common.Id 
    2932 
    3033compose :: (Ord a) => Set.Set (a, Int) -> 
     
    102105    in computeCoeqs graph (colim', morMap') edges' 
    103106 
     107class (Eq a, Ord a) => SymbolName a where 
     108  addIntAsSuffix :: (a, Int) -> a 
     109 
     110instance SymbolName Id where 
     111 addIntAsSuffix (x,y) = appendNumber x y 
     112 
     113addIntToSymbols :: (SymbolName a) => 
     114               (Set.Set (a, Node), Map.Map Node (Map.Map a (a, Node))) -> 
     115               (Set.Set a, Map.Map Node (Map.Map a a)) 
     116addIntToSymbols (set, fun) = let 
     117  fstEqual (x1,_) (x2,_) = x1 == x2 
     118  partList pairSet = leqClasses fstEqual pairSet 
     119  namePartitions elemList f0 s1 f1 = case elemList of 
     120   [] -> (s1, f1) 
     121   p:ps -> if length p == 1 then 
     122     -- a single element with this name,it can be kept 
     123    let s2 = Set.insert (fst $ head p) s1 
     124        updateF node = Map.union (Map.findWithDefault (error "f1") node f1) $ 
     125                       Map.fromList $ map (\x -> (x, fst $ head p)) $ 
     126                       filter (\x -> Map.findWithDefault (error "fo(node)") x 
     127                                      (Map.findWithDefault (error "f0") node f0) 
     128                                     == head p) $ 
     129                       Map.keys $ Map.findWithDefault (error "f0") 
     130                                   node f0 
     131        f2 = Map.fromList $ zip (Map.keys f0) $ map updateF $ Map.keys f0 
     132    in namePartitions ps f0 s2 f2 
     133                else 
     134     --several elements with same name, the number is added at the end 
     135    let s2 = Set.union s1 $ Set.fromList $ map addIntAsSuffix p 
     136        updateF node = Map.union (Map.findWithDefault (error "f1") node f1) $ 
     137             Map.fromList $ 
     138             map ( \x -> (x, addIntAsSuffix $ 
     139                                  Map.findWithDefault (error "addSuffixToId") x 
     140                                  (Map.findWithDefault (error "f0") node f0))) $ 
     141             filter (\x -> (Map.findWithDefault (error "fo(node)") x 
     142                           (Map.findWithDefault (error "f0") node f0)) 
     143                           `elem` p) $ 
     144             Map.keys $ Map.findWithDefault (error "f0") node f0 
     145        f2 = Map.fromList $ zip (Map.keys f0) $ map updateF $ Map.keys f0 
     146    in namePartitions ps f0 s2 f2 
     147 in namePartitions (partList set) fun (Set.empty) $ 
     148    Map.fromList $ zip (Map.keys fun) (repeat Map.empty) 
    104149 
    105150 
    106  
  • trunk/Propositional/Analysis.hs

    r11534 r12726  
    4343import Data.Graph.Inductive.Graph 
    4444import Common.SetColimit 
    45 import CASL.ColimSign(renameSorts) 
    4645 
    4746-- | Datatype for formulas with diagnosis data 
     
    393392signatureColimit graph = do 
    394393 let graph1 = nmap Sign.items $ emap (\(x,y) -> (x, Morphism.propMap y)) graph 
    395      (set, maps) = renameSorts $ computeColimitSet graph1 
     394     (set, maps) = addIntToSymbols $ computeColimitSet graph1 
    396395     cSig = Sign.Sign{Sign.items = set} 
    397396 return (cSig,