How does the trait entity extraction in wit.ai work? - machine-learning

Wit.ai provides an entity of type "trait". Wit.ai defines trait entities as
When the entity value is not inferred from a keyword or specific
phrase in the sentence. There is no obvious association between
certain words in the sentence and the value of the entity, but rather
you need the sentence as a whole to determine the value.
(https://wit.ai/docs/recipes#which-entity-should-i-use)
I'm curious to know how does this work? For example,
I want to know the status
Check the status
How is it going?
I want to extract the entity entities["cmd":"status"] from all of these statements. How do I go on about starting to implement this?

Related

Data model for enum with associated values

I'm trying to figure out what's the recommended way to implement enum with associated values in Core Data data model. Let's say I have a book entity and I want to save in database how I got the book, like:
it's bought by me (or other family members)
it's borrowed from someone (e.g., a colleague)
it's given as a gift by someone (e.g., a friend)
This would be an enum in swift:
enum WhereItCameFrom {
case Bought(who: String, date: Date, where: String)
case Borrorwed(who: String, date: Date, dueDate: Date)
case GivenAsGift(who: String, date: Date, forWhat: String)
}
I'm thinking to implement it in data model using inheritance , as below:
Introduce a parent entity WhereItCameFrom and define the above cases as its children entities.
Define a to-one relationship from Book to WhereItCameFrom. Its deletion rule is Cascade.
Define a to-one relationship from WhereItCameFrom to Book. Its deletion rule is Deny.
See the diagram:
I'm wondering if this this the right way to do it and I have a few specific questions.
1) What's the typical way to implement enum with associated values?
I think my above modal is good. But just in case, are there other better ways to do it?
2) Is entity with no attributes normal?
In above diagram, WhereItCameFrom doesn't have any attributes. At first I added a type attribute to it to indicate if it's a Bought, Borrowed, or GivenAsGift entity. But then I realized this information is implicit in its child entity class type, so I removed it. So the only purpose of the parent entity is to hold the relationship. Is this use typical in Core Data?
3) Will the old object be removed automatically when modifying relationship at run time?
Suppose I modify book.whereItCameFrom relationship value at run time. Its previous value is a Borrowed object. Its new value is a GivenAsGift object. Do I need to delete the Borrowed object manually (I mean, doing that explicitly in application code)?
I guess I should do it. But given Core Data is a framework helping to maintain data consistency in object graph, that seems awkward to me. I wonder if Core Data has some feature that can figure out the Borrowed object is not needed and delete it automatically?
Thanks for any help.
UPDATE:
In the third question, after the old Borrowed object is disconnected with Book object, is my understanding correct that, from the Borrowed object perspective, the peer object has been delete and hence the peer object's Cascade deletion rule is applied to the Borrowed object? If so, then it will be deleted automatically. I think the real question here is if deletion rule applies to relationship update or not. I'll do some experiments on this later today.
A few thoughts...
1) What's the typical way to implement enum with associated values?
I think my above modal is good. But just in case, are there other better ways to do it?
I can't comment on typical ways of implementing enums with associated values, but your model seems to make sense. One word of caution: if you search StackOverflow for questions regarding entity inheritance, you will find several answers advising against using it. The way CD implements subentities (at least for SQLite stores) is to add all the attributes of all the subentities to the parent entity SQLite table. That's handled for you "under the hood" by CoreData, but the SQLite table can potentially end up being very "wide", which can affect performance. I've never found it an issue, but you might want to have that in mind if you have lots of data and/or the entities are more complex than you indicate in the question. Subentities can also cause issues in some rare situations - for example, I've seen questions indicating problems with uniqueness constraints.
2) Is entity with no attributes normal?
It's unusual, but not a problem. However, as all three subentities have date and who attributes, it would be wise to move these from the subentities to the parent WhereItComeFrom entity. (Otherwise, as noted above, your parent entity table will have three columns for date (one for each subentity) and three for who).
3) Will the old object be removed automatically when modifying relationship at run time?
No. If you modify the book.whereItCameFrom relationship value at run time, with a GivenAsGift object replacing a Borrowed object, CD's graph management will ensure that the Borrowed object's book property is set to nil. The cascade rule does not prevent objects being "orphaned" in this way and you must manually delete the Borrowed object.

Data type and approach for Rails attributes with occasional second value

I have a use case where a user clicks on a word and sees information about its base word. Very occasionally there are words with two different but equally accepted spellings with identical meanings, and I'd like to display the alternate spelling when this happens (examples for Spanish: 'video' and 'vídeo', or 'quizá' and 'quizás').
Similarly, there are times where a base_word will need two inflection_forms.
The BaseWord model has attributes for base_word:string, inflection_form:string (i.e., 'ND3XX'), and the language_id. A base_word has_many :inflections to handle related words, but it seems silly to create a new inflection for a differently spelled word with an identical grammatical role.
I tried serializing both of the fields into an Array, and then later as a Set, but in both cases I had trouble querying the database for base_words where base_word was equal to one of the set/array members.
What is the most logical way to handle this case?
Since you are using Postgres you can use it's built in Array type which can be queried using SQL queries. cf http://edgeguides.rubyonrails.org/active_record_postgresql.html#array
Update 1 : Query example
Yes, its not as simple but, assuming you add an inflections column of type array to your migration, you should be able to hide the complexity with something like:
class BaseWord < ActiveRecord::Base
...
scope :has_inflection, -> (word) { where('? = ANY(inflections)', word) }
And then use it like any other scope. For ex.
BaseWord.has_inflection('vídeo').order('base_word').limit(5)

Many values for enum

I have to sort the stores registered in segments. I want to have pre-registered segments for the user to choose, but they are many. It's a good idea to put everyone in an enum? There are over 15.
A Store is a model that have a type, the type is the segment. There is several types. The pre-registered are the several types in enum. I was thinking that the code will be dirty with all types in enum.
It's up to you, really. You'll have people tell you that it's better to manage something like a field that can only have one of several values as an enum, and others would say that the field should be a string and you should validate it on your Segments model.
I'm partial to the latter.

Entity Framework Where Any Column Contains

When writing a where condition on an Entity Framework context object, is there a shorthand way of testing all the columns, sort of like this:
context.tableName.where(t => t.AnyColumn.Contains(...))
Or am I forced to test each column individually?
There is no out-of-the-box way to do that but you can write your own method which will use reflection to get the list of your model's properties and check each of them
I don't know that this is possible you may have to search each field individually, but why not search for a value in a specific column instead of searching the whole table, it reduces the room for error and makes for a quicker query

CoreData Entity Unique Attributes

I am building an app around CoreData and have bumped into a dilemma. Hopefully has a simple solution.
I have an entity, 'Equipment'. Each equipment object has a name and type. When selecting a type depending on the selection, I need to add more attributes to that entity, but only to that object.
So if I have an equipment object of type bowl. I want to add the attribute containsMilk for example. Whereas if the type is knife, I want to add the attribute isBreadKnife.
Any tips on how to do this? As you can see, not every equipment object will necessarily have the same attributes and different types require unique ones.
How can I achieve this? Thanks.

Resources