module TripleApi where import "TripleData" import "Utils" import "Observe" -- Author: G.Naudts. Mail: naudts_vannoten@yahoo.com. -- type Alternatives = [(TripleSet, SubstitutionList)] -- depending on the predicate of the triple a certain function is -- started -- The first bool indicates special predicate found. -- the second bool indicates successful unification. tripleApi :: Triple -> (Bool,(Bool, Alternatives)) tripleApi t = (bool, res) where (bool, res) = anPred t -- analyze the predicate anPred :: Triple -> (Bool,( Bool, Alternatives)) anPred t |checkPredicate t ":equal" = (True, (equality t)) -- |checkPredicate t ":diff" = checkDifference t |checkPredicate t ":length" = (True, (lengthS t)) |otherwise = (False,( False, [])) -- this is an implementation of equality predicate. -- It handles equality at the URI level. equality :: Triple -> (Bool, Alternatives) equality (t@(Triple(sub, _, obj))) | bv1 && bv2 && bv3 = (True, [([t],[])]) | otherwise = (sub == obj, [([t],[])]) where -- check the subject bv1 = testURI sub -- check the object bv2 = testURI obj URI s1 = sub URI s2 = obj (_,_,r1) = parseUntil ' ' s1 (_,_,r2) = parseUntil ' ' s2 bv3 = r1 == r2 equality t = (False, []) -- get the length of a string -- the length is placed in the object lengthS :: Triple -> (Bool, Alternatives) lengthS (t@(Triple(sub, pred, obj))) | bv1 = (True, [([Triple(sub, pred, observe "obj1" obj1)],[])]) | otherwise = (False, [([t],[])]) where -- check the subject bv1 = testLiteral sub n = observe "len" (length (getLiteral sub)) s = observe "l" (intToString n) obj1 = observe "uri" (URI (":" ++ s ++ " :" ++ s)) lengthS t = (False, []) -- other string predicatees: head(s,h); tail(s,t); addString (s,s1) -- math: greater(n1,n2) ==> n1 > n2; lesser(n1,n2); ge(n1,n2); le(n1,n2) testURI (URI s) = True testURI r = False testRule (Rule r) = True testRule t = False testLiteral (Literal l) = True testLiteral r = False testTriple (Triple (s, p, v)) = True testTriple t = False -- this checks whether a predicate has a certain value checkPredicate :: Triple -> String -> Bool checkPredicate x sIn | bv2 && bv3 && bv1 = True | otherwise = False where Triple (s, p, v) = x URI s2 = p (bool, s1, r) = parseUntil ' ' s2 bv1 = s1 == sIn bv2 = testTriple x bv3 = testURI p testURI (URI u) = True testURI r = False -- get the full URI getRest (URI s) = r where (_, _, r) = parseUntil ' ' s -- get a literal getLiteral (Literal s) = r where (_, _, r) = parseUntil ' ' s