For our Online Test Software, Java Paper API is used heavily to mark the examination questions. For any Exam Software marking is a very important part and requires some way of automating the marking process.
Here is the process adopted for Examination Software
- Create a pattern string with a regular expression.
- Compile it so it can be used multiple times.
- apply matches(0 function.
- if matches() functions return true then a patter is a match
- if matches() return false then pattern does not exist inside the search text.
static void simpleMatchesTest(final String patternString, final String text) {
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(text);
System.out.printf("%s found is : %s\n", patternString, matcher.matches());
}
Java Pattern API provides matcher pattern gives us more information about the matching. for Online Examination Software here is an excerpt of the code which gives detailed information about the match.
static void simpleMatcherTest(final String patternString, final String text) {
Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(text);
int count = 0;
while (matcher.find()) {
count++;
System.out.printf("found: %d : %d - %d %n", count, matcher.start(), matcher.end());
}
}
Here is the output:
Here is the output: Online Assessment Software
Task :MatcherTest.main()
.*exam-system.* found is : true
.*test-system.* found is : false
found: 1 : 31 - 35
found: 2 : 50 - 54
Assessment Management Software
java pattern API allows you to group one or more patterns or searches together. which is used for Examination Management Software and Exam Management Software
static void simpleGroupTest(final String patternString, final String text) {
Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.printf("found: %s %s %n", matcher.group(1), matcher.group(2));
}
}
Here is the complete illustration for the Group and Matcher: Online Examination System
public static void main(String[] args) {
String text = "https://www.onlinetestplus.com/exam-system/";
String patternString = ".*exam-system.*";
simpleMatchesTest(patternString, text);
patternString = ".*test-system.*";
simpleMatchesTest(patternString, text);
text = "https://www.onlinetestplus.com/exam-system/online-exam-software/";
patternString = "exam";
simpleMatcherTest(patternString, text);
patternString = "(exam)-(.+?/)";
simpleGroupTest(patternString, text);
}
Please visit the following links for detailed information and usages of the API pattern.