Revolutionizing Timetable Management: Natural Language Input for Teacher Assignments
We’re excited to announce a powerful new feature in our school scheduling application: the ability to assign teachers to classrooms and subjects using natural language commands. This
update is designed to streamline the often-tedious process of creating and managing school timetables, making it faster and more intuitive than ever before.
The Power of Natural Language
Gone are the days of navigating complex menus and forms to make simple assignments. With our new natural language processing (NLP) capabilities, you can now type commands like:
“add teacher John Doe to class 10A with subject Mathematics, with distribution of 221”
The system will instantly parse this command, identify the teacher, classroom, and subject, and make the assignment with the specified distribution pattern. This not only saves time but
also reduces the cognitive load on school administrators, allowing them to focus on creating the best possible schedule for their students.
How It Works
This new feature is powered by a robust backend that intelligently parses natural language commands. Let’s take a look at the code that makes this possible.
In the app/Livewire/School/ClassroomsSubjectsTeachersTable.php component, we’ve added a new processNaturalLanguage method. This method uses a regular expression to capture the essential
information from the input string:
$pattern = '/add teacher (.+?) to class (.+?) with subject (.+?), with distribution of (\d+)/i';
if (! preg_match($pattern, $this->naturalLanguageInput, $matches)) {
session()->flash('assignment_error', 'Invalid command format. Please use: add teacher [name] to class [name] with subject [name], with distribution of [pattern]');
return;
}
Once the command is parsed, the system finds the corresponding teacher, classroom, and subject in the database. We’ve made sure to handle cases where the entity is not found, providing
clear error messages to the user.
/ Find teacher by name
$teacher = $this->school->teachers()->where('name', 'like', '%'.$teacherName.'%')->first();
if (! $teacher) {
session()->flash('assignment_error', "Teacher '{$teacherName}' not found.");
return;
}
The same logic is applied to find the classroom and subject, with the added flexibility of searching by name or short code.
A Seamless User Experience
To complement this powerful backend functionality, we’ve introduced a new “Quick Assignment” section to the lesson distribution grid. This provides a simple and intuitive interface for
users to enter their natural language commands.
The resources/views/livewire/school/classrooms-subjects-teachers-table.blade.php file has been updated to include this new section:
<div class="mt-4 p-4 bg-gray-50 rounded-lg border">
<h3 class="text-md font-semibold text-gray-800 mb-2">Quick Assignment with Natural Language</h3>
<p class="text-sm text-gray-600 mb-3">
Enter commands like: "add teacher John Doe to class 10A with subject Mathematics, with distribution of
221"
</p>
<form wire:submit.prevent="processNaturalLanguage" class="flex gap-2">
<input type="text" wire:model="naturalLanguageInput" list="entity-suggestions"
placeholder="add teacher [name] to class [name] with subject [name], with distribution of [pattern]"
class="flex-1 border border-gray-300 rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
required>
<datalist id="entity-suggestions">
@foreach($school->teachers as $teacher)
<option value="{{ $teacher->name }}">
@endforeach
@foreach($school->subjects as $subject)
<option value="{{ $subject->name }}">
@if($subject->short_code)
<option value="{{ $subject->short_code }}">
@endif
@endforeach
@foreach($school->classrooms as $classroom)
<option value="{{ $classroom->name }}">
@if($classroom->short_code)
<option value="{{ $classroom->short_code }}">
@endif
@endforeach
</datalist>
<button type="submit"
class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700 transition-colors">
Add Assignment
</button>
</form>
@error('naturalLanguageInput')
<span class="text-red-500 text-sm mt-1 block">{{ $message }}</span>
@enderror
@if(session()->has('assignment_success'))
<div class="text-green-600 text-sm mt-2">{{ session('assignment_success') }}</div>
@endif
@if(session()->has('assignment_error'))
<div class="text-red-600 text-sm mt-2">{{ session('assignment_error') }}</div>
@endif
</div>
10 class=”flex-1 border border-gray-300 rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500″
11 required>
12 14 Add Assignment 15
16
17
We’ve also included a datalist with suggestions for teachers, subjects, and classrooms to further enhance the user experience.
Other Improvements
In addition to the new natural language feature, we’ve also made a minor improvement to the dashboard. The “System Health” section has been removed to provide a cleaner and more focused
interface for users.
Conclusion
We’re confident that these new features will make a significant difference in how you manage your school’s timetable. By leveraging the power of natural language processing, we’re making
our application more intuitive, efficient, and user-friendly. We’re excited to hear your feedback on these new features and look forward to continuing to improve our application to meet
your needs.

Leave a Reply