StaticAnalysis.hs revision f20c085644aa49702488405bc2d4245cf0e5a713
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian MaederModule : $Header$
f9e0b18852b238ddb649d341194e05d7200d1bbeChristian MaederCopyright : Felix Gabriel Mance
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian MaederMaintainer : f.mance@jacobs-university.de
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian MaederStability : provisional
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian MaederPortability : portable
f9e0b18852b238ddb649d341194e05d7200d1bbeChristian MaederContains : static analysis for OWL 2
64e1905404e5135e98a26d2ab4150b6764956576Christian Maederimport qualified Data.Map as Map
f9e0b18852b238ddb649d341194e05d7200d1bbeChristian Maederimport qualified Data.Set as Set
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder-- | Error messages for static analysis
64e1905404e5135e98a26d2ab4150b6764956576Christian MaederfailMsg :: Maybe Entity -> String -> String
64e1905404e5135e98a26d2ab4150b6764956576Christian MaederfailMsg ent s = case ent of
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder Just (Entity ty e) -> "Static analysis cannot find " ++ showEntityType ty
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder ++ " " ++ showQN e ++ s
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian MaedergetObjRoleFromExpression :: ObjectPropertyExpression -> IndividualRoleIRI
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian MaedergetObjRoleFromExpression opExp =
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder case opExp of
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder ObjectProp u -> u
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder ObjectInverseOf objProp -> getObjRoleFromExpression objProp
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian MaedergetObjRoleFromSubExpression :: SubObjectPropertyExpression
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder -> [IndividualRoleIRI]
64e1905404e5135e98a26d2ab4150b6764956576Christian MaedergetObjRoleFromSubExpression sopExp =
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder case sopExp of
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder OPExpression opExp -> [getObjRoleFromExpression opExp]
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder SubObjectPropertyChain expList ->
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder map getObjRoleFromExpression expList
65dce48b81f69e11a36bf1051314a845299446e1Christian MaedersortObjData :: Sign -> ObjectPropertyExpression
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder -> Maybe ObjectPropertyExpression
64e1905404e5135e98a26d2ab4150b6764956576Christian MaedersortObjData s op =
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder let p = getObjRoleFromExpression op in
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder if Set.member p (objectProperties s) then Just op
67869d63d1725c79e4c07b51acd466a31932b275Christian MaedersortObjDataList :: Sign -> [ObjectPropertyExpression]
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder -> [ObjectPropertyExpression]
64e1905404e5135e98a26d2ab4150b6764956576Christian MaedersortObjDataList s = mapMaybe $ sortObjData s
64e1905404e5135e98a26d2ab4150b6764956576Christian MaedermodEntity :: (IRI -> Set.Set IRI -> Set.Set IRI) -> Entity -> State Sign ()
62eaa2fb831613d8a6e59687f83a45be1041ab17Christian MaedermodEntity f (Entity ty u) = do
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder let chg = f u
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder put $ case ty of
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder Datatype -> s { datatypes = chg $ datatypes s }
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder Class -> s { concepts = chg $ concepts s }
67869d63d1725c79e4c07b51acd466a31932b275Christian Maeder ObjectProperty -> s { objectProperties = chg $ objectProperties s }
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder DataProperty -> s { dataProperties = chg $ dataProperties s }
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder NamedIndividual -> s { individuals = chg $ individuals s }
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder AnnotationProperty -> s {annotationRoles = chg $ annotationRoles s}
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder-- | adding entities to the signature
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian MaederaddEntity :: Entity -> State Sign ()
67869d63d1725c79e4c07b51acd466a31932b275Christian MaederaddEntity = modEntity Set.insert
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder-- | adding annotations for theorems
64e1905404e5135e98a26d2ab4150b6764956576Christian MaederanaAxiom :: Axiom -> Named Axiom
64e1905404e5135e98a26d2ab4150b6764956576Christian MaederanaAxiom x = findImplied x $ makeNamed "" x
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder-- | checks if an entity is in the signature
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian MaedercheckEntity :: Sign -> a -> Entity -> Result a
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian MaedercheckEntity s a ent = let Entity ty e = ent in case ty of
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder Datatype -> if Set.member e (datatypes s) then return a
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder else fail $ failMsg (Just ent) ""
67869d63d1725c79e4c07b51acd466a31932b275Christian Maeder Class -> if Set.member e (concepts s) then return a
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder else fail $ failMsg (Just ent) ""
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder ObjectProperty -> if Set.member e (objectProperties s) then return a
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder else fail $ failMsg (Just ent) ""
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder DataProperty -> if Set.member e (dataProperties s) then return a
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder else fail $ failMsg (Just ent) ""
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder NamedIndividual -> if Set.member e (individuals s) then return a
67869d63d1725c79e4c07b51acd466a31932b275Christian Maeder else fail $ failMsg (Just ent) ""
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder AnnotationProperty -> if Set.member e (annotationRoles s) then return a
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder else fail $ failMsg (Just ent) ""
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder-- | checks if a DataRange is valid
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian MaedercheckDataRange :: Sign -> DataRange -> Result DataRange
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian MaedercheckDataRange s dr =
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder DataType dt _ -> do
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder checkEntity s dr (Entity Datatype dt)
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder DataJunction _ drl -> do
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder mapM_ (checkDataRange s) drl
67869d63d1725c79e4c07b51acd466a31932b275Christian Maeder DataComplementOf r -> checkDataRange s r
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder _ -> return dr
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder{- | converts ClassExpression to DataRanges because some
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder DataProperties may be parsed as ObjectProperties -}
ecf557c0b4f953106755a239da2c0b168064d3f4Christian MaederclassExpressionToDataRange :: Sign -> ClassExpression -> Result DataRange
ecf557c0b4f953106755a239da2c0b168064d3f4Christian MaederclassExpressionToDataRange s ce = case ce of
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder Expression u -> do
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder checkEntity s ce (Entity Datatype u)
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder return $ DataType u []
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder ObjectJunction jt cel -> do
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder nrl <- mapM (classExpressionToDataRange s) cel
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder return $ DataJunction jt nrl
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder ObjectComplementOf c -> do
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder nr <- classExpressionToDataRange s c
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder return $ DataComplementOf nr
65dce48b81f69e11a36bf1051314a845299446e1Christian Maeder _ -> fail $ failMsg Nothing
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder "Static analysis cannot correct so parsed ClassExpression\n\n"
65dce48b81f69e11a36bf1051314a845299446e1Christian Maeder ++ show ce ++ "\n\nto a DataRange"
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder{- | checks a ClassExpression and recursively converts the
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder (maybe inappropriately) parsed syntax to a one satisfying the signature -}
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian MaedercheckClassExpression :: Sign -> ClassExpression -> Result ClassExpression
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian MaedercheckClassExpression s desc = case desc of
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder Expression u -> case u of
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder QN _ "Thing" _ _ -> return $ Expression $ QN "owl" "Thing" False ""
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder QN _ "Nothing" _ _ -> return $ Expression $ QN "owl" "Nothing" False ""
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder _ -> checkEntity s desc (Entity Class u)
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder ObjectJunction a ds -> do
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder nl <- mapM (checkClassExpression s) ds
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder return $ ObjectJunction a nl
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder ObjectComplementOf d -> do
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder n <- checkClassExpression s d
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder return $ ObjectComplementOf n
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder ObjectOneOf is -> do
64e1905404e5135e98a26d2ab4150b6764956576Christian Maeder mapM_ (checkEntity s desc . Entity NamedIndividual) is
x = Set.member iri (objectProperties s)
z = Set.member iri (dataProperties s)
if Set.member iri (objectProperties s) then return desc
x = Set.member iri (objectProperties s)
let x = Set.member iri (objectProperties s)
let z = Set.member iri (dataProperties s)
let x = Set.member dExp (dataProperties s)
let x = Set.member dExp (dataProperties s)
if Set.member (getObjRoleFromExpression op) (objectProperties s) then
if Set.member dp (dataProperties s) then return fb
let x = map (\ u -> Set.member (getObjRoleFromExpression u)
let x = map (\ u -> Set.member u (dataProperties s) ) dl
let x = map (\ u -> Set.member (getObjRoleFromExpression u)
y = map (\ u -> Set.member u (dataProperties s) ) dl
let syms = Set.difference (symOf accSign) $ symOf inSign
case Map.lookup pre old of
Nothing -> return $ Map.insert pre ouri old
foldM testAndInteg oldNsMap (Map.toList testNsMap)