Extract.hs revision dc8c83e9922e4746c192916565f3522418534f3a
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederModule : $Header$
e071fb22ea9923a2a4ff41184d80ca46b55ee932Till MossakowskiDescription : extraction of the sign from the frames
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettCopyright : (c) Francis-Nicolae Bungiu
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuLicense : GPLv2 or higher, see LICENSE.txt
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettMaintainer : f.bungiu@jacobs-university.de
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettStability : provisional
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettPortability : portable
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett Extraction of all the entities in the ontology
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reillyimport qualified Data.Set as Set
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederaddObjPropExpr :: ObjectPropertyExpression -> State Sign ()
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederaddObjPropExpr = addEntity . Entity ObjectProperty . getObjRoleFromExpression
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederaddDataPropExpr :: DataPropertyExpression -> State Sign ()
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederaddDataPropExpr = addEntity . Entity DataProperty
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederaddIndividual :: Individual -> State Sign ()
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederaddIndividual ind =
8db2221917c1bc569614f3481bcdb3b988facaedChristian Maeder unless (iriType ind == NodeID) $ addEntity $ Entity NamedIndividual ind
8db2221917c1bc569614f3481bcdb3b988facaedChristian MaederaddAnnoProp :: AnnotationProperty -> State Sign ()
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederaddAnnoProp = addEntity . Entity AnnotationProperty
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'ReillyaddLiteral :: Literal -> State Sign ()
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'ReillyaddLiteral (Literal _ ty) = {-case ty of
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly Typed u -> addEntity $ Entity Datatype u
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder _ -> -}return ()
9f93b2a8b552789cd939d599504d39732672dc84Christian MaederaddDType :: Datatype -> State Sign ()
9f93b2a8b552789cd939d599504d39732672dc84Christian MaederaddDType = addEntity . Entity Datatype
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder-- | Adds the DataRange to the Signature and returns it as a State Sign ()
23a073e0a3433ca80a286d46202841b569ec36fdChristian MaederaddDataRange :: DataRange -> State Sign ()
a5f3a8cdc3ceb045c3c166ee840d3e59ec7efac6Christian MaederaddDataRange dr = case dr of
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder DataJunction _ lst -> mapM_ addDataRange lst
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly DataComplementOf r -> addDataRange r
0b8146e4f675518993a34eb2255ad7ddd7bf82a4Christian Maeder DataOneOf cs -> mapM_ addLiteral cs
23a073e0a3433ca80a286d46202841b569ec36fdChristian Maeder DataType r fcs -> do
0b8146e4f675518993a34eb2255ad7ddd7bf82a4Christian Maeder mapM_ (addLiteral . snd) fcs
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett-- | Adds the Fact to the Signature and returns it as a State Sign()
53f89daf88665d3ea96d871110a5c0d9d8326bd2Andy GimblettaddFact :: Fact -> State Sign ()
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy GimblettaddFact f = case f of
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett ObjectPropertyFact _ obe ind -> do
53f89daf88665d3ea96d871110a5c0d9d8326bd2Andy Gimblett addObjPropExpr obe
53f89daf88665d3ea96d871110a5c0d9d8326bd2Andy Gimblett addIndividual ind
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder DataPropertyFact _ dpe _ ->
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett addDataPropExpr dpe
c052e3ee4a53ee3a2da829aa142fd596ef6c9e3dAndy Gimblett-- | Adds the Description to the Signature. Returns it as a State
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy GimblettaddDescription :: ClassExpression -> State Sign ()
b25c72845890740c2f8a21214752574990b943cfChristian MaederaddDescription desc = case desc of
b25c72845890740c2f8a21214752574990b943cfChristian Maeder Expression u ->
b25c72845890740c2f8a21214752574990b943cfChristian Maeder unless (isThing u) $ addEntity $ Entity Class u
c052e3ee4a53ee3a2da829aa142fd596ef6c9e3dAndy Gimblett ObjectJunction _ ds -> mapM_ addDescription ds
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett ObjectComplementOf d -> addDescription d
a5f3a8cdc3ceb045c3c166ee840d3e59ec7efac6Christian Maeder ObjectOneOf is -> mapM_ addIndividual is
dfc58f5ec6492d1a9b9babd9cdcdbb15baa6e657Christian Maeder ObjectValuesFrom _ opExpr d -> do
a5f3a8cdc3ceb045c3c166ee840d3e59ec7efac6Christian Maeder addObjPropExpr opExpr
a5f3a8cdc3ceb045c3c166ee840d3e59ec7efac6Christian Maeder addDescription d
dfc58f5ec6492d1a9b9babd9cdcdbb15baa6e657Christian Maeder ObjectHasSelf opExpr -> addObjPropExpr opExpr
b25c72845890740c2f8a21214752574990b943cfChristian Maeder ObjectHasValue opExpr i -> do
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett addObjPropExpr opExpr
61051521e4d82769a47f23aecb5fb477de47d534Andy Gimblett addIndividual i
61051521e4d82769a47f23aecb5fb477de47d534Andy Gimblett ObjectCardinality (Cardinality _ _ opExpr md) -> do
61051521e4d82769a47f23aecb5fb477de47d534Andy Gimblett addObjPropExpr opExpr
61051521e4d82769a47f23aecb5fb477de47d534Andy Gimblett maybe (return ()) addDescription md
61051521e4d82769a47f23aecb5fb477de47d534Andy Gimblett DataValuesFrom _ dExp r -> do
b25c72845890740c2f8a21214752574990b943cfChristian Maeder addDataPropExpr dExp
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett addDataRange r
b22c258cca179a5ffe777b64b32e10687c5f6b2cAndy Gimblett DataHasValue dExp c -> do
a5f3a8cdc3ceb045c3c166ee840d3e59ec7efac6Christian Maeder addDataPropExpr dExp
23a073e0a3433ca80a286d46202841b569ec36fdChristian Maeder DataCardinality (Cardinality _ _ dExp mr) -> do
876bd2c70a93981cc80f8376284616bce4a0fefcChristian Maeder addDataPropExpr dExp
aa0d5f8be9950e788884f7431cf4cb7bee74788cAndy Gimblett maybe (return ()) addDataRange mr
aa0d5f8be9950e788884f7431cf4cb7bee74788cAndy Gimblett{- | Adds possible ListFrameBits to the Signature by calling
aa0d5f8be9950e788884f7431cf4cb7bee74788cAndy Gimblettbottom level functions -}
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettcomSigLFB :: Maybe Relation -> ListFrameBit
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett -> State Sign ()
197888c54795ec1e79e77289b7e20436a6db74c0Andy GimblettcomSigLFB r lfb =
197888c54795ec1e79e77289b7e20436a6db74c0Andy Gimblett AnnotationBit ab ->
b25c72845890740c2f8a21214752574990b943cfChristian Maeder unless (r `elem` [Just (DRRelation ADomain), Just (DRRelation ARange)])
b25c72845890740c2f8a21214752574990b943cfChristian Maeder $ do let map2nd = map snd ab
a1f6118e7ce7f8892fc4299e316630ec74083f0aAndy Gimblett mapM_ addAnnoProp map2nd
b25c72845890740c2f8a21214752574990b943cfChristian Maeder ExpressionBit ancls -> do
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett let clslst = map snd ancls
fcd11c35e645b0744a308f7961a519826bbaa2f5Christian Maeder mapM_ addDescription clslst
b25c72845890740c2f8a21214752574990b943cfChristian Maeder ObjectBit anob ->
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder let map2nd = map snd anob
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett mapM_ addObjPropExpr map2nd
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder DataBit dlst ->
b25c72845890740c2f8a21214752574990b943cfChristian Maeder let map2nd = map snd dlst
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder mapM_ addDataPropExpr map2nd
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett IndividualSameOrDifferent anind ->
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder let map2nd = map snd anind
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder mapM_ addIndividual map2nd
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder ObjectCharacteristics _anch ->
b25c72845890740c2f8a21214752574990b943cfChristian Maeder DataPropRange dr ->
b25c72845890740c2f8a21214752574990b943cfChristian Maeder let map2nd = map snd dr
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder mapM_ addDataRange map2nd
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett IndividualFacts fct ->
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder let map2nd = map snd fct
b25c72845890740c2f8a21214752574990b943cfChristian Maeder mapM_ addFact map2nd
b25c72845890740c2f8a21214752574990b943cfChristian Maeder{- | Adds AnnotationFrameBits to the Signature
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maederby calling the corresponding bottom level functions -}
b25c72845890740c2f8a21214752574990b943cfChristian MaedercomSigAFB :: AnnFrameBit
b25c72845890740c2f8a21214752574990b943cfChristian Maeder -> State Sign ()
b25c72845890740c2f8a21214752574990b943cfChristian MaedercomSigAFB afb =
b25c72845890740c2f8a21214752574990b943cfChristian Maeder AnnotationFrameBit -> return ()
b25c72845890740c2f8a21214752574990b943cfChristian Maeder DataFunctional -> return ()
b25c72845890740c2f8a21214752574990b943cfChristian Maeder DatatypeBit dr ->
0a83f8dcd5598436966584b858313eb5efd95d5bLiam O'Reilly addDataRange dr
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly ClassDisjointUnion cls ->
2f35e5f6757968746dbab385be21fcae52378a3fLiam O'Reilly mapM_ addDescription cls
2f35e5f6757968746dbab385be21fcae52378a3fLiam O'Reilly ClassHasKey obe dpe -> do
23a073e0a3433ca80a286d46202841b569ec36fdChristian Maeder mapM_ addObjPropExpr obe
23a073e0a3433ca80a286d46202841b569ec36fdChristian Maeder mapM_ addDataPropExpr dpe
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett ObjectSubPropertyChain ope ->
fd4ad12563262ebe380d810df8f7755cfab5fb42Liam O'Reilly mapM_ addObjPropExpr ope
fd4ad12563262ebe380d810df8f7755cfab5fb42Liam O'Reilly{- | Calls the completion of Signature based on
fd4ad12563262ebe380d810df8f7755cfab5fb42Liam O'Reillycase separation of ListFrameBit and AnnotationFrameBit -}
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettcomFB :: FrameBit -> State Sign ()
4f4e94264f48e255d4125f47649f585d9d062fabChristian MaedercomFB fb = case fb of
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder ListFrameBit rel lfb -> comSigLFB rel lfb
da955132262baab309a50fdffe228c9efe68251dCui Jian AnnFrameBit _an anf -> comSigAFB anf
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder-- | Maps the function comFB on the entire FrameBit list of the Frame
310d12b88f902a597cdb08a1c7d11ae7130855eeChristian MaedercompleteSignForFrame :: Frame -> State Sign ()
310d12b88f902a597cdb08a1c7d11ae7130855eeChristian MaedercompleteSignForFrame (Frame _ex fblist) =
310d12b88f902a597cdb08a1c7d11ae7130855eeChristian Maeder mapM_ comFB fblist
4f4e94264f48e255d4125f47649f585d9d062fabChristian MaedercompleteWithExt :: Frame -> State Sign ()
4f4e94264f48e255d4125f47649f585d9d062fabChristian MaedercompleteWithExt (Frame ex fblist) = do
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder mapM_ comFB fblist
4f4e94264f48e255d4125f47649f585d9d062fabChristian MaedercomExt :: Extended -> State Sign ()
4f4e94264f48e255d4125f47649f585d9d062fabChristian MaedercomExt ext = case ext of
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder SimpleEntity e -> addEntity e
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder ObjectEntity op -> addObjPropExpr op
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder ClassEntity ce -> addDescription ce
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder _ -> return ()
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder{- | Top level function: takes the OntologyDocument and completes
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maederthe signature by calling completeSignForFrame -}
4f4e94264f48e255d4125f47649f585d9d062fabChristian MaedercompleteSign :: OntologyDocument -> State Sign ()
4f4e94264f48e255d4125f47649f585d9d062fabChristian MaedercompleteSign od =
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder mapM_ completeSignForFrame $ ontFrames $ ontology od
4f4e94264f48e255d4125f47649f585d9d062fabChristian MaedertoDecl :: Sign -> [Frame]
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder let cls = map (Entity Class) $ Set.toList (concepts s)
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder dt = map (Entity Datatype) $ Set.toList (datatypes s)
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder op = map (Entity ObjectProperty) $ Set.toList (objectProperties s)
4f4e94264f48e255d4125f47649f585d9d062fabChristian Maeder dp = map (Entity DataProperty) $ Set.toList (dataProperties s)
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett i = map (Entity NamedIndividual) $ Set.toList (individuals s)
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett ans = Set.toList (annotationRoles s)
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett in map (\ c -> Frame (SimpleEntity c) [AnnFrameBit [] AnnotationFrameBit])
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett (cls ++ dt ++ op ++ dp ++ i) ++
576a4ca6de740c90afd448607c2323477139de24Liam O'Reilly map (\ a -> Frame (Misc []) [AnnFrameBit
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett [Annotation [] a $ AnnValue a] AnnotationFrameBit]) ans
fd4ad12563262ebe380d810df8f7755cfab5fb42Liam O'ReillysignToFrames :: [Frame] -> [Frame]
2bb060537a37352251aa04d8dc09aa53aad5d4bfLiam O'ReillysignToFrames f =
576a4ca6de740c90afd448607c2323477139de24Liam O'Reilly let s = mapM_ completeWithExt f
b25c72845890740c2f8a21214752574990b943cfChristian Maeder in toDecl $ execState s emptySign