Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/keml/analysis/AnalysisProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void main(String[] args) throws IOException {
runFurtherAnalysis = Boolean.parseBoolean(args[0]);
folder = args[1];
sourceFolder = new File(folder + "/keml/");
file = new File(sourceFolder.getAbsolutePath() + args[2]);
file = new File(sourceFolder.getAbsolutePath() + "/" + args[2]);
}
runAnalysis(file.toPath(), runFurtherAnalysis, folder, ExecutionMode.STANDARD);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/keml/analysis/PythonExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ public static boolean runPythonScript(String filePath, String fileName, Executio
}
}
}

public static void main(String[] args) {
runPythonScript("../keml.sample/introductoryExamples/analysis/2-1-keml", "2-1-keml", ExecutionMode.STANDARD);
}

}
51 changes: 42 additions & 9 deletions src/main/java/keml/analysis/WorkbookController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
Expand Down Expand Up @@ -43,6 +44,8 @@ public class WorkbookController {
XSSFCellStyle factStyle;
XSSFCellStyle origLLMStyle;
XSSFCellStyle origOtherStyle;
XSSFCellStyle targetStyle;
XSSFCellStyle repeatedStyle;

// data properties
int firstFreeColumn = 0;
Expand Down Expand Up @@ -128,44 +131,60 @@ public WorkbookController() {
trustStyle = wb.createCellStyle();
trustStyle.setDataFormat(floatStyle.getDataFormat());
trustStyle.setAlignment(HorizontalAlignment.CENTER);
trustStyle.setVerticalAlignment(VerticalAlignment.CENTER);
trustStyle.setFillForegroundColor(new XSSFColor(java.awt.Color.decode("#339966"), null));
trustStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// *************** Distrust *************
distrustStyle = wb.createCellStyle();
trustStyle.setDataFormat(floatStyle.getDataFormat());
distrustStyle.setAlignment(HorizontalAlignment.CENTER);
distrustStyle.setVerticalAlignment(VerticalAlignment.CENTER);
distrustStyle.setFillForegroundColor(new XSSFColor(java.awt.Color.decode("#FF5F5F"), null));
distrustStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// *************** neutral about trust *************
neutTrustStyle = wb.createCellStyle();
trustStyle.setDataFormat(floatStyle.getDataFormat());
neutTrustStyle.setDataFormat(floatStyle.getDataFormat());
neutTrustStyle.setAlignment(HorizontalAlignment.CENTER);
neutTrustStyle.setVerticalAlignment(VerticalAlignment.CENTER);
neutTrustStyle.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
neutTrustStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// ************** isFact *************
factStyle = wb.createCellStyle();
factStyle.setAlignment(HorizontalAlignment.CENTER);
factStyle.setVerticalAlignment(VerticalAlignment.CENTER);
factStyle.setFillForegroundColor(new XSSFColor(java.awt.Color.decode("#99CC00"), null));
factStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

// ************* is Instruction **********
instructionStyle = wb.createCellStyle();
instructionStyle.setAlignment(HorizontalAlignment.CENTER);
instructionStyle.setVerticalAlignment(VerticalAlignment.CENTER);
instructionStyle.setFillForegroundColor(new XSSFColor(java.awt.Color.decode("#FFCC00"), null));
instructionStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

// *************** origin LLM style**************
origLLMStyle = wb.createCellStyle();
origLLMStyle.setWrapText(true);
origLLMStyle.setAlignment(HorizontalAlignment.LEFT);
origLLMStyle.setFillForegroundColor(new XSSFColor(java.awt.Color.decode("#CCFFFF"), null));
origLLMStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

// *************** origin Other style**************
origOtherStyle = wb.createCellStyle();
origOtherStyle.setWrapText(true);
origOtherStyle.setAlignment(HorizontalAlignment.LEFT);
origOtherStyle.setFillForegroundColor(new XSSFColor(java.awt.Color.decode("#FFFF99"), null));
origOtherStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);


// *************** target style**************
targetStyle = wb.createCellStyle();
targetStyle.setAlignment(HorizontalAlignment.CENTER);
targetStyle.setVerticalAlignment(VerticalAlignment.CENTER);

// *************** repeated style**************
repeatedStyle = wb.createCellStyle();
repeatedStyle.setAlignment(HorizontalAlignment.CENTER);
repeatedStyle.setVerticalAlignment(VerticalAlignment.CENTER);
}

public void initialize(List<NewInformation> newInfos, List<PreKnowledge> preKnowledge) {
Expand All @@ -178,16 +197,21 @@ public void initialize(List<NewInformation> newInfos, List<PreKnowledge> preKnow
t.setCellValue(-1);
colorByIsInstruction(t, pre.isIsInstruction());
Cell msg = r.createCell(1);
msg.setCellValue(pre.getMessage());
msg.setCellValue(pre.getMessage());
colorByOrigin(msg, false);
r.createCell(2).setCellValue(pre.getTargetedBy().size());
r.createCell(3).setCellValue(pre.getRepeatedBy().size());
Cell target = r.createCell(2);
target.setCellValue(pre.getTargetedBy().size());
target.setCellStyle(targetStyle);
Cell repeated = r.createCell(3);
repeated.setCellValue(pre.getRepeatedBy().size());
repeated.setCellStyle(repeatedStyle);
Float fTi = pre.getFeltTrustImmediately();
Float fTa = pre.getFeltTrustAfterwards();
float fTiCellValue = fTi != null ? fTi.floatValue() : Float.NaN;
float fTaCellValue = fTa != null ? fTa.floatValue() : Float.NaN;
setAndColorByValue(r.createCell(4), fTiCellValue);
setAndColorByValue(r.createCell(5), fTaCellValue);
r.setHeight((short)-1);
}
for (int i = 0; i < newInfos.size(); i++) {
NewInformation info = newInfos.get(i);
Expand All @@ -197,16 +221,21 @@ public void initialize(List<NewInformation> newInfos, List<PreKnowledge> preKnow
t.setCellValue(info.getTiming());
colorByIsInstruction(t, info.isIsInstruction());
Cell msg = r.createCell(1);
msg.setCellValue(info.getMessage());
msg.setCellValue(info.getMessage());
colorByOrigin(msg, info.getSourceConversationPartner().getName().equals("LLM"));
r.createCell(2).setCellValue(info.getTargetedBy().size());
r.createCell(3).setCellValue(info.getRepeatedBy().size());
Cell target = r.createCell(2);
target.setCellValue(info.getTargetedBy().size());
target.setCellStyle(targetStyle);
Cell repeated = r.createCell(3);
repeated.setCellValue(info.getRepeatedBy().size());
repeated.setCellStyle(repeatedStyle);
Float fTi = info.getFeltTrustImmediately();
Float fTa = info.getFeltTrustAfterwards();
float fTiCellValue = fTi != null ? fTi.floatValue() : Float.NaN;
float fTaCellValue = fTa != null ? fTa.floatValue() : Float.NaN;
setAndColorByValue(r.createCell(4), fTiCellValue);
setAndColorByValue(r.createCell(5), fTaCellValue);
r.setHeight((short)-1);
}
}

Expand Down Expand Up @@ -240,7 +269,11 @@ public void addTrusts(HashMap<Information, Pair<Float, Float>> trusts, String na

private void sizeColumns() {
for (int i = 0; i < firstFreeColumn; i++) {
sheet.autoSizeColumn(i);
if (i == 1) {
sheet.setColumnWidth(i, 50*250);
} else {
sheet.autoSizeColumn(i);
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/keml/analysis/py/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ def main():
continue
f_s = os.path.join(user_dir_path, ana_file)
h_t = f'{user_dir_path}/stats_{file_name}/{os.path.splitext(ana_file)[0]}'
workbook_editor.insert_rand_values(f_s)
workbook_analyser.run_wb_analysis(f_s, h_t)
success = workbook_analyser.run_wb_analysis(f_s, h_t)
if not success:
print("Cannot provide further analysis if felt trusts are not set.")
return

if __name__ == '__main__':
main()
41 changes: 31 additions & 10 deletions src/main/java/keml/analysis/py/workbook_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def add_new_columns(ws):
for i in range(len(cells)):
if (i % 2 == 0):
cells[i].border = Border(left=b2)
cells[i].alignment = Alignment(horizontal='center')
cells[i].alignment = Alignment(horizontal='center', vertical='center')
cells[i].number_format = "+0.00;-0.00;0.00"

def fill_diff_columns(ws):
Expand Down Expand Up @@ -73,9 +73,10 @@ def run_wb_analysis(path_f, path_h):
ws = wb['Trust']
add_new_columns(ws)
fill_diff_columns(ws)
create_stats(ws, path_h)
success = create_stats(ws, path_h)
wb.save(path_f)
wb.close()
return success

def create_histograms(path_t_h, diffs_fT, key):
fig = plt.figure(figsize=(10,4))
Expand Down Expand Up @@ -118,6 +119,8 @@ def create_stats(ws, path_t_h):
for key in diffs_fT:
diffs_fT[key][0] = [cells[0].value for cells in ws[f'{columns[key][0]}3:{columns[key][0]}{l}']]
diffs_fT[key][1] = [cells[0].value for cells in ws[f'{columns[key][1]}3:{columns[key][1]}{l}']]
if '#NUM!' in diffs_fT[key][0]:
return False
if not os.path.exists(path_t_h):
os.mkdir(path_t_h)
create_histograms(path_t_h, diffs_fT, key)
Expand Down Expand Up @@ -148,15 +151,33 @@ def create_stats(ws, path_t_h):
cells[1].value = std_abs_diffs_fT[key][1]
i += 1
stat_names = ['Mean of |fT_ - F(mode)|', 'Variance of |fT_ - F(mode)|', 'Standard deviation of |fT_ - F(mode)|']
b1 = Side(border_style="medium", color="000000")
b1 = Side(border_style="medium", color="FFFFFF")
mean_fill = PatternFill(start_color='629BF0', end_color='629BF0', fill_type='solid')
var_fill = PatternFill(start_color='E79221', end_color='E79221', fill_type='solid')
std_fill = PatternFill(start_color='8ECA3E', end_color='8ECA3E', fill_type='solid')
k = 0
ws.column_dimensions['N'].width = np.max([len(stat_name) for stat_name in stat_names])
for cells in ws[f'N{l + 3}:V{l + 5}']:
cells[0].alignment = Alignment(horizontal='right')
for cells in ws[f'B{l + 3}:B{l + 5}']:
cells[0].alignment = Alignment(horizontal='left')
cells[0].value = stat_names[k]
for i in range(1, len(cells)):
if (i % 2 != 0):
match k:
case 0:
cells[0].fill = mean_fill
case 1:
cells[0].fill = var_fill
case 2:
cells[0].fill = std_fill
k+=1
k = 0
for cells in ws[f'O{l + 3}:V{l + 5}']:
for i in range(0, len(cells)):
if ((i + 1) % 2 != 0):
cells[i].border = Border(left=b1)
match k:
case 0:
cells[i].fill = mean_fill
case 1:
cells[i].fill = var_fill
case 2:
cells[i].fill = std_fill
k+=1


return True