Skip to content

Tag patterns

David Megginson edited this page Jun 12, 2018 · 4 revisions

You use a Tag pattern to select one or more columns in a HXL dataset. The tag pattern looks a lot like a hashtag, except that it can include attributes beginning with "-" as well as "+":

#country +code -dest  

As with regular attributes, internal whitespace is optional, so "#country+code-dest" and "#country +code -dest" have the same meaning. Order of attributes is not significant.

Wildcards

You can also use a wildcard character (*) for the tag portion to match any hashtag. The attribute rules still apply. Example:

#* +f -children

Absolute tag patterns

A tag pattern may optionally end in "!", in which case it is an absolute pattern. That means that exactly the attributes specified in the pattern must be present, but no other ones. For example

#affected +f +children!

will match "#affected +f +children" or "#affected +children +f" but not "#affected" or "#affected +f +children +refugees". Use absolute tag patterns with care—they may break things when you add new attributes to your dataset in the future (it's usually better to use exclusions).

Matching rules

  1. The hashtag portion of the pattern must always match the hashtag specification unless the pattern uses a wildcard ("#*").
  2. Any attribute beginning with "+" in the pattern must be present in the target hashtag specification (even if the hashtag portion is a wildcard).
  3. Any attribute beginning with "-" in the pattern must not be present in the target hashtag specification (even if the hashtag portion is a wildcard).
  4. Any attribute not included in the pattern may optionally be present in target hashtag specification, unless the pattern is absolute.

Examples

Pattern Description Matching hashtags Non-matching hashtags
#country The core hashtag must be #country, with any or no attributes #country, #country +code #adm1
#country +code The core hashtag must be #country, and at least the +code attribute must be present #country +code, #country +iso3 +code #country, #country +iso3
#country -code The core hashtag must be #country, and the +code attribute must not be present #country, #country +name #country +code, #country +iso3 +code
#country -dest +code The core hashtag must be #country, the +dest attribute must not be present, and the +code attribute must be present #country +code, #country +source +code #country +dest +name, #country +dest +code
* Match any data column #country +code, #affected +f
* +code -source Match any column that has the attribute +code and does not have the attribute +source, regardless of the main hashtag #country+dest+code #country+source+code
#inneed+f+elderly! The core hashtag must be #inneed, and the +f and +elderly attributes (and only those attributes) must be present #inneed +f +elderly, #inneed +elderly +f #inneed, #inneed +f +elderly +idps
Clone this wiki locally