MP5
This commit is contained in:
14
Semester 2/Assignments/MP5_CalebFontenot/pom.xml
Normal file
14
Semester 2/Assignments/MP5_CalebFontenot/pom.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.calebfontenot</groupId>
|
||||
<artifactId>MP5_CalebFontenot</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<exec.mainClass>com.calebfontenot.mp5_calebfontenot.MP5_CalebFontenot</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@@ -0,0 +1,97 @@
|
||||
package com.calebfontenot.mp5_calebfontenot;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ASDV2
|
||||
*/
|
||||
public class FD
|
||||
{
|
||||
|
||||
private String lhs;
|
||||
|
||||
private String rhs;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param lhs the LHS of the FD
|
||||
* @param rhs the RHS of the FD
|
||||
* @throws IllegalArgumentException if the length of the LHS or the length
|
||||
* of the RHS are less than 1 or if they are null.
|
||||
*/
|
||||
public FD(String lhs, String rhs)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (lhs == null || rhs == null )
|
||||
throw new IllegalArgumentException( "the LHS and/or RHS cannot be null.");
|
||||
|
||||
if (lhs.length() < 1 || rhs.length() < 1 )
|
||||
throw new IllegalArgumentException( "the LHS and/or RHS cannot be of lenght less than 1.");
|
||||
|
||||
this.lhs = lhs;
|
||||
this.rhs = rhs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of rhs
|
||||
*
|
||||
* @return the value of rhs
|
||||
*/
|
||||
public String getRhs()
|
||||
{
|
||||
return rhs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of rhs
|
||||
*
|
||||
* @param rhs new value of rhs
|
||||
*/
|
||||
public void setRhs(String rhs)
|
||||
{
|
||||
this.rhs = rhs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of lhs
|
||||
*
|
||||
* @return the value of lhs
|
||||
*/
|
||||
public String getLhs()
|
||||
{
|
||||
return lhs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of lhs
|
||||
*
|
||||
* @param lhs new value of lhs
|
||||
*/
|
||||
public void setLhs(String lhs)
|
||||
{
|
||||
this.lhs = lhs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return lhs + " -> " + rhs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decomposes the RHS of the FD into singletons. where the LHS is the same
|
||||
* as this FD and the RHS is 1 character of each character of the FD.
|
||||
*
|
||||
* @return array of FD he
|
||||
*/
|
||||
public FD[] decomposeRightHandSide()
|
||||
{
|
||||
FD[] fdDecomosition = new FD[this.rhs.length()];
|
||||
|
||||
for (int i = 0; i < this.rhs.length(); ++i)
|
||||
{
|
||||
fdDecomosition[i] = new FD(this.lhs, Character.toString(rhs.charAt(i)));
|
||||
}
|
||||
return fdDecomosition;
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package com.calebfontenot.mp5_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class MP5_CalebFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.mp5_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ASDV2
|
||||
*/
|
||||
public class NormalizeDatabase {
|
||||
|
||||
/**
|
||||
* Finds the closure of a set of attributes given a set of FDs of a relation R
|
||||
*
|
||||
* @param attributes attributes to find their closure
|
||||
* @param fds set of FDs of relation R
|
||||
* @return the closure of the parameter attributes.
|
||||
*/
|
||||
public static String closure(String attributes, ArrayList<FD> fds)
|
||||
{
|
||||
attributes = attributes.toUpperCase();
|
||||
String closurePrevious = attributes;
|
||||
String closure = attributes;
|
||||
for (int i = 0; i < fds.size(); ++i) {
|
||||
|
||||
if (closure.contains(fds.get(i).getRhs())) {
|
||||
continue;
|
||||
}
|
||||
FD capitalFD = new FD(fds.get(i).getLhs().toUpperCase(),
|
||||
fds.get(i).getRhs().toUpperCase());
|
||||
}
|
||||
//1. Set x+ = x
|
||||
//2. Starting with x+ apply each FD xF —> y in F where
|
||||
//xF belongs in closure x+, but whre the rhs y is not already in the closure x+
|
||||
//to find the determined attribute
|
||||
//3. x+ = x+ U y
|
||||
while (true) {
|
||||
for (int i = 0; i < fds.size(); ++i) {
|
||||
//the LHS of the FD is contained in the closure
|
||||
//then add to the closure the RHS of the FD
|
||||
if (attributes.contains(fds.get(i).getLhs())) {
|
||||
attributes += fds.get(i).getRhs();
|
||||
}
|
||||
}
|
||||
if (closurePrevious.equals(closure)) {
|
||||
break;
|
||||
} else {
|
||||
closurePrevious = closure;
|
||||
}
|
||||
}
|
||||
//4, If y not empty go to (2)
|
||||
//5. Return x+
|
||||
|
||||
return closure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Eliminates redundant attributes from the LHS of each FD of a set of FDs given as parameters.
|
||||
*
|
||||
* @param fds the set of FDs to eliminate the redundancy
|
||||
* @return and ArrayList with no redundancy on LHS of each FD.
|
||||
*/
|
||||
public static ArrayList<FD> eliminateRedundantAttributes(ArrayList<FD> fds)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
ArrayList<FD> fds = new ArrayList<FD>();
|
||||
FD fd = new FD("a", "bc");
|
||||
FD[] fdDecomposed = fd.decomposeRightHandSide();
|
||||
for (int i = 0; i < fdDecomposed.length; ++i) {
|
||||
fds.add(new FD(fdDecomposed[i].getLhs(), fdDecomposed[i].getRhs()));
|
||||
}
|
||||
fds.add(new FD("a", "bc"));
|
||||
fds.add(new FD("b", "c"));
|
||||
fds.add(new FD("AB", "B"));
|
||||
System.out.println(fds);
|
||||
System.out.println(closure("ac", fds));
|
||||
|
||||
/* TEST it with
|
||||
Let F1 = {1. A -> BC
|
||||
2. B -> C,
|
||||
3. AB -> D }.
|
||||
Attribute B is extraneous in FD 3 AB -> D
|
||||
|
||||
*/
|
||||
/*
|
||||
F2 = { 1. AB -> C,
|
||||
2. C -> A,
|
||||
3. BC -> D,
|
||||
4. ACD -> B,
|
||||
5. D -> E,
|
||||
6. D -> G,
|
||||
7. BE -> C,
|
||||
8. CG -> B,
|
||||
9. CG -> D,
|
||||
10. CE -> A,
|
||||
11. CE -> G}
|
||||
*/
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user