Commit 80248a4f by Jonathan Thomas

Adding more logs to message parsing and behavior parsing

parent 29db3e51
Pipeline #11928 passed with stage
in 19 seconds
package com.owlmaddie.message; package com.owlmaddie.message;
import java.util.regex.Pattern; import org.slf4j.Logger;
import java.util.regex.Matcher; import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* The {@code MessageParser} class parses out behaviors that are included in messages, and outputs * The {@code MessageParser} class parses out behaviors that are included in messages, and outputs
* a {@code ParsedMessage} result, which separates the cleaned message and the included behaviors. * a {@code ParsedMessage} result, which separates the cleaned message and the included behaviors.
*/ */
public class MessageParser { public class MessageParser {
public static final Logger LOGGER = LoggerFactory.getLogger("mobgpt");
public static ParsedMessage parseMessage(String input) { public static ParsedMessage parseMessage(String input) {
LOGGER.info("Parsing message: {}", input); // Log the input string
StringBuilder cleanedMessage = new StringBuilder(); StringBuilder cleanedMessage = new StringBuilder();
List<Behavior> behaviors = new ArrayList<>(); List<Behavior> behaviors = new ArrayList<>();
Pattern pattern = Pattern.compile("<(\\w+)(?:\\s+(-?\\d+))?>"); Pattern pattern = Pattern.compile("<(\\w+)(?:\\s+(-?\\d+))?>");
Matcher matcher = pattern.matcher(input); Matcher matcher = pattern.matcher(input);
while (matcher.find()) { while (matcher.find()) {
// Extract and store behaviors
String behaviorName = matcher.group(1); String behaviorName = matcher.group(1);
Integer argument = null; Integer argument = null;
if (matcher.group(2) != null) { if (matcher.group(2) != null) {
argument = Integer.valueOf(matcher.group(2)); argument = Integer.valueOf(matcher.group(2));
} }
behaviors.add(new Behavior(behaviorName, argument)); behaviors.add(new Behavior(behaviorName, argument));
LOGGER.info("Found behavior: {} with argument: {}", behaviorName, argument); // Log each found behavior
// Remove the matched pattern from the original string
matcher.appendReplacement(cleanedMessage, ""); matcher.appendReplacement(cleanedMessage, "");
} }
matcher.appendTail(cleanedMessage); matcher.appendTail(cleanedMessage);
LOGGER.info("Cleaned message: {}", cleanedMessage.toString()); // Log the cleaned message
// Create and return the ParseResult object
return new ParsedMessage(cleanedMessage.toString().trim(), behaviors); return new ParsedMessage(cleanedMessage.toString().trim(), behaviors);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment