bots - Add label to an intent of a composite entity in LUIS via LUIS API using c# -
i figured out how add label intent, not sure how can composite entities. here code working fine non-composite entities;
public static void addlabels(string originalmessage, string intent, list<label> labels) { var client = new httpclient(); var querystring = httputility.parsequerystring(string.empty); var uri = "https://westus.api.cognitive.microsoft.com/luis/v1.0/prog/apps/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/example?" + querystring; // request headers client.defaultrequestheaders.add("ocp-apim-subscription-key", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); httpresponsemessage response; string body = string.empty; string entitylabels = string.empty; //get position of labels foreach (var label in labels) { entitylabels += label.tostring() + ","; } //remove last "," entitylabels = entitylabels.remove(entitylabels.length - 1, 1); body = string.format("{{\"exampletext\": \"{0}\", \"selectedintentname\": \"{1}\", \"entitylabels\": [", originalmessage, intent); body += entitylabels + "]}"; byte[] bytedata = encoding.utf8.getbytes(body); using (var content = new bytearraycontent(bytedata)) { content.headers.contenttype = new mediatypeheadervalue("application/json"); try { response = client.postasync(uri, content).result; }catch(exception ex) { } } }
any appreciated.
i found answer, need add 1 more label in list of labels composite entity name , pass list of labels above method , automatically resolves relationship you.
for example; if contact composite entity , contact.firstname , contact.lastname child entities.
so in below example scenario; original message : want create sam smith new contact. word marked label: sam intent label : contact.firstname word marked label: smith intent label : contact.lastname now, parent contact, use statement needs marked : create sam smith new contact label intent : contact wrap both firstname , lastname within contact composite entity.
Comments
Post a Comment