Wit.ai How to Get an whole sentence in an entity - wit.ai

I would like to store an entire sentence an user said and store it.
This his how I did but I can't get the sentence from A to Z an an whole entity, just few parts knows as "number", "location", ....
merge(request) {
return new Promise(function(resolve, reject) {
var entities = request.entities;
var context = request.context;
var message = request.message;
var sessionId = request.sessionId;
var intent = firstEntityValue(entities, 'intent');
if (intent == "write_free_text") {
context.free_text = request["text"];
}
if (intent == "choose_city") {
var city = firstEntityValue(entities, 'location');
context.city = city;
}
return resolve(context);
});
}
How can I do that and store the whole sentence with merge function ? Thank you

If you want the whole sentence, maybe you don't needs a entity, just get the message sent:
// Merge action
function merge(request) {
context.freetext = request["text"];
return context;
}
Bot: https://wit.ai/Godoy/bottest/stories/4da2840f-513e-42ed-a494-c5516c07242e
Fiddle with code: https://wit-ai.github.io/witty-fiddle/?id=e4c16a624c87d37f9c0c29d8299ca5fc

if you want to get the whole phrase, use the wit/phrase_to_translate built-in entity

a snapshot of the uunderstanding tab
you just have to train the bot, once or twice.
It will pick up all the free text later.

Related

ASP.NET Core Linq Compare Id and Sum value

I have a problem and unfortunately can not find the solution!
This is my database:
enter image description here
and I would like to store all PaymentSum(double) [PaymentInformation] in the Total (double) [Document].
This is the SQL statement:
Select SUM(PaymentSum)
from PaymentInformations
where DocumentId = 1;
I have tried this, but without success:
// POST: api/PaymentInformations
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost("new/{eId}")]
public async Task<ActionResult<PaymentInformation>> PostpaymentInformations(long eId, PaymentInformation paymentInformation)
{
Document document = await _context.Documents.FindAsync(eId);
document.Total = _context.PaymentInformations
.Where(b => b.Document.Id == eId)
.Sum(a => a.PaymentSum);
//document.Total = _context.PaymentInformations.FromSqlRaw("Select SUM(PaymentSum) from PaymentInformations where DocumentId = {0}",eId).FirstOrDefault();
foreach (var item in _context.PaymentInformations)
{
System.Console.WriteLine(item.PaymentSum);
System.Console.WriteLine(item.DocumentId);
}
_context.PaymentInformations.Add(paymentInformation);
document.addPaymentInformation(paymentInformation);
await _context.SaveChangesAsync();
return CreatedAtAction("GetpaymentInformations", new { id = paymentInformation.Id }, paymentInformation);
}
I hope someone can help me.
Thank you!!
It looks like you are setting document.Total correctly, are you perhaps overriding the Total value when you call document.addPaymentInformation(paymentInformation) further down?
I set an breakpoint and it has shown that the id matches
enter image description here
transfer without success
enter image description here
public void addPaymentInformation(PaymentInformation paymentInformation)
{
if (PaymentInformations == null)
{
PaymentInformations = new List<PaymentInformation>();
}
paymentInformation.Document = this;
PaymentInformations.Add(paymentInformation);
}

Podio .NET View.Items always returns zero

Using the Podio.NET library (Podio.Async), I am trying to get a Podio View object using the ViewService.GetView() method. The Podio View object represents a predefined view, or set of filters, within a Podio Application.
One of the properties of the Podio View object (PodioAPI.Models.View) is the Items property, as in var noOfItems = myView.Items. However, this field always seems to return zero for me.
I guess that I can make a call to ItemService.FilterItemsByView() using the view-id, which in turn returns a PodioCollection<Item> object that has a FilteredItems property that can be used to get the number of items, but this would mean an additional call.
Does anyone have any thoughts or information that may help me?
Thanks for taking the time to read my question, and I hope that you can help, or others find this helpful.
Kaine
Example code
class Program
{
const string CLIENT_ID = "[Your Client Id]";
const string CLIENT_SECRET = "[Your Client Secret]";
const int APP_ID = [Your App Id];
const string APP_TOKEN = "[Your App Token]";
const string VIEW_NAME = "[Your View Id]";
static void Main(string[] args)
{
Task.Run(async () => { await Go(); }).GetAwaiter().GetResult();
Console.ReadKey();
}
static async Task Go()
{
var client = await GetClient();
var views = await GetViews(client);
var view = await GetView(client);
var viewItems = await GetViewItems(client, view);
}
static async Task<View> GetView(Podio client)
{
var view = await client.ViewService.GetView(APP_ID, VIEW_NAME);
Console.WriteLine("View Name: {0}, Id: {1}, Items: {2}",view.Name, view.ViewId, view.Items);
return view;
}
static async Task<List<View>> GetViews(Podio client)
{
var views = await client.ViewService.GetViews(APP_ID);
Console.WriteLine("Views: " + views.Count);
foreach (var view in views)
{
Console.WriteLine(" - ({0}) {1}", view.ViewId, view.Name);
}
return views;
}
static async Task<List<Item>> GetViewItems(Podio client, View view)
{
Console.WriteLine("View Items: " + view.Items); // This always return 0
var itemList = new List<Item>();
var itemsRemaining = true;
var offset = 0;
while (itemsRemaining)
{
var colItems = await client.ItemService.FilterItemsByView(appId: APP_ID, viewId: Int32.Parse(view.ViewId), offset: offset);
Console.WriteLine(" Downloaded: {0} to {1}", offset, offset + colItems.Items.Count());
itemList.AddRange(colItems.Items);
offset += colItems.Items.Count();
if (offset >= colItems.Filtered)
{
itemsRemaining = false;
break;
}
}
Console.WriteLine("Total View Items Downloaded: " + itemList.Count);
return itemList;
}
static async Task<Podio> GetClient()
{
var client = new Podio(CLIENT_ID, CLIENT_SECRET);
var auth = await client.AuthenticateWithApp(APP_ID, APP_TOKEN);
Console.WriteLine("Auth expires in: " + auth.ExpiresIn);
return client;
}
}
There are 2 similar methods:
Get Views: https://developers.podio.com/doc/views/get-views-27460
This method is returning items for each view returned
"items": The number of items matching the view
Get View: https://developers.podio.com/doc/views/get-view-27450
This method is not returning items parameter, but you can still get that from groupings param (if there is any grouping). Otherwise - number of items in view is not returned.
"groupings": individual groups data, if grouping is present, otherwise {}
{
"total": total count of items in all groups,
"groups": [{
"count": items count of the single group,
In case if there are no groupings you'll have to call https://developers.podio.com/doc/items/filter-items-by-view-4540284. And then use filtered response value.
"filtered": Total number of items matching the filter,
If you only need number of filtered items - please add limit=1 parameter to your request.

breeze.js not honoring the "noTracking" option when end point returns multiple result sets

Consider this breze query:
return EntityQuery.from('myAPI')
.noTracking(true)
.using(manager).execute()
.then(querySucceeded)
.fail(queryFailed);
My API is defined like this:
[HttpGet]
public object myAPI()
{
// var userId = get the users id from auth ticket
var userPref = _contextProvider.Context.UserPreferences.Where(u => u.userId == userId);
var userOptions = _contextProvider.Context.UserOptions.Where(u => u.userId == userId);
return new
{
userPref,
userOptions
};
}
I know I can get access to the raw data, which is great. But in addition to this, the entities are created in the entity manager, which I would prefer they not be. This works fine for apis that return IQueryable. Is there a different syntax for noTracking for web apis that returns multiple result sets?
thanks
I can't reproduce the error you describe. I have a similar DocCode test that passes which references Breeze v1.5.3.
Here is the pertinent NorthwindController method:
[HttpGet]
public object Lookups()
{
var regions = _repository.Regions;
var territories = _repository.Territories;
var categories = _repository.Categories;
var lookups = new { regions, territories, categories };
return lookups;
}
And here's the passing QUnit test:
asyncTest('object query (e.g., lookups) w/ "no tracking" does not add to cache', function () {
expect(2);
var em = newNorthwindEm();
EntityQuery.from('Lookups')
.noTracking(true)
.using(em).execute()
.then(success).fail(handleFail).fin(start);
function success(data) {
var lookups = data.results[0];
var hasLookups = lookups &&
lookups.categories && lookups.regions && lookups.territories;
ok(hasLookups, 'Expected a lookups object w/ categories, regions and territories');
var cached = em.getEntities();
var len = cached.length;
equal(0, len, 'Expected ZERO cached entities of any kind and got ' + len);
}
});
If I comment out the noTracking(true) clause, the test fails and tells me that there are 65 entities in cache ... as predicted.
What am I missing?

MS Dynamics CRM. Get users who current record shared with

I have a entity record which is shared with or more users. I would like to unshare this record when Deactivate it. I want to do that in Plugin. But I can't understand how to get all users from sharing list who have access to this record. How to do that?
Here is my code snippet:
protected void ExecutePostPersonSetStateDynamicEntity(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
var context = localContext.PluginExecutionContext;
var targetEntity = (Entity)context.InputParameters["EntityMoniker"];
var state = (OptionSetValue)context.InputParameters["State"];
var columns = new ColumnSet(new[] { "statecode" });
var retrivedEntity = localContext.OrganizationService.Retrieve(targetEntity.LogicalName, targetEntity.Id, columns);
if (state.Value == 1)
{
RevokeAccessRequest revokeRequest = new RevokeAccessRequest()
{
Target = new EntityReference(personEntity.LogicalName, personEntity.Id),
Revokee = new EntityReference(neededEntity.LogicalName, needed.Id)
};
// Execute the request.
}
}
As you can see, I need an entity "neededEntity", I don't know how to get it from "targetEntity" or "retrievedEntity".
You need to use a RetrieveSharedPrincipalsAndAccessRequest
http://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.retrievesharedprincipalsandaccessrequest.aspx
You can start from the included example, basically inside the foreach you call your RevokeAcessRequest

Calling 2 httpwebrequests in parallel using Reactive Extensions

i m trying to call 2 httpwebrequest in parallel and make them call the same callback when they are done using Rx extensions.
But i don0t know how i can achive this..here's my code:
private static IObservable<Stream> GetImage(string path)
{
var uri = new Uri(path);
var thumburi = new Uri(path + "_thumb.jpg");
return Observable.Create<Stream>(o =>
{
var request = (HttpWebRequest) HttpWebRequest.Create(uri);
var readComplete =
Observable.FromAsyncPattern<WebResponse>(
request.BeginGetResponse,
request.EndGetResponse)();
var subscription = readComplete
.Select(e => e.GetResponseStream())
.Subscribe(o);
return subscription;
});
}
With the latest bits and .Net 4.5, you could do something like this:
private static IObservable<byte[]> GetImages(string path)
{
var sources = new Uri[]
{
var uri = new Uri(path),
var thumburi = new Uri(path + "_thumb.jpg")
};
var obs = from uri in sources.ToObservable()
from data in Observable.Using(
() => new WebClient(),
client => client.DownloadDataTaskAsync(uri).ToObservable())
select data;
return obs;
}
I do wonder if you really want to just return steams of data and not care which stream corresponds to the base and which is the thumbnail. Once you make the request in parallel, you no longer control the order that they come back in. You could project a type that includes the uri and data stream to disambiguate them if you want.
I'm guessing you would pull out the asynchronous calls to two separate streams then concatenate them, no? Like this: http://leecampbell.blogspot.com/2010/06/rx-part-5-combining-multiple.html
I'd suggest this kind of solution.
Make GetImage more general purpose:
private static IObservable<Stream> GetImage(Uri uri)
{
return Observable.Create<Stream>(o =>
{
var request = (HttpWebRequest)HttpWebRequest.Create(uri);
var readComplete =
Observable.FromAsyncPattern<WebResponse>(
request.BeginGetResponse,
request.EndGetResponse)();
var subscription =
readComplete
.Select(e => e.GetResponseStream())
.Subscribe(o);
return subscription;
});
}
Then add a specific GetImages method that does the querying for the image and its thumb:
private static IObservable<Tuple<Uri, Stream>> GetImages(string path)
{
var uris = new []
{
new Uri(path + ".jpg"),
new Uri(path + "_thumb.jpg"),
}.ToObservable();
return
from uri in uris
from stream in GetImage(uri)
select Tuple.Create(uri, stream);
}
I've assumed that your path variable cannot contain the ".jpg" extension otherwise you'd have had to done some string manipulation.
Now GetImages returns a IObservable<Tuple<Uri, Stream>> because the SelectMany doesn't guarantee the return order of the streams so we need to use the Uri to disambiguate the streams.
Let me know if this works for you.
Why not just use Zip?
GetStream("foo.jpg").Zip(GetStream("bar.jpg"), (foo, bar) => new { foo, bar })
.Subscribe(fooAndBar => ...);