data OWL22CASL = OWL22CASL deriving Show
instance Language OWL22CASL
ProfSub -- sublogics domain
OntologyDocument -- Basic spec domain
SymbItems -- symbol items domain
SymbMapItems -- symbol map items domain
OWLMorphism -- morphism domain
RawSymb -- rawsymbol domain
ProofTree -- proof tree codomain
CASL_Sublogics -- sublogics codomain
CASLBasicSpec -- Basic spec codomain
CASLFORMULA -- sentence codomain
SYMB_ITEMS -- symbol items codomain
SYMB_MAP_ITEMS -- symbol map items codomain
CASLSign -- signature codomain
CASLMor -- morphism codomain
Symbol -- symbol codomain
RawSymbol -- rawsymbol codomain
ProofTree -- proof tree domain
sourceLogic OWL22CASL = OWL2
sourceSublogic OWL22CASL = topS
targetLogic OWL22CASL = CASL
mapSublogic OWL22CASL _ = Just $ cFol
{ cons_features = emptyMapConsFeature }
map_theory OWL22CASL = mapTheory
map_morphism OWL22CASL = mapMorphism
map_symbol OWL22CASL _ = mapSymbol
isInclusionComorphism OWL22CASL = True
has_model_expansion OWL22CASL = True
-- | Mapping of OWL morphisms to CASL morphisms
mapMorphism :: OWLMorphism -> Result CASLMor
cdm <- mapSign $ osource oMor
ccd <- mapSign $ otarget oMor
ObjectProperty ->
Map.insert (i1, objectPropPred) i2
Map.insert (uriToId u1, indiConst) (uriToId u2, Total)
return (embedMorphism () cdm ccd)
mapSymbol :: Entity ->
Set.Set Symbol
mapSymbol (Entity ty iri) = let
Class -> syN $ PredAsItemType conceptPred
ObjectProperty -> syN $ PredAsItemType objectPropPred
DataProperty -> syN $ PredAsItemType dataPropPred
NamedIndividual -> syN $ OpAsItemType indiConst
data VarOrIndi = OVar Int | OIndi IRI
objectPropPred :: PredType
objectPropPred = PredType [thing, thing]
dataPropPred = PredType [thing, dataS]
indiConst = OpType Total [] thing
mapSign ::
OS.Sign -- ^ OWL signature
-> Result CASLSign -- ^ CASL signature
cPreds = thing : nothing : cvrt conc
, tMp objectPropPred oPreds
, tMp dataPropPred dPreds ]
in return $ uniteCASLSign predefSign (emptySign ())
loadDataInformation :: ProfSub -> Sign f ()
mapTheory :: (
OS.Sign, [Named Axiom])
-> Result (CASLSign, [Named CASLFORMULA])
mapTheory (owlSig, owlSens) =
let pSig = loadDataInformation sl
(cSens, nSig) <- foldM (\ (x, y) z ->
(sen, sig) <- mapSentence y z
return (sen ++ x, uniteCASLSign sig y)
return (uniteCASLSign nSig pSig, predefinedAxioms ++ cSens)
-- | mapping of OWL to CASL_DL formulae
mapSentence :: CASLSign -- ^ CASL Signature
-> Named Axiom -- ^ OWL2 Sentence
-> Result ([Named CASLFORMULA], CASLSign) -- ^ CASL Sentence
mapSentence cSig inSen = do
(outAx, outSig) <- mapAxioms cSig $ sentence inSen
return (map (flip mapNamed inSen . const) outAx, outSig)
-> Result ([CASLFORMULA], CASLSign)
mapListFrameBit cSig ex rel lfb
mapAnnFrameBit cSig ex afb
toIRILst ty ane = case ane of
SimpleEntity (Entity ty2 iri) | ty == ty2 -> Just iri
mapFact :: CASLSign -> Extended -> Fact -> Result CASLFORMULA
mapFact cSig ex f = case f of
ObjectPropertyFact posneg obe ind ->
SimpleEntity (Entity NamedIndividual siri) ->
inS <- mapIndivURI cSig siri
inT <- mapIndivURI cSig ind
oPropH <- mapObjProp cSig obe 1 2
let oProp = case posneg of
Negative -> Negation oPropH nullRange
[mkVarDecl (mkNName 1) thing,
mkVarDecl (mkNName 2) thing]
(mkVarDecl (mkNName 1) thing)) inS,
(mkVarDecl (mkNName 2) thing)) inT]
_ -> fail $ "ObjectPropertyFactsFacts Entity fail: " ++ show ex
DataPropertyFact posneg dpe lit ->
SimpleEntity (Entity ty iri) ->
inS <- mapIndivURI cSig iri
inT <- mapLiteral cSig lit
oPropH <- mapDataProp cSig dpe 1 2
let oProp = case posneg of
Negative -> Negation oPropH nullRange
[mkVarDecl (mkNName 1) thing,
mkVarDecl (mkNName 2) dataS]
(mkVarDecl (mkNName 1) thing)) inS,
(mkVarDecl (mkNName 2) dataS)) inT]
_ -> fail "DataPropertyFact EntityType fail"
_ -> fail "DataPropertyFact Entity fail"
-- | Mapping of ListFrameBit
mapListFrameBit :: CASLSign
-> Result ([CASLFORMULA], CASLSign)
mapListFrameBit cSig ex rel lfb = case lfb of
AnnotationBit _a -> return ([], cSig)
Misc _ -> return ([], cSig)
SimpleEntity (Entity ty iri) ->
NamedIndividual | rel == Just Types ->
inD <- mapIndivURI cSig iri
ocls <- mapM (\ (_, c) -> mapDescription cSig c 1) cls
[mkVarDecl (mkNName 1) thing] .
mkImpl (mkStEq (toQualVar
(mkVarDecl (mkNName 1) thing)) inD)
DataProperty | rel == (Just $ DRRelation ADomain) ->
oEx <- mapDataProp cSig iri 1 2
odes <- mapM (\ (_, c) -> mapDescription cSig c 1) cls
let vars = (mkNName 1, mkNName 2)
[mkVarDecl (fst vars) thing] .
[mkVarDecl (snd vars) dataS] .
Nothing -> return ([], cSig)
tobjP <- mapObjProp cSig oe 1 2
tdsc <- mapM (\ (_, c) -> mapDescription cSig c $
ADomain -> (mkNName 1, mkNName 2)
ARange -> (mkNName 2, mkNName 1)
[mkVarDecl (fst vars) thing] .
[mkVarDecl (snd vars) thing] .
_ -> fail "ObjectEntity Relation nyi"
Nothing -> return ([], cSig)
decrsS <- mapDescriptionListP cSig 1
let decrsP = map (\ (x, y) -> mkForall
[mkVarDecl (mkNName 1) thing]
Disjoint -> mkNeg (conjunct [x, y])
domT <- mapDescription cSig ce 1
codT <- mapDescriptionList cSig 1 map2nd
[mkVarDecl (mkNName 1) thing] .
_ -> fail "ClassEntity Relation nyi"
let mol = fmap ObjectProp (toIRILst ObjectProperty ex)
Nothing -> return ([], cSig)
pairs <- mapComObjectPropsList cSig mol map2nd 1 2
return (map (\ (a, b) -> mkForall
[mkVarDecl (mkNName 1) thing,
mkVarDecl (mkNName 2) thing]
Disjoint -> mkNeg (conjunct [a, b])
SubPropertyOf | isJ -> do
os <- mapM (\ (o1, o2) -> mapSubObjProp cSig o1 o2 3)
os1 <- mapM (\ o1 -> mapObjProp cSig o1 1 2) map2nd
o2 <- mapObjProp cSig ob 2 1
[mkVarDecl (mkNName 1) thing,
mkVarDecl (mkNName 2) thing]
let mol = toIRILst DataProperty ex
Nothing -> return ([], cSig)
SubPropertyOf | isJ -> do
os1 <- mapM (\ o1 -> mapDataProp cSig o1 1 2) map2nd
o2 <- mapDataProp cSig ob 2 1
return (map (mkForall [mkVarDecl (mkNName 1) thing,
mkVarDecl (mkNName 2) dataS]
pairs <- mapComDataPropsList cSig map2nd 1 2
return (map (\ (a, b) -> mkForall
[mkVarDecl (mkNName 1) thing,
mkVarDecl (mkNName 2) thing]
Disjoint -> mkNeg (conjunct [a, b])
IndividualSameOrDifferent al ->
let mol = toIRILst NamedIndividual ex
Nothing -> return ([], cSig)
fs <- mapComIndivList cSig re mol map2nd
Nothing -> return ([], cSig)
oEx <- mapDataProp cSig iri 1 2
odes <- mapM (\ (_, c) ->
mapDataRange cSig c 2) dpr
let vars = (mkNName 1, mkNName 2)
return (map (mkForall [mkVarDecl
_ -> fail "DataPropRange EntityType fail"
_ -> fail "DataPropRange Entity fail"
_ -> fail "DataPropRange ADomain ni"
_ -> fail "DataPropRange Relations ni"
IndividualFacts indf -> do
fl <- mapM (mapFact cSig ex . snd) indf
ObjectCharacteristics ace ->
so1 <- mapObjProp cSig ope 1 2
so2 <- mapObjProp cSig ope 1 3
[mkVarDecl (mkNName 1) thing,
mkVarDecl (mkNName 2) thing,
mkVarDecl (mkNName 3) thing]
(toQualVar (mkVarDecl (mkNName 2) thing))
(toQualVar (mkVarDecl (mkNName 3) thing))
so1 <- mapObjProp cSig ope 1 3
so2 <- mapObjProp cSig ope 2 3
[mkVarDecl (mkNName 1) thing,
mkVarDecl (mkNName 2) thing,
mkVarDecl (mkNName 3) thing]
(toQualVar (mkVarDecl (mkNName 1) thing))
(toQualVar (mkVarDecl (mkNName 2) thing))
so <- mapObjProp cSig ope 1 1
[mkVarDecl (mkNName 1) thing]
(mkImpl (Membership (toQualVar
(mkVarDecl (mkNName 1) thing))
so <- mapObjProp cSig ope 1 1
[mkVarDecl (mkNName 1) thing]
(mkImpl (Membership (toQualVar
(mkVarDecl (mkNName 1) thing))
so1 <- mapObjProp cSig ope 1 2
so2 <- mapObjProp cSig ope 2 1
[mkVarDecl (mkNName 1) thing,
mkVarDecl (mkNName 2) thing]
so1 <- mapObjProp cSig ope 1 2
so2 <- mapObjProp cSig ope 2 1
[mkVarDecl (mkNName 1) thing,
mkVarDecl (mkNName 2) thing]
so1 <- mapObjProp cSig ope 1 2
so2 <- mapObjProp cSig ope 2 1
[mkVarDecl (mkNName 1) thing,
mkVarDecl (mkNName 2) thing]
(toQualVar (mkVarDecl (mkNName 1) thing))
(toQualVar (mkVarDecl (mkNName 2) thing))
so1 <- mapObjProp cSig ope 1 2
so2 <- mapObjProp cSig ope 2 3
so3 <- mapObjProp cSig ope 1 3
[mkVarDecl (mkNName 1) thing,
mkVarDecl (mkNName 2) thing,
mkVarDecl (mkNName 3) thing]
(mkImpl (conjunct [so1, so2]) so3)
_ -> fail "ObjectCharacteristics Character fail"
_ -> fail "ObjectCharacteristics Entity fail"
-- | Mapping of AnnFrameBit
mapAnnFrameBit :: CASLSign
-> Result ([CASLFORMULA], CASLSign)
mapAnnFrameBit cSig ex afb =
AnnotationFrameBit _ -> return ([], cSig)
SimpleEntity (Entity ty iri) ->
so1 <- mapDataProp cSig iri 1 2
so2 <- mapDataProp cSig iri 1 3
[mkVarDecl (mkNName 1) thing,
mkVarDecl (mkNName 2) dataS,
mkVarDecl (mkNName 3) dataS]
(toQualVar (mkVarDecl (mkNName 2) thing))
(toQualVar (mkVarDecl (mkNName 3) thing))
_ -> fail "DataFunctional EntityType fail"
_ -> fail "DataFunctional Extend fail"
SimpleEntity (Entity ty iri) ->
odes <- mapDataRange cSig dr 2
[mkVarDecl (mkNName 1) thing]
(toQualVar (mkVarDecl (mkNName 2) thing))
_ -> fail "DatatypeBit EntityType fail"
_ -> fail "DatatypeBit Extend fail"
ClassDisjointUnion clsl ->
SimpleEntity (Entity ty iri) ->
decrs <- mapDescriptionList cSig 1 clsl
decrsS <- mapDescriptionListP cSig 1 $ comPairs clsl clsl
let decrsP = map (\ (x, y) -> conjunct [x, y]) decrsS
mcls <- mapClassURI cSig iri (mkNName 1)
[mkVarDecl (mkNName 1) thing]
_ -> fail "ClassDisjointUnion EntityType fail"
_ -> fail "ClassDisjointUnion Extend fail"
ClassHasKey _obpe _dpe -> return ([], cSig)
ObjectSubPropertyChain oplst ->
os <- mapM (\ cd -> mapSubObjPropChain cSig afb cd 3) oplst
-- | Mapping of ObjectSubPropertyChain
mapSubObjPropChain :: CASLSign
-> ObjectPropertyExpression
mapSubObjPropChain cSig prop oP num1 =
ObjectSubPropertyChain props ->
let zprops = zip (tail props) [(num2 + 1) ..]
oProps <- mapM (\ (z, x, y) -> mapObjProp cSig z x y) $
zip3 props ((num1 : vars) ++ [num2]) $
tail ((num1 : vars) ++ [num2])
ooP <- mapObjProp cSig oP num1 num2
[mkVarDecl (mkNName 1) thing
, mkVarDecl (mkNName 2) thing]
(mkForall (map (\ x -> mkVarDecl
(mkImpl (conjunct oProps) ooP))
_ -> fail "mapping of ObjectSubPropertyChain failed"
{- | Mapping along ObjectPropsList for creation of pairs for commutative
mapComObjectPropsList :: CASLSign -- ^ CASLSignature
-> Maybe ObjectPropertyExpression
-> [ObjectPropertyExpression]
-> Int -- ^ First variable
-> Int -- ^ Last variable
-> Result [(CASLFORMULA, CASLFORMULA)]
mapComObjectPropsList cSig mol props num1 num2 = do
fs <- mapM (\ x -> mapObjProp cSig x num1 num2) props
Nothing -> return $ comPairs fs fs
f <- mapObjProp cSig ol num1 num2
return $ comPairsaux f fs
-- | mapping of individual list
mapComIndivList :: CASLSign -- ^ CASLSignature
mapComIndivList cSig sod mol inds = do
fs <- mapM (mapIndivURI cSig) inds
Nothing -> return $ comPairs fs fs
return $ comPairsaux f fs
return $ map (\ (x, y) -> case sod of
Different -> mkNeg (mkStEq x y)) tps
-- | Mapping of subobj properties
mapSubObjProp :: CASLSign
-> ObjectPropertyExpression
-> ObjectPropertyExpression
mapSubObjProp cSig oPL oP num1 = do
l <- mapObjProp cSig oPL num1 num2
r <- mapObjProp cSig oP num1 num2
return $ mkForallRange [mkVarDecl (mkNName num1) thing,
mkVarDecl (mkNName num2) thing]
{- | Mapping along DataPropsList for creation of pairs for commutative
mapComDataPropsList :: CASLSign
-> [DataPropertyExpression]
-> Int -- ^ First variable
-> Int -- ^ Last variable
-> Result [(CASLFORMULA, CASLFORMULA)]
mapComDataPropsList cSig props num1 num2 =
l <- mapDataProp cSig x num1 num2
r <- mapDataProp cSig z num1 num2
mapNNInt :: NNInt -> TERM ()
in foldr1 joinDigits $ map mkDigit uInt
mapIntLit :: IntLit -> TERM ()
let cInt = mapNNInt $ absInt int
in if isNegInt int then upcast (negateInt cInt) negIntS else upcast cInt nonNegInt
mapDecLit :: DecLit -> TERM ()
n = mkDecimal (mapIntLit $ abInt ip) (mapNNInt fp)
in Sorted_term (if isNegInt ip then negateFloat n else n) dataS nullRange
mapFloatLit :: FloatLit -> TERM ()
n = mkDecimal (mapDecLit $ abDec fb) (mapIntLit ex)
in Sorted_term (if isNegDec fb then negateFloat n else n) dataS nullRange
mapLiteral :: CASLSign -> Literal -> Result (TERM ())
mapLiteral _ lit = case lit of
$ Sorted_term (case ty of
Untyped _ -> foldr consChar emptyStringTerm l
Typed dt -> case datatypeType dt of
OWL2Int -> foldr1 joinDigits
$ map (mkDigit . digitToInt) $ filter isDigit l
_ -> foldr consChar emptyStringTerm l)
| isFloatInt f -> return $ mapIntLit $ truncDec $ floatBase f
| isFloatDec f -> return $ mapDecLit $ floatBase f
| otherwise -> return $ mapFloatLit f
-- | Mapping of data properties
-> DataPropertyExpression
(mkQualPred ur (toPRED_TYPE dataPropPred))
[Qual_var l thing nullRange, Qual_var r dataS nullRange]
-- | Mapping of obj props
-> ObjectPropertyExpression
mapObjProp cSig ob num1 num2 =
(mkQualPred ur (toPRED_TYPE objectPropPred))
[Qual_var l thing nullRange, Qual_var r thing nullRange]
mapObjProp cSig u num2 num1
-- | Mapping of obj props with Individuals
-> ObjectPropertyExpression
mapObjPropI cSig ob lP rP =
OVar num1 -> return $ Qual_var (mkNName num1)
OIndi indivID -> mapIndivURI cSig indivID
OVar num1 -> return $ Qual_var (mkNName num1)
OIndi indivID -> mapIndivURI cSig indivID
(mkQualPred ur (toPRED_TYPE objectPropPred))
ObjectInverseOf u -> mapObjPropI cSig u rP lP
-- | Mapping of Class URIs
(mkQualPred ur (toPRED_TYPE conceptPred))
[Qual_var uid thing nullRange]
-- | Mapping of Individual URIs
(mkQualOp ur (Op_type Total [] thing nullRange))
uriToIdM :: IRI -> Result Id
uriToIdM = return . uriToId
-- | Extracts Id from URI
ur = if isThing urI then mkQName l else urI
nP = concatMap repl $ namePrefix ur
in stringToId $ nP ++ "" ++ lP
-- | Mapping of a list of descriptions
mapDescriptionList :: CASLSign
mapDescriptionList cSig n lst =
mapM (uncurry $ mapDescription cSig)
$ zip lst $ replicate (length lst) n
-- | Mapping of a list of pairs of descriptions
mapDescriptionListP :: CASLSign
-> [(ClassExpression, ClassExpression)]
-> Result [(CASLFORMULA, CASLFORMULA)]
mapDescriptionListP cSig n lst =
llst <- mapDescriptionList cSig n l
rlst <- mapDescriptionList cSig n r
-- | Get all distinct pairs for commutative operations
comPairs :: [t] -> [t1] -> [(t, t1)]
comPairs (a : as) (_ : bs) = comPairsaux a bs ++ comPairs as bs
comPairsaux :: t -> [t1] -> [(t, t1)]
comPairsaux a = map (\ b -> (a, b))
-- | mapping of Data Range
mapDataRange cSig dr inId =
(Qual_var uid thing nullRange)
dc <- mapDataRange cSig drc inId
DataOneOf _ -> error "nyi"
DataJunction _ _ -> error "nyi"
-- | mapping of OWL2 Descriptions
mapDescription :: CASLSign
mapDescription cSig desc var = case desc of
Expression u -> mapClassURI cSig u (mkNName var)
des0 <- mapM (flip (mapDescription cSig) var) ds
IntersectionOf -> conjunct des0
des0 <- mapDescription cSig d var
ind0 <- mapM (mapIndivURI cSig) is
let var0 = toQualVar (mkVarDecl (mkNName var) thing)
let forms = map (mkStEq var0) ind0
ObjectValuesFrom ty o d ->
oprop0 <- mapObjProp cSig o var (var + 1)
desc0 <- mapDescription cSig d (var + 1)
[mkVarDecl (mkNName (var + 1)) thing]
(conjunct [oprop0, desc0])
[mkVarDecl (mkNName (var + 1)) thing]
ObjectHasSelf o -> mapObjProp cSig o var var
ObjectHasValue o i -> mapObjPropI cSig o (OVar var) (OIndi i)
let vlst = [(var + 1) .. (n + var)]
vlstM = [(var + 1) .. (n + var + 1)]
dOut <- (\ x -> case x of
mapM (mapDescription cSig y) vlst
let dlst = map (\ (x, y) ->
mkVarDecl (mkNName x) thing
mkVarDecl (mkNName x) thing
oProps <- mapM (mapObjProp cSig oprop var) vlst
oPropsM <- mapM (mapObjProp cSig oprop var) vlstM
(conjunct (dlst ++ dOut ++ oProps))
(conjunct (oPropsM ++ dOut))
MinCardinality -> return minLst
MaxCardinality -> return maxLst
ExactCardinality -> return $ conjunct [minLst, maxLst]
DataValuesFrom ty dpe dr ->
oprop0 <- mapDataProp cSig dpe var (var + 1)
desc0 <- mapDataRange cSig dr (var + 1)
[mkVarDecl (mkNName (var + 1)) thing]
(conjunct [oprop0, desc0])
[mkVarDecl (mkNName (var + 1)) thing]
DataHasValue _ _ -> fail "DataHasValue handling nyi"
DataCardinality _ -> fail "DataCardinality handling nyi"