-------------------------------------------------------------------------------- -- $Id: ClassRestrictionRuleTest.hs,v 1.14 2004/01/07 19:49:12 graham Exp $ -- -- Copyright (c) 2003, G. KLYNE. All rights reserved. -- See end of this file for licence information. -------------------------------------------------------------------------------- -- | -- Module : ClassRestrictionRuleTest -- Copyright : (c) 2003, Graham Klyne -- License : GPL V2 -- -- Maintainer : Graham Klyne -- Stability : provisional -- Portability : H98 -- -- This module tests module ClassRestrictionRule. -- It also performs tests basic functions of modules Datatype and RDFDatatype -- -------------------------------------------------------------------------------- module ClassRestrictionRuleTest where import ClassRestrictionRule ( ClassRestriction(..), ClassRestrictionFn , makeDatatypeRestriction, makeDatatypeRestrictionFn , makeRDFDatatypeRestrictionRules , falseGraph, falseGraphStr ) import RDFGraph ( RDFLabel(..) , RDFGraph ) import RDFRuleset ( RDFFormula, RDFRule, RDFClosure, RDFRuleset , makeRDFGraphFromN3String , makeRDFFormula ) import Ruleset ( Ruleset(..) , makeRuleset , getRulesetAxiom, getRulesetRule ) import Rule ( Expression(..), Formula(..), Rule(..) ) import RDFDatatype ( RDFDatatype , RDFDatatypeVal , fromRDFLabel, toRDFLabel, makeDatatypedLiteral ) import Datatype ( Datatype(..), typeMkRules -- , typeMkModifiers , DatatypeVal(..) , getDTRel , DatatypeMap(..) , DatatypeRel(..) , altArgs, unaryFnApp, binaryFnApp, binMaybeFnApp ) import Namespace ( Namespace(..) , ScopedName(..) , getQName ) import Vocabulary ( namespaceRDF , namespaceRDFS , namespaceRDFD , namespaceXSD , namespaceXsdType ) import ListHelpers ( equiv ) import Dfa ( Re(..) , matchRe ) import HUnit ( Test(TestCase,TestList,TestLabel) , Assertion , assertBool, assertEqual, assertString, assertFailure , runTestTT, runTestText, putTextToHandle ) import IO ( Handle, IOMode(WriteMode) , openFile, hClose, hPutStr, hPutStrLn ) import Monad ( unless ) import List ( sort, union, intersect ) import Maybe ( isJust, fromJust, fromMaybe, listToMaybe ) ------------------------------------------------------------ -- Test case helpers ------------------------------------------------------------ assertMember :: (Eq a, Show a) => String -> a -> [a] -> Assertion assertMember preface expected actual = unless (expected `elem` actual ) (assertFailure msg) where msg = (if null preface then "" else preface ++ "\n") ++ "expected: " ++ show expected ++ "\nbut got: " ++ show actual test :: String -> Bool -> Test test lab bv = TestCase ( assertBool ("test:"++lab) bv ) testEq :: (Eq a, Show a) => String -> a -> a -> Test testEq lab a1 a2 = TestCase ( assertEqual ("testEq:"++lab) a1 a2 ) testElem :: (Eq a, Show a) => String -> a -> [a] -> Test testElem lab a1 as = TestCase ( assertMember ("testElem:"++lab) a1 as ) testLe :: (Ord a, Show a) => String -> Bool -> a -> a -> Test testLe lab eq a1 a2 = TestCase ( assertEqual ("testLe:"++lab) eq (a1<=a2) ) -- Test for Just x or Nothing testJust :: String -> Maybe a -> Test testJust lab av = TestCase ( assertBool ("testJust:"++lab) (isJust av) ) testNothing :: String -> Maybe a -> Test testNothing lab av = TestCase ( assertBool ("testJust:"++lab) (not $ isJust av) ) -- Compare lists and lists of lists and Maybe lists for set equivalence: data ListTest a = ListTest [a] instance (Eq a) => Eq (ListTest a) where (ListTest a1) == (ListTest a2) = a1 `equiv` a2 instance (Show a) => Show (ListTest a) where show (ListTest a) = show a data MaybeListTest a = MaybeListTest (Maybe [a]) instance (Eq a) => Eq (MaybeListTest a) where MaybeListTest (Just a1) == MaybeListTest (Just a2) = a1 `equiv` a2 MaybeListTest Nothing == MaybeListTest Nothing = True _ == _ = False instance (Show a) => Show (MaybeListTest a) where show (MaybeListTest a) = show a testEqv :: (Eq a, Show a) => String -> [a] -> [a] -> Test testEqv lab a1 a2 = TestCase ( assertEqual ("testEqv:"++lab) (ListTest a1) (ListTest a2) ) testEqvEqv :: (Eq a, Show a) => String -> [[a]] -> [[a]] -> Test testEqvEqv lab a1 a2 = TestCase ( assertEqual ("testEqvEqv:"++lab) ma1 ma2 ) where ma1 = ListTest $ map ListTest a1 ma2 = ListTest $ map ListTest a2 testHasEqv :: (Eq a, Show a) => String -> [a] -> [[a]] -> Test testHasEqv lab a1 a2 = TestCase ( assertMember ("testHasEqv:"++lab) ma1 ma2 ) where ma1 = ListTest a1 ma2 = map ListTest a2 testMaybeEqv :: (Eq a, Show a) => String -> Maybe [a] -> Maybe [a] -> Test testMaybeEqv lab a1 a2 = TestCase ( assertEqual ("testMaybeEqv:"++lab) ma1 ma2 ) where ma1 = (MaybeListTest a1) ma2 = (MaybeListTest a2) ------------------------------------------------------------ -- Define a Boolean datatype ------------------------------------------------------------ nameXsdBoolean = "boolean" typeNameXsdBoolean = ScopedName namespaceXSD nameXsdBoolean namespaceXsdBoolean = namespaceXsdType nameXsdBoolean rdfDatatypeXsdBoolean :: RDFDatatype rdfDatatypeXsdBoolean = Datatype rdfDatatypeValXsdBoolean rdfDatatypeValXsdBoolean :: RDFDatatypeVal Bool rdfDatatypeValXsdBoolean = DatatypeVal { tvalName = typeNameXsdBoolean , tvalRules = rdfRulesetXsdBoolean -- Ruleset RDFGraph , tvalMkRules = makeRDFDatatypeRestrictionRules rdfDatatypeValXsdBoolean , tvalMkMods = error "ClassRestrictionRuleTest: no tvalMkMods for rdfDatatypeValXsdBoolean" , tvalMap = mapXsdBoolean -- DatatypeMap Bool , tvalRel = relXsdBoolean -- [DatatypeRel Bool] , tvalMod = error "ClassRestrictionRuleTest: no tvalMod for rdfDatatypeValXsdBoolean" } -- |mapXsdBoolean contains functions that perform lexical-to-value -- and value-to-canonical-lexical mappings for xsd:boolean values -- mapXsdBoolean :: DatatypeMap Bool mapXsdBoolean = DatatypeMap { -- mapL2V :: String -> Maybe Bool mapL2V = \s -> case s of s | matchT s -> Just True | matchF s -> Just False | otherwise -> Nothing -- mapV2L :: Bool -> Maybe String , mapV2L = Just . (\b -> if b then "true" else "false") } where matchT = matchRe reTrue reTrue = ReOr $ [ ReTerm "true", ReTerm "1" ] matchF = matchRe reFalse reFalse = ReOr $ [ ReTerm "false", ReTerm "0" ] mkBoolRel2 nam fns = DatatypeRel { dtRelName = ScopedName namespaceXsdBoolean nam , dtRelFunc = altArgs (const True) fns unaryFnApp } mkBoolRelTest2 nam pr fns = DatatypeRel { dtRelName = ScopedName namespaceXsdBoolean nam , dtRelFunc = altArgs pr fns unaryFnApp } mkBoolRel3 nam fns = DatatypeRel { dtRelName = ScopedName namespaceXsdBoolean nam , dtRelFunc = altArgs (const True) fns binaryFnApp } mkBoolRelMaybe3 nam fns = DatatypeRel { dtRelName = ScopedName namespaceXsdBoolean nam , dtRelFunc = altArgs (const True) fns binMaybeFnApp } relXsdBoolean :: [DatatypeRel Bool] relXsdBoolean = [ relnot, relor, reland, releqv, releq ] c2 = (.) . (.) -- compose with function of two arguments relnot = mkBoolRel2 "not" [ (const True,[(not,1)]) , (const True,[(not,0)]) ] maybeInv1 f res arg = list1 $ f res arg where list1 (a:_) = Just [a] list1 _ = Nothing -- No values means inconsistent values supplied maybeInv2 f res arg = list2 $ f res arg where list2 (_:a:_) = Just [a] list2 _ = Just [] invOr False False = [False] invOr False True = [] invOr True False = [True] invOr True True = [False,True] relor = mkBoolRelMaybe3 "or" [ (const True,[((Just . (:[])) `c2` (||),1,2)]) , (const True,[(maybeInv1 invOr,0,2),(maybeInv2 invOr,0,2)]) , (const True,[(maybeInv1 invOr,0,1),(maybeInv2 invOr,0,1)]) ] invAnd False False = [False,True] invAnd False True = [False] invAnd True False = [] invAnd True True = [True] reland = mkBoolRelMaybe3 "and" [ (const True,[((Just . (:[])) `c2` (&&),1,2)]) , (const True,[(maybeInv1 invAnd,0,2),(maybeInv2 invAnd,0,2)]) , (const True,[(maybeInv1 invAnd,0,1),(maybeInv2 invAnd,0,1)]) ] releqv = mkBoolRel3 "eqv" [ (const True,[((==),1,2)]) , (const True,[((==),0,2)]) , (const True,[((==),0,1)]) ] releq :: DatatypeRel Bool releq = mkBoolRelTest2 "eq" (\xs -> head xs == head (tail xs)) (repeat (const True,[])) -- |rdfRulesetXsdBoolean contains rules and axioms that allow additional -- deductions when xsd:boolean values appear in a graph. -- -- makeRuleset :: Namespace -> [Formula ex] -> [Rule ex] -> Ruleset ex -- rdfRulesetXsdBoolean = makeRuleset namespaceXsdBoolean axiomsXsdBoolean rulesXsdBoolean prefixXsdBoolean = "@prefix rdf: <" ++ nsURI namespaceRDF ++ "> . \n" ++ "@prefix rdfs: <" ++ nsURI namespaceRDFS ++ "> . \n" ++ "@prefix rdfd: <" ++ nsURI namespaceRDFD ++ "> . \n" ++ "@prefix xsd: <" ++ nsURI namespaceXSD ++ "> . \n" ++ "@prefix xsd_boolean: <" ++ nsURI namespaceXsdBoolean ++ "> . \n" ++ " \n" mkAxiom :: String -> String -> RDFFormula mkAxiom local gr = makeRDFFormula namespaceXsdBoolean local (prefixXsdBoolean++gr) axiomsXsdBoolean = [ mkAxiom "dt" "xsd:boolean rdf:type rdfs:Datatype ." , mkAxiom "notprop" "xsd_boolean:not rdf:type rdf:Property ." , mkAxiom "notdom" "xsd_boolean:not rdfs:domain xsd:boolean ." , mkAxiom "notrng" "xsd_boolean:not rdfs:domain xsd:boolean ." -- [[[more]]] -- ] rulesXsdBoolean = typeMkRules rdfDatatypeXsdBoolean gr where gr = makeRDFGraphFromN3String (prefixXsdBoolean++boolRestrictions) boolRestrictions = " xsd_boolean:Not a rdfd:GeneralRestriction ; " ++ " rdfd:onProperties (rdf:_1 rdf:_2) ; " ++ " rdfd:constraint xsd_boolean:not ; " ++ " rdfd:maxCardinality \"1\"^^xsd:integer . " ++ " xsd_boolean:Or a rdfd:GeneralRestriction ; " ++ " rdfd:onProperties (rdf:_1 rdf:_2 rdf:_3) ; " ++ " rdfd:constraint xsd_boolean:or ; " ++ " rdfd:maxCardinality \"1\"^^xsd:integer . " ++ " xsd_boolean:And a rdfd:GeneralRestriction ; " ++ " rdfd:onProperties (rdf:_1 rdf:_2 rdf:_3) ; " ++ " rdfd:constraint xsd_boolean:and ; " ++ " rdfd:maxCardinality \"1\"^^xsd:integer . " ++ " xsd_boolean:AndX a rdfd:GeneralRestriction ; " ++ " rdfd:onProperties (rdf:_1 rdf:_2 rdf:_3) ; " ++ " rdfd:constraint xsd_boolean:and . " ++ " xsd_boolean:Eqv a rdfd:GeneralRestriction ; " ++ " rdfd:onProperties (rdf:_1 rdf:_2 rdf:_3) ; " ++ " rdfd:constraint xsd_boolean:eqv ; " ++ " rdfd:maxCardinality \"1\"^^xsd:integer . " ++ " xsd_boolean:Eq a rdfd:GeneralRestriction ; " ++ " rdfd:onProperties (rdf:_1 rdf:_2) ; " ++ " rdfd:constraint xsd_boolean:eq ; " ++ " rdfd:maxCardinality \"1\"^^xsd:integer . " ------------------------------------------------------------ -- Test datatype ------------------------------------------------------------ testDT01 = testEq "testDT01" typeNameXsdBoolean $ tvalName rdfDatatypeValXsdBoolean testDTMap01 = testEq "testDTMap01" (Just True) $ mapL2V (tvalMap rdfDatatypeValXsdBoolean) "true" testDTMap02 = testEq "testDTMap02" (Just False) $ mapL2V (tvalMap rdfDatatypeValXsdBoolean) "false" testDTMap03 = testEq "testDTMap03" Nothing $ mapL2V (tvalMap rdfDatatypeValXsdBoolean) "xyzzy" testDTMap04 = testEq "testDTMap04" (Just "true") $ mapV2L (tvalMap rdfDatatypeValXsdBoolean) True testDTMap05 = testEq "testDTMap05" (Just "false") $ mapV2L (tvalMap rdfDatatypeValXsdBoolean) False testDatatypeSuite = TestList [ testDT01 , testDTMap01, testDTMap02, testDTMap03, testDTMap04, testDTMap05 ] ------------------------------------------------------------ -- Test datatype relation ------------------------------------------------------------ xsd_boolean_not = ScopedName namespaceXsdBoolean "not" Just testrelnot = getDTRel xsd_boolean_not rdfDatatypeValXsdBoolean testRelNot01 = testEq "testRelNot01" "xsd_boolean:not" $ show (dtRelName testrelnot) testRelNot02 = testEq "testRelNot02" (Just [[True,False]]) $ dtRelFunc testrelnot [Nothing,Just False] testRelNot03 = testEq "testRelNot03" (Just [[False,True]]) $ dtRelFunc testrelnot [Nothing,Just True] testRelNot04 = testEq "testRelNot04" (Just [[True,False]]) $ dtRelFunc testrelnot [Just True,Nothing] testRelNot05 = testEq "testRelNot05" (Just [[False,True]]) $ dtRelFunc testrelnot [Just False,Nothing] testRelNot06 = testEq "testRelNot06" Nothing $ dtRelFunc testrelnot [Just False,Just False] testRelNot07 = testEq "testRelNot07" Nothing $ dtRelFunc testrelnot [Just True,Just True] testRelNot08 = testEq "testRelNot08" (Just []) $ dtRelFunc testrelnot [Nothing,Nothing] xsd_boolean_or = ScopedName namespaceXsdBoolean "or" Just testrelor = getDTRel xsd_boolean_or rdfDatatypeValXsdBoolean testRelOr01 = testEq "testRelOr01" "xsd_boolean:or" $ show (dtRelName testrelor) testRelOr02 = testEq "testRelOr02" (Just [[False,False,False]]) $ dtRelFunc testrelor [Nothing,Just False,Just False] testRelOr03 = testEq "testRelOr03" (Just [[True,True,False]]) $ dtRelFunc testrelor [Nothing,Just True,Just False] testRelOr04 = testEq "testRelOr04" (Just [[True,False,True]]) $ dtRelFunc testrelor [Just True,Just False,Just True] testRelOr05 = testEq "testRelOr05" (Just [[True,True,True]]) $ dtRelFunc testrelor [Just True,Just True,Just True] testRelOr06 = testEq "testRelOr06" Nothing $ dtRelFunc testrelor [Just False,Just True,Just True] testRelOr07 = testEq "testRelOr07" Nothing $ dtRelFunc testrelor [Just True,Just False,Just False] testRelOr08 = testEq "testRelOr08" (Just [[True,False,True],[True,True,True]]) $ dtRelFunc testrelor [Just True,Nothing,Just True] testRelOr09 = testEq "testRelOr09" (Just [[True,True,False]]) $ dtRelFunc testrelor [Just True,Nothing,Just False] testRelOr10 = testEq "testRelOr10" Nothing $ dtRelFunc testrelor [Just False,Nothing,Just True] xsd_boolean_and = ScopedName namespaceXsdBoolean "and" Just testreland = getDTRel xsd_boolean_and rdfDatatypeValXsdBoolean testRelAnd01 = testEq "testRelAnd01" "xsd_boolean:and" $ show (dtRelName testreland) testRelAnd02 = testEq "testRelAnd02" (Just [[False,False,False]]) $ dtRelFunc testreland [Nothing,Just False,Just False] testRelAnd03 = testEq "testRelAnd03" (Just [[False,True,False]]) $ dtRelFunc testreland [Nothing,Just True,Just False] testRelAnd04 = testEq "testRelAnd04" (Just [[False,False,True]]) $ dtRelFunc testreland [Just False,Just False,Just True] testRelAnd05 = testEq "testRelAnd05" (Just [[True,True,True]]) $ dtRelFunc testreland [Just True,Just True,Just True] testRelAnd06 = testEq "testRelAnd06" Nothing $ dtRelFunc testreland [Just False,Just True,Just True] testRelAnd07 = testEq "testRelAnd07" Nothing $ dtRelFunc testreland [Just True,Just True,Just False] testRelAnd08 = testEq "testRelAnd08" (Just [[False,False,False],[False,True,False]]) $ dtRelFunc testreland [Just False,Nothing,Just False] testRelAnd09 = testEq "testRelAnd09" (Just [[True,True,True]]) $ dtRelFunc testreland [Just True,Nothing,Just True] testRelAnd10 = testEq "testRelAnd10" Nothing $ dtRelFunc testreland [Just True,Nothing,Just False] xsd_boolean_eqv = ScopedName namespaceXsdBoolean "eqv" Just testreleqv = getDTRel xsd_boolean_eqv rdfDatatypeValXsdBoolean testRelEqv01 = testEq "testRelEqv01" "xsd_boolean:eqv" $ show (dtRelName testreleqv) testRelEqv02 = testEq "testRelEqv02" (Just [[True,False,False]]) $ dtRelFunc testreleqv [Nothing,Just False,Just False] testRelEqv03 = testEq "testRelEqv03" (Just [[False,True,False]]) $ dtRelFunc testreleqv [Nothing,Just True,Just False] testRelEqv04 = testEq "testRelEqv04" (Just [[False,False,True]]) $ dtRelFunc testreleqv [Just False,Just False,Just True] testRelEqv05 = testEq "testRelEqv05" (Just [[True,True,True]]) $ dtRelFunc testreleqv [Just True,Just True,Just True] testRelEqv06 = testEq "testRelEqv06" Nothing $ dtRelFunc testreleqv [Just True,Just False,Just True] testRelEqv07 = testEq "testRelEqv07" (Just [[True,False,False]]) $ dtRelFunc testreleqv [Just True,Nothing,Just False] testRelEqv08 = testEq "testRelEqv08" (Just []) $ dtRelFunc testreleqv [Nothing,Nothing,Just False] xsd_boolean_eq = ScopedName namespaceXsdBoolean "eq" Just testreleq = getDTRel xsd_boolean_eq rdfDatatypeValXsdBoolean testRelEq01 = testEq "testRelEq01" "xsd_boolean:eq" $ show (dtRelName testreleq) testRelEq02 = testEq "testRelEq02" (Just [[False,False]]) $ dtRelFunc testreleq [Just False,Just False] testRelEq03 = testEq "testRelEq03" (Nothing) $ dtRelFunc testreleq [Just True,Just False] testRelEq04 = testEq "testRelEq04" (Nothing) $ dtRelFunc testreleq [Just False,Just True] testRelEq05 = testEq "testRelEq05" (Just [[True,True]]) $ dtRelFunc testreleq [Just True,Just True] testRelEq06 = testEq "testRelEq06" (Just []) $ dtRelFunc testreleq [Nothing,Just True] testRelEq07 = testEq "testRelEq07" (Just []) $ dtRelFunc testreleq [Just False,Nothing] testRelationSuite = TestList [ testRelNot01, testRelNot02, testRelNot03, testRelNot04 , testRelNot05, testRelNot06, testRelNot07, testRelNot08 , testRelOr01, testRelOr02, testRelOr03, testRelOr04 , testRelOr05, testRelOr06, testRelOr07, testRelOr08 , testRelOr09, testRelOr10 , testRelAnd01, testRelAnd02, testRelAnd03, testRelAnd04 , testRelAnd05, testRelAnd06, testRelAnd07, testRelAnd08 , testRelAnd09, testRelAnd10 , testRelEqv01, testRelEqv02, testRelEqv03, testRelEqv04 , testRelEqv05, testRelEqv06, testRelEqv07, testRelEqv08 , testRelEq01, testRelEq02, testRelEq03, testRelEq04 , testRelEq05, testRelEq06, testRelEq07 ] ------------------------------------------------------------ -- Test class restriction ------------------------------------------------------------ testclsnot = makeDatatypeRestriction rdfDatatypeValXsdBoolean testrelnot lt = makeDatatypedLiteral typeNameXsdBoolean "true" lf = makeDatatypedLiteral typeNameXsdBoolean "false" ln = makeDatatypedLiteral typeNameXsdBoolean "xyzzy" rn = Res typeNameXsdBoolean testClsNot01 = testEq "testClsNot01" "xsd_boolean:not" $ show (crName testclsnot) testClsNot02 = testEq "testClsNot02" (Just [[lt,lf]]) $ crFunc testclsnot [Nothing,Just lf] testClsNot03 = testEq "testClsNot03" (Just [[lf,lt]]) $ crFunc testclsnot [Nothing,Just lt] testClsNot04 = testEq "testClsNot04" (Just [[lt,lf]]) $ crFunc testclsnot [Just lt,Nothing] testClsNot05 = testEq "testClsNot05" (Just [[lf,lt]]) $ crFunc testclsnot [Nothing,Just lt] testClsNot06 = testEq "testClsNot06" (Just [[lt,lf]]) $ crFunc testclsnot [Just lt,Just ln] testClsNot07 = testEq "testClsNot07" (Just [[lf,lt]]) $ crFunc testclsnot [Just rn,Just lt] testClsNot08 = testEq "testClsNot08" Nothing $ crFunc testclsnot [Just lf,Just lf] testClsNot09 = testEq "testClsNot09" Nothing $ crFunc testclsnot [Just lt,Just lt] testClsNot10 = testEq "testClsNot10" (Just []) $ crFunc testclsnot [Just ln,Just rn] testclseqv = makeDatatypeRestriction rdfDatatypeValXsdBoolean testreleqv testClsEqv01 = testEq "testClsEqv01" "xsd_boolean:eqv" $ show (crName testclseqv) testClsEqv02 = testEq "testClsEqv02" (Just [[lt,lf,lf]]) $ crFunc testclseqv [Nothing,Just lf,Just lf] testClsEqv03 = testEq "testClsEqv03" (Just [[lf,lt,lf]]) $ crFunc testclseqv [Just ln,Just lt,Just lf] testClsEqv04 = testEq "testClsEqv04" (Just [[lf,lf,lt]]) $ crFunc testclseqv [Just lf,Just lf,Just lt] testClsEqv05 = testEq "testClsEqv05" (Just [[lt,lt,lt]]) $ crFunc testclseqv [Just lt,Just lt,Just lt] testClsEqv06 = testEq "testClsEqv06" Nothing $ crFunc testclseqv [Just lt,Just lf,Just lt] testClsEqv07 = testEq "testClsEqv07" (Just []) $ crFunc testclseqv [Nothing,Nothing,Just lf] testClsEqv08 = testEq "testClsEqv08" (Just []) $ crFunc testclseqv [Just ln,Just rn,Just lf] testclseq = makeDatatypeRestriction rdfDatatypeValXsdBoolean testreleq testClsEq01 = testEq "testClsEq01" "xsd_boolean:eq" $ show (crName testclseq) testClsEq02 = testEq "testClsEq02" (Just [[lf,lf]]) $ crFunc testclseq [Just lf,Just lf] testClsEq03 = testEq "testClsEq03" (Nothing) $ crFunc testclseq [Just lt,Just lf] testClsEq04 = testEq "testClsEq04" (Just [[lt,lt]]) $ crFunc testclseq [Just lt,Just lt] testClsEq05 = testEq "testClsEq05" (Just []) $ crFunc testclseq [Nothing,Just lt] testClsEq06 = testEq "testClsEq06" (Just []) $ crFunc testclseq [Just lf,Nothing] testClassRestrictionSuite = TestList [ testClsNot01, testClsNot02, testClsNot03, testClsNot04 , testClsNot05, testClsNot06, testClsNot07, testClsNot08 , testClsNot09, testClsNot10 , testClsEqv01, testClsEqv02, testClsEqv03, testClsEqv04 , testClsEqv05, testClsEqv06, testClsEqv07, testClsEqv08 , testClsEq01, testClsEq02, testClsEq03, testClsEq04 , testClsEq05, testClsEq06 ] ------------------------------------------------------------ -- Test datatype axioms ------------------------------------------------------------ testAxiom lab axnam axstr = testEq lab axgr axgr1 where axgr = makeRDFGraphFromN3String (prefixXsdBoolean++axstr) axgr1 = formExpr $ fromJust $ getRulesetAxiom axnam rdfRulesetXsdBoolean testAxiom01 = testAxiom "testAxiom01" (ScopedName namespaceXsdBoolean "dt") "xsd:boolean rdf:type rdfs:Datatype ." testAxiomSuite = TestList [ testAxiom01 ] ------------------------------------------------------------ -- Test datatype rules ------------------------------------------------------------ grnot01inpstr = [ "test:not01 a xsd_boolean:Not ; " ++ " rdf:_1 \"true\"^^xsd:boolean . " ] grnot01resstr = [ "test:not01 rdf:_2 \"false\"^^xsd:boolean . " ] grnot01prestr = [ [ "test:not01 a xsd_boolean:Not . " , "test:not01 rdf:_2 \"false\"^^xsd:boolean . " ] ] grnot02inpstr = [ " test:not01 a xsd_boolean:Not ; " ++ " rdf:_1 \"true\"^^xsd:boolean . " ++ " test:not02 a xsd_boolean:Not ; " ++ " rdf:_2 \"true\"^^xsd:boolean . " ++ " test:not03 a xsd_boolean:Not ; " ++ " rdf:_1 \"false\"^^xsd:boolean . " ++ " test:not04 a xsd_boolean:Not ; " ++ " rdf:_2 \"false\"^^xsd:boolean . " , " test:not05 a xsd_boolean:Not ; " ++ " rdf:_1 \"xyzzy\"^^xsd:boolean . " ++ " test:not06 a xsd_boolean:Not ; " ++ " rdf:_1 \"true\" . " ] grnot02resstr = [ "test:not01 rdf:_2 \"false\"^^xsd:boolean . " , "test:not02 rdf:_1 \"false\"^^xsd:boolean . " , "test:not03 rdf:_2 \"true\"^^xsd:boolean . " , "test:not04 rdf:_1 \"true\"^^xsd:boolean . " ] grnot02prestra = [ [ "test:not04 a xsd_boolean:Not . " , "test:not04 rdf:_1 \"true\"^^xsd:boolean . " , "test:not03 a xsd_boolean:Not . " , "test:not03 rdf:_2 \"true\"^^xsd:boolean . " , "test:not02 a xsd_boolean:Not . " , "test:not02 rdf:_1 \"false\"^^xsd:boolean . " , "test:not01 a xsd_boolean:Not . " , "test:not01 rdf:_2 \"false\"^^xsd:boolean . " ] ] grnot02prestrb = [] grnot03inpstr = [ " test:not07 a xsd_boolean:Not ; " ++ " rdf:_1 \"true\"^^xsd:boolean ; " ++ " rdf:_2 \"true\"^^xsd:boolean . " ] grnot03resstr = [ falseGraphStr ] grnot03prestr = [ [ falseGraphStr ] ] grand04inpstr = [ " test:and01 a xsd_boolean:And ; " ++ " rdf:_1 \"true\"^^xsd:boolean ; " ++ " rdf:_2 \"true\"^^xsd:boolean ; " ++ " rdf:_3 \"true\"^^xsd:boolean . " , " test:and02 a xsd_boolean:And ; " ++ " rdf:_1 \"false\"^^xsd:boolean ; " ++ " rdf:_2 \"false\"^^xsd:boolean ; " ++ " rdf:_3 \"true\"^^xsd:boolean . " , " test:and03 a xsd_boolean:And ; " ++ " rdf:_2 \"true\"^^xsd:boolean ; " ++ " rdf:_3 \"false\"^^xsd:boolean . " , " test:and04 a xsd_boolean:And ; " ++ " rdf:_2 \"true\"^^xsd:boolean ; " ++ " rdf:_3 \"true\"^^xsd:boolean . " , " test:and05 a xsd_boolean:And ; " ++ " rdf:_1 \"false\"^^xsd:boolean ; " ++ " rdf:_2 \"false\"^^xsd:boolean . " , " test:and06 a xsd_boolean:And ; " ++ " rdf:_1 \"false\"^^xsd:boolean ; " ++ " rdf:_2 \"true\"^^xsd:boolean . " , " test:and07 a xsd_boolean:And ; " ++ " rdf:_1 \"false\"^^xsd:boolean . " , " test:and08 a xsd_boolean:And ; " ++ " rdf:_1 \"true\"^^xsd:boolean . " , " test:and09 a xsd_boolean:And ; " ++ " rdf:_2 \"false\"^^xsd:boolean . " , " test:and10 a xsd_boolean:And ; " ++ " rdf:_3 \"true\"^^xsd:boolean . " ] grand04resstr = [ " test:and03 rdf:_1 \"false\"^^xsd:boolean . " , " test:and04 rdf:_1 \"true\"^^xsd:boolean . " , " test:and06 rdf:_3 \"false\"^^xsd:boolean . " ] grand04prestr01 = -- True = True && True [ [ "test:and01 a xsd_boolean:And . " , "test:and01 rdf:_2 \"true\"^^xsd:boolean . " , "test:and01 rdf:_3 \"true\"^^xsd:boolean . " ] , [ "test:and01 a xsd_boolean:And . " , "test:and01 rdf:_1 \"true\"^^xsd:boolean . " , "test:and01 rdf:_2 \"true\"^^xsd:boolean . " ] , [ "test:and01 a xsd_boolean:And . " , "test:and01 rdf:_1 \"true\"^^xsd:boolean . " , "test:and01 rdf:_3 \"true\"^^xsd:boolean . " ] ] grand04prestr02 = -- False = False && True [ [ "test:and02 a xsd_boolean:And . " , "test:and02 rdf:_2 \"false\"^^xsd:boolean . " , "test:and02 rdf:_3 \"true\"^^xsd:boolean . " ] , [ "test:and02 a xsd_boolean:And . " , "test:and02 rdf:_1 \"false\"^^xsd:boolean . " , "test:and02 rdf:_3 \"true\"^^xsd:boolean . " ] ] grand04prestr03 = -- ? = True && False [ [ "test:and03 a xsd_boolean:And . " , "test:and03 rdf:_1 \"false\"^^xsd:boolean . " , "test:and03 rdf:_2 \"true\"^^xsd:boolean . " ] ] grand04prestr04 = -- ? = True && True [ [ "test:and04 a xsd_boolean:And . " , "test:and04 rdf:_1 \"true\"^^xsd:boolean . " , "test:and04 rdf:_2 \"true\"^^xsd:boolean . " ] , [ "test:and04 a xsd_boolean:And . " , "test:and04 rdf:_1 \"true\"^^xsd:boolean . " , "test:and04 rdf:_3 \"true\"^^xsd:boolean . " ] ] grand04prestr05 = -- False = False && ? [ [ "test:and05 a xsd_boolean:And . " , "test:and05 rdf:_1 \"false\"^^xsd:boolean . " , "test:and05 rdf:_3 \"true\"^^xsd:boolean . " ] , [ "test:and05 a xsd_boolean:And . " , "test:and05 rdf:_2 \"false\"^^xsd:boolean . " , "test:and05 rdf:_3 \"true\"^^xsd:boolean . " ] , [ "test:and05 a xsd_boolean:And . " , "test:and05 rdf:_2 \"false\"^^xsd:boolean . " , "test:and05 rdf:_3 \"false\"^^xsd:boolean . " ] ] grand04prestr06 = -- False = True && ? [ [ "test:and06 a xsd_boolean:And . " , "test:and06 rdf:_2 \"true\"^^xsd:boolean . " , "test:and06 rdf:_3 \"false\"^^xsd:boolean . " ] ] grand04prestr07 = -- False = ? && ? [ ] grand04prestr08 = -- True = ? && ? [ ] grand04prestr09 = -- ? = False && ? [ ] grand04prestr10 = -- ? = ? && True [ ] grand05inpstr = [ "test:and07 a xsd_boolean:And ; " ++ " rdf:_1 \"true\"^^xsd:boolean ; " ++ " rdf:_2 \"false\"^^xsd:boolean ; " ++ " rdf:_3 \"true\"^^xsd:boolean . " ] grand05resstr = [ falseGraphStr ] grand05prestr = [ [ falseGraphStr ] ] -- Isolate alternative backward chaining results test case for debugging grand06inpstr = [ " test:and01 a xsd_boolean:And ; " ++ " rdf:_1 \"true\"^^xsd:boolean ; " ++ " rdf:_2 \"true\"^^xsd:boolean ; " ++ " rdf:_3 \"true\"^^xsd:boolean . " ] grand06prestr = -- True = True && True [ [ "test:and01 a xsd_boolean:And . " , "test:and01 rdf:_2 \"true\"^^xsd:boolean . " , "test:and01 rdf:_3 \"true\"^^xsd:boolean . " ] , [ "test:and01 a xsd_boolean:And . " , "test:and01 rdf:_1 \"true\"^^xsd:boolean . " , "test:and01 rdf:_2 \"true\"^^xsd:boolean . " ] , [ "test:and01 a xsd_boolean:And . " , "test:and01 rdf:_1 \"true\"^^xsd:boolean . " , "test:and01 rdf:_3 \"true\"^^xsd:boolean . " ] ] -- Test duplicate arc elimination with bnode subject grnot07inpstr = [ "_:not01 a xsd_boolean:Not ; " ++ " rdf:_1 \"true\"^^xsd:boolean . " ] grnot07resstr = [ "_:not01 rdf:_2 \"false\"^^xsd:boolean . " ] -- Conflicting And values without cardinality constraint grand08inpstr = [ " test:and01 a xsd_boolean:AndX ; " ++ " rdf:_2 \"false\"^^xsd:boolean ; " ++ " rdf:_2 \"true\"^^xsd:boolean ; " ++ " rdf:_3 \"true\"^^xsd:boolean . " ] grand08resstr = [ "test:and01 rdf:_1 \"false\"^^xsd:boolean . " ++ "test:and01 rdf:_1 \"true\"^^xsd:boolean . " ] -- Eq relation greq09inpstr = [ "test:eq09 a xsd_boolean:Eq ; " ++ " rdf:_1 \"true\"^^xsd:boolean ; " ++ " rdf:_2 \"true\"^^xsd:boolean . " ] greq09resstr = [] greq09prestr = [] greq10inpstr = [ " test:eq10 a xsd_boolean:Eq ; " ++ " rdf:_1 \"true\"^^xsd:boolean ; " ++ " rdf:_2 \"false\"^^xsd:boolean . " ] greq10resstr = [ falseGraphStr ] greq10prestr = [ [ falseGraphStr ] ] testRuleFwd lab rulnam prem cons = testEqv lab consgrs appgrs where premgrs = map (makeRDFGraphFromN3String . (prefixXsdBoolean++)) prem consgrs = map (makeRDFGraphFromN3String . (prefixXsdBoolean++)) cons appgrs = fwdApply apprul premgrs apprul = fromJust $ getRulesetRule rulnam rdfRulesetXsdBoolean testFwdNot01 = testRuleFwd "testFwdNot01" (ScopedName namespaceXsdBoolean "Not") grnot01inpstr grnot01resstr testFwdNot02 = testRuleFwd "testFwdNot02" (ScopedName namespaceXsdBoolean "Not") grnot02inpstr grnot02resstr testFwdNot03 = testRuleFwd "testFwdNot03" (ScopedName namespaceXsdBoolean "Not") grnot03inpstr grnot03resstr testFwdAnd04 = testRuleFwd "testFwdAnd04" (ScopedName namespaceXsdBoolean "And") grand04inpstr grand04resstr testFwdAnd05 = testRuleFwd "testFwdAnd05" (ScopedName namespaceXsdBoolean "And") grand05inpstr grand05resstr testFwdNot07 = testRuleFwd "testFwdNot07" (ScopedName namespaceXsdBoolean "Not") grnot07inpstr grnot07resstr testFwdAnd08 = testRuleFwd "testFwdAnd08" (ScopedName namespaceXsdBoolean "AndX") grand08inpstr grand08resstr testFwdEq09 = testRuleFwd "testFwdEq09" (ScopedName namespaceXsdBoolean "Eq") greq09inpstr greq09resstr testFwdEq10 = testRuleFwd "testFwdEq10" (ScopedName namespaceXsdBoolean "Eq") greq10inpstr greq10resstr testRuleBwd lab rulnam cons prems = testEqvEqv lab premgrs appgr where premgrs = map (map (makeRDFGraphFromN3String . (prefixXsdBoolean++))) prems consgr = makeRDFGraphFromN3String (prefixXsdBoolean++cons) appgr = bwdApply apprul consgr apprul = fromJust $ getRulesetRule rulnam rdfRulesetXsdBoolean testBwdNot01 = testRuleBwd "testBwdNot01" (ScopedName namespaceXsdBoolean "Not") (grnot01inpstr!!0) grnot01prestr testBwdNot02a = testRuleBwd "testBwdNot02a" (ScopedName namespaceXsdBoolean "Not") (grnot02inpstr!!0) grnot02prestra testBwdNot02b = testRuleBwd "testBwdNot02b" (ScopedName namespaceXsdBoolean "Not") (grnot02inpstr!!1) grnot02prestrb testBwdNot03 = testRuleBwd "testBwdNot03" (ScopedName namespaceXsdBoolean "Not") (grnot03inpstr!!0) grnot03prestr testBwdAnd04a = testRuleBwd "testBwdAnd04a" (ScopedName namespaceXsdBoolean "And") (grand04inpstr!!0) grand04prestr01 testBwdAnd04b = testRuleBwd "testBwdAnd04b" (ScopedName namespaceXsdBoolean "And") (grand04inpstr!!1) grand04prestr02 testBwdAnd04c = testRuleBwd "testBwdAnd04c" (ScopedName namespaceXsdBoolean "And") (grand04inpstr!!2) grand04prestr03 testBwdAnd04d = testRuleBwd "testBwdAnd04d" (ScopedName namespaceXsdBoolean "And") (grand04inpstr!!3) grand04prestr04 testBwdAnd04e = testRuleBwd "testBwdAnd04e" (ScopedName namespaceXsdBoolean "And") (grand04inpstr!!4) grand04prestr05 testBwdAnd04f = testRuleBwd "testBwdAnd04f" (ScopedName namespaceXsdBoolean "And") (grand04inpstr!!5) grand04prestr06 testBwdAnd04g = testRuleBwd "testBwdAnd04g" (ScopedName namespaceXsdBoolean "And") (grand04inpstr!!6) grand04prestr07 testBwdAnd04h = testRuleBwd "testBwdAnd04h" (ScopedName namespaceXsdBoolean "And") (grand04inpstr!!7) grand04prestr08 testBwdAnd04i = testRuleBwd "testBwdAnd04i" (ScopedName namespaceXsdBoolean "And") (grand04inpstr!!8) grand04prestr09 testBwdAnd04j = testRuleBwd "testBwdAnd04j" (ScopedName namespaceXsdBoolean "And") (grand04inpstr!!9) grand04prestr10 testBwdAnd05 = testRuleBwd "testBwdAnd05" (ScopedName namespaceXsdBoolean "And") (grand05inpstr!!0) grand05prestr testBwdAnd06 = testRuleBwd "testBwdAnd06" (ScopedName namespaceXsdBoolean "And") (grand06inpstr!!0) grand06prestr testBwdEq09 = testRuleBwd "testBwdEq09" (ScopedName namespaceXsdBoolean "Eq") (greq09inpstr!!0) greq09prestr testBwdEq10 = testRuleBwd "testBwdEq10" (ScopedName namespaceXsdBoolean "Eq") (greq10inpstr!!0) greq10prestr testRuleSuite = TestList [ testFwdNot01, testFwdNot02, testFwdNot03 , testFwdAnd04, testFwdAnd05 , testFwdNot07, testFwdAnd08 , testFwdEq09, testFwdEq10 , testBwdNot01 , testBwdNot02a, testBwdNot02b , testBwdNot03 , testBwdAnd04a, testBwdAnd04b, testBwdAnd04c, testBwdAnd04d , testBwdAnd04e, testBwdAnd04f, testBwdAnd04g, testBwdAnd04h , testBwdAnd04i, testBwdAnd04j , testBwdAnd05 , testBwdAnd06 , testBwdEq09, testBwdEq10 ] ------------------------------------------------------------ -- All tests ------------------------------------------------------------ allTests = TestList [ testDatatypeSuite , testRelationSuite , testClassRestrictionSuite , testRuleSuite ] main = runTestTT allTests runTestFile t = do h <- openFile "a.tmp" WriteMode runTestText (putTextToHandle h False) t hClose h tf = runTestFile tt = runTestTT -------------------------------------------------------------------------------- -- -- Copyright (c) 2003, G. KLYNE. All rights reserved. -- -- This file is part of Swish. -- -- Swish is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- Swish is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with Swish; if not, write to: -- The Free Software Foundation, Inc., -- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- -------------------------------------------------------------------------------- -- $Source: /file/cvsdev/HaskellRDF/ClassRestrictionRuleTest.hs,v $ -- $Author: graham $ -- $Revision: 1.14 $ -- $Log: ClassRestrictionRuleTest.hs,v $ -- Revision 1.14 2004/01/07 19:49:12 graham -- Reorganized RDFLabel details to eliminate separate language field, -- and to use ScopedName rather than QName. -- Removed some duplicated functions from module Namespace. -- -- Revision 1.13 2004/01/06 13:53:10 graham -- Created consolidated test harness (SwishTestAll.hs) -- -- Revision 1.12 2003/12/20 12:53:40 graham -- Fix up code to compile and test with GHC 5.04.3 -- -- Revision 1.11 2003/12/10 03:48:57 graham -- SwishScript nearly complete: BwdChain and PrrofCheck to do. -- -- Revision 1.10 2003/11/28 00:17:55 graham -- Datatype constraint test cases all passed. -- -- Revision 1.9 2003/11/27 11:35:49 graham -- Variable modifier tests all run. -- Initial class constraint reasoning tests pass. -- Fixed bug in class constraint backward-chained reasoning that returned -- multiple instances of some statements, and did not filter out all occurrences -- of the original statements. -- -- Revision 1.8 2003/11/25 23:02:17 graham -- Reworked datatype variable modifier logic. -- Limited range of test cases so far all pass. -- -- Revision 1.7 2003/11/24 22:13:09 graham -- Working on reworking datatype variable modifiers to work with -- revised datatype framework. -- -- Revision 1.6 2003/11/24 17:20:35 graham -- Separate module Vocabulary from module Namespace. -- -- Revision 1.5 2003/11/20 17:58:09 graham -- Class-constraint backward chaining: all test cases passed. -- -- Revision 1.4 2003/11/19 22:13:03 graham -- Some backward chaining tests passed -- -- Revision 1.3 2003/11/17 21:53:30 graham -- Datatype inference forward chaining updated to allow inconsistent -- partial inputs to be detected. All forward chaining test cases passed. -- Need to develop backward chaining test cases. -- -- Revision 1.2 2003/11/14 21:48:35 graham -- First cut cardinality-checked datatype-constraint rules to pass test cases. -- Backward chaining is still to do. -- -- Revision 1.1 2003/11/13 01:15:23 graham -- Working on ClassRestrictionRule. -- Code almost complete, some test cases missing. --