Skip to content

Commit

Permalink
Improve natty parsing speed
Browse files Browse the repository at this point in the history
  • Loading branch information
IanTeo committed Nov 6, 2016
1 parent e16b14f commit f1ef5fe
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/java/seedu/taskitty/logic/parser/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import seedu.taskitty.commons.core.LogsCenter;
import seedu.taskitty.commons.exceptions.IllegalValueException;
import seedu.taskitty.commons.util.DateTimeUtil;
import seedu.taskitty.commons.util.StringUtil;
import seedu.taskitty.commons.util.TaskUtil;
import seedu.taskitty.logic.commands.*;
Expand Down Expand Up @@ -54,6 +55,16 @@ public class CommandParser {
private static final Pattern TASK_DATA_ARGS_FORMAT = // Tags must be at the end
Pattern.compile("(?<arguments>[\\p{Graph} ]+)"); // \p{Graph} is \p{Alnum} or \p{Punct}

// Parser to use Natty to parse dates and times
private static final Parser nattyParser = new Parser();

public CommandParser() {
// Natty takes while to parse the first date.
// We parse today's date when CommandParser is initialized to allow Natty to "warm up"
logger.info("Starting Natty");
nattyParser.parse(DateTimeUtil.createCurrentTime().toString());
}

/**
* Parses user input into command for execution.
*
Expand Down Expand Up @@ -313,8 +324,7 @@ private String extractNameInQuotes(String dataArguments, ArrayList<String> detai
* Returns the index where the task name should end.
*/
private int extractDateTimeUsingNatty(String dataArguments, ArrayList<String> details) {
Parser dateTimeParser = new Parser();
List<DateGroup> dateGroups = dateTimeParser.parse(dataArguments);
List<DateGroup> dateGroups = nattyParser.parse(dataArguments);
int nameEndIndex = dataArguments.length();

for (DateGroup group : dateGroups) {
Expand Down

0 comments on commit f1ef5fe

Please sign in to comment.