import "Utils" import "IO" -- Definition of the data structures ---------------------------------------- -- a triple is made with a subject, a verb and an object , -- or it is null data Triple = Triple Subject Verb Object| TripleNull -- a triple list can be null data TripleList = TripleList [Triple]| TripleListNull data Term = Subject|Verb|Object -- a subject is an atom, a triple , a list of triples or null data Subject = Subject Atom| SubjectTriple Triple| SubjectTripleList TripleList| SubjectNull -- a verb is an atom data Verb = Verb Atom -- an object is an atom, a triple, a list of triples or null data Object = Atom| Triple| TripleList| ObjectNull -- an atom is an uri or a variable or a NullAtom data Atom = Uri String| Var Var| NullAtom -- a variable is a triple containing the name of the variable, -- a Globals list and a list of strings: -- the Globals list contains the properties of the variable; -- the String list contains a chain of Terms -- Definition of type Globals: see Utils.hs -- The variable name is the first entry in the list of strings -- type Var = (String, Globals, [Term]) -- the input is a list of triples type Input = [Triple] -- a rule is a tuple made of an input and a triple . type Rule = (Input, Triple) -- a query is a list of triples type Query = [Triple] -- a goallist is a list of triples type GoalList = [Triple] -- a goal is a triple type Goal = Triple -- a substitution is a list of tuples (Var, Term) type Subsitution = [(Var, Term)] -- Functions ---------------- -- unification takes as input two triples and produces a substitution unify :: (Triple, Triple) -> Substitution unify (TripleNull, TripleNull) = (TripleNull, TripleNull) unify (TripleNull, t2) = [] unify (t1, TripleNull) = [] unify (Triple s1 v1 o1, Triple s2 v2 o2) = [] -- (Triple s3 v1 o1, Triple s4 v2 o2) -- where (s3, s4) = unifySubjects (s1, s2) -- Example data ------------------ -- unify test t1 = Triple (Subject x1) (Verb uri1) (Object x2) t2 = Triple (Subject x3) (Verb x4) (Object uri2) x1 = ("X1",[],[]) x2 = ("X2",[],[]) x3 = ("X3",[],[]) x4 = ("X4",[],[]) uri1 = "http://test1" uri2 = "http://test2"