Extract.hs revision 551caf6791c20ff4ca928f93c520b85648693958
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederModule : $Header$
e071fb22ea9923a2a4ff41184d80ca46b55ee932Till MossakowskiDescription : extraction of the sign from the frames
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettCopyright : (c) Francisc-Nicolae Bungiu, Felix Gabriel Mance
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuLicense : GPLv2 or higher, see LICENSE.txt
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettMaintainer : f.bungiu@jacobs-university.de
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettStability : provisional
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettPortability : portable
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettExtraction of all the entities in the ontology
aa0d5f8be9950e788884f7431cf4cb7bee74788cAndy Gimblettimport qualified Data.Set as Set
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettaddObjPropExpr :: ObjectPropertyExpression -> State Sign ()
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederaddObjPropExpr = addEntity . Entity ObjectProperty . objPropToIRI
567db7182e691cce5816365d8c912d09ffe92f86Andy GimblettaddDataPropExpr :: DataPropertyExpression -> State Sign ()
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederaddDataPropExpr = addEntity . Entity DataProperty
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederaddIndividual :: Individual -> State Sign ()
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederaddIndividual ind =
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder unless (iriType ind == NodeID) $ addEntity $ Entity NamedIndividual ind
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederaddAnnoProp :: AnnotationProperty -> State Sign ()
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian MaederaddAnnoProp = addEntity . Entity AnnotationProperty
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy GimblettaddLiteral :: Literal -> State Sign ()
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'ReillyaddLiteral l = case l of
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly Literal _ ty -> case ty of
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly Typed u -> addEntity $ Entity Datatype u
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder _ -> return ()
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder _ -> return ()
9f93b2a8b552789cd939d599504d39732672dc84Christian MaederaddDType :: Datatype -> State Sign ()
9f93b2a8b552789cd939d599504d39732672dc84Christian MaederaddDType dt = unless (isDatatypeKey dt) $ addEntity $ Entity Datatype dt
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder-- | Adds the DataRange to the Signature and returns it as a State Sign ()
9f93b2a8b552789cd939d599504d39732672dc84Christian MaederaddDataRange :: DataRange -> State Sign ()
9f93b2a8b552789cd939d599504d39732672dc84Christian MaederaddDataRange dr = case dr of
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly DataJunction _ lst -> mapM_ addDataRange lst
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly DataComplementOf r -> addDataRange r
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder DataOneOf cs -> mapM_ addLiteral cs
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder DataType r fcs -> do
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly mapM_ (addLiteral . snd) fcs
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder-- | Adds the Fact to the Signature and returns it as a State Sign()
9f93b2a8b552789cd939d599504d39732672dc84Christian MaederaddFact :: Fact -> State Sign ()
9f93b2a8b552789cd939d599504d39732672dc84Christian MaederaddFact f = case f of
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett ObjectPropertyFact _ obe ind -> do
53f89daf88665d3ea96d871110a5c0d9d8326bd2Andy Gimblett addObjPropExpr obe
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett addIndividual ind
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett DataPropertyFact _ dpe _ ->
53f89daf88665d3ea96d871110a5c0d9d8326bd2Andy Gimblett addDataPropExpr dpe
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder-- | Adds the Description to the Signature. Returns it as a State
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy GimblettaddDescription :: ClassExpression -> State Sign ()
c052e3ee4a53ee3a2da829aa142fd596ef6c9e3dAndy GimblettaddDescription desc = case desc of
c052e3ee4a53ee3a2da829aa142fd596ef6c9e3dAndy Gimblett Expression u ->
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett unless (isThing u) $ addEntity $ Entity Class u
c052e3ee4a53ee3a2da829aa142fd596ef6c9e3dAndy Gimblett ObjectJunction _ ds -> mapM_ addDescription ds
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett ObjectComplementOf d -> addDescription d
a181b88611e09ffc9701a5f1022002cc0bc0c584Andy Gimblett ObjectOneOf is -> mapM_ addIndividual is
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett ObjectValuesFrom _ opExpr d -> do
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett addObjPropExpr opExpr
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett addDescription d
05b3e12808da901dccd665715cb934462290d550Andy Gimblett ObjectHasSelf opExpr -> addObjPropExpr opExpr
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett 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
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett addDataPropExpr dExp
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett addDataRange r
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett DataHasValue dExp c -> do
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett addDataPropExpr dExp
b22c258cca179a5ffe777b64b32e10687c5f6b2cAndy Gimblett DataCardinality (Cardinality _ _ dExp mr) -> do
b22c258cca179a5ffe777b64b32e10687c5f6b2cAndy Gimblett addDataPropExpr dExp
b22c258cca179a5ffe777b64b32e10687c5f6b2cAndy Gimblett maybe (return ()) addDataRange mr
876bd2c70a93981cc80f8376284616bce4a0fefcChristian MaederaddAnno :: Annotation -> State Sign ()
aa0d5f8be9950e788884f7431cf4cb7bee74788cAndy GimblettaddAnno (Annotation as apr _) = do
aa0d5f8be9950e788884f7431cf4cb7bee74788cAndy Gimblett addAnnoProp apr
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettaddAnnos :: Annotations -> State Sign ()
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettaddAnnos = mapM_ addAnno
197888c54795ec1e79e77289b7e20436a6db74c0Andy GimblettaddAnnoList :: (a -> State Sign ()) -> AnnotatedList a -> State Sign ()
197888c54795ec1e79e77289b7e20436a6db74c0Andy GimblettaddAnnoList f al = do
a1f6118e7ce7f8892fc4299e316630ec74083f0aAndy Gimblett addAnnos $ concatMap fst al
a1f6118e7ce7f8892fc4299e316630ec74083f0aAndy Gimblett mapM_ (f . snd) al
a1f6118e7ce7f8892fc4299e316630ec74083f0aAndy Gimblett{- | Adds possible ListFrameBits to the Signature by calling
a1f6118e7ce7f8892fc4299e316630ec74083f0aAndy Gimblettbottom level functions -}
042fd01d46834d3fecb5ac109ff905c5eb034376Liam O'ReillyextLFB :: Maybe Relation -> ListFrameBit -> State Sign ()
a1f6118e7ce7f8892fc4299e316630ec74083f0aAndy GimblettextLFB r lfb = case lfb of
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett AnnotationBit ab ->
06dd4e7c29f33f6122a910719e3bd9062256e397Andy Gimblett unless (r `elem` [Just (DRRelation ADomain), Just (DRRelation ARange)])
05b3e12808da901dccd665715cb934462290d550Andy Gimblett $ addAnnoList addAnnoProp ab
05b3e12808da901dccd665715cb934462290d550Andy Gimblett ExpressionBit al -> addAnnoList addDescription al
05b3e12808da901dccd665715cb934462290d550Andy Gimblett ObjectBit anob -> addAnnoList addObjPropExpr anob
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett DataBit dlst -> addAnnoList addDataPropExpr dlst
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett IndividualSameOrDifferent anind -> addAnnoList addIndividual anind
06dd4e7c29f33f6122a910719e3bd9062256e397Andy Gimblett ObjectCharacteristics al -> addAnnos $ concatMap fst al
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy Gimblett DataPropRange dr -> addAnnoList addDataRange dr
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett IndividualFacts fct -> addAnnoList addFact fct
fd4ad12563262ebe380d810df8f7755cfab5fb42Liam O'Reilly{- | Adds AnnotationFrameBits to the Signature
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblettby calling the corresponding bottom level functions -}
06dd4e7c29f33f6122a910719e3bd9062256e397Andy GimblettextAFB :: AnnFrameBit -> State Sign ()
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy GimblettextAFB afb = case afb of
9f31535736c3d43a98f0157efaa7f87ea73c9be0Liam O'Reilly AnnotationFrameBit _ -> return ()
576a4ca6de740c90afd448607c2323477139de24Liam O'Reilly DataFunctional -> return ()
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett DatatypeBit dr -> addDataRange dr
06dd4e7c29f33f6122a910719e3bd9062256e397Andy Gimblett ClassDisjointUnion cls -> mapM_ addDescription cls
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy Gimblett ClassHasKey obe dpe -> do
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy Gimblett mapM_ addObjPropExpr obe
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy Gimblett mapM_ addDataPropExpr dpe
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett ObjectSubPropertyChain ope -> mapM_ addObjPropExpr ope
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy Gimblett{- | Calls the completion of Signature based on
06dd4e7c29f33f6122a910719e3bd9062256e397Andy Gimblettcase separation of ListFrameBit and AnnotationFrameBit -}
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy GimblettextFB :: Extended -> FrameBit -> State Sign ()
06dd4e7c29f33f6122a910719e3bd9062256e397Andy GimblettextFB ext fb = case fb of
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy Gimblett ListFrameBit rel lfb -> do
06dd4e7c29f33f6122a910719e3bd9062256e397Andy Gimblett extLFB rel lfb
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy Gimblett AnnFrameBit an anf -> do
0a83f8dcd5598436966584b858313eb5efd95d5bLiam O'Reilly AnnotationFrameBit Assertion -> case ext of
0a83f8dcd5598436966584b858313eb5efd95d5bLiam O'Reilly Misc _ -> return ()
0a83f8dcd5598436966584b858313eb5efd95d5bLiam O'Reilly _ -> addExt ext
0a83f8dcd5598436966584b858313eb5efd95d5bLiam O'Reilly _ -> addExt ext
0a83f8dcd5598436966584b858313eb5efd95d5bLiam O'ReillyextFrame :: Frame -> State Sign ()
0a83f8dcd5598436966584b858313eb5efd95d5bLiam O'ReillyextFrame (Frame ex fblist) = mapM_ (extFB ex) fblist
2f35e5f6757968746dbab385be21fcae52378a3fLiam O'ReillyaddExt :: Extended -> State Sign ()
2f35e5f6757968746dbab385be21fcae52378a3fLiam O'ReillyaddExt ext = case ext of
33bdce26495121cdbce30331ef90a1969126a840Liam O'Reilly SimpleEntity e -> addEntity e
d9c1248c7972dfdafbacb1b73b2eb965eac9ef42Liam O'Reilly ObjectEntity op -> addObjPropExpr op
d9c1248c7972dfdafbacb1b73b2eb965eac9ef42Liam O'Reilly ClassEntity ce -> addDescription ce
d9c1248c7972dfdafbacb1b73b2eb965eac9ef42Liam O'Reilly Misc ans -> addAnnos ans
fd4ad12563262ebe380d810df8f7755cfab5fb42Liam O'Reilly{- | Top level function: takes the OntologyDocument and completes
fd4ad12563262ebe380d810df8f7755cfab5fb42Liam O'Reillythe signature by calling completeSignForFrame -}
fd4ad12563262ebe380d810df8f7755cfab5fb42Liam O'ReillyextractSign :: OntologyDocument -> State Sign ()
fd4ad12563262ebe380d810df8f7755cfab5fb42Liam O'ReillyextractSign od =
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett mapM_ extFrame $ ontFrames $ ontology od
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimbletttoDecl :: Sign -> [Frame]
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett let cls = map (Entity Class) $ Set.toList (concepts s)
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett dt = map (Entity Datatype) $ Set.toList (datatypes s)
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett op = map (Entity ObjectProperty) $ Set.toList (objectProperties s)
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett dp = map (Entity DataProperty) $ Set.toList (dataProperties s)
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett i = map (Entity NamedIndividual) $ Set.toList (individuals s)
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett ans = map (Entity AnnotationProperty) $ Set.toList (annotationRoles s)
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett in map (\ c -> Frame (SimpleEntity c)
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett [AnnFrameBit [] $ AnnotationFrameBit Declaration])
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett (cls ++ dt ++ op ++ dp ++ i ++ ans)
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettsignToFrames :: [Frame] -> [Frame]
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettsignToFrames f =
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett let s = mapM_ extFrame f
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett in toDecl $ execState s emptySign