






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A simple query language for retrieving information from a database using logic programming. The language includes concepts such as pattern matching, binding, and unification for deduction. The document also covers the implementation of the language, including database of assertions, simple queries, compound queries, rules, and system architecture.
Typology: Papers
1 / 30
This page cannot be seen from the preview
Don't miss anything!























(address (Bitdiddle Ben) (Slumerville (Ridge Road) 10))(job (Bitdiddle Ben) (computer wizard))(salary (Bitdiddle Ben) 60000) (address (Hacker Alyssa P) (Cambridge (Mass Ave) 78)) (job (Hacker Alyssa P) (computer programmer)) (salary (Hacker Alyssa P) 40000) (supervisor (Hacker Alyssa P) (Bitdiddle Ben)) (address (Reasoner Louis) (Slumerville (Pine Tree Road) 80)) (job (Reasoner Louis) (computer programmer trainee)) (salary (Reasoner Louis) 30000) (supervisor (Reasoner Louis) (Hacker Alyssa P))
;;; Query input: (job ?x (computer programmer)) ;;; Query results: (job (Hacker Alyssa P) (computer programmer)) (job (Fect Cy D) (computer programmer)) ;;; More queries (job ?x (computer ?type)) (job ?x (computer. ?type)) (supervisor ?x ?x)
(and (job ?person (computer programmer))^ (address ?person ?where)) ;;; Query results: (and (job (Hacker Alyssa P) (computer programmer))^ (address (Hacker Alyssa P) (Cambridge (Mass Ave) 78))) (and (job (Fect Cy D) (computer programmer))^ (address (Fect Cy D) (Cambridge (Ames Street) 3))) ;;; another compound query – not as a filter (and (supervisor ?x (Bitdiddle Ben))^ (not (job ?x (computer programmer))))
(rule (lives-near ?person-1 ?person-2)^ (and (address ?person-1 (?town. ?rest-1))^ (address ?person-2 (?town. ?rest-2))^ (not (same ?person-1 ?person-2)))) (rule (same ?x ?x)) (lives-near ?x (Bitdiddle Ben)) ;;; Query results: (lives-near (Reasoner Louis) (Bitdiddle Ben)) (lives-near (Aull DeWitt) (Bitdiddle Ben))
query (job (? x) (? y)) Input stream of frames
Output stream of frames,extended and filtered
Stream of assertions fromdatabase
(or A B)
Input stream of frames
Output stream of frames,extended and filtered A^ B Stream of assertions fromdatabase
Merge
Input stream of frames
Output stream of frames,extended and filtered
Stream of assertions fromdatabase
Remove if satisfied
Simple Queries & Pattern Matching Match query against assertions in database (pattern-match pat dat frame)^ ¾^ Attempt to match pattern and datum consistent withbindings in frame^ ¾^ Return extended frame with bindings implied by match Examples^ ¾^ dat = ((a b) c (a b)), pat = ((? x) c (? x))
⇒^ x = (a b)
¾^ dat = ((a b) c (a b)), pat = ((? x) c (? y))
⇒^ x = (a b), y =
(a b) ¾ dat = ((a b) c (a b)), pat = ((? x) b (? x))
⇒^ failed
(define (pattern-match pat dat frame)(cond ((eq? frame 'failed) 'failed)((equal? pat dat) frame)((var? pat) (extend-if-consistent pat dat frame))((and (pair? pat) (pair? dat))(pattern-match (cdr pat)
(cdr dat)(pattern-match (car pat)(car dat)frame))) (else 'failed)))
(and (address ?person-1 (?town. ?rest-1))(address ?person-2 (?town. ?rest-2))(not (same ?person-1 ?person-2))))