Changeset 11757

Show
Ignore:
Timestamp:
24.04.2009 16:50:10 (11 months ago)
Author:
maeder
Message:

actually rename sentences #643

Location:
trunk/OWL
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/OWL/Logic_OWL.hs

    r11751 r11757  
    6262 
    6363instance Sentences OWL Axiom Sign OWLMorphism Entity where 
    64     map_sen OWL = const return -- this is still wrong for renamings! 
     64    map_sen OWL = mapSen 
    6565    print_named OWL namedSen = 
    6666        pretty (sentence namedSen) <> 
  • trunk/OWL/Morphism.hs

    r11744 r11757  
    2323  , statSymbMapItems 
    2424  , inducedFromMor 
     25  , mapSen 
    2526  ) where 
    2627 
     
    103104  && Set.isSubsetOf (Set.fromList $ inducedElems mm) (symOf $ otarget m) 
    104105 
     106getUri :: EntityType -> URI -> Map.Map Entity URI -> URI 
     107getUri ty u = fromMaybe u . Map.lookup (Entity ty u) 
     108 
    105109composeMor :: OWLMorphism -> OWLMorphism -> Result OWLMorphism 
    106110composeMor m1 m2 = 
    107111  let nm = Set.fold (\ s@(Entity ty u) -> let 
    108             t = case Map.lookup s $ mmaps m1 of 
    109               Nothing -> u 
    110               Just v -> v 
    111             r = case Map.lookup (Entity ty t) $ mmaps m2 of 
    112               Nothing -> t 
    113               Just w -> w 
     112            t = getUri ty u $ mmaps m1 
     113            r = getUri ty t $ mmaps m2 
    114114            in if r == u then id else Map.insert s r) Map.empty 
    115            $ symOf $ osource m1 
     115           . symOf $ osource m1 
    116116  in return m1 
    117117     { otarget = otarget m2 
     
    156156                   map (\ (s, t) -> (mS s, mS t)) ps) 
    157157 
    158  
     158mapEntity :: Map.Map Entity URI -> Entity -> Entity 
     159mapEntity m (Entity ty u) = Entity ty $ getUri ty u m 
     160 
     161mapAnno :: Map.Map Entity URI -> Annotation -> Annotation 
     162mapAnno m ann = case ann of 
     163  Annotation a e -> Annotation a $ mapEntity m e 
     164  _ -> ann 
     165 
     166mapSen :: OWLMorphism -> Axiom -> Result Axiom 
     167mapSen m = return . mapAxiom (mmaps m) 
     168 
     169mapAxiom :: Map.Map Entity URI -> Axiom -> Axiom 
     170mapAxiom m axm = case axm of 
     171  PlainAxiom as a -> PlainAxiom (map (mapAnno m) as) $ mapPlainAxiom m a 
     172  EntityAnno (EntityAnnotation as e bs) -> 
     173    EntityAnno $ EntityAnnotation (map (mapAnno m) as) (mapEntity m e) 
     174      $ map (mapAnno m) bs 
     175 
     176mapObjExpr :: Map.Map Entity URI -> ObjectPropertyExpression 
     177           -> ObjectPropertyExpression 
     178mapObjExpr m ope = case ope of 
     179  OpURI u -> OpURI $ getUri ObjectProperty u m 
     180  InverseOp o -> InverseOp $ mapObjExpr m o 
     181 
     182mapDRange :: Map.Map Entity URI -> DataRange -> DataRange 
     183mapDRange m dr = case dr of 
     184    DRDatatype u -> DRDatatype $ getUri Datatype u m 
     185    DataComplementOf d -> DataComplementOf $ mapDRange m d 
     186    DataOneOf _ -> dr 
     187    DatatypeRestriction d l -> DatatypeRestriction (mapDRange m d) l 
     188 
     189mapDataExpr :: Map.Map Entity URI -> DataPropertyExpression 
     190            -> DataPropertyExpression 
     191mapDataExpr m dpe = getUri DataProperty dpe m 
     192 
     193getClassUri :: URI -> Map.Map Entity URI -> URI 
     194getClassUri = getUri OWLClass 
     195 
     196getIndUri :: URI -> Map.Map Entity URI -> URI 
     197getIndUri = getUri Individual 
     198 
     199mapCard :: (a -> b) -> (c -> d) -> Cardinality a c -> Cardinality b d 
     200mapCard f g (Cardinality ty i a mb) = 
     201  Cardinality ty i (f a) $ fmap g mb 
     202 
     203mapDescr :: Map.Map Entity URI -> Description -> Description 
     204mapDescr m desc = case desc of 
     205    OWLClassDescription u -> OWLClassDescription $ getClassUri u m 
     206    ObjectJunction ty ds -> ObjectJunction ty $ map (mapDescr m) ds 
     207    ObjectComplementOf d -> ObjectComplementOf $ mapDescr m d 
     208    ObjectOneOf is -> ObjectOneOf $ map (flip getIndUri m) is 
     209    ObjectValuesFrom ty o d -> ObjectValuesFrom ty (mapObjExpr m o) 
     210      $ mapDescr m d 
     211    ObjectExistsSelf o -> ObjectExistsSelf $ mapObjExpr m o 
     212    ObjectHasValue o i -> ObjectHasValue (mapObjExpr m o) $ getIndUri i m 
     213    ObjectCardinality c -> ObjectCardinality 
     214      $ mapCard (mapObjExpr m) (mapDescr m) c 
     215    DataValuesFrom ty d ds dr -> DataValuesFrom ty (mapDataExpr m d) 
     216      (map (mapDataExpr m) ds) $ mapDRange m dr 
     217    DataHasValue d c -> DataHasValue (mapDataExpr m d) c 
     218    DataCardinality c -> DataCardinality 
     219       $ mapCard (mapDataExpr m) (mapDRange m) c 
     220 
     221mapSubObjExpr :: Map.Map Entity URI -> SubObjectPropertyExpression 
     222              -> SubObjectPropertyExpression 
     223mapSubObjExpr m ope = case ope of 
     224  OPExpression o -> OPExpression $ mapObjExpr m o 
     225  SubObjectPropertyChain os -> SubObjectPropertyChain 
     226    $ map (mapObjExpr m) os 
     227 
     228mapDataDomOrRange :: Map.Map Entity URI -> DataDomainOrRange 
     229                  -> DataDomainOrRange 
     230mapDataDomOrRange m ddr = case ddr of 
     231  DataDomain d -> DataDomain $ mapDescr m d 
     232  DataRange d -> DataRange $ mapDRange m d 
     233 
     234mapAssertion :: Map.Map Entity URI -> (a -> b) -> (c -> d) 
     235             -> Assertion a c -> Assertion b d 
     236mapAssertion m f g (Assertion a ty i b) = 
     237  Assertion (f a) ty (getIndUri i m) $ g b 
     238 
     239mapPlainAxiom :: Map.Map Entity URI -> PlainAxiom -> PlainAxiom 
     240mapPlainAxiom m pax = case pax of 
     241    SubClassOf s t -> SubClassOf (mapDescr m s) $ mapDescr m t 
     242    EquivOrDisjointClasses ty ds -> EquivOrDisjointClasses ty 
     243      $ map (mapDescr m) ds 
     244    DisjointUnion u ds -> DisjointUnion (getClassUri u m) 
     245      $ map (mapDescr m) ds 
     246    SubObjectPropertyOf so o -> SubObjectPropertyOf (mapSubObjExpr m so) 
     247      $ mapObjExpr m o 
     248    EquivOrDisjointObjectProperties ty os -> EquivOrDisjointObjectProperties ty 
     249      $ map (mapObjExpr m) os 
     250    ObjectPropertyDomainOrRange odr o d -> ObjectPropertyDomainOrRange odr 
     251      (mapObjExpr m o) $ mapDescr m d 
     252    InverseObjectProperties o p -> InverseObjectProperties (mapObjExpr m o) 
     253      $ mapObjExpr m p 
     254    ObjectPropertyCharacter c o -> ObjectPropertyCharacter c $ mapObjExpr m o 
     255    SubDataPropertyOf d e -> SubDataPropertyOf (mapDataExpr m d) 
     256      $ mapDataExpr m e 
     257    EquivOrDisjointDataProperties ty ds -> EquivOrDisjointDataProperties ty 
     258      $ map (mapDataExpr m) ds 
     259    DataPropertyDomainOrRange dd d -> DataPropertyDomainOrRange 
     260      (mapDataDomOrRange m dd) $ mapDataExpr m d 
     261    FunctionalDataProperty d -> FunctionalDataProperty $ mapDataExpr m d 
     262    SameOrDifferentIndividual ty is -> SameOrDifferentIndividual ty 
     263      $ map (flip getIndUri m) is 
     264    ClassAssertion i d -> ClassAssertion (getIndUri i m) $ mapDescr m d 
     265    ObjectPropertyAssertion a -> ObjectPropertyAssertion 
     266      $ mapAssertion m (mapObjExpr m) (flip getIndUri m) a 
     267    DataPropertyAssertion a -> DataPropertyAssertion 
     268      $ mapAssertion m (mapDataExpr m) id a 
     269    Declaration (Entity ty u) -> Declaration $ Entity ty $ getUri ty u m 
     270