Schedule-Creator

Java GUI to create schedules for UNCG students
git clone git://git.wrycode.com/wrycode/archive/Schedule-Creator.git
Log | Files | Refs | README

commit aed86e5269439f8b5f860ddd8aa67b086abf6bec
parent 8a33aea65df7b4d1dd18e5a87ae237ee116bbaa6
Author: wrycode <wry@mm.st>
Date:   Thu, 27 Feb 2020 13:45:02 -0500

Merge pull request #17 from cloud0x9/sfar

Improve regex and code structure in ParseData
Diffstat:
MScheduleCreator/ParseData.java | 72+++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
MScheduleCreator/Tests.java | 2+-
2 files changed, 56 insertions(+), 18 deletions(-)

diff --git a/ScheduleCreator/ParseData.java b/ScheduleCreator/ParseData.java @@ -1,8 +1,8 @@ package ScheduleCreator; /** - * This class parses text for class name, time, and day - * Last updated: February 20, 2020 + * Parses a text file, and returns the parsed data + * updated: February, 27, 2020 * * @author Sfar */ @@ -11,23 +11,62 @@ import java.util.regex.*; public class ParseData { - protected static void parse(String semester) throws IOException { - //Regular expression, includes class name, time and day. - final String RegexExpression = "(\\b[A-Z]{3}\\b.\\b[0-9]{3}\\b.* [0-9]{2}\\b)|((?:(?:1[0-2]|0?[1-9]):(?:[0-5][0-9])?(?:[AaPp][Mm])).-.(?:(?:1[0-2]|0?[1-9]):(?:[0-5][0-9]) ?(?:[AaPp][Mm])))|(TR\\b|MW\\b|MWF\\b|M\\b|T\\\\b|W\\b|R\\b|F\\b)"; + /** + *Applies regex to a text file. + * + * @param semester - This determines which file will be parsed, based on + * semester. + * @param Group - This is the group number that will be output from the + * regex(number is based on parentheses count), specific parts of the regex + * can be used instead of the whole thing + * @throws IOException + */ + protected static void applyRegex(String _semester, int _group) throws IOException { + { + //Regular expression, includes full class name, abbreviated class name with section, the instructor, crn, time and day + final String RegexExpression = "(.*?(?= - (?:[0-9]{5}))|[0-9]{5})|(\\b[A-Z]{3}\\b.\\b[0-9]{3}\\b.* [0-9]{2}\\b)|(([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9].([AaPp][Mm])\\b).-.([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9].([AaPp][Mm])\\b|\\b(TR\\b|MW\\b|MWF\\b|M\\b|T\\b|W\\b|R\\b|F\\b)\\s|(?<=Lecture|Lab|Individual Study|Seminar|Clinical|Colloquia|Dissertation or Thesis|Ensemble|Internship, Field Exp, Coop Ed|Lecture and lab|Performance|Physical Activity|Practicum - Dlvrd Ind Setting|Recitations|Student Teaching).*?(?=\\(P\\)E-mail)"; - // get fulltext of the semester - String content = Boilerplate.GetResourceString(semester); + // get fulltext of the semester + String content = Boilerplate.GetResourceString(_semester); - //Give the matcher the both the text and the regex expression so it can parse. - Matcher m = Pattern.compile(RegexExpression).matcher(content); + //Give the matcher both the text and the regex expression so it can parse. + Matcher match = Pattern.compile(RegexExpression).matcher(content); - //loop that prints matches. - while (m.find()) { - //print all matches, group(0) means everything. - System.out.println(m.group(0)); + while (match.find()) { + //Should be a return statment, but is sout for now + //print matches, based on which method calls it + System.out.println(match.group(_group)); - //The print statement below doesn't work fully yet, but this would create a csv format of all the data - //System.out.println("{" +m.group(1) +" , "+ m.group(2) +" , "+ m.group(3) + "}"); + } } } -}- \ No newline at end of file + + /** + * Returns all parsed data + * + * @param semester - this determines which file will be parsed, based on + * semester. + * @throws IOException + */ + protected static void getAllData(String _semester) throws IOException { + //passes the semster to the ApplyRegex method to do the parseing + //The number that is passed is the group number, which determines what will be output, 0 means everything + applyRegex(_semester, 0); + } + + /** + * Returns only class names with sections, also returns a bunch of null + * values which can be ignored (this can be used in the class lookup) + * + * @param semester - this determines which file will be parsed, based on + * semester. + * @throws IOException + */ + protected static void getClassData(String _semester) throws IOException { + //passes the semster to the ApplyRegex method to do the parseing + //The number that is passed is the group number, which determines what will be output + //1 means the first set of capturing parthesses + applyRegex(_semester, 2); + } + +} diff --git a/ScheduleCreator/Tests.java b/ScheduleCreator/Tests.java @@ -11,7 +11,7 @@ import java.util.logging.Logger; public class Tests { public static void main(String[] args) { try { - ParseData.parse("raw/spring2020"); + ParseData.getAllData("raw/spring2020"); } catch (IOException ex) { Logger.getLogger(Tests.class.getName()).log(Level.SEVERE, null, ex); }