Skip to content
Merged
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
8 changes: 8 additions & 0 deletions code/parsing-engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ repositories {

dependencies {
// Use JUnit Jupiter API for testing.
implementation 'commons-lang:commons-lang:2.6'
implementation 'edu.stanford.nlp:stanford-corenlp:4.3.1'
implementation 'edu.stanford.nlp:stanford-corenlp:4.3.1:models'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.2'
implementation 'org.apache.poi:poi-ooxml:4.1.2'

compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'

// Use JUnit Jupiter Engine for testing.
Expand Down
94 changes: 92 additions & 2 deletions code/parsing-engine/src/main/java/edu/illinois/phantom/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,102 @@
*/
package edu.illinois.phantom;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.illinois.phantom.model.Experience;
import edu.illinois.phantom.wordParser.ResumeParser;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

import java.io.*;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static edu.illinois.phantom.wordParser.Constants.*;

public class App {
public String getGreeting() {
return "Hello World!";
}

public static void main(String[] args) {
System.out.println(new App().getGreeting());
public static void main(String[] args) throws IOException {

ResumeParser resumeParser = new ResumeParser();
//Creating a File object for directory
ClassLoader classLoader = App.class.getClassLoader();
File directoryPath = new File(classLoader.getResource("Resumes").getFile());
//List of all files and directories
File filesList[] = directoryPath.listFiles();
List<ObjectNode> experienceObjectList = new ArrayList<>();
ObjectMapper objectMapper = new ObjectMapper();
System.out.println("Parsing resumes...");
for(File file : filesList) {
InputStream targetStream = new FileInputStream(file);
try (XWPFDocument doc = new XWPFDocument(Objects.requireNonNull(targetStream))) {
List<XWPFParagraph> list = doc.getParagraphs();
List<String> textList = new ArrayList<>();
StringBuilder sb = new StringBuilder();
for (XWPFParagraph paragraph : list) {
String text = paragraph.getText();
String lowertext = StringUtils.lowerCase(text);
if (pattern4.matcher(lowertext).find()) {
textList.add(sb.toString());
sb = new StringBuilder();
sb.append(lowertext);
} else if (pattern3.matcher(lowertext).find()) {
textList.add(sb.toString());
sb = new StringBuilder();
sb.append(lowertext);
} else if (pattern2.matcher(lowertext).find()) {
textList.add(sb.toString());
sb = new StringBuilder();
sb.append(lowertext);
} else if (pattern1.matcher(lowertext).find()) {
textList.add(sb.toString());
sb = new StringBuilder();
sb.append(lowertext);
} else if (pattern5.matcher(lowertext).find()) {
textList.add(sb.toString());
sb = new StringBuilder();
sb.append(lowertext);
}
else sb.append(lowertext);
}
if (sb != null && sb.length() > 0)
textList.add(sb.toString());
ArrayNode skillArray = objectMapper.createArrayNode();

for (String text : textList) {
Optional<List<Experience>> optionalList = resumeParser.parseResume(text);
if (optionalList.isPresent()) {
List<Experience> experienceList = optionalList.get();
for (Experience e : experienceList) {
String s = objectMapper.writeValueAsString(e);
skillArray.add(s);
}
}
}
// System.out.println(skillArray);
ObjectNode experienceObject = objectMapper.createObjectNode();
// It is similar to map put method. put method is overloaded to accept different types of data
// String as field value
experienceObject.put("location", file.getAbsolutePath());
experienceObject.put("skills", skillArray);
experienceObjectList.add(experienceObject);
} catch (IOException e) {
System.err.println("Error reading file " + e.getMessage());

}
}
System.out.println("Finished parsing resumes...");
System.out.println("Writing parsed data...");
objectMapper.writeValue(Paths.get("experiences.json").toFile(), experienceObjectList);
System.out.println("Finished");

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package edu.illinois.phantom.model;

import lombok.Builder;
import lombok.ToString;

@Builder
@ToString
public class Experience {

private String skill;
private Integer duration;

public Experience(String skill, Integer duration) {
this.skill = skill;
this.duration = duration;
}

public String getSkill() {
return skill;
}

public void setSkill(String skill) {
this.skill = skill;
}

public Integer getDuration() {
return duration;
}

public void setDuration(Integer duration) {
this.duration = duration;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package edu.illinois.phantom.model;

import org.apache.commons.lang.StringUtils;

import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.Period;
import java.util.Objects;

import static edu.illinois.phantom.wordParser.Constants.monthToInt;


public class MonthYear {
String month;
String year;


public MonthYear(String month, String year) {
this.month = month;
this.year = year;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MonthYear monthYear = (MonthYear) o;
return month == monthYear.month && year == monthYear.year;
}

@Override
public int hashCode() {
return Objects.hash(month, year);
}

public int diffMonths(MonthYear other) {
LocalDate localDate;
LocalDate otherLocalDate;
//we will assume day is first day of month
int day = 1;
try {

if (month.equalsIgnoreCase("present") || year.equalsIgnoreCase("present")) {
localDate = LocalDate.now();
} else {
int thisIntMonth;
if(StringUtils.isNumeric(month)) {
thisIntMonth = Integer.parseInt(month);
}
else thisIntMonth = monthToInt.get(month);
String normalizedYear = normalizeYear(year);
localDate = LocalDate.of(Integer.parseInt(normalizedYear), thisIntMonth, day);
}

if (other.month.equalsIgnoreCase("present") || other.year.equalsIgnoreCase("present")) {
otherLocalDate = LocalDate.now();
} else {
int otherIntmonth;
if(StringUtils.isNumeric(other.month)) {
otherIntmonth = Integer.parseInt(other.month);
}
else otherIntmonth = monthToInt.get(other.month);
String normalizedYear = normalizeYear(other.year);
otherLocalDate = LocalDate.of(Integer.parseInt(normalizedYear), otherIntmonth, day);
}

if (localDate.compareTo(otherLocalDate) > 0) {
Period period = Period.between(otherLocalDate, localDate);
return period.getYears() * 12 + period.getMonths();

} else {
Period period = Period.between(localDate, otherLocalDate);
return period.getYears() * 12 + period.getMonths();
}
} catch (DateTimeException e) {
return 0;
}
}

private String normalizeYear(String year) {
String normalizedYear;
if (year.length() < 4) {
if (Integer.parseInt(year) >= 0 && Integer.parseInt(year) <= 21)
normalizedYear = "20" + year;
else
normalizedYear = "19" + year;
} else normalizedYear = year;
return normalizedYear;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package edu.illinois.phantom.wordParser;

import java.util.*;
import java.util.regex.Pattern;

public class Constants {

Set<String> Education = new HashSet<>(Arrays.asList(
"BE", "B.E.", "B.E", "BS", "B.S", "ME", "M.E",
"M.E.", "MS", "M.S", "BTECH", "MTECH",
"SSC", "HSC", "CBSE", "ICSE", "X", "XII", "BSC", "DIPLOMA", "BACHELOR", "MASTER",
"MASTERS"
));
// public static final Pattern pattern1 = Pattern.compile("(jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|jun(e)?|jul(y)?|aug(ust)?|sep(tember)?|oct(ober)?|nov(ember)?|dec(ember)?)(\\s|\\S)(\\d{2,4}).*(jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|jun(e)?|jul(y)?|aug(ust)?|sep(tember)?|oct(ober)?|nov(ember)?|dec(ember)?)(\\s|\\S)(\\d{2,4})",Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
public static final Pattern pattern1 = Pattern.compile("(?<startMonth>jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|jun(e)?|jul(y)?|aug(ust)?|sep(tember)?|oct(ober)?|nov(ember)?|dec(ember)?)(\\s|\\S)(?<startYear>\\d{2,4}).*(?<endMonth>jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|jun(e)?|jul(y)?|aug(ust)?|sep(tember)?|oct(ober)?|nov(ember)?|dec(ember)?)(\\s|\\S)(?<endYear>\\d{2,4})", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
public static final Pattern pattern2 = Pattern.compile("(?<startYear>(\\d{2}(.|..)\\d{4}).{1,4})(?<endYear>\\d{2}(.|..)\\d{4})", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
public static final Pattern pattern3 = Pattern.compile("(?<startYear>(\\d{2}(.|..)\\d{4}).{1,4})(?<endYear>present)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
public static final Pattern pattern4 = Pattern.compile("(?<startMonth>jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|jun(e)?|jul(y)?|aug(ust)?|sep(tember)?|oct(ober)?|nov(ember)?|dec(ember)?)(\\s|\\S)(?<startYear>\\d{2,4}).*(?<endYear>present)",
Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
public static final Pattern pattern5 = Pattern.compile("(?<startYear>\\d{2}\\/\\d{4})(.|..|\\s|\\S)(?<endYear>\\d{2}\\/\\d{4})", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
public static final Map<String, Integer> monthToInt =
new HashMap<String, Integer>() {
{
put("jan", 1);
put("feb", 2);
put("mar", 3);
put("apr", 4);
put("may", 5);
put("jun", 6);
put("jul", 7);
put("aug", 8);
put("sep", 9);
put("oct", 10);
put("nov", 11);
put("dec", 12);
put("january", 1);
put("february", 2);
put("march", 3);
put("april", 4);
put("may", 5);
put("june", 6);
put("july", 7);
put("august", 8);
put("september", 9);
put("october", 10);
put("november", 11);
put("december", 12);
}
};


}
Loading