mapbox gl setFilter filter by indexOf, contains, or substring - mapbox

I want to use setFilter expression to filter by substring for a given feature property inside a tileset. Note: I do NOT want to have to load an array of features external to the tileset, I want it to use setFilter only, not getFeatures functions and no looping. If user begins typing, "smith .." it would filter out features as they typed using setFilter only.
I only see "==" or "match" but neither do case insensitive substring filtering, such as indexOf, contains, Like, etc. Something like ['contains', feature.prop, 'smi'] then ['contains', feature.prop, 'smith'], for example.
I see the example on mapbox examples, for filtering as you type, but I want to only use setFilter. It doesn't look like it supports what I want to do, but I thought I'd ask anyway. It is a waste of client-side resources to have to populate any local array of features from the tileset. It defeats the purpose of putting the data inside a tileset to begin with.
Any standard expression for parsing a feature property by a partial string, not an exact match?

As you have noticed, Mapbox-GL expressions don't support substrings or regexes. So I think the only workaround is along the lines you mentioned: getting a list of attribute values and using that as an autocomplete.
There are two ways to get that list of attribute values that don't require making separate, arguably redundant, queries.
Use the values within the TileJSON. Depending how the TileJSON is generated, it often contains a list of the most common values for each attribute (up to 1000 or so, I think).
Use querySourceFeatures() to fetch all features within the current viewport, then filter down to find the values of the attribute you care about. This won't help if the user wants to filter towards something which is currently outside the viewport.

Now mapbox support to filter for tyle layer for sub string from string
expression code is
['in', {filter-substring-value}, ['string', ['get', {mapbox-property-field-string}]]]

Related

More advanced filtering system (LHS brackets | RHS colon) in FastAPI

Is it possible to create a filtering system in FastAPI like:
?something[lte]=120&something2[in]=12,34
or
?something=lte:120&something2=in:12,34
And how to make OpenAPI documentation for it?
Imagine if there are many such endpoints and even more fields? I do not want to describe a set of fields with the same type of Depends classes with a certain logic parse (I don't know how to dynamically pass type annotating for it).
It is also not possible to subclass fastapi.Query and add extra logic to it.
Also there was an idea in the implementation of the f key as a query parameter:
?f=<field_name>:<operator>:<value>&f=<field_name N>:<operator>:<value>
But in this case, the documentation is not complete and you have to fill it in description (it will also be the same for all endpoints). As a result, it will not be clear which fields can be filtered and which operators are used for them.

mapbox gl setFilter by feature property that is an array

I have a feature property that is an array of ids:
feature.properties.ownerTypeIds: [1,2,3]
I have a form. In it it has a multi-select for Owner Types that produces an array: [1,2]
What is the mapbox gl latest version expression to compare a feature's array to an array of values? Match doesn't appear to support a feature property that is an array.
If ANY id in the feature's array is also in the selected choices array, I want it set to true. So that when it gets combined with many other filters inside an "all", it will work. The all works with many other filters, I just need help with the ownerTypeIds array scenario presented here.
Any value the user selects, is it inside the feature's ownerTypeIds array?
I'd appreciate any help. The mapbox expressions documentation doesn't appear to support feature properties that are an array. I hope I'm wrong in that assessment!
Appreciate you!
Thanks,
Donnie
From mapbox support ...
Hi Donnie,
Thanks for contacting Mapbox Support.
You are correct; only simple types are supported in Feature's properties.
With that said, you cannot compare the two lists at runtime using the style spec.
For your information, there is a publicly tracked issue here.
https://github.com/mapbox/mapbox-gl-js/issues/2434
One workaround would be to create a new property that computes whether an element in one array also exists in another array and sets a true/false value.
Then that boolean value can be used to compare in your filters.
Let me know if you still have any questions
Regards,

IBM Watson Assistant: Regular expressions with context variables

I am gathering some context variables with slots, and they work just fine.
So I decided to do in another node of the conversation, check if one of these context variables is a specific number:
I was thinking on enabling multi-responses and check if, for example $dni:1 (it is an integer, pattern of 1 integer only), or if it is 2 or 3:
But this is not working. I was trying to solve it for some days with different approaches but I really cannot find a way through it.
My guess is that a context variable has a value, and you can print it to use it like responding with the user's name and stuff like that (which indeed is useful!), but comparing values is not possible.
Any insights on this I can receive?
Watson Assistant uses a short-hand syntax but also supports the more complex expressions. What you could do is to edit the condition in the JSON editor. There, for the condition, use a function like matches() on the value of the context variable.
Note that it is not recommended to check for context variables in the slot conditions. You can use multi-responses. An alternative way is to put the check into the response itself. There, you can use predicates to generate the answer.
<? context.dni==1 ? 'Very well' : 'Your number is not 1' ?>
You can nest the evaluation to have three different answers. Another way is to build an array of responses and use dni as key.
Instead of matching to specific integers, you could consider using the Numbers system entity. Watson Assistant supports several languages. As a benefit, users could answer "the first one", "the 2nd option", etc., and the bot still would understand and your logic could still route to the correct answer.

Regular Expressions (HTML parsing on iPhone)

I am trying to pull data from a website using objective-c. This is all very new to me, so I've done some research. What I know now is that I need to use xpath, and I have another wrapper for that called hpple for the iPhone. I've got it up and running in my project.
I am confused about the way I retrieve information from the site. Apparently I am to use regular expressions in this line of code:
NSArray * a = [doc search:#"//a[#class='sponsor']"];
This is just an example. Is that stuff in the search:#"...." the regular expression? If so, I guess I can develop the hundreds of patterns that I will need for my program to parse the site (I need a lot of data), but is there a better way? I'm very lost in this. Any help is appreciated.
The parameter is an XPath, not a regular expression. Here's a breakdown:
All xpaths are interpreted relative to a context node. In this case, it's the root node.
// is an abbreviation meaning "all descendents"
a means "all child nodes with a node type of 'a'" (in HTML, that's anchors)
[...] contains a predicate, refining just which a to match
# is an abbreviation for attribute nodes
#class means an attribute named "class"
#class='sponsor' means a class attribute equal to "sponsor". Note this will not match nodes with a class containing "sponsor", such as <a class="big sponsor" ...>; the class must be equal.
All together, we have "'a' nodes descending from the root that have class equal to 'sponsor'".
That is an XPath expression, not a regular expression. The W3C has an XPath reference here: http://www.w3.org/TR/xpath/. Basically you are searching for <a> elements with the class "sponsor".
Note that this is a good thing! Regular expressions are bad for parsing HTML.

Using YAML tags to denote types

I don't quite understand how to use application specific YAML tags, and maybe its because my desired use of them is purely wrong. I am using YAML for a configuration file and was hoping to use tags to provide my configuration loader with a hint as to what datatype it should parse the data into - application specific datatypes.
I'm also using libyaml with C.
So I'm trying to do something like...
shapes:
square: "0,4,8,16"
circle: "5,10"
In my app I'd like to use tags as hints so I can load the values of square into my square data structure, and the values of circle into my circle data structure (these values mean nothing in this example).
So I'm currently doing:
shapes:
square: !square "0,4,8,16"
circle: !circle "5,10"
Libyaml will provide a tag of "!square" when I'm passed the scalar "0,4,8,16". Is it valid to use this tag to provide my loader with a hint of how to process the scalar?
Since it does work for me, I'm more curious to know if its proper. And if not, how would I go about making this more proper.
Thanks.
I know that this is an ancient question, but anyway I've seen !int, etc being used in yaml files before so I went to look up the specs at Yaml 1.2 Spec # Tags
application specific tag: !something |
The semantics of the tag
above may be different for
different documents.
As per the document, it does look like your intended usage of tags is correct for application specific tag.