Skip to content

Commit

Permalink
add a fileprinter function
Browse files Browse the repository at this point in the history
  • Loading branch information
Hossiphi committed Apr 29, 2021
1 parent e5564cf commit 2542a0d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ release.properties
Pipeline/src/main/resources/texts/
Pipeline/evaluations/
Pipeline/ecsaEvaluations/
pipeline/src/main/resources/evaluations/
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ private static void run(String name, File inputText, File inputModel, File addit

private static void printResultsInFiles(File outputDir, AgentDatastructure data, Duration duration) {

FilePrinter.writeEval1ToFile(Path.of(outputDir.getAbsolutePath(), "eval1.csv").toFile(), data.getText(), data.getTextState(), 0);

FilePrinter.writeEval1ToFile(Path.of(outputDir.getAbsolutePath(), "eval1.csv").toFile(), data.getText(), data.getTextState());
FilePrinter.writeTraceLinksWithTextInFile(Path.of(outputDir.getAbsolutePath(), "traceLinksToText.csv").toFile(), data.getText(),
data.getConnectionState());
FilePrinter.writeStatesToFile(Path.of(outputDir.getAbsolutePath(), "stats.csv").toFile(), //
data.getModelState(), data.getTextState(), data.getRecommendationState(), data.getConnectionState(), duration);
FilePrinter.writeNounMappingsInCsvFile(Path.of(outputDir.getAbsolutePath(), "noun_mappings.csv").toFile(), data.getTextState());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private static boolean createFileIfNonExistent(File file) {
return true;
}

public static void writeEval1ToFile(File debugGraphSentences, IText graph, ITextState textExtractionState, double min) {
public static void writeEval1ToFile(File debugGraphSentences, IText graph, ITextState textExtractionState) {

boolean fileCreated = createFileIfNonExistent(debugGraphSentences);
if (!fileCreated) {
Expand Down Expand Up @@ -143,9 +143,6 @@ public static void writeEval1ToFile(File debugGraphSentences, IText graph, IText
}
myWriter.append(LINE_SEPARATOR + valueBuilder.toString() + LINE_SEPARATOR);

myWriter.append(LINE_SEPARATOR + LINE_SEPARATOR);
myWriter.append(PROCESSING_TIME + min);

logger.info(SUCCESS_WRITE);
} catch (IOException | NumberFormatException e) {
logger.error(GENERIC_ERROR);
Expand All @@ -154,6 +151,52 @@ public static void writeEval1ToFile(File debugGraphSentences, IText graph, IText

}

public static void writeTraceLinksWithTextInFile(File debugGraphSentences, IText graph, IConnectionState connectionState) {
boolean fileCreated = createFileIfNonExistent(debugGraphSentences);
if (!fileCreated) {
return;
}

try (FileWriter myWriter = new FileWriter(debugGraphSentences)) {
int minSentenceNumber = 0;
StringBuilder valueBuilder = new StringBuilder(SINGLE_SEPARATOR_WITH_SPACES);

for (IWord node : graph.getWords()) {
int sentenceNo = Integer.parseInt(String.valueOf(node.getSentenceNo()));

if (sentenceNo + 1 > minSentenceNumber) {
myWriter.append(LINE_SEPARATOR + valueBuilder.toString() + LINE_SEPARATOR);
myWriter.append(LINE_SEPARATOR + (sentenceNo + 1) + SINGLE_SEPARATOR_WITH_SPACES);
valueBuilder = new StringBuilder(SINGLE_SEPARATOR_WITH_SPACES);
minSentenceNumber++;
}

String nodeValue = node.getText();
if (nodeValue.length() == 1 && !Character.isLetter(nodeValue.charAt(0))) {
continue;
}
myWriter.append(nodeValue + SINGLE_SEPARATOR_WITH_SPACES);

if (!connectionState.getInstanceLinks()
.stream()
.anyMatch(
link -> link.getTextualInstance().getNameMappings().stream().anyMatch(mapping -> mapping.getNodes().contains(node) == true))) {
valueBuilder.append("0");
valueBuilder.append(SINGLE_SEPARATOR_WITH_SPACES);
} else {
valueBuilder.append("1");
valueBuilder.append(SINGLE_SEPARATOR_WITH_SPACES);
}
}
myWriter.append(LINE_SEPARATOR + valueBuilder.toString() + LINE_SEPARATOR);

logger.info(SUCCESS_WRITE);
} catch (IOException | NumberFormatException e) {
logger.error(GENERIC_ERROR);
logger.debug(e.getMessage(), e.getCause());
}
}

public static void writeRecommendedRelationToFile(IRecommendationState recommendationState) {
File debugGraphSentences = new File("evaluations/EvalRecommendationRelations.txt");

Expand Down

0 comments on commit 2542a0d

Please sign in to comment.