use of dna.dataStructures.Statement in project dna by leifeld.
the class ContradictionPanel method findContradictions.
/*
* method: find Contradictions (previously Thread ContradictionReporter)
*/
public void findContradictions() {
String statType = (String) filterComboBoxType.getSelectedItem();
int statTypeId = -1;
for (int i = 0; i < Dna.data.getStatementTypes().size(); i++) {
if (Dna.data.getStatementTypes().get(i).getLabel().equals(statType)) {
statTypeId = Dna.data.getStatementTypes().get(i).getId();
}
}
String var1 = (String) filterComboBoxVar1.getSelectedItem();
String var2 = (String) filterComboBoxVar2.getSelectedItem();
String varBoolean = (String) filterComboBoxBoolean.getSelectedItem();
// get list of statement IDs
ArrayList<Integer> ids = new ArrayList<Integer>();
for (int i = 0; i < Dna.data.getStatements().size(); i++) {
ids.add(Dna.data.getStatements().get(i).getId());
}
// get List of actors:
ArrayList<String> actors = new ArrayList<String>();
ArrayList<Statement> statements = Dna.data.getStatementsByStatementTypeId(statTypeId);
// String[] actors = new String[statements.size()];
for (int i = 0; i < statements.size(); i++) {
String a = (String) Dna.data.getStatements().get(i).getValues().get(var1);
if (!actors.contains(a)) {
actors.add(a);
}
}
// String[] actors; //Problem if not ArrayList?
// actors = Dna.dna.db.getVariableStringEntries(var1, statType);
ArrayList<Integer> tabuId = new ArrayList<Integer>();
// actors-loop
for (int i = 0; i < actors.size(); i++) {
DefaultMutableTreeNode actor = new DefaultMutableTreeNode(actors.get(i));
ArrayList<Integer> indices = new ArrayList<Integer>();
// for j = statement IDs
for (int j : ids) {
// if (actors.get(i).equals(Dna.dna.db.getVariableStringEntryWithType(j, var1, statType))) {
if (actors.get(i).equals(Dna.data.getStatement(j).getValues().get(var1))) {
indices.add(j);
}
}
for (int j : indices) {
for (int k : indices) {
if (j != k && !tabuId.contains(j) && !tabuId.contains(k) && Dna.data.getStatement(j).getValues().get(var2).equals(Dna.data.getStatement(k).getValues().get(var2)) && // ! Dna.dna.db.getVariableStringEntryWithType(j, varBoolean, statType).equals(Dna.dna.db.getVariableStringEntryWithType(k, varBoolean, statType))
Dna.data.getStatement(j).getValues().get(varBoolean).equals(Dna.data.getStatement(k).getValues().get(varBoolean))) {
// DefaultMutableTreeNode category = new DefaultMutableTreeNode(
// Dna.dna.db.getVariableStringEntryWithType(
// j, var2, statType));
DefaultMutableTreeNode category = new DefaultMutableTreeNode(Dna.data.getStatement(j).getValues().get(var2));
ArrayList<Integer> matches = new ArrayList<Integer>();
for (int l : indices) {
// j, var2, statType))){
if (Dna.data.getStatement(l).getValues().get(var2).equals(Dna.data.getStatement(j).getValues().get(var2))) {
matches.add(l);
DefaultMutableTreeNode id = new DefaultMutableTreeNode(// l, varBoolean, statType) +
Dna.data.getStatement(l).getValues().get(varBoolean) + " (" + l + ")");
category.add(id);
}
}
tabuId.addAll(matches);
if (category.getChildCount() > 0) {
actor.add(category);
}
}
}
// closes k-loop
}
// closes j-loop
if (actor.getChildCount() > 0) {
top.add(actor);
}
}
// closes i-loop
if (top.getChildCount() == 0) {
DefaultMutableTreeNode message = new DefaultMutableTreeNode("No contradictions found!");
top.add(message);
}
// display first node in tree:
tree.expandRow(0);
/*//display the entire tree:
* for (int d = 0; d < tree.getRowCount(); d++) {
* tree.expandRow(d);
* }
*/
}
Aggregations