Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@lazyproperty
def cols(self):
return self.col_defs()
@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
@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())
@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
@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)
@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
@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,
@lazyproperty
def legends(self):
return list(self.get_legends())