Skip to content

Commit

Permalink
Parmis final commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Parmis Naddaf committed Mar 11, 2024
1 parent 4c4441e commit 3b4aa5e
Show file tree
Hide file tree
Showing 54 changed files with 2,505 additions and 934 deletions.
Binary file added code/common/target/common-1.0-SNAPSHOT 2.jar
Binary file not shown.
Binary file modified code/common/target/common-1.0-SNAPSHOT.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ca/sfu/cs/common/Configuration/Config.class
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/Users/mingyiwu/Desktop/Project/FactorBase_hub/Untitled/code/common/src/main/java/ca/sfu/cs/common/Configuration/Config.java
/Users/parmis/Desktop/FactorBase/code/common/src/main/java/ca/sfu/cs/common/Configuration/Config.java
Binary file not shown.
Binary file modified code/componentsrunner/target/componentsrunner-1.0-SNAPSHOT.jar
Binary file not shown.
3 changes: 3 additions & 0 deletions code/componentsrunner/target/maven-archiver/pom 2.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifactId=componentsrunner
groupId=ca.sfu.cs
version=1.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ca/sfu/cs/componentsrunner/app/RunComponent.class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/parmis/Desktop/FactorBase/code/componentsrunner/src/main/java/ca/sfu/cs/componentsrunner/app/RunComponent.java
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/Users/mingyiwu/Desktop/Project/FactorBase_hub/Untitled/code/componentsrunner/src/main/java/ca/sfu/cs/componentsrunner/app/RunComponent.java
/Users/parmis/Desktop/FactorBase/code/componentsrunner/src/main/java/ca/sfu/cs/componentsrunner/app/RunComponent.java
Binary file not shown.
Binary file not shown.
189 changes: 169 additions & 20 deletions code/factorbase/src/main/java/ca/sfu/cs/factorbase/learning/CP.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.StringJoiner;
import java.util.logging.Logger;
Expand Down Expand Up @@ -191,6 +192,30 @@ public static void prepare(String rchain, Connection con1) throws SQLException {
" FROM Path_BayesNets as FamilyRNodes, FNodes as RNode_check " +
" where FamilyRNodes.Rchain = '" + rchain + "' and RNode_check.Fid = FamilyRNodes.parent and RNode_check.Type = 'RNode';"
);
// pnaddaf Dec 5ht 2023
st.execute("drop view if exists RNodes_inFamily_view;");
st.execute(
"CREATE VIEW RNodes_inFamily_view AS " +
"SELECT distinct child, rnid, short_rnid " +
"from `Final_Path_BayesNets_view` `BN`, `RNodes`, lattice_mapping lm " +
"where `RNodes`.`rnid` = `BN`.`parent` AND lm.orig_rnid = BN.parent " +
"union " +
"select distinct `BN`.`child` AS `child`, `RNodes`.`rnid` AS rnid, short_rnid " +
"from `Final_Path_BayesNets_view` `BN`, `RNodes`, lattice_mapping lm " +
"where `RNodes`.`rnid` = `BN`.`child` AND lm.orig_rnid = child " +
"union " +
"select distinct `BN`.`child` AS `child`, `RNodes_2Nodes`.`rnid` AS `Rnid`,short_rnid " +
"from (`Final_Path_BayesNets_view` `BN`, lattice_mapping lm " +
"join `RNodes_2Nodes`) " +
"where `RNodes_2Nodes`.`2nid` = `BN`.`parent` and `RNodes_2Nodes`.`rnid`=lm.orig_rnid " +
"union " +
"select distinct `BN`.`child` AS `child`, `RNodes_2Nodes`.`rnid` AS `Rnid`, short_rnid " +
"from (`Final_Path_BayesNets_view` `BN`, lattice_mapping lm " +
"join `RNodes_2Nodes`) " +
"where `RNodes_2Nodes`.`2nid` = `BN`.`child` and `RNodes_2Nodes`.`rnid` = lm.orig_rnid ; "
);



st.execute("drop table if exists 2Nodes_inFamily;");
st.execute(
Expand Down Expand Up @@ -285,24 +310,83 @@ public static void nopar(String rchain, Connection con1) throws SQLException {
logger.fine("noparent node: " + rst.getString(1));
noparent_tables.add(rst.getString(1));
}
// zqian Nov 13, computing sum(mult) from biggest CT table
// and close the connections
java.sql.Statement st2 = con1.createStatement();
String sql2 =
"SELECT SUM(MULT) " +
"FROM " + databaseName2 + ".`" + bigTable + "`;"; // Only need to do this query once, Nov 12 zqian.
logger.fine(sql2 + "\n");
ResultSet deno = st2.executeQuery(sql2);
deno.absolute(1);
double mydeno = deno.getDouble(1);
logger.fine("SUM(mult) in bigCTTable : "+mydeno + "\n");
for(int i = 0; i < noparent_tables.size(); i++) {
// pnaddaf Dec 5th 2023
for (int i = 0; i < noparent_tables.size(); i++) {
ResultSet rst_short_rnids = st.executeQuery("SELECT short_rnid FROM RNodes_inFamily_view where child = '" + noparent_tables.get(i) + "' ORDER BY short_rnid;");
logger.fine("*************************************************");
logger.fine("SELECT short_rnid FROM RNodes_inFamily_view where child = '" + noparent_tables.get(i) + "';");
// Initialize a StringBuilder to concatenate the elements
StringBuilder concatenated_rnids = new StringBuilder();
boolean isFirst = true;
if (rst_short_rnids.next()) {
do{
// Add a comma if it's not the first value
if (!isFirst) {
concatenated_rnids.append(",");
} else {
isFirst = false;
}
// Retrieve data from the result set
String short_rnid = rst_short_rnids.getString("short_rnid");

// Append the value to the StringBuilder
concatenated_rnids.append(short_rnid);

} while(rst_short_rnids.next());

bigTable = concatenated_rnids.toString() + "_CT";
logger.fine("tableName for " + noparent_tables.get(i) + " is: " + bigTable);


} else {
// ResultSet is empty

logger.fine("ResultSet is empty");
ResultSet rst_pvid = st.executeQuery("SELECT distinct pvid FROM Pvars_Family WHERE child = '" + noparent_tables.get(i) + "' ;");
if (rst_pvid.next()) {
do {
// Add a comma if it's not the first value
if (!isFirst) {
concatenated_rnids.append(",");
} else {
isFirst = false;
}
// Retrieve data from the result set
String short_rnid = rst_pvid.getString("pvid");

// Append the value to the concatenated_rnids
concatenated_rnids.append(short_rnid);
} while (rst_pvid.next());

}
bigTable = concatenated_rnids.toString() + "_counts";
logger.fine("tableName is: " + bigTable);

// Close the ResultSet when you're done with it
rst_pvid.close();
}

// Close the ResultSet when you're done with it
rst_short_rnids.close();


// zqian Nov 13, computing sum(mult) from biggest CT table
// and close the connections
java.sql.Statement st2 = con1.createStatement();
String sql2 =
"SELECT SUM(MULT) " +
"FROM " + databaseName2 + ".`" + bigTable + "`;";
logger.fine(sql2 + "\n");
ResultSet deno = st2.executeQuery(sql2);
deno.absolute(1);
double mydeno = deno.getDouble(1);
logger.fine("SUM(mult) in bigTable : "+mydeno + "\n");
nopar_update(rchain, bigTable, noparent_tables.get(i), con1, mydeno);
}
st2.close();
}
st.close();
}

st2.close();
st.close();
}

/**
* Similar simpler computation for nodes without parents.
Expand All @@ -317,11 +401,15 @@ public static void nopar_update(String rchain, String bigTable, String nodeName,
st.execute(
"CREATE TABLE `" + tableName + "` (" +
"`" + nodeName + "` VARCHAR(200) NOT NULL, " +
"CP FLOAT(11,10), " +
"CP FLOAT(7,6), " +
"MULT DECIMAL(65), " +
"local_mult DECIMAL(65)" +
");"
);
logger.fine("tableName : "+ tableName + "\n");
logger.fine("nodeName : "+ nodeName + "\n");
logger.fine("databaseName2 : "+ databaseName2 + "\n");
logger.fine("bigTable : "+ bigTable + "\n");
st.execute(
"INSERT INTO `" + tableName + "` (`" + nodeName + "`) " +
"SELECT DISTINCT `" + nodeName + "` " +
Expand Down Expand Up @@ -460,10 +548,71 @@ public static void haspar(String rchain, Connection con1) throws SQLException {
logger.fine("hasparent node: " + rst.getString(1));
hasparent_tables.add(rst.getString(1));
}
for(int i = 0; i < hasparent_tables.size(); i++) {


// pnaddaf Dec 8th 2023
for (int i = 0; i < hasparent_tables.size(); i++) {
ResultSet rst_short_rnids = st.executeQuery("SELECT short_rnid FROM RNodes_inFamily_view where child = '" + hasparent_tables.get(i) + "' ORDER BY short_rnid ;");
logger.fine("*************************************************");
logger.fine("SELECT short_rnid FROM RNodes_inFamily_view where child = '" + hasparent_tables.get(i) + "';");
// Initialize a StringBuilder to concatenate the elements
StringBuilder concatenated_rnids = new StringBuilder();
boolean isFirst = true;
if (rst_short_rnids.next()) {
do{
// Add a comma if it's not the first value
if (!isFirst) {
concatenated_rnids.append(",");
} else {
isFirst = false;
}
// Retrieve data from the result set
String short_rnid = rst_short_rnids.getString("short_rnid");

// Append the value to the StringBuilder
concatenated_rnids.append(short_rnid);

} while(rst_short_rnids.next());

bigTable = concatenated_rnids.toString() + "_CT";
logger.fine("tableName for " + hasparent_tables.get(i) + " is: " + bigTable);


} else {
// ResultSet is empty

logger.fine("ResultSet is empty");
ResultSet rst_pvid = st.executeQuery("SELECT distinct pvid FROM Pvars_Family WHERE child = '" + hasparent_tables.get(i) + "';");
if (rst_pvid.next()) {
do {
// Add a comma if it's not the first value
if (!isFirst) {
concatenated_rnids.append(",");
} else {
isFirst = false;
}
// Retrieve data from the result set
String short_rnid = rst_pvid.getString("pvid");

// Append the value to the concatenated_rnids
concatenated_rnids.append(short_rnid);
} while (rst_pvid.next());

}
bigTable = concatenated_rnids.toString() + "_counts";
logger.fine("tableName is: " + bigTable);

// Close the ResultSet when you're done with it
rst_pvid.close();
}

// Close the ResultSet when you're done with it
rst_short_rnids.close();
haspar_update(rchain, bigTable, hasparent_tables.get(i), con1, databaseName2);


}
st.close();
st.close();
}

/**
Expand Down Expand Up @@ -586,7 +735,7 @@ public static void haspar_update(String rchain, String bigTable, String nodeName
// String sql = "UPDATE " + escapedTableName + " SET local_mult = MULT / " + local + ";"; OS Dec 5 make local_mult = mult
st1.execute(sql);
}

logger.fine("UPDATE " + escapedTableName + " SET likelihood = LOG(CP) * local_mult;");
st.execute("UPDATE " + escapedTableName + " SET likelihood = LOG(CP) * local_mult;");
st.execute("drop table if exists temp;");

Expand Down
28 changes: 14 additions & 14 deletions code/factorbase/src/main/resources/scripts/metadata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,17 @@ FROM
WHERE
EntityTables.TABLE_NAME = SelfRelationships.REFERENCED_TABLE_NAME
AND EntityTables.COLUMN_NAME = SelfRelationships.REFERENCED_COLUMN_NAME;
/*
UNION
SELECT
CONCAT(EntityTables.TABLE_NAME, '2') AS pvid,
EntityTables.TABLE_NAME, EntityTables.COLUMN_NAME as ID_COLUMN_NAME,
2 AS index_number
FROM
EntityTables,
SelfRelationships
WHERE
EntityTables.TABLE_NAME = SelfRelationships.REFERENCED_TABLE_NAME
AND EntityTables.COLUMN_NAME = SelfRelationships.REFERENCED_COLUMN_NAME ;
*/
-- UNION
-- SELECT
-- CONCAT(EntityTables.TABLE_NAME, '2') AS pvid,
-- EntityTables.TABLE_NAME, EntityTables.COLUMN_NAME as ID_COLUMN_NAME,
-- 2 AS index_number
-- FROM
-- EntityTables,
-- SelfRelationships
-- WHERE
-- EntityTables.TABLE_NAME = SelfRelationships.REFERENCED_TABLE_NAME
-- AND EntityTables.COLUMN_NAME = SelfRelationships.REFERENCED_COLUMN_NAME ;

/*zqian,Oct-02-13, reduce copies from 3 to 2*/
/*
Expand Down Expand Up @@ -389,7 +387,9 @@ CREATE table RNodes_MM_Self AS
ForeignKeys_pvars1.TABLE_NAME = ForeignKeys_pvars2.TABLE_NAME
AND RelationTables.TABLE_NAME = ForeignKeys_pvars1.TABLE_NAME
AND ForeignKeys_pvars1.ARGUMENT_POSITION < ForeignKeys_pvars2.ARGUMENT_POSITION
AND ForeignKeys_pvars1.index_number < ForeignKeys_pvars2.index_number /*comment this out to allow all pairs of Pvariables as Rnodes*/
-- AND (ForeignKeys_pvars1.index_number = 0 AND ForeignKeys_pvars2.index_number = 1) /* Jan17th 2024 - pnaddaf: removing loops*/
-- OR (ForeignKeys_pvars1.index_number = 1 AND ForeignKeys_pvars2.index_number = 2 )
AND ForeignKeys_pvars1.index_number = ForeignKeys_pvars2.index_number -1 /*comment this out to allow all pairs of Pvariables as Rnodes*/
AND RelationTables.SelfRelationship = 1
AND RelationTables.Many_OneRelationship = 0;

Expand Down
Loading

0 comments on commit 3b4aa5e

Please sign in to comment.