2022-05-02 11:59:43 -04:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2015-03-18 13:32:24 -04:00
|
|
|
<!--
|
2022-05-03 14:14:29 -04:00
|
|
|
Copyright (C) 2014-2022 Ryan Specialty Group, LLC.
|
2015-03-18 13:32:24 -04:00
|
|
|
|
|
|
|
This file is part of tame-core.
|
|
|
|
|
|
|
|
tame-core is free software: you can redistribute it and/or modify it
|
2018-01-26 11:13:33 -05:00
|
|
|
under the terms of the GNU General Public License as
|
2015-03-18 13:32:24 -04:00
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
-->
|
2015-03-18 11:31:47 -04:00
|
|
|
<package xmlns="http://www.lovullo.com/rater"
|
2013-02-13 09:27:33 -05:00
|
|
|
xmlns:c="http://www.lovullo.com/calc"
|
2015-07-20 10:18:44 -04:00
|
|
|
xmlns:t="http://www.lovullo.com/rater/apply-template"
|
2013-02-13 09:27:33 -05:00
|
|
|
core="true"
|
|
|
|
desc="Vector operations on classification matches">
|
|
|
|
|
2015-03-18 11:31:47 -04:00
|
|
|
<import package="../base" />
|
|
|
|
<import package="arithmetic" export="true" />
|
2015-07-20 10:18:44 -04:00
|
|
|
<import package="minmax" export="true" />
|
2013-02-13 09:27:33 -05:00
|
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
This wonderful little gem takes a classification match and stores it in a
|
|
|
|
vector, allowing for hassle-free use in calculations without awkward
|
|
|
|
hasany() calls on classification matrices (where a classification yields a
|
|
|
|
matrix, that is). This is useless for classifications that yield vectors,
|
|
|
|
since the result will be the same.
|
|
|
|
|
|
|
|
This template is also useful for combining various classification vectors
|
|
|
|
and matrices, whoose reduction would otherwise be a bit complicated. Of
|
|
|
|
course, the alternative there is also to create a classification that
|
|
|
|
relies on other classifications; use your best judgement.
|
|
|
|
|
|
|
|
This exploits the fact that _CMATCH_'s are always vectors, even if we are
|
|
|
|
matching on a matrix. As such, the system has already gone through the
|
|
|
|
trouble of reducing the matrix into a vector for us, so all we need to do
|
|
|
|
is store each value into a vector, which can be easily accomplished using a
|
|
|
|
generator.
|
|
|
|
|
|
|
|
This is an excellent example of building a feature atop of the DSL without
|
|
|
|
having to add a new language feature.
|
|
|
|
-->
|
2015-03-18 11:31:47 -04:00
|
|
|
<template name="_cmatch-to-vector_" desc="Vectorizes a classification match">
|
|
|
|
<param name="@class@" desc="Classification match string" />
|
|
|
|
<param name="@generates@" desc="Variable to yield generates (will yield a vector)" />
|
|
|
|
<param name="@keep@" desc="Rate block @keep">
|
|
|
|
<text></text>
|
|
|
|
</param>
|
|
|
|
|
|
|
|
<param name="@yields@" desc="Dummy variable to yield generates (useless, but required)">
|
|
|
|
<text>__</text>
|
|
|
|
<param-value name="@generates@" />
|
|
|
|
</param>
|
|
|
|
|
|
|
|
<param name="@gendesc@" desc="Generator description">
|
|
|
|
<text>Vector containing boolean </text>
|
|
|
|
<param-value name="@class@" />
|
|
|
|
<text> classification matches</text>
|
|
|
|
</param>
|
|
|
|
|
|
|
|
<param name="@sym@" desc="Generator symbol (corresponds to @generates@)">
|
2013-02-13 09:27:33 -05:00
|
|
|
<!-- defaults to nothing -->
|
2015-03-18 11:31:47 -04:00
|
|
|
<text></text>
|
|
|
|
</param>
|
2013-02-13 09:27:33 -05:00
|
|
|
|
|
|
|
<!-- this conversion is as simple as using a generator to yield the value
|
|
|
|
of _CMATCH_ for each index -->
|
2015-03-18 11:31:47 -04:00
|
|
|
<rate class="@class@" accumulate="none" yields="@yields@" always="true" keep="@keep@">
|
2013-02-13 09:27:33 -05:00
|
|
|
<c:sum of="_CMATCH_" index="k" generates="@generates@" desc="@gendesc@" sym="@sym@">
|
|
|
|
<c:value-of name="_CMATCH_" index="k" />
|
|
|
|
</c:sum>
|
2015-03-18 11:31:47 -04:00
|
|
|
</rate>
|
|
|
|
</template>
|
2013-02-13 09:27:33 -05:00
|
|
|
|
|
|
|
|
2015-03-18 11:31:47 -04:00
|
|
|
<template name="_cmatch-to-scalar_" desc="Reduces a classification match into a scalar">
|
|
|
|
<param name="@class@" desc="Classification match string" />
|
|
|
|
<param name="@yields@" desc="Variable to yield into" />
|
|
|
|
<param name="@sym@" desc="Yield symbol (defaults to nothing)">
|
2013-02-13 09:27:33 -05:00
|
|
|
<!-- defaults to nothing -->
|
2015-03-18 11:31:47 -04:00
|
|
|
<text></text>
|
|
|
|
</param>
|
2013-02-13 09:27:33 -05:00
|
|
|
|
2015-03-18 11:31:47 -04:00
|
|
|
<param name="@keep@" desc="Rate block @keep">
|
|
|
|
<text></text>
|
|
|
|
</param>
|
2013-02-13 09:27:33 -05:00
|
|
|
|
|
|
|
|
2015-03-18 11:31:47 -04:00
|
|
|
<rate class="@class@" accumulate="none" yields="@yields@" sym="@sym@" keep="@keep@">
|
2013-02-13 09:27:33 -05:00
|
|
|
<!-- if any single one matches, then we want to yield a 1 -->
|
|
|
|
<c:apply name="maxreduce" maxreduce_set="_CMATCH_" />
|
2015-03-18 11:31:47 -04:00
|
|
|
</rate>
|
|
|
|
</template>
|
2013-02-13 09:27:33 -05:00
|
|
|
|
|
|
|
|
2015-07-20 10:18:44 -04:00
|
|
|
In cases where a classification needs to be based on a result that
|
|
|
|
has been reduced to a scalar, \ref{_cmatch_to-scalar_} does not
|
|
|
|
solve the whole problem: for this, \ref{_classify-scalar_} may be
|
|
|
|
used. In addition to performing the action of the former (if {\tt
|
|
|
|
@yields} is provided), the resulting classification itself will
|
|
|
|
match on the scalar result. While this is not strictly
|
|
|
|
necessary---the predicate itself is already scalar---this is
|
|
|
|
important for systems or templates that derive the classification
|
|
|
|
result from the name of the classification.
|
|
|
|
|
|
|
|
|
|
|
|
<template name="_classify-scalar_"
|
|
|
|
desc="Classification with a forced-scalar result">
|
|
|
|
<param name="@values@" desc="Predicates" />
|
|
|
|
<param name="@as@" desc="Classification name" />
|
|
|
|
<param name="@desc@" desc="Classification description" />
|
|
|
|
|
|
|
|
<param name="@yields@" desc="Scalar result name">
|
|
|
|
<text>__</text>
|
|
|
|
<param-value snake="true" name="@as@" />
|
|
|
|
</param>
|
|
|
|
|
|
|
|
<param name="@keep@" desc="Whether to force compilation">
|
|
|
|
<text></text>
|
|
|
|
</param>
|
|
|
|
|
|
|
|
<param name="@sym@" desc="Optional yield symbol">
|
|
|
|
<text></text>
|
|
|
|
</param>
|
|
|
|
|
|
|
|
|
|
|
|
<classify as="--{@as@}-pre"
|
2018-02-20 15:03:31 -05:00
|
|
|
yields="__{@yields@}Pre"
|
|
|
|
desc="{@desc@}, pre-scalar">
|
2015-07-20 10:18:44 -04:00
|
|
|
<param-copy name="@values@" />
|
|
|
|
</classify>
|
|
|
|
|
|
|
|
<t:cmatch-to-scalar class="--{@as@}-pre"
|
|
|
|
yields="__{@yields@}Scalar"
|
|
|
|
sym="@sym@"
|
|
|
|
keep="@keep@" />
|
|
|
|
|
|
|
|
<classify as="@as@" yields="@yields@"
|
|
|
|
desc="@desc@"
|
|
|
|
keep="@keep@"
|
|
|
|
sym="@sym@">
|
|
|
|
<match on="__{@yields@}Scalar" />
|
|
|
|
</classify>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
2019-07-29 14:51:38 -04:00
|
|
|
The vector analog to \ref{_classify-scalar_} is
|
|
|
|
\ref{_classify-vector_}. The results are undefined if the classification
|
|
|
|
would have otherwise yielded a scalar value (that is, do not use this to
|
|
|
|
force a scalar into a vector). It may work in an intuitive way, but it's
|
|
|
|
not designed to.
|
|
|
|
|
|
|
|
<template name="_classify-vector_"
|
|
|
|
desc="Classification with a forced-vector result">
|
|
|
|
<param name="@values@" desc="Predicates" />
|
|
|
|
<param name="@as@" desc="Classification name" />
|
|
|
|
<param name="@desc@" desc="Classification description" />
|
|
|
|
|
|
|
|
<param name="@yields@" desc="Scalar result name">
|
|
|
|
<text>__</text>
|
|
|
|
<param-value snake="true" name="@as@" />
|
|
|
|
</param>
|
|
|
|
|
|
|
|
<param name="@sym@" desc="Optional yield symbol">
|
|
|
|
<text></text>
|
|
|
|
</param>
|
|
|
|
|
|
|
|
|
|
|
|
<classify as="--{@as@}-pre"
|
|
|
|
yields="__{@yields@}Pre"
|
|
|
|
desc="{@desc@}, pre-vector">
|
|
|
|
<param-copy name="@values@" />
|
|
|
|
</classify>
|
|
|
|
|
|
|
|
<t:cmatch-to-vector class="--{@as@}-pre"
|
|
|
|
generates="__{@yields@}Vector"
|
|
|
|
sym="@sym@" />
|
|
|
|
|
|
|
|
<classify as="@as@" yields="@yields@"
|
|
|
|
desc="@desc@"
|
|
|
|
sym="@sym@">
|
|
|
|
<match on="__{@yields@}Vector" />
|
|
|
|
</classify>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
2013-02-13 09:27:33 -05:00
|
|
|
|
|
|
|
<!--
|
|
|
|
Counts one for each classification vector match
|
|
|
|
-->
|
2015-03-18 11:31:47 -04:00
|
|
|
<template name="_cmatch-count_" desc="Counts the number of classification matches of a vector">
|
|
|
|
<param name="@class@" desc="Classification match" />
|
|
|
|
<param name="@yields@" desc="Value to yield" />
|
2013-02-13 09:27:33 -05:00
|
|
|
|
|
|
|
<!-- nothing by default -->
|
2015-03-18 11:31:47 -04:00
|
|
|
<param name="@no@" desc="Non-match">
|
|
|
|
<text></text>
|
|
|
|
</param>
|
2013-02-13 09:27:33 -05:00
|
|
|
|
|
|
|
|
2015-03-18 11:31:47 -04:00
|
|
|
<rate class="@class@" no="@no@" yields="@yields@">
|
2013-02-13 09:27:33 -05:00
|
|
|
<c:sum of="_CMATCH_" />
|
2015-03-18 11:31:47 -04:00
|
|
|
</rate>
|
|
|
|
</template>
|
2013-02-13 09:27:33 -05:00
|
|
|
|
|
|
|
|
|
|
|
<!-- because verbose repition is an evil -->
|
2015-03-18 11:31:47 -04:00
|
|
|
<inline-template>
|
|
|
|
<for-each>
|
|
|
|
<set cmp="eq" />
|
|
|
|
<set cmp="ne" />
|
|
|
|
<set cmp="gt" />
|
|
|
|
<set cmp="gte" />
|
|
|
|
<set cmp="lt" />
|
|
|
|
<set cmp="lte" />
|
|
|
|
</for-each>
|
2013-02-13 09:27:33 -05:00
|
|
|
|
|
|
|
|
2015-03-18 11:31:47 -04:00
|
|
|
<template name="_match-{@cmp@}_" desc="Match value {@cmp@}">
|
|
|
|
<param name="@on@" desc="Value to assert" />
|
2013-02-13 09:27:33 -05:00
|
|
|
|
|
|
|
<!-- pick one -->
|
2015-03-18 11:31:47 -04:00
|
|
|
<param name="@const@" desc="Match against constant value" />
|
|
|
|
<param name="@value@" desc="Match against variable" />
|
2013-02-13 09:27:33 -05:00
|
|
|
|
2018-01-18 15:43:11 -05:00
|
|
|
<if name="@const@">
|
|
|
|
<warning>
|
|
|
|
@const@ is deprecated; use @value@ with a #-prefix instead.
|
|
|
|
</warning>
|
|
|
|
</if>
|
|
|
|
|
2015-03-18 11:31:47 -04:00
|
|
|
<match on="@on@">
|
|
|
|
<dyn-node name="c:{@cmp@}">
|
|
|
|
<if name="@const@">
|
2022-08-15 10:18:30 -04:00
|
|
|
<c:const value="@const@" desc="Comparison" />
|
2015-03-18 11:31:47 -04:00
|
|
|
</if>
|
2013-02-13 09:27:33 -05:00
|
|
|
|
2015-03-18 11:31:47 -04:00
|
|
|
<unless name="@const@">
|
2013-02-13 09:27:33 -05:00
|
|
|
<c:value-of name="@value@" />
|
2015-03-18 11:31:47 -04:00
|
|
|
</unless>
|
|
|
|
</dyn-node>
|
|
|
|
</match>
|
|
|
|
</template>
|
|
|
|
</inline-template>
|
2013-02-13 09:27:33 -05:00
|
|
|
|
|
|
|
|
2015-03-18 11:31:47 -04:00
|
|
|
<template name="_match-class_"
|
2013-02-13 09:27:33 -05:00
|
|
|
desc="Match on a class name (rather than @yields)">
|
2015-03-18 11:31:47 -04:00
|
|
|
<param name="@name@" desc="Classification name" />
|
|
|
|
|
|
|
|
<param name="@__yields@" desc="Classification yield to match on">
|
|
|
|
<param-class-to-yields name="@name@" />
|
|
|
|
</param>
|
2013-02-13 09:27:33 -05:00
|
|
|
|
2015-03-18 11:31:47 -04:00
|
|
|
<param name="@value@" desc="Value to match on">
|
|
|
|
<text></text>
|
|
|
|
</param>
|
2013-02-13 09:27:33 -05:00
|
|
|
|
2015-03-18 11:31:47 -04:00
|
|
|
<match on="@__yields@" value="@value@" />
|
|
|
|
</template>
|
2017-12-21 10:51:43 -05:00
|
|
|
|
|
|
|
|
|
|
|
\ref{_vector-to-class_} converts a vector into a classification.
|
|
|
|
|
|
|
|
<template name="_vector-to-class_"
|
|
|
|
desc="Convert a vector to a classification">
|
|
|
|
<param name="@name@" desc="Source vector" />
|
|
|
|
<param name="@as@" desc="Classification name" />
|
|
|
|
|
|
|
|
<param name="@yields@" desc="Classification yield">
|
|
|
|
<text></text>
|
|
|
|
</param>
|
|
|
|
|
|
|
|
<param name="@desc@" desc="Classification description">
|
|
|
|
<text>Classification of </text>
|
|
|
|
<param-value name="@name@" />
|
|
|
|
</param>
|
|
|
|
|
|
|
|
|
|
|
|
<classify as="@as@" desc="@desc@" yields="@yields@">
|
|
|
|
<match on="@name@" />
|
|
|
|
</classify>
|
|
|
|
</template>
|
2015-03-18 11:31:47 -04:00
|
|
|
</package>
|
2013-02-13 09:27:33 -05:00
|
|
|
|