Skip to content

Commit

Permalink
Merge pull request #54 from allan-shoup/system-exit
Browse files Browse the repository at this point in the history
Converted System.exit to throw exceptions, cleaned up leaked …
  • Loading branch information
gpapadis authored Aug 27, 2021
2 parents 3eb67fc + ac37156 commit eb8d063
Show file tree
Hide file tree
Showing 60 changed files with 267 additions and 453 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public int getTotalNoOfEntities() {
if (entityProfilesD2 == null) {
return noOfEntitiesD1;
}
return noOfEntitiesD1 + noOfEntitiesD2;
return Math.addExact(noOfEntitiesD1, noOfEntitiesD2);
}

protected void indexEntities(Map<String, TIntList> index, List<EntityProfile> entities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ protected void printOriginalStatistics(List<AbstractBlock> inputBlocks) {
}

Log.info("Original blocks\t:\t" + inputBlocks.size());
Log.info("Original comparisons\t:\t" + ((long)comparisons));
Log.info("Original comparisons\t:\t" + comparisons);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ protected void getBilateralLimits(List<AbstractBlock> blocks) {
});

for (int i = 0; i < limitsD1.length; i++) {
limitsD1[i] = (int) Math.round(ratio * limitsD1[i]);
limitsD1[i] = Math.round(ratio * limitsD1[i]);
}
for (int i = 0; i < limitsD2.length; i++) {
limitsD2[i] = (int) Math.round(ratio * limitsD2[i]);
limitsD2[i] = Math.round(ratio * limitsD2[i]);
}
}

Expand Down Expand Up @@ -193,7 +193,7 @@ protected void getUnilateralLimits(List<AbstractBlock> blocks) {
});

for (int i = 0; i < limitsD1.length; i++) {
limitsD1[i] = (int) Math.round(ratio * limitsD1[i]);
limitsD1[i] = Math.round(ratio * limitsD1[i]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private int getMaxBlockSize(List<AbstractBlock> blocks) {
entities.addAll(uBlock.getEntities());
});

return (int) Math.round(entities.size()*purgingFactor);
return Math.round(entities.size()*purgingFactor);
}

private int getMaxInnerBlockSize(List<AbstractBlock> blocks) {
Expand All @@ -76,7 +76,7 @@ private int getMaxInnerBlockSize(List<AbstractBlock> blocks) {
d2Entities.addAll(bBlock.getIndex2Entities());
});

return (int) Math.round(Math.min(d1Entities.size(), d2Entities.size())*purgingFactor);
return Math.round(Math.min(d1Entities.size(), d2Entities.size())*purgingFactor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.scify.jedai.blockprocessing.comparisoncleaning;

import com.esotericsoftware.minlog.Log;
import org.scify.jedai.datamodel.AbstractBlock;
import org.scify.jedai.utilities.enumerations.WeightingScheme;
import gnu.trove.iterator.TIntIterator;
Expand Down Expand Up @@ -56,8 +55,8 @@ public CanopyClustering(float inThr, float outThr, WeightingScheme scheme) {
exclusiveThreshold = outThr;
inclusiveThreshold = inThr;
if (exclusiveThreshold < inclusiveThreshold) {
Log.error(getMethodName(), "The " + getParameterName(1) + " cannot be smaller than the " + getParameterName(0));
System.exit(-1);
throw new IllegalStateException(
"The " + getParameterName(1) + " cannot be smaller than the " + getParameterName(0));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.scify.jedai.blockprocessing.comparisoncleaning;

import com.esotericsoftware.minlog.Log;
import org.scify.jedai.datamodel.AbstractBlock;
import org.scify.jedai.datamodel.Comparison;
import org.scify.jedai.utilities.enumerations.WeightingScheme;
Expand Down Expand Up @@ -60,8 +59,7 @@ public ExtendedCanopyClustering(int inThr, int outThr, WeightingScheme scheme) {
exclusiveThreshold = outThr;
inclusiveThreshold = inThr;
if (inclusiveThreshold < exclusiveThreshold) {
Log.error(getMethodName(), "The Exclusive Threshold cannot be larger than the Inclusive one.");
System.exit(-1);
throw new IllegalStateException("The Exclusive Threshold cannot be larger than the Inclusive one.");
}
}

Expand Down Expand Up @@ -133,7 +131,7 @@ protected List<AbstractBlock> pruneEdges() {

excludedEntities = new TIntHashSet();
nearestEntities = new HashSet[noOfEntities];
topKEdges = new PriorityQueue<>((int) (2 * inclusiveThreshold), new IncComparisonWeightComparator());
topKEdges = new PriorityQueue<>(2 * inclusiveThreshold, new IncComparisonWeightComparator());
if (weightingScheme.equals(WeightingScheme.ARCS)) {
while (iterator.hasNext()) {
int currentId = iterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public abstract class AbstractRandomSearchConfiguration implements IRandomSearch

protected final static Random RANDOM_GEN = new Random();

protected final List selectedRandomValues;
protected final List<Object> selectedRandomValues;

public AbstractRandomSearchConfiguration() {
selectedRandomValues = new ArrayList();
selectedRandomValues = new ArrayList<>();
}

@Override
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/scify/jedai/datamodel/Comparison.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public int getEntityId2() {
/**
* Returns the measure of the weight or similarity between two entities.
* Higher utility measures correspond to greater weight or stronger similarity.
* @return
*/
public float getUtilityMeasure() {
return utilityMeasure;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/scify/jedai/datamodel/GomoryHuTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public SimpleGraph<Integer, DefaultEdge> MinCutTree() {

final Set<V> sourcePartition = minSourceSinkCut.getSourcePartition();
// float flowValue = minSourceSinkCut.getCutWeight();
DefaultWeightedEdge e = (DefaultWeightedEdge) returnGraphClone.addEdge(vertex, predecessor);
DefaultWeightedEdge e = returnGraphClone.addEdge(vertex, predecessor);
returnGraph.addEdge(Integer.parseInt(vertex + ""), Integer.parseInt(predecessor + ""));
returnGraphClone.setEdgeWeight(e, flowValue);

Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/scify/jedai/datamodel/SimilarityPairs.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
*/
package org.scify.jedai.datamodel;

import com.esotericsoftware.minlog.Log;
import java.io.Serializable;

import java.util.List;
import org.scify.jedai.utilities.IConstants;

Expand Down Expand Up @@ -64,10 +62,9 @@ private long countComparisons(List<AbstractBlock> blocks) {
comparisons += block.getNoOfComparisons();
}

if (MAX_COMPARISONS < comparisons) {
Log.error("Very high number of comparisons to be executed! "
+ "Maximum allowed number is : " + MAX_COMPARISONS);
System.exit(-1);
if (comparisons > MAX_COMPARISONS) {
throw new IllegalStateException("Very high number of comparisons to be executed. "
+ "Maximum allowed number is : " + MAX_COMPARISONS);
}
return comparisons;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/scify/jedai/datamodel/joins/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public Category(int len, float threshold, int categoryN) {
Category.THRESHOLD = threshold;
Category.N = categoryN;
s_len = len;
e_len = (int) ((float) (s_len / THRESHOLD));
K = (int) (2 * (1 - THRESHOLD) / (1 + THRESHOLD) * (float) e_len);
e_len = (int) (s_len / THRESHOLD);
K = (int) (2 * (1 - THRESHOLD) / (1 + THRESHOLD) * e_len);
N1 = K + 1;
N2 = 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import org.apache.jena.atlas.json.JsonArray;
import org.apache.jena.atlas.json.JsonObject;
import org.scify.jedai.datamodel.EntityProfile;

import java.io.IOException;
import org.scify.jedai.utilities.DBUtils;
import java.sql.*;
import java.util.*;

Expand Down Expand Up @@ -60,33 +59,25 @@ public List<EntityProfile> getEntityProfiles() {
return null;
}

//inputFilePath is assigned the Database URL
try {
if (user == null) {
Log.error("Database user has not been set!");
return null;
}
if (password == null) {
Log.error("Database password has not been set!");
return null;
}
if (table == null) {
Log.error("Database table has not been set!");
return null;
}

Connection conn;
if (inputFilePath.startsWith("mysql")) {
conn = getMySQLconnection(inputFilePath);
} else if (inputFilePath.startsWith("postgresql")) {
conn = getPostgreSQLconnection(inputFilePath);
} else {
Log.error("Only MySQL and PostgreSQL are supported for the time being!");
return null;
}
if (user == null) {
Log.error("Database user has not been set!");
return null;
}
if (password == null) {
Log.error("Database password has not been set!");
return null;
}
if (table == null) {
Log.error("Database table has not been set!");
return null;
}

final Statement stmt = conn.createStatement();
final ResultSet rs = stmt.executeQuery("SELECT * FROM " + table);//retrieve the appropriate table
//inputFilePath is assigned the Database URL
try (Connection conn = DBUtils.getDBConnection(inputFilePath, user, password, ssl);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM " + table);//retrieve the appropriate table
) {

final ResultSetMetaData rsmd = rs.getMetaData();
int columnsNum = rsmd.getColumnCount();
String[] columns = new String[columnsNum];
Expand All @@ -113,7 +104,7 @@ public List<EntityProfile> getEntityProfiles() {
}
}
rs.close();
} catch (IOException | SQLException ex) {
} catch (SQLException ex) {
Log.error("Error in entities reading!", ex);
return null;
}
Expand Down Expand Up @@ -157,16 +148,6 @@ public String getMethodParameters() {
+ "6)" + getParameterDescription(5) + ".";
}

private Connection getMySQLconnection(String dbURL) throws IOException {
try {
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection("jdbc:" + dbURL + "?user=" + user + "&password=" + password);
} catch (Exception ex) {
Log.error("Error with database connection!", ex);
return null;
}
}

@Override
public JsonArray getParameterConfiguration() {
final JsonObject obj1 = new JsonObject();
Expand Down Expand Up @@ -273,25 +254,6 @@ public String getParameterName(int parameterId) {
}
}

private Connection getPostgreSQLconnection(String dbURL) throws IOException {
try {
final Properties props = new Properties();
if (!(user == null)) {
props.setProperty("user", user);
}
if (!(password == null)) {
props.setProperty("password", password);
}
if (ssl) {
props.setProperty("ssl", "true");
}
return DriverManager.getConnection("jdbc:" + dbURL, props);
} catch (SQLException ex) {
Log.error("Error with database connection!", ex);
return null;
}
}

public void setAttributesToExclude(String[] attributesNamesToExclude) {
attributesToExclude.addAll(Arrays.asList(attributesNamesToExclude));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
import org.apache.jena.atlas.json.JSON;
import org.apache.jena.atlas.json.JsonArray;
import org.apache.jena.atlas.json.JsonObject;
import org.rdfhdt.hdt.exceptions.NotFoundException;
import org.scify.jedai.datamodel.EntityProfile;

import java.io.IOException;
import java.util.*;

/**
Expand Down Expand Up @@ -57,11 +55,9 @@ public List<EntityProfile> getEntityProfiles() {
//load the rdf model from the input file
try {
readModel(inputFilePath);
} catch (IOException ex) {
} catch (Exception ex) {
Log.error("Error in entities reading!", ex);
return null;
} catch (NotFoundException e) {
Log.error(e.getMessage());
}

return entityProfiles;
Expand Down Expand Up @@ -145,7 +141,7 @@ public String getParameterName(int parameterId) {
}
}

private void readModel(String inpFIle) throws IOException, NotFoundException {
private void readModel(String inpFIle) {
//read each ntriples
JsonObject jsonObject = JSON.read(inpFIle);
String key = jsonObject.keys().toArray()[0].toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.jena.riot.RDFDataMgr;
import org.scify.jedai.datamodel.EntityProfile;

import java.io.IOException;
import java.util.*;

/**
Expand Down Expand Up @@ -58,7 +57,7 @@ public List<EntityProfile> getEntityProfiles() {
try {
final Model model = RDFDataMgr.loadModel(inputFilePath);
readModel(model);
} catch (IOException ex) {
} catch (Exception ex) {
Log.error("Error in entities reading!", ex);
return null;
}
Expand Down Expand Up @@ -144,7 +143,7 @@ public String getParameterName(int parameterId) {
}
}

private void readModel(Model m) throws IOException {
private void readModel(Model m) {
//read each ntriples
//get spo, create a separate profile for each separate subject,
//with Attribute=predicate and Value=object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.esotericsoftware.minlog.Log;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -69,7 +68,7 @@ public List<EntityProfile> getEntityProfiles() {
//load the rdf model from the input file
try {
readEndpoint(inputFilePath);
} catch (IOException ex) {
} catch (Exception ex) {
Log.error("Error in data reading", ex);
return null;
}
Expand Down Expand Up @@ -189,7 +188,7 @@ public String getParameterName(int parameterId) {
}
}

private void readEndpoint(String endpointUrl) throws IOException {
private void readEndpoint(String endpointUrl) {
//read each ntriples
//get spo, create a separate profile for each separate subject,
//with Attribute=predicate and Value=object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public String getParameterName(int parameterId) {
}
}

private void readXMLdoc(Document document) throws IOException {
private void readXMLdoc(Document document) {
final Element classElement = document.getRootElement();

final List<Element> dblpRoot = classElement.getChildren();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public abstract class AbstractGtReader extends AbstractReader implements IGround
protected final Set<IdDuplicates> idDuplicates;
protected final TObjectIntMap<String> urlToEntityId1;
protected final TObjectIntMap<String> urlToEntityId2;
protected final SimpleGraph duplicatesGraph;
protected final SimpleGraph<Integer, DefaultEdge> duplicatesGraph;

public AbstractGtReader (String filePath) {
super(filePath);
idDuplicates = new HashSet<>();
duplicatesGraph = new SimpleGraph(DefaultEdge.class);
urlToEntityId1 = new TObjectIntHashMap();
urlToEntityId2 = new TObjectIntHashMap();
duplicatesGraph = new SimpleGraph<>(DefaultEdge.class);
urlToEntityId1 = new TObjectIntHashMap<>();
urlToEntityId2 = new TObjectIntHashMap<>();
}

@Override
Expand Down
Loading

0 comments on commit eb8d063

Please sign in to comment.