Search in sources :

Example 6 with Statement

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);
		 * }
		 */
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Statement(dna.dataStructures.Statement) ArrayList(java.util.ArrayList)

Aggregations

Statement (dna.dataStructures.Statement)6 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)3 StatementType (dna.dataStructures.StatementType)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 HashMap (java.util.HashMap)2 Data (dna.dataStructures.Data)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Calendar (java.util.Calendar)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1