Can we use a regex in the synonyms for LUIS list model? - azure-language-understanding

I want to use a list model. Can I use the regex in the synonym list? For example:
{'canonicalForm': 'cat',
'list': ['kitty',
'c*']}
I want my model to return "cat" for "kitty", "cccccc", "chiuoiu", and any other string starting with "c".

Related

Linq C# query for combining multiple ARRAY_CONTAINS into a list

A field with name 'Field' is checked against multiple values, right now am doing something as shown below:
ARRAY_CONTAINS(Field, "Value1")) OR
ARRAY_CONTAINS(Field, "Value2")) OR
ARRAY_CONTAINS(Field, "Value3"))
Instead is there a Linq query equivalent to just do something like Field.Contains("Value1", "Value2", "Value3"). If one exists, how is it written as Linq expression. Thanks!
You could use Enumerable.Intersect for the purpose.
if(sourceArray.Intersect(elementsToSearch).Any())
{
}
Where elementsToSearch to search are collection of values you want to compare against.

Convert String to linq condition Entity Framework core

I have a Combobox with different conditions like "=", ">=", "<=" ... and dates.
I would like to use the conditions in strings to compare dates. It's possible to convert the operators in string format to logical operators to compare dates on linq query to Oracle Database?
I need dynamic conditions based on strings like "=", ">=" ...
You cannot compare a DateTime variable with a String variable.
So you need to create a DateTime. May design pattern can help a bit for your special case like Factory Pattern ;)
Look at
DbTransectionFunctions
Here is a sample codes
var entity = dbContext.MyTable
.Where(w => DbFunctions.TruncateTime(w.SavedDateOnDb) == model.SelectedDate)
.First();
Another sample like this after ef6 :)
var list = db.MyClass.Where(c=> DbFunctions.TruncateTime(c.DbrecordDate)
> DbFunctions.TruncateTime(DateTime.UtcNow));

How to search records with a string which contains some characters of the target field string in Odoo v10?

I am using Odoo v10. While scanning a barcode, a string contains some characters of a char field value. For example,
A field value ('tracknum') = "20171103"
Search the field by entering a string "xxxxxx20171103" or "xxxx20171103yyy"
is there any way to do it?
I have modified the search view :
<field name="tracknum" string="Tracknum" filter_domain="..."/>
How to dig out related records?
You can create an auxiliar computed field like this
custom_name = fields.Char(
string='Custom',
compute='_compute_custom_name',
search='_search_custom_name'
)
#api.multi
#api.depends()
def _compute_custom_name(self):
''' The field has to be a computed field
You do not need to do anything here
'''
pass
def _search_custom_name(self, operator, value):
''' Actually this converts a domain into another one.
With this new domain Odoo can search well
Arguments:
* operator: if you are searchig words it is going to be ilike
* value: the string ro search
The method could return something like this
* [('id', 'in', id_list)]
'''
all_records = self.search([]) # recordset with all the values of the current model
ids = []
if operator == 'ilike':
ids = all_records.filtered(lambda r: r.tracknum in value).mapped('id')
return [('id', 'in', ids)]
Then you can add this field to the search view like this:
<field name="custom_name" string="Tracking Number" />
Keep in mind that it is not a stored field, so it is going to be very inefficient. And you should iterate over all the values each time you want to make a search.
Once you have added the field to the search view it shoul look like this, Tracking Number should appear in the field name

Sphinx search infix and exact words in different fields

I'm using sphinx as search engine and I need to be able to do a search in different fields but using infix for one of the fields and exact word matches for another.
Simple example:
My source has for field_1 the value "abcdef" and for field_2 the value "12345", what I need to accomplish is to be able to search by infix in field_1 and exact word in field_2. So a search like "cde 12345" would return the doc I mentioned.
Before when using sphinx v2.0.4 I was able to obtain these results just by defining infix_fields/prefix_fields on my index but now that I'm using v2.2.9 with the new dict=keywords mode and infix_fields are deprecated.
My index definition:
index my_index : my_base_index
{
source = my_src
path = /path/to/my_index
min_word_len = 1
min_infix_len = 3
}
I've tried so far to use extended query syntax in the following way:
$cl = new SphinxClient();
$q = (#(field_1) *cde* *12345*) | (#(field_2) cde 12345)
$result = $cl->Query($q, 'my_index');
This doesn't work because for each field, sphinx is doing an AND search and one of the words is not in the specified field, "12345" is not a match on field_1 and "cde" is not a match in field_2. Also I don't want to do an OR search, but need the both words to match.
Is there a way to accomplish what I need?
Its a bit tricky, but can do
$q = "((#field_1 *cde*) | (#field_2 cde)) ((#field_1 *12345*) | (#field_2 12345))"
(dont need the brackets around the field name in the #syntax - if just one field, so removed them for brevity)

How can I store a hash in my database?

Is there a Ruby, or Activerecord method that can write and read a hash to and from a database field?
I need to write a web utility to accept POST data and save it to a database, then later on pull it from the database in its original hash form. But ideally without 'knowing' what the structure is. In other words, my data store needs to be independent of any particular set of hash keys.
For example, one time the external app might POST to my app:
"user" => "Bill",
"city" => "New York"
But another time the external app might POST to my app:
"company" => "Foo Inc",
"telephone" => "555-5555"
So my utility needs to save an arbitrary hash to a text field in the database, then, later, recreate the hash from what was saved.
Rails 4 adds support for the Postgres hstore data type which will let you add hashes directly into your (postgres) database.
If you are using Rails 4 and Postgres, you can use hstore in your migration:
def up
execute "create extension hstore"
add_column :table, :column, :hstore
end
def down
remove_column :table, :column
end
That execute command will enable hstore in Postgres, so you only have to do that once.
This will enable you to store a hash in :column just like you would any other data type.
There are two ways to do this:
Serialize your hash and store it in a text field.
Split the hash and store each key in a separate row.
The problem with the first approach is that finding and manipulating is difficult and expensive. For example, prefix a "0" before the telephone number of all employees working in Foo Inc. will be a nightmare, compared to storing the data in regular tabular format.
Your schema would be:
employees (id, created_at, updated_at)
employee_details (id, employee_id, key, value)
So, to store
"company" => "Foo Inc",
"telephone" => "555-5555"
you would do:
employees: 1, 2012-01-01, 2012-01-01
employee_details (1, 1, "company", "Foo Inc"), (2, 1, "telephone", "555-5555")
Drawbacks of this approach: Rails does not natively support such kind of a schema.
You can use serialization with 3 options: Marshal in binary format, YAML and JSON human-readable formats of data store.
Once you are trying each of methods, do not forget to measure time to serialize and deserialize as well. If you need to pull data back in origin format, JSON is the good choice to use, because you don't need to deserialize it, but use it as a string itself.
You're looking for serialization. It will help you to do exactly what you want.
Rails 4 has a new feature called Store, so you can easily use it to solve your problem. You can define an accessor for it and it is recommended you declare the database column used for the serialized store as a text, so there's plenty of room. The original example:
class User < ActiveRecord::Base
store :settings, accessors: [ :color, :homepage ], coder: JSON
end
u = User.new(color: 'black', homepage: '37signals.com')
u.color # Accessor stored attribute
u.settings[:country] = 'Denmark' # Any attribute, even if not specified with an accessor
# There is no difference between strings and symbols for accessing custom attributes
u.settings[:country] # => 'Denmark'
u.settings['country'] # => 'Denmark'

Resources