Working on speech rec

This commit is contained in:
Hillel Coren 2017-04-04 21:08:35 +03:00
parent c4e960a805
commit 4abb5dd2c5
4 changed files with 59 additions and 6 deletions

View File

@ -84,6 +84,17 @@ class BaseIntent
return false; return false;
} }
protected function hasField($field, $value = false)
{
$fieldValue = $this->getField($field);
if ($value) {
return $fieldValue && $fieldValue == $value;
} else {
return $fieldValue ? true : false;
}
}
public function process() public function process()
{ {
throw new Exception(trans('texts.intent_not_supported')); throw new Exception(trans('texts.intent_not_supported'));
@ -154,6 +165,20 @@ class BaseIntent
return $client; return $client;
} }
protected function requestInvoice()
{
$invoiceRepo = app('App\Ninja\Repositories\InvoiceRepository');
$invoice = false;
foreach ($this->data->entities as $param) {
if ($param->type == 'builtin.number') {
return $invoiceRepo->findPhonetically($param->entity);
}
}
return false;
}
protected function requestFields() protected function requestFields()
{ {
$data = []; $data = [];

View File

@ -8,12 +8,18 @@ class CreatePaymentIntent extends BaseIntent
{ {
public function process() public function process()
{ {
$client = $this->requestClient(); $clientPublicId = 0;
$clientPublicId = $client ? $client->public_id : null; $invoicePublicId = 0;
if ($invoice = $this->requestInvoice()) {
$invoicePublicId = $invoice->public_id;
} elseif ($client = $this->requestClient()) {
$clientPublicId = $client->public_id;
}
//$invoiceItems = $this->requestInvoiceItems(); //$invoiceItems = $this->requestInvoiceItems();
$url = '/payments/create/' . $clientPublicId . '?'; $url = sprintf('/payments/create/%s/%s', $clientPublicId, $invoicePublicId);
//$url .= $this->requestFieldsAsString(Invoice::$requestFields); //$url .= $this->requestFieldsAsString(Invoice::$requestFields);
return redirect($url); return redirect($url);

View File

@ -1121,4 +1121,26 @@ class InvoiceRepository extends BaseRepository
$this->save($data, $invoice); $this->save($data, $invoice);
$invoice->load('invoice_items'); $invoice->load('invoice_items');
} }
public function findPhonetically($invoiceNumber)
{
$map = [];
$max = SIMILAR_MIN_THRESHOLD;
$invoiceId = 0;
$invoices = Invoice::scope()->get(['id', 'invoice_number', 'public_id']);
foreach ($invoices as $invoice) {
$map[$invoice->id] = $invoice;
$similar = similar_text($invoiceNumber, $invoice->invoice_number, $percent);
var_dump($similar);
if ($percent > $max) {
$invoiceId = $invoice->id;
$max = $percent;
}
}
return ($invoiceId && isset($map[$invoiceId])) ? $map[$invoiceId] : null;
}
} }

View File

@ -172,11 +172,11 @@
} }
function onMicrophoneClick() { function onMicrophoneClick() {
//$('#search').val('create new invoice for edgar a po number of 1234'); $('#search').val('new payment for invoice 1279');
//$('#search').val('invoice for edgar'); //$('#search').val('invoice for edgar');
//$('#search').val('create a task for edgar'); //$('#search').val('create a task for edgar');
//$('#search-form').submit(); $('#search-form').submit();
//return; return;
$('.fa-microphone').hide(); $('.fa-microphone').hide();
$('#search').val("{{ trans('texts.listening') }}"); $('#search').val("{{ trans('texts.listening') }}");