How to use the clldutils.misc.lazyproperty function in clldutils

To help you get started, we’ve selected a few clldutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github clld / clld / src / clld / web / datatables / base.py View on Github external
    @lazyproperty
    def cols(self):
        return self.col_defs()
github lingpy / lingpy / lingpy / evaluate / apa.py View on Github external
    @lazyproperty
    def c_scores(self):
        """
        Calculate the c-scores.
        """
        almsGold = misc.transpose(self.gold.alm_matrix)
        almsTest = misc.transpose(self.test.alm_matrix)

        commons = len([i for i in almsGold if i in almsTest])

        cp = commons / len(almsTest)
        cr = commons / len(almsGold)
        c_ = 2 * commons / (len(almsTest) + len(almsGold))
        try:
            cf = 2 * cp * cr / (cp + cr)
        except ZeroDivisionError:
            cf = 0.0
github clld / clld / src / clld / web / maps / __init__.py View on Github external
    @lazyproperty
    def layers(self):
        """The list of layers of the map.

        .. note:: Since layers may be costly to compute, we cache them per map instance.

        :return: list of :py:class:`clld.web.maps.Layer` instances.
        """
        return list(self.get_layers())
github lingpy / lingpy / lingpy / evaluate / apa.py View on Github external
    @lazyproperty
    def pairwise_column_scores(self):
        """
        Compute the different column scores for pairwise alignments. The method
        returns the precision, the recall score, and the f-score, following the
        proposal of Bergsma and Kondrak (2007), and the column score proposed
        by Thompson et al. (1999).
        """
        # the variables which store the different counts
        crp = 0.0  # number of common residue pairs in reference and test alm.
        rrp = 0.0  # number of residue pairs in reference alignment
        trp = 0.0  # number of residue pairs in test alignment
        urp = 0.0  # number of unique residue pairs in reference and test alm.
        
        gtrp = 0.0  # number of residue pairs (including gaps) in test alm.
        grrp = 0.0  # number of residue pairs (including gaps) in reference alm.
        gcrp = 0.0  # number of common residue pairs (including gaps) in r and t
github clld / clld / src / clld / db / models / parameter.py View on Github external
    @lazyproperty
    def values(self):
        from . import ValueSet, Value

        def _filter(query, operation):
            q = query.filter(Parameter.pk == self.parameters[0].pk)
            return getattr(q, operation)(
                *[query.filter(Parameter.pk == p.pk) for p in self.parameters[1:]])

        # determine relevant languages, i.e. languages having a value for all parameters:
        languages = _filter(
            DBSession.query(Language.pk).join(ValueSet).join(Parameter),
            'intersect').subquery()

        # value query:
        return _filter(
            DBSession.query(Value)
github clld / clld / src / clld / web / util / component.py View on Github external
    @lazyproperty
    def options(self):
        """Typically options to configure a corresponding JavaScript object.

        :return: JSON serializable dict
        """
        opts = self.get_default_options()
        opts.update(self.get_options() or {})
        opts.update(self.get_options_from_req() or {})
        return opts
github clld / clld / src / clld / db / models / parameter.py View on Github external
    @lazyproperty
    def domain(self):
        """Compute the domain as cartesian product of constituent domains.

        .. note::

            This does only work well with parameters which have a discrete domain.
        """
        d = OrderedDict()
        for i, des in enumerate(product(*[p.domain for p in self.parameters])):
            cde = CombinationDomainElement(
                self, des, icon=ORDERED_ICONS[i % len(ORDERED_ICONS)])
            d[cde.number] = cde

        for language, values in groupby(
            sorted(self.values, key=lambda v: v.valueset.language_pk),
            lambda i: i.valueset.language,
github clld / clld / src / clld / web / maps / __init__.py View on Github external
    @lazyproperty
    def legends(self):
        return list(self.get_legends())