Question
Functional Dependency & Closure of Attributes -- Using book A First Course in Database Systems, 3rd ed. by Ullman and Widom, 2008 Chapter 3 Complete
Functional Dependency & Closure of Attributes -- Using book A First Course in Database Systems, 3rd ed. by Ullman and Widom, 2008 Chapter 3
Complete FDS.java with the four incomplete functions. Test the program on some examples.
// FDS.java
// Algorithm 3.7 closure of X under F
// Usage: java FDS F X
// F is a file that has the first line all the attributes and
// then an FD a line with a space between the left-hand side and the right-hand side
// X is a string of characters represent a set of attributes
import java.io.*;
import java.util.*;
class FD{
HashSet
public FD(HashSet
public boolean equals(Object obj){
FD fd2 = (FD)obj;
return lhs.equals(fd2.lhs) && rhs == fd2.rhs;
}
};
public class FDS{
HashSet
HashSet
public FDS(String filename){ // 1. split FDs so each FD has a single attribute on the right
Scanner in = null;
try {
in = new Scanner(new File(filename));
} catch (FileNotFoundException e){
System.err.println(filename + " not found");
System.exit(1);
}
String line = in.nextLine();
for (int i = 0; i < line.length(); i++) R.add(line.charAt(i));
while (in.hasNextLine()){
HashSet
String[] terms = in.nextLine().split(" ");
for (int i = 0; i < terms[0].length(); i++) l.add(terms[0].charAt(i));
for (int i = 0; i < terms[1].length(); i++) F.add(new FD(l, terms[1].charAt(i)));
}
in.close();
}
HashSet
HashSet
for (int i = 0; i < X.length(); i++) Y.add(X.charAt(i));
return Y;
}
void printSet(Set
for (char c: X) System.out.print(c);
}
HashSet
HashSet
int len = 0;
do { // 3. push out
len = Xplus.size();
for (FD fd: F)
if (Xplus.containsAll(fd.lhs) && !Xplus.contains(fd.rhs)) Xplus.add(fd.rhs);
} while (Xplus.size() > len);
return Xplus; // 4. found closure of X
}
boolean follows(FD fd){ // fd follows from FDS
return // ?
}
boolean covers(FDS T){ // FDs in T follows F
// your code
return // ?
}
boolean equivalent(FDS T){ // this covers T and T covers this
return // ?
}
HashSet
// your code
}
public static void main(String[] args){
FDS fds = new FDS(args[0]);
HashSet
fds.printSet(fds.closure(X));
// and other functions to test
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started