Implement the Relational Algebra operations (rename, project, union, minus, intersect, select, join, and times) in Prolog. Each operator will be provided with an OutputRelationName by the user, the name for the output relation. Your program should create a "relation" fact for the output relation (using the assert predicate of SWI-Prolog). We will assume that the user does not provide the same names twice in a session.
You should also implement a displayRelation(Rname) predicate that displays the relation with name Rname on the terminal as follows:
$ pl Welcome to SWI-Prolog (Multi-threaded, Version 5.4.7) Copyright (c) 1990-2003 University of Amsterdam. SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details. For help, use ?- help(Topic). or ?- apropos(Word). ?- ['hw3.pl']. % hw3.pl compiled 0.01 sec, 17,972 bytes Yes ?- displayRelation(suppliers). suppliers(sno:string,sname:string,city:string) Number of Tuples=3 S1:Jones:Atlanta: S2:Smith:Duluth: S3:Blake:Marietta: Yes ?- halt. $Assume the following data structure to store relations and their schemas in Prolog's memory:
?-dynamic(relation/4). relation(c1,[city],[string],[["Atlanta"],["Duluth"],["Wichita"],["Dodge City"]]). relation(c2,[city],[string],[["Carson City"],["Duluth"],["Chennai"]]). relation( suppliers, [sno,sname,city], [string,string,string], [["S1","Jones","Atlanta"], ["S2","Smith","Duluth"], ["S3","Blake","Marietta"]] ). relation( parts, [pno,pname,color,city], [string,string,string,string], [["P1","Nut","Red","Duluth"], ["P2","Bolt","Blue","Marietta"], ["P3","Screw","Red","Dunwoody"], ["P4","Axle","Green","Marietta"]] ). relation( projects, [jno,jname,city], [string,string,string], [["J1","Bicycles","Duluth"], ["J2","Motorcycles","Dunwoody"]] ). relation( spj, [sno,pno,jno,qty], [string,string,string,number], [["S1","P1","J1",100], ["S1","P2","J2",100], ["S1","P1","J2",100], ["S2","P1","J1",100], ["S2","P3","J1",100], ["S2","P3","J2",100], ["S3","P1","J1",100], ["S3","P2","J2",100]] ).Some details of the various operations to be implemented: