Installation
composer require avris/suml
Ensure your project uses PHP 8.0+ (SUML requires this).
Basic Usage
use Avris\SUML\SUML;
$suml = new SUML();
$result = $suml->parse('Hello, world!');
echo $result->getText(); // Outputs: "Hello, world!"
First Use Case Parse a simple text string to extract structured data (e.g., entities, relationships):
$suml = new SUML();
$parsed = $suml->parse('John Doe works at Acme Corp.');
$entities = $parsed->getEntities(); // Array of detected entities
Where to Look First
tests/ for real-world usage patterns.Avris\SUML\SUML for primary methods like parse(), getEntities(), and getRelationships().Text Parsing Pipeline
$suml = new SUML();
$parsed = $suml->parse($rawText);
$entities = $parsed->getEntities();
$relationships = $parsed->getRelationships();
getEntities() to extract named entities (e.g., people, organizations).getRelationships() to analyze connections between entities.Integration with Laravel
$this->app->singleton(SUML::class, function ($app) {
return new SUML();
});
// app/Facades/SUML.php
public static function parse($text) {
return app(SUML::class)->parse($text);
}
Batch Processing
$suml = new SUML();
$texts = ['Text 1', 'Text 2', 'Text 3'];
$results = array_map([$suml, 'parse'], $texts);
Customizing Output
$people = array_filter($entities, fn($e) => $e->getType() === 'PERSON');
Extending SUML
SUML class or using middleware:
$suml->addMiddleware(function ($text, $next) {
// Pre-process text (e.g., clean HTML)
return $next($text);
});
Storing Results
$serialized = $parsed->toArray();
cache()->put('suml_result', $serialized, now()->addHours(1));
Error Handling
try {
$result = $suml->parse($text);
} catch (\Exception $e) {
Log::error("SUML parsing failed: " . $e->getMessage());
return response()->json(['error' => 'Processing failed'], 500);
}
Performance
cache()->remember()).Entity/Relationship Granularity
Dependency Conflicts
composer.json for bloat.Locale Support
Inspect Raw Output
$debug = $suml->parse($text, ['debug' => true]);
dd($debug->getRawData()); // Inspect internal parsing steps
Logging
Log::debug().Testing Edge Cases
John Doe & Co.).Custom Entity Types
Str::contains() or regex.Middleware Hooks
$suml->addMiddleware(function ($text, $next) {
$text = preg_replace('/[^a-zA-Z0-9\s]/', '', $text); // Sanitize
return $next($text);
});
Configuration
$suml->setConfig(['min_confidence' => 0.7]);
Queue Long-Running Parses
ParseJob::dispatch($text)->onQueue('suml');
ParseJob to handle SUML parsing asynchronously.API Integration
Route::post('/api/parse', function (Request $request) {
$suml = app(SUML::class);
return response()->json($suml->parse($request->text)->toArray());
});
Database Storage
suml_entities table:
$entity->save(); // Assuming Entity model with fillable fields
How can I help you explore Laravel packages today?