Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
CreatureChat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Public
CreatureChat
Commits
80248a4f
Commit
80248a4f
authored
Apr 03, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding more logs to message parsing and behavior parsing
parent
29db3e51
Pipeline
#11928
passed with stage
in 19 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
5 deletions
+9
-5
MessageParser.java
src/main/java/com/owlmaddie/message/MessageParser.java
+9
-5
No files found.
src/main/java/com/owlmaddie/message/MessageParser.java
View file @
80248a4f
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
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment