mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 14:14:29 -04:00
Added test-data command for LUIS
This commit is contained in:
parent
7a4a72fa35
commit
6bb47c3b95
221
app/Console/Commands/CreateLuisData.php
Normal file
221
app/Console/Commands/CreateLuisData.php
Normal file
@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Utils;
|
||||
use stdClass;
|
||||
use App\Models\Account;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* Class CreateLuisData.
|
||||
*/
|
||||
class CreateLuisData extends Command
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create LUIS Data';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'ninja:create-luis-data';
|
||||
|
||||
/**
|
||||
* CreateLuisData constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->faker = Factory::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$intents = [];
|
||||
$entityTypes = [
|
||||
ENTITY_INVOICE,
|
||||
ENTITY_QUOTE,
|
||||
ENTITY_CLIENT,
|
||||
ENTITY_CREDIT,
|
||||
ENTITY_EXPENSE,
|
||||
ENTITY_PAYMENT,
|
||||
ENTITY_PRODUCT,
|
||||
ENTITY_RECURRING_INVOICE,
|
||||
ENTITY_TASK,
|
||||
ENTITY_VENDOR,
|
||||
];
|
||||
|
||||
foreach ($entityTypes as $entityType) {
|
||||
$intents = array_merge($intents, $this->createIntents($entityType));
|
||||
}
|
||||
|
||||
$intents = array_merge($intents, $this->getNavigateToIntents($entityType));
|
||||
|
||||
$this->info(json_encode($intents));
|
||||
}
|
||||
|
||||
private function createIntents($entityType)
|
||||
{
|
||||
$intents = [];
|
||||
|
||||
$intents = array_merge($intents, $this->getCreateEntityIntents($entityType));
|
||||
$intents = array_merge($intents, $this->getFindEntityIntents($entityType));
|
||||
$intents = array_merge($intents, $this->getListEntityIntents($entityType));
|
||||
|
||||
return $intents;
|
||||
}
|
||||
|
||||
private function getCreateEntityIntents($entityType)
|
||||
{
|
||||
$intents = [];
|
||||
$phrases = [
|
||||
"create new {$entityType}",
|
||||
"new {$entityType}",
|
||||
"make a {$entityType}",
|
||||
];
|
||||
|
||||
foreach ($phrases as $phrase) {
|
||||
$intents[] = $this->createIntent('CreateEntity', $phrase, [
|
||||
$entityType => 'EntityType',
|
||||
]);
|
||||
if ($entityType != ENTITY_CLIENT) {
|
||||
$client = $this->faker->firstName;
|
||||
$phrase .= " for {$client}";
|
||||
$intents[] = $this->createIntent('CreateEntity', $phrase, [
|
||||
$entityType => 'EntityType',
|
||||
$client => 'Name',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $intents;
|
||||
}
|
||||
|
||||
private function getFindEntityIntents($entityType)
|
||||
{
|
||||
$intents = [];
|
||||
|
||||
if (in_array($entityType, [ENTITY_CLIENT, ENTITY_INVOICE, ENTITY_QUOTE])) {
|
||||
$name = $entityType === ENTITY_CLIENT ? $this->faker->firstName : $this->faker->randomNumber(4);
|
||||
$intents[] = $this->createIntent('FindEntity', "find {$entityType} {$name}", [
|
||||
$entityType => 'EntityType',
|
||||
$name => 'Name',
|
||||
]);
|
||||
if ($entityType === ENTITY_CLIENT) {
|
||||
$name = $this->faker->firstName;
|
||||
$intents[] = $this->createIntent('FindEntity', "find {$name}", [
|
||||
$name => 'Name',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $intents;
|
||||
}
|
||||
|
||||
private function getListEntityIntents($entityType)
|
||||
{
|
||||
$intents = [];
|
||||
$entityTypePlural = Utils::pluralizeEntityType($entityType);
|
||||
|
||||
$intents[] = $this->createIntent('ListEntity', "show me {$entityTypePlural}", [
|
||||
$entityTypePlural => 'EntityType',
|
||||
]);
|
||||
$intents[] = $this->createIntent('ListEntity', "list {$entityTypePlural}", [
|
||||
$entityTypePlural => 'EntityType',
|
||||
]);
|
||||
|
||||
$intents[] = $this->createIntent('ListEntity', "show me active {$entityTypePlural}", [
|
||||
$entityTypePlural => 'EntityType',
|
||||
'active' => 'Filter',
|
||||
]);
|
||||
$intents[] = $this->createIntent('ListEntity', "list archived and deleted {$entityTypePlural}", [
|
||||
$entityTypePlural => 'EntityType',
|
||||
'archived' => 'Filter',
|
||||
'deleted' => 'Filter',
|
||||
]);
|
||||
|
||||
if ($entityType != ENTITY_CLIENT) {
|
||||
$client = $this->faker->firstName;
|
||||
$intents[] = $this->createIntent('ListEntity', "list {$entityTypePlural} for {$client}", [
|
||||
$entityTypePlural => 'EntityType',
|
||||
$client => 'Name',
|
||||
]);
|
||||
$intents[] = $this->createIntent('ListEntity', "show me {$client}'s {$entityTypePlural}", [
|
||||
$entityTypePlural => 'EntityType',
|
||||
$client . '\'s' => 'Name',
|
||||
]);
|
||||
$intents[] = $this->createIntent('ListEntity', "show me {$client}'s active {$entityTypePlural}", [
|
||||
$entityTypePlural => 'EntityType',
|
||||
$client . '\'s' => 'Name',
|
||||
'active' => 'Filter',
|
||||
]);
|
||||
}
|
||||
|
||||
return $intents;
|
||||
}
|
||||
|
||||
private function getNavigateToIntents($entityType)
|
||||
{
|
||||
$intents = [];
|
||||
$locations = array_merge(Account::$basicSettings, Account::$advancedSettings);
|
||||
|
||||
foreach ($locations as $location) {
|
||||
$location = str_replace('_', ' ', $location);
|
||||
$intents[] = $this->createIntent('NavigateTo', "go to {$location}", [
|
||||
$location => 'Location',
|
||||
]);
|
||||
$intents[] = $this->createIntent('NavigateTo', "show me {$location}", [
|
||||
$location => 'Location',
|
||||
]);
|
||||
}
|
||||
|
||||
return $intents;
|
||||
}
|
||||
|
||||
private function createIntent($name, $text, $entities)
|
||||
{
|
||||
$intent = new stdClass();
|
||||
$intent->intent = $name;
|
||||
$intent->text = $text;
|
||||
$intent->entities = [];
|
||||
|
||||
foreach ($entities as $value => $entity) {
|
||||
$startPos = strpos($text, (string)$value);
|
||||
if (! $startPos) {
|
||||
dd("Failed to find {$value} in {$text}");
|
||||
}
|
||||
$entityClass = new stdClass();
|
||||
$entityClass->entity = $entity;
|
||||
$entityClass->startPos = $startPos;
|
||||
$entityClass->endPos = $entityClass->startPos + strlen($value) - 1;
|
||||
$intent->entities[] = $entityClass;
|
||||
}
|
||||
|
||||
return $intent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
@ -18,7 +18,6 @@ use Utils;
|
||||
*/
|
||||
class CreateTestData extends Command
|
||||
{
|
||||
//protected $name = 'ninja:create-test-data';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -20,6 +20,7 @@ class Kernel extends ConsoleKernel
|
||||
'App\Console\Commands\CheckData',
|
||||
'App\Console\Commands\PruneData',
|
||||
'App\Console\Commands\CreateTestData',
|
||||
'App\Console\Commands\CreateLuisData',
|
||||
'App\Console\Commands\SendRenewalInvoices',
|
||||
'App\Console\Commands\ChargeRenewalInvoices',
|
||||
'App\Console\Commands\SendReminders',
|
||||
|
Loading…
x
Reference in New Issue
Block a user