How to setup a complicated 'IsList' parameter in Dialogflow - dialogflow-es

I'm looking at this link:
Actions and parameters | Dialogflow Documentation | Google Cloud
Where it explains 'List parameters' it uses these examples:
"I want apples"
"I want apples and oranges"
"I want apples, oranges, and bananas"
Then I was wondering if it's possible to set up a 'List parameter' to handle something like this:
"I want 7 apples, 8 oranges and 12 bananas"
So you'd have a sort of Key - Value pair list.
Pseudo code:
List<KeyValuePair<string, int>> fruitList = new List<KeyValuePair<string, int>>();
KeyValuePair<string, int> applesItem = new KeyValuePair<string, int>("apples", 7);
KeyValuePair<string, int> orangesItem = new KeyValuePair<string, int>("oranges", 8);
KeyValuePair<string, int> bananasItem = new KeyValuePair<string, int>("bananas", 12);
fruitList.Add(applesItem);
fruitList.Add(orangesItem);
fruitList.Add(bananasItem);
So, in dialogflow, the $FruitList parameter would be something like the Key - Value pair list fruitList above.
The number part should then match with the #sys.cardinal entity. And the fruit part should match to a custom entity #Fruits with a bunch of fruits in it.
Pseudo code: List<KeyValuePair<#sys.cardinal, #Fruits>>
How can I make an 'Intent' in Dialogflow that can do this?
Is it possible?
Help / Advice appreciated.

Im not sure if you could get dialogflow return a key value pair object, but using composite entities you can create an entity which consists of an amount (number) and a fruit (fruit entity). You could call this composite entity order and make that a list in the parameters in your intent. When you enter
"I want 7 apples, 8 oranges and 12 bananas"
You should get a list with 3 order entities ( 7 apples, 8 oranges, 12 bananas)
https://cloud.google.com/dialogflow/docs/entities-developer#developer_composite

Related

In Microsoft Luis, how do I break up one word into multiple entities?

For example, I have user utterance of courses that look like this:
CS101
PHY101
CHE101
How do I get 2 entities from this like: Course Name, Course Number?
So in my example:
Utterance: CS101
Entities:
Course Name: CS
Course Number: 101
Unfortunately as #Zeryth and #Javier mentioned in the comments, Luis currently does not support this. Here is the work around I used based on the comments:
let regex = /([A-Za-z]+)[^a-zA-Z\d:]?(\d{1,3})/g
var match = regex.exec(matchString);
if(match){
ClassName = new Entity({type:"ClassName",entity:match[1],score:1});
ClassNumber = new Entity({type:"ClassNumber",entity:match[2],score:1});
}

Am I designing and constructing my value objects correctly?

Sorry in advance if this question is unclear. Please tell me what to change to make it a better question.
I am currently maintaining a C# WinForm system where I'm trying to learn and use DDD and CQRS principles. Vaughn Vernon's Implementing Domain Driven Design is my main DDD reference literature.
The system currently uses legacy code which makes use of Data Aware Controls.
In the Asset Inventory Context, i have designed my aggregate root Asset which composes of multiple valueObjects which are standard entries in the system:
In this Context, i'm trying to implement a use case where the user can manually register an Asset to the system.
My current implementation is the following:
From Presentation Layer:
Upon loading the RegisterAssetForm.cs it loads the existing standard entry lists of Group, ItemName, etc. through the Data Aware controls, all consisting of data rows with columnsid: int and name: string.
When the user selects the desired ItemName, Group, PropertyLevel, Department, and Category, then clicks save, a command is performed:
RegisterAssetForm.cs
...
AssetInventoryApplicationService _assetInventoryServ;
...
void btnSave_Click(object sender, EventArgs e)
{
int itemNameId = srcItemName.Value // srcItemName is a custom control whose Value = datarow["id"]
int groupId = srcGroup.Value;
string categoryId = srcCategory.Value;
string departmentId = srcDepartment.Value;
string propLvlId = srcPropLevel.Value;
...
RegisterAssetCommand cmd = new RegisterAssetCommand(itemNameId, groupId, categoryId, departmentId, propLvlId);
_assetInventoryServ.RegisterAsset(cmd);
...
}
From Application Layer:
The AssetInventoryApplicationService depends on domain services.
AssetInventoryApplicationService.cs
...
IAssetRepository _assetRepo;
...
public void RegisterAsset(RegisterAssetCommand cmd)
{
...
AssetFactory factory = new AssetFactory();
AssetID newId = _assetRepo.NextId();
Asset asset = factory.CreateAsset(newId, cmd.ItemNameId, cmd.PropertyLevelId,
cmd.GroupId, cmd.CategoryId, cmd.DepartmentId);
_assetRepo.Save(asset);
...
}
From Domain Layer:
AssetFactory.cs //not my final implementation
...
public class AssetFactory
{
...
public Asset CreateAsset(AssetID id, int itemNameId, int propLvlId, int groupId, int categoryId, int departmentId)
{
ItemName itemName = new ItemName(itemNameId);
PropertyLevel propLvl = new PropertyLevel(propLvlNameId);
Group group = new Group(groupNameId);
Category category = new Category(categoryNameId);
Department department = new Department(departmentNameId);
return new Asset(id, itemName, propLvl, group, category, deparment);
}
...
}
Sample table of what fills my value objects
+------------+--------------+
| CategoryID | CategoryName |
+------------+--------------+
| 1 | Category1 |
| 2 | Category2 |
| 3 | Category3 |
| 4 | Category4 |
| 5 | Category5 |
+------------+--------------+
I know domain models must be persistence-ignorant that's why i intend to use surrogate identites (id field) in Layer Supertype with my valueobject to separate the persistence concern from the domain.
The main property to distinguish my value objects is their Name
From the presentation layer, i send the standard entry value as integer id corresponding to primary keys through a command to the application layer which uses domain services.
Problem
* Is it right for me to pass the standard entry's id when creating the command, or should I pass the string name?
* If id is passed, how do i construct the standard entry value object if name is needed?
* If name is passed, do i need to figure out the id from a repository?
* Or am I simply designing my standard entry value objects incorrectly?
Thanks for your help.
It looks to me that you may be confusing a Value Object and an Entity.
The essential difference is that an Entity needs an Id but a VO is a thing (rather than a specific thing). A telephone number in a CRM would likely be a VO. But it would likely be an Entity in if you are a telephone company.
I have an example of VO in this post which you may find helpful - you can get it here
To answer your 'Problems' more specifically:
If you are creating some entity then it can be advantageous to pass in the id to a command. That way you already know what the id will be.
You shouldn't be able to create an invalid value object.
Why can't you pass in the name and the ID? Again - not sure this is relevant to a Value Object
I think you have designed them incorrectly. But I can't be sure because I don't know your specific domain.
Hope this helps!

Creating a group of test objects with AutoMapper

I'm trying to create a repository of data that I can use for testing purposes for an emerging car production and design company.
Beginning Automapper Question:
In this project, I have 2 classes that share the same properties for the most part. I don't need the Id, so I am ignoring that.
My existing code looks like this:
Mapper.CreateMap<RaceCar, ProductionCar>()
.Ignore(d => d.fId) //ignore the ID
.ForMember(d=> d.ShowRoomName,
o=> o.MapFrom(s => s.FactoryName) //different property names but same thing really
//combine into my new test car
var testCarObject = Mapper.Map<RaceCar, ProductionCar>()
My main requirements are:
1) I need to create 100 of these test car objects
2) and that for every ProductionCar I use, it needs to have a corresponding RaceCar which are matched up by the name(ShowRoomName & FactoryName)
So is there a way of sticking this in some type of loop or array so that I can create the needed 100?
Also, is there a way to ensure that each new test car has the combined FactoryCar and RaceCar?
Thanks!
Use AutoMapper with AutoFixture:
var fixture = new Fixture();
var items = Enumerable.Range(1, 100)
.Select(i => fixture.Create<RaceCar>())
.Select(car => new { RaceCar = car, ProductionCar = Mapper.Map<RaceCar, ProductionCar>(car))
.ToList();
items.Profit()

SimpleNLG - Creating a 2 part sentence using "placeholders"

Does anyone know how to (using SimpleNLG) create a proper "two part" sentence like so (I'm not a linguist so I'm not exactly sure what syntactic categories each word/phrase:
"I bought a new widget engine, which created product A, product B, and product C."
The text in bold will be inserted dynamically at runtime by a syntactic parser or something else. I went through the SimpleNLG tutorial (there doesn't seem to be anything else that's more in-depth) and subsequently tried to attach a PPPhraseSpec object (representing the second part of the sentence above) to a SPhraseSpec (which has a nounphrase and verbphrase), but the result is incomprehensible and is grammatically incorrect.
Here is a solution for your problem: the first part in bold is a grammatical object (a noun phrase) and the second part in bold is an object to the verb "create" (coordinate clause).
import simplenlg.realiser.english.Realiser;
import simplenlg.lexicon.Lexicon;
import simplenlg.phrasespec.*;
import simplenlg.framework.*;
import simplenlg.features.*;
public class Test {
// Target:
// I bought a new widget engine,
// which created product A, product B, and product C.
public static void main(String[] args) {
System.out.println("Starting...");
Lexicon lexicon = Lexicon.getDefaultLexicon();
NLGFactory nlgFactory = new NLGFactory(lexicon);
Realiser realiser = new Realiser(lexicon);
SPhraseSpec s1 = nlgFactory.createClause("I",
"bought", "a new widget engine");
s1.setFeature(Feature.TENSE, Tense.PAST);
SPhraseSpec s2 = nlgFactory.createClause("", "created");
NPPhraseSpec object1 = nlgFactory.createNounPhrase("product A");
NPPhraseSpec object2 = nlgFactory.createNounPhrase("product B");
NPPhraseSpec object3 = nlgFactory.createNounPhrase("product C");
CoordinatedPhraseElement cc = nlgFactory.createCoordinatedPhrase();
cc.addCoordinate(object1);
cc.addCoordinate(object2);
cc.addCoordinate(object3);
s2.setObject(cc);
s2.setFeature(Feature.TENSE, Tense.PAST);
s2.setFeature(Feature.COMPLEMENTISER, ", which"); // non-restrictive?
s1.addComplement(s2);
String output = realiser.realiseSentence(s1);
System.out.println(output);
}
}
I am not a native English speaker and often get this part wrong, but I think you want a restrictive relative clause instead of a non-restrictive one: "I bought a new widget engine that created..." instead of "I bought a new widget engine, which created ..." If that is the case, just comment the line setting the complementiser.

Key Value in combobox lwuit?

I want to store and retrieve a key value associated with the comboBox. I have used only
getSelectedIndex() and getSelectedItem(). This will not help my purpose as I have to get a unique key value assocaiated with the item.
Example Scenario :
India - 10, China - 15, Russia - 18. Here if 'India' is the comboBox item then '10' is its key. Likewise, 15 for china and 18 for Russia.
When India is selected I need to get the value as 10, if china 15, if Russia 18.
How can I achieve this in Lwuit 1.5. could you guys guide me to do this.
I think that you must map the values with the items in the ComboBox.
You can do this in some different ways.
You can do it with a Hashtable for example. You will need to make the proper castings to get the value in the data type what you want.
ComboBox combo;
//Here create the hash
Hashtable h = new Hashtable();
h.put("India", "10");
h.put("China", "15");
h.put("Russia", "18");
//create the combo
Vector v = new Vector();
v.addElement("India");
v.addElement("China");
v.addElement("Russia");
combo = new ComboBox(v);
combo.addActionListerner(new ActionListener ae){
public void actionPerformed(ActionEvent ae){
String selected = (String) combo.getSelectedItem();
//get the value
String value = (String) h.get(selected);
}
});

Resources