Constants (constant variables) in ALFA - authorization

The OASIS Working Draft 01 for ALFA (alfa-for-xacml-v1.0-wd01) of 10 March 2015 says about constant values
3.15 Constant Values
Constant values can appear in the policy expressions. ALFA supports constants of type strings, integers,
doubles and Booleans directly. Strings are quoted with single or
double quotes. Integers consist of a number and optionally a minus
sign. Double consists of a number with a decimal dot and optionally a
minus sign. Booleans consist of the value true and false, without
quotes. Other datatypes are represented using a string followed by a
colon and the name of the datatype..
What that means is, you can use constant values like in that example (while report is the constant value):
target clause requestedType == "report"
But the thing is, once the ALFA files grow and you have written the constant value report all over, you might want to change the constant value into let's say my.company.attributes.medicalReport. In order to do that you have to find and replace all occurrences of the constant value.
Therefore (for the sake of avoiding redundancy) constants have been invented in other languages, where you define smth. like
const string REPORT_TYPE = "my.company.attributes.medicalReport"
or even more performant:
const integer REPORT_TYPE_ID = 3
or even more elegant:
const enum SUBJECT_TYPES { PATIENT, USER, EXAM, REPORT }
With those constants being defined I could write my target like:
target clause requestedType == REPORT_TYPE_ID
Does ALFA support constants or is there a way to "emulate" them (maybe a function that returns the desired value)?

Not yet! It is definitely a feature we want to have. We've had similar requests so stay tuned.

Related

The set of atomic irrational numbers used to express the character table and corresponding (unitary) representations

I want to calculate the irrational number, expressed by the following formula in gap:
3^(1/7). I've read through the related description here, but still can't figure out the trick. Will numbers like this appear in the computation of the character table and corresponding (unitary) representations?
P.S. Basically, I want to figure out the following question: For the computation of the character table and corresponding (unitary) representations, what is the minimum complete set of atomic irrational numbers used to express the results?
Regards,
HZ
You can't do that with GAP's standard cyclotomic numbers, as seventh roots of 3 are not cyclotomic. Indeed, suppose $r$ is such a root, i.e. a rot of the polynomial $f = x^7-3 \in \mathbb{Q}[x]$. Then $r$ is cyclotomic if and only if the field extension \mathbb{Q}[x] is a subfield of a cyclotomic field. By Kronecker-Weber this is equivalent to that field being an abelian extension, i.e., the Galois group is abelian. One can check that this is not the case here (the Galois group is a semidirect product of C_7 with C_6).
So, $r$ is not cyclotomic.

How do I design a validation rule for a Microsoft Access field that restricts input to characters from specific Unicode ranges?

Suppose I needed to restrict a field to 1 character from the Hangul Jamo Extended-A range (U+A960–U+A97f), how would I compare the code of the character against the range? My validation fails for characters in that range as it’s written:
Len([C])=1 And AscW([C]) Between 43360 And 43391
Though this non-working example looks simple, I may have to replace [C] with more complex expressions, and so the simplicity of AscW with the Between operator is handy to avoid repeating [C].
AscW returns signed 16-bit integers, so the Between expression will always return False since the integers being compared are out of that type’s range (-32,768 to 32,767). Use the two’s complement of any values greater than 32,767. In your case, 43360 becomes -22176 and 43391 becomes -22145.
Len([C])=1 And AscW([C]) Between -22176 And -22145
When [C] = "ꥼ", AscW([C]) will return -22148 which will cause the entire expression to evaluate to True.
There's no need to use character numbers when creating a field validation rule. Just test if the character is within the desired range by specifying the upper and lower limit:
Len([C])=1 And [C] Between "ꥠ" And "ꥼ"
Note that this uses the database sort order, so you want to make sure that's set to an appropriate sort order and not General (legacy) which can cause issues with unicode characters.

Call for global variable in JS block of Selenium Webdriver test (Python)

I have a string of numbers set by user. Defined in the beginning of the Webdriver test:
numbers = input("prompt")
Then I need to enter value of this variable by JS code like this:
driver.execute_script("document.getElementsByName('phone')[0].value=***")
Where instead of *** I need the value of "numbers" variable. How should I properly insert it to make it work?
Here is what you want to do.
numbers = input("prompt")
driver.execute_script("document.getElementsByName('phone')[0].value={}".format(numbers))
The documentation link:
https://docs.python.org/3/library/string.html
And a snip-it from the docs:
The field_name itself begins with an arg_name that is either a number or a keyword. If it’s a number, it refers to a positional argument, and if it’s a keyword, it refers to a named keyword argument. If the numerical arg_names in a format string are 0, 1, 2, … in sequence, they can all be omitted (not just some) and the numbers 0, 1, 2, … will be automatically inserted in that order. Because arg_name is not quote-delimited, it is not possible to specify arbitrary dictionary keys (e.g., the strings '10' or ':-]') within a format string. The arg_name can be followed by any number of index or attribute expressions. An expression of the form '.name' selects the named attribute using getattr(), while an expression of the form '[index]' does an index lookup using getitem().
Changed in version 3.1: The positional argument specifiers can be omitted for str.format(), so '{} {}'.format(a, b) is equivalent to '{0} {1}'.format(a, b).
OR
numbers = input("prompt")
driver.execute_script("document.getElementsByName('phone')[0].value=%s" % numbers)
See examples of both here:
https://pyformat.info/
If your python variable's value is simple string without single quotes or special characters, you can simply use:
driver.execute_script("document.getElementsByName('phone')[0].value='" +
python_variable + "'");
If it has quote marks in it, or special characters that need escaping, or if it's not a string at all, you need to obtain JavaScript string representation of your Python variable's value. json.dumps will handle all the necessary formatting and escaping for you, appropriate to the type of your variable:
from json import dumps
driver.execute_script("document.getElementsByName('phone')[0].value=" +
dumps(python_variable))

How to write strict-greater? (-lesser?, -greater-or-equal?, -lesser-or-equal?)

Rebol and Red have a notion of the ordinary equal? function (offered infix simply as =) as being a sort of "natural equality". Hence it is willing to compare 1 = 1.0 even though one is an integer and the other a float... and to compare strings and characters case-insensitively by default.
The strict-equal? function is case-sensitive, demands things be the same datatype, and is tied to == as infix. (There is also a strict-not-equal? function as !==.)
However, the other comparison operators don't seem to have a strict variant. How would one implement a strict-greater? or a strict-lesser-or-equal?, etc. with the primitives in the box?
Behavior would be, for instance:
>> strict-lesser? "A" "a"
== true
As endo64 points out, strings are the stumbling block but since their components, characters, have the desired strict inequalities, the solution would seem to be to compare strings character by character ("lexicographically", if you wish). This goes for Rebol2, Rebol3 and Red alike.

How to format numbers in Google API Linechart?

I need to format the numbers in the axis and the numbers that appear when you hover your mouse over the line chart.
There are two steps involved. The first step is to find out what pattern you should use; the second step is to put the pattern in the proper place in your code. To make this post more beautiful, I show you step 2 and then step 1.
Step 2: Putting the pattern in your code
Here's the code:
var options = {
hAxis: {format:'###,###'}
vAxis: {title: 'Time', format:'0.0E00'},
};
var formatter1 = new google.visualization.NumberFormat({pattern:'###,###'});
formatter1.format(dataTable, 0);
var formatter2 = new google.visualization.NumberFormat({pattern:'0.0E00'});
formatter2.format(dataTable, 1);
var fchartvar = new google.visualization.LineChart(document.getElementById('fchart'));
fchartvar.draw(dataTable, options);
vAxis: {title: 'Time', format:'0.0E00'} formats the labels on the vertical axis.
This formats the numbers you see when you hover over points on the line chart:
var formatter1 = new google.visualization.NumberFormat({pattern:'0.0E00'});
formatter1.format(dataTable, 1);
Note how (dataTable,0) formats the hAxis information while (dataTable,1) formats the vAxis information (again, which you see when you hover over the points on the line chart).
The last two lines of code:
var fchartvar = new google.visualization.LineChart(document.getElementById('fchart'));
fchartvar.draw(dataTable, options);
are for you two compare with your own chart. Replace fchartvar,dataTable and fchart by the names used in your code. If you're using something other than line chart, replace LineChart with the chart you're using.
An example of 0.0E00 is turning 1,234 into 1.2E03.
Step 1: Finding the right pattern
Google NumberFormat documentation
NumberFormat supports the following options, passed in to the constructor: (source: Google NumberFormat documentation)
decimalSymbol
A character to use as the decimal marker. The default is a dot (.).
fractionDigits
A number specifying how many digits to display after the decimal. The
default is 2. If you specify more digits than the number contains, it
will display zeros for the smaller values. Truncated values will be
rounded (5 rounded up).
groupingSymbol
A character to be used to group digits to the left of the decimal
into sets of three. Default is a comma (,).
negativeColor
The text color for negative values. No default value. Values can be
any acceptable HTML color value, such as "red" or "#FF0000".
negativeParens
A boolean, where true indicates that negative values should be
surrounded by parentheses. Default is true.
pattern
A format string. When provided, all other options are ignored, except
negativeColor.
The format string is a subset of the ICU pattern set. For instance,
{pattern:'#,###%'} will result in output values "1,000%", "750%", and
"50%" for values 10, 7.5, and 0.5.
prefix
A string prefix for the value, for example "$".
suffix
A string suffix for the value, for example "%".
ICU DecimalFormat Reference
As you might have noticed from the Google NumberFormat documentation above, you can find out more detailed information about formatting the numbers from the ICU DecimalFormat Reference. Here is some of the most important information from the ICU DecimalFormat Reference (it's in the 'middle' of the webpage):
A DecimalFormat pattern contains a postive and negative subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a prefix, a numeric part, and a suffix. If there is no explicit negative subpattern, the negative subpattern is the localized minus sign prefixed to the positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there is an explicit negative subpattern, it serves only to specify the negative prefix and suffix; the number of digits, minimal digits, and other characteristics are ignored in the negative subpattern. That means that "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)".
The prefixes, suffixes, and various symbols used for infinity, digits, thousands separators, decimal separators, etc. may be set to arbitrary values, and they will appear properly during formatting. However, care must be taken that the symbols and strings do not conflict, or parsing will be unreliable. For example, either the positive and negative prefixes or the suffixes must be distinct for parse() to be able to distinguish positive from negative values. Another example is that the decimal separator and thousands separator should be distinct characters, or parsing will be impossible.
The grouping separator is a character that separates clusters of integer digits to make large numbers more legible. It commonly used for thousands, but in some locales it separates ten-thousands. The grouping size is the number of digits between the grouping separators, such as 3 for "100,000,000" or 4 for "1 0000 0000". There are actually two different grouping sizes: One used for the least significant integer digits, the primary grouping size, and one used for all others, the secondary grouping size. In most locales these are the same, but sometimes they are different. For example, if the primary grouping interval is 3, and the secondary is 2, then this corresponds to the pattern "#,##,##0", and the number 123456789 is formatted as "12,34,56,789". If a pattern contains multiple grouping separators, the interval between the last one and the end of the integer defines the primary grouping size, and the interval between the last two defines the secondary grouping size. All others are ignored, so "#,##,###,####" == "###,###,####" == "##,#,###,####".
Illegal patterns, such as "#.#.#" or "#.###,###", will cause DecimalFormat to set a failing UErrorCode.
If you need to simply format all numbers shown in the graph, in the hover and in the axis according to the locale of a country, the simplest in IMHO is to use the country code when loading the library.
E.g.:
google.charts.load('44', {packages: ['corechart', 'bar', 'sankey'], 'language': 'fr'});
That is the way I would format all numbers using space separators for thousands and a comma for the decimal place.