Skip to content

Commit

Permalink
UnitCode and Semester fortified
Browse files Browse the repository at this point in the history
  • Loading branch information
pgram1 committed Mar 7, 2020
1 parent 4e3fa8c commit 239c7b3
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.regex.*;

public class Document {
private String path;
Expand Down Expand Up @@ -38,15 +39,16 @@ public Document(String path) {
}

void getImages() throws IOException, InterruptedException {
//System.out.println("\n-----\nCreating output directory\n-----\n");
//System.out.println((this.outputFolder).toString());
// System.out.println("\n-----\nCreating output directory\n-----\n");
// System.out.println((this.outputFolder).toString());
new File(this.outputFolder).mkdirs();

//System.out.println("\n-----\nGetting document info\n-----\n");
// System.out.println("\n-----\nGetting document info\n-----\n");
getDocInfo();

//System.out.println("\n-----\nExporting all images as PNG\n-----\n");
//System.out.println("pdfimages.exe \"" + this.path + "\" \"" + this.outputFile + "\"");
// System.out.println("\n-----\nExporting all images as PNG\n-----\n");
// System.out.println("pdfimages.exe \"" + this.path + "\" \"" + this.outputFile
// + "\"");
Runtime.getRuntime().exec("3rdbinaries\\pdfimages.exe \"" + this.path + "\" \"" + this.outputFile + "\"")
.waitFor();

Expand All @@ -62,13 +64,13 @@ private void getDocInfo() throws InterruptedException, IOException {
return;

this.unitTitle = between(content, "UNIT TITLE", "CREDITS");
this.unitCodeHelper = new UnitCodeHelper(between(content, "UNIT CODE", "UNIT TITLE"));
this.unitCodeHelper = new UnitCodeHelper(findUnitCode(content, "UNIT CODE"));

// we use the information derived from the unit code to achieve data uniformity
this.department = this.unitCodeHelper.getDepartment();
this.levelofstudy = this.unitCodeHelper.getLevelofstudy();
this.programme = this.unitCodeHelper.getProgramme();
this.semester = between(content, "SEMESTER/SESSION", "LEVEL OF STUDY");
this.semester = findSemester(content, "SEMESTER/SESSION");

}

Expand All @@ -94,6 +96,29 @@ private String between(String value, String a, String b) {
return value.substring(adjustedPosA, posB).trim().replaceAll("\\s{2,}", " ");
}

private String findSemester(String str, String word) {
Pattern p = Pattern.compile(word + "\\W+(\\w+)");
Matcher m = p.matcher(str);
if (m.find())
if (m.group(1).equalsIgnoreCase("Fall")) {
return "Autumn";
} else {
return m.group(1);
}
else
return "Whole Session";
}

private String findUnitCode(String str, String word) {
Pattern p = Pattern.compile(word + "\\W+(\\w+)");
Matcher m = p.matcher(str);
if (m.find()) {
return m.group(1);
} else {
return null;
}
}

public String getOutputFolder() {
return outputFolder;
}
Expand Down

0 comments on commit 239c7b3

Please sign in to comment.