_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q258200
sim_manhattan
validation
def sim_manhattan(src, tar, qval=2, alphabet=None): """Return the normalized Manhattan similarity of two strings. This is a wrapper for :py:meth:`Manhattan.sim`. Parameters ---------- src : str Source string (or QGrams/Counter objects) for comparison tar : str Target string (or...
python
{ "resource": "" }
q258201
dist_jaro_winkler
validation
def dist_jaro_winkler( src, tar, qval=1, mode='winkler', long_strings=False, boost_threshold=0.7, scaling_factor=0.1, ): """Return the Jaro or Jaro-Winkler distance between two strings. This is a wrapper for :py:meth:`JaroWinkler.dist`. Parameters ---------- src : str ...
python
{ "resource": "" }
q258202
sim_hamming
validation
def sim_hamming(src, tar, diff_lens=True): """Return the normalized Hamming similarity of two strings. This is a wrapper for :py:meth:`Hamming.sim`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison diff_lens : bool ...
python
{ "resource": "" }
q258203
SkeletonKey.fingerprint
validation
def fingerprint(self, word): """Return the skeleton key. Parameters ---------- word : str The word to transform into its skeleton key Returns ------- str The skeleton key Examples -------- >>> sk = SkeletonKey() ...
python
{ "resource": "" }
q258204
mean_pairwise_similarity
validation
def mean_pairwise_similarity( collection, metric=sim, mean_func=hmean, symmetric=False ): """Calculate the mean pairwise similarity of a collection of strings. Takes the mean of the pairwise similarity between each member of a collection, optionally in both directions (for asymmetric similarity met...
python
{ "resource": "" }
q258205
pairwise_similarity_statistics
validation
def pairwise_similarity_statistics( src_collection, tar_collection, metric=sim, mean_func=amean, symmetric=False, ): """Calculate the pairwise similarity statistics a collection of strings. Calculate pairwise similarities among members of two collections, returning the maximum, minimum,...
python
{ "resource": "" }
q258206
_Snowball._sb_r1
validation
def _sb_r1(self, term, r1_prefixes=None): """Return the R1 region, as defined in the Porter2 specification. Parameters ---------- term : str The term to examine r1_prefixes : set Prefixes to consider Returns ------- int ...
python
{ "resource": "" }
q258207
_Snowball._sb_r2
validation
def _sb_r2(self, term, r1_prefixes=None): """Return the R2 region, as defined in the Porter2 specification. Parameters ---------- term : str The term to examine r1_prefixes : set Prefixes to consider Returns ------- int ...
python
{ "resource": "" }
q258208
_Snowball._sb_ends_in_short_syllable
validation
def _sb_ends_in_short_syllable(self, term): """Return True iff term ends in a short syllable. (...according to the Porter2 specification.) NB: This is akin to the CVC test from the Porter stemmer. The description is unfortunately poor/ambiguous. Parameters ---------- ...
python
{ "resource": "" }
q258209
_Snowball._sb_short_word
validation
def _sb_short_word(self, term, r1_prefixes=None): """Return True iff term is a short word. (...according to the Porter2 specification.) Parameters ---------- term : str The term to examine r1_prefixes : set Prefixes to consider Returns ...
python
{ "resource": "" }
q258210
_Snowball._sb_has_vowel
validation
def _sb_has_vowel(self, term): """Return Porter helper function _sb_has_vowel value. Parameters ---------- term : str The term to examine Returns ------- bool True iff a vowel exists in the term (as defined in the Porter stemm...
python
{ "resource": "" }
q258211
Eudex.encode
validation
def encode(self, word, max_length=8): """Return the eudex phonetic hash of a word. Parameters ---------- word : str The word to transform max_length : int The length in bits of the code returned (default 8) Returns ------- int ...
python
{ "resource": "" }
q258212
_TokenDistance._get_qgrams
validation
def _get_qgrams(self, src, tar, qval=0, skip=0): """Return the Q-Grams in src & tar. Parameters ---------- src : str Source string (or QGrams/Counter objects) for comparison tar : str Target string (or QGrams/Counter objects) for comparison qval :...
python
{ "resource": "" }
q258213
NCDlzma.dist
validation
def dist(self, src, tar): """Return the NCD between two strings using LZMA compression. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison Returns ------- float Compress...
python
{ "resource": "" }
q258214
sim_levenshtein
validation
def sim_levenshtein(src, tar, mode='lev', cost=(1, 1, 1, 1)): """Return the Levenshtein similarity of two strings. This is a wrapper of :py:meth:`Levenshtein.sim`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison mode : str...
python
{ "resource": "" }
q258215
OmissionKey.fingerprint
validation
def fingerprint(self, word): """Return the omission key. Parameters ---------- word : str The word to transform into its omission key Returns ------- str The omission key Examples -------- >>> ok = OmissionKey() ...
python
{ "resource": "" }
q258216
sim_minkowski
validation
def sim_minkowski(src, tar, qval=2, pval=1, alphabet=None): """Return normalized Minkowski similarity of two strings. This is a wrapper for :py:meth:`Minkowski.sim`. Parameters ---------- src : str Source string (or QGrams/Counter objects) for comparison tar : str Target string...
python
{ "resource": "" }
q258217
Cosine.sim
validation
def sim(self, src, tar, qval=2): r"""Return the cosine similarity of two strings. Parameters ---------- src : str Source string (or QGrams/Counter objects) for comparison tar : str Target string (or QGrams/Counter objects) for comparison qval : in...
python
{ "resource": "" }
q258218
dist_monge_elkan
validation
def dist_monge_elkan(src, tar, sim_func=sim_levenshtein, symmetric=False): """Return the Monge-Elkan distance between two strings. This is a wrapper for :py:meth:`MongeElkan.dist`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparis...
python
{ "resource": "" }
q258219
Phonem.encode
validation
def encode(self, word): """Return the Phonem code for a word. Parameters ---------- word : str The word to transform Returns ------- str The Phonem value Examples -------- >>> pe = Phonem() >>> pe.encode('Chri...
python
{ "resource": "" }
q258220
CLEFSwedish.stem
validation
def stem(self, word): """Return CLEF Swedish stem. Parameters ---------- word : str The word to stem Returns ------- str Word stem Examples -------- >>> clef_swedish('undervisa') 'undervis' >>> cle...
python
{ "resource": "" }
q258221
SnowballDutch._undouble
validation
def _undouble(self, word): """Undouble endings -kk, -dd, and -tt. Parameters ---------- word : str The word to stem Returns ------- str The word with doubled endings undoubled """ if ( len(word) > 1 ...
python
{ "resource": "" }
q258222
String.fingerprint
validation
def fingerprint(self, phrase, joiner=' '): """Return string fingerprint. Parameters ---------- phrase : str The string from which to calculate the fingerprint joiner : str The string that will be placed between each word Returns ------- ...
python
{ "resource": "" }
q258223
ipa_to_features
validation
def ipa_to_features(ipa): """Convert IPA to features. This translates an IPA string of one or more phones to a list of ints representing the features of the string. Parameters ---------- ipa : str The IPA representation of a phone or series of phones Returns ------- list o...
python
{ "resource": "" }
q258224
get_feature
validation
def get_feature(vector, feature): """Get a feature vector. This returns a list of ints, equal in length to the vector input, representing presence/absence/neutrality with respect to a particular phonetic feature. Parameters ---------- vector : list A tuple or list of ints r...
python
{ "resource": "" }
q258225
cmp_features
validation
def cmp_features(feat1, feat2): """Compare features. This returns a number in the range [0, 1] representing a comparison of two feature bundles. If one of the bundles is negative, -1 is returned (for unknown values) If the bundles are identical, 1 is returned. If they are inverses of one ano...
python
{ "resource": "" }
q258226
Length.sim
validation
def sim(self, src, tar): """Return the length similarity of two strings. Length similarity is the ratio of the length of the shorter string to the longer. Parameters ---------- src : str Source string for comparison tar : str Target strin...
python
{ "resource": "" }
q258227
hmean
validation
def hmean(nums): r"""Return harmonic mean. The harmonic mean is defined as: :math:`\frac{|nums|}{\sum\limits_{i}\frac{1}{nums_i}}` Following the behavior of Wolfram|Alpha: - If one of the values in nums is 0, return 0. - If more than one value in nums is 0, return NaN. Cf. https://en.wiki...
python
{ "resource": "" }
q258228
lmean
validation
def lmean(nums): r"""Return logarithmic mean. The logarithmic mean of an arbitrarily long series is defined by http://www.survo.fi/papers/logmean.pdf as: :math:`L(x_1, x_2, ..., x_n) = (n-1)! \sum\limits_{i=1}^n \frac{x_i} {\prod\limits_{\substack{j = 1\\j \ne i}}^n ln \frac{x_i}{x_j}}`...
python
{ "resource": "" }
q258229
seiffert_mean
validation
def seiffert_mean(nums): r"""Return Seiffert's mean. Seiffert's mean of two numbers x and y is: :math:`\frac{x - y}{4 \cdot arctan \sqrt{\frac{x}{y}} - \pi}` It is defined in :cite:`Seiffert:1993`. Parameters ---------- nums : list A series of numbers Returns ------- ...
python
{ "resource": "" }
q258230
lehmer_mean
validation
def lehmer_mean(nums, exp=2): r"""Return Lehmer mean. The Lehmer mean is: :math:`\frac{\sum\limits_i{x_i^p}}{\sum\limits_i{x_i^(p-1)}}` Cf. https://en.wikipedia.org/wiki/Lehmer_mean Parameters ---------- nums : list A series of numbers exp : numeric The exponent of the...
python
{ "resource": "" }
q258231
heronian_mean
validation
def heronian_mean(nums): r"""Return Heronian mean. The Heronian mean is: :math:`\frac{\sum\limits_{i, j}\sqrt{{x_i \cdot x_j}}} {|nums| \cdot \frac{|nums| + 1}{2}}` for :math:`j \ge i` Cf. https://en.wikipedia.org/wiki/Heronian_mean Parameters ---------- nums : list A seri...
python
{ "resource": "" }
q258232
agmean
validation
def agmean(nums): """Return arithmetic-geometric mean. Iterates between arithmetic & geometric means until they converge to a single value (rounded to 12 digits). Cf. https://en.wikipedia.org/wiki/Arithmetic-geometric_mean Parameters ---------- nums : list A series of numbers ...
python
{ "resource": "" }
q258233
ghmean
validation
def ghmean(nums): """Return geometric-harmonic mean. Iterates between geometric & harmonic means until they converge to a single value (rounded to 12 digits). Cf. https://en.wikipedia.org/wiki/Geometric-harmonic_mean Parameters ---------- nums : list A series of numbers Retur...
python
{ "resource": "" }
q258234
aghmean
validation
def aghmean(nums): """Return arithmetic-geometric-harmonic mean. Iterates over arithmetic, geometric, & harmonic means until they converge to a single value (rounded to 12 digits), following the method described in :cite:`Raissouli:2009`. Parameters ---------- nums : list A series ...
python
{ "resource": "" }
q258235
median
validation
def median(nums): """Return median. With numbers sorted by value, the median is the middle value (if there is an odd number of values) or the arithmetic mean of the two middle values (if there is an even number of values). Cf. https://en.wikipedia.org/wiki/Median Parameters ---------- ...
python
{ "resource": "" }
q258236
var
validation
def var(nums, mean_func=amean, ddof=0): r"""Calculate the variance. The variance (:math:`\sigma^2`) of a series of numbers (:math:`x_i`) with mean :math:`\mu` and population :math:`N` is: :math:`\sigma^2 = \frac{1}{N}\sum_{i=1}^{N}(x_i-\mu)^2`. Cf. https://en.wikipedia.org/wiki/Variance Para...
python
{ "resource": "" }
q258237
Schinke.stem
validation
def stem(self, word): """Return the stem of a word according to the Schinke stemmer. Parameters ---------- word : str The word to stem Returns ------- str Word stem Examples -------- >>> stmr = Schinke() >...
python
{ "resource": "" }
q258238
sim_editex
validation
def sim_editex(src, tar, cost=(0, 1, 2), local=False): """Return the normalized Editex similarity of two strings. This is a wrapper for :py:meth:`Editex.sim`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison cost : tuple ...
python
{ "resource": "" }
q258239
NCDarith.dist
validation
def dist(self, src, tar, probs=None): """Return the NCD between two strings using arithmetic coding. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison probs : dict A dictionary trained ...
python
{ "resource": "" }
q258240
readfile
validation
def readfile(fn): """Read fn and return the contents. Parameters ---------- fn : str A filename Returns ------- str The content of the file """ with open(path.join(HERE, fn), 'r', encoding='utf-8') as f: return f.read()
python
{ "resource": "" }
q258241
FONEM.encode
validation
def encode(self, word): """Return the FONEM code of a word. Parameters ---------- word : str The word to transform Returns ------- str The FONEM code Examples -------- >>> pe = FONEM() >>> pe.encode('March...
python
{ "resource": "" }
q258242
Synoname._synoname_strip_punct
validation
def _synoname_strip_punct(self, word): """Return a word with punctuation stripped out. Parameters ---------- word : str A word to strip punctuation from Returns ------- str The word stripped of punctuation Examples ------...
python
{ "resource": "" }
q258243
Synoname.dist
validation
def dist( self, src, tar, word_approx_min=0.3, char_approx_min=0.73, tests=2 ** 12 - 1, ): """Return the normalized Synoname distance between two words. Parameters ---------- src : str Source string for comparison t...
python
{ "resource": "" }
q258244
Jaccard.sim
validation
def sim(self, src, tar, qval=2): r"""Return the Jaccard similarity of two strings. Parameters ---------- src : str Source string (or QGrams/Counter objects) for comparison tar : str Target string (or QGrams/Counter objects) for comparison qval : i...
python
{ "resource": "" }
q258245
Jaccard.tanimoto_coeff
validation
def tanimoto_coeff(self, src, tar, qval=2): """Return the Tanimoto distance between two strings. Tanimoto distance :cite:`Tanimoto:1958` is :math:`-log_{2} sim_{Tanimoto}(X, Y)`. Parameters ---------- src : str Source string (or QGrams/Counter objects) for c...
python
{ "resource": "" }
q258246
sim_sift4
validation
def sim_sift4(src, tar, max_offset=5, max_distance=0): """Return the normalized "common" Sift4 similarity of two terms. This is a wrapper for :py:meth:`Sift4.sim`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison max_offset...
python
{ "resource": "" }
q258247
NCDbz2.dist
validation
def dist(self, src, tar): """Return the NCD between two strings using bzip2 compression. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison Returns ------- float Compres...
python
{ "resource": "" }
q258248
MetaSoundex.encode
validation
def encode(self, word, lang='en'): """Return the MetaSoundex code for a word. Parameters ---------- word : str The word to transform lang : str Either ``en`` for English or ``es`` for Spanish Returns ------- str The Me...
python
{ "resource": "" }
q258249
SStemmer.stem
validation
def stem(self, word): """Return the S-stemmed form of a word. Parameters ---------- word : str The word to stem Returns ------- str Word stem Examples -------- >>> stmr = SStemmer() >>> stmr.stem('summarie...
python
{ "resource": "" }
q258250
RatcliffObershelp.sim
validation
def sim(self, src, tar): """Return the Ratcliff-Obershelp similarity of two strings. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison Returns ------- float Ratcliff-Ob...
python
{ "resource": "" }
q258251
MRA.dist_abs
validation
def dist_abs(self, src, tar): """Return the MRA comparison rating of two strings. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison Returns ------- int MRA comparison r...
python
{ "resource": "" }
q258252
ParmarKumbharana.encode
validation
def encode(self, word): """Return the Parmar-Kumbharana encoding of a word. Parameters ---------- word : str The word to transform Returns ------- str The Parmar-Kumbharana encoding Examples -------- >>> pe = Parm...
python
{ "resource": "" }
q258253
eudex_hamming
validation
def eudex_hamming( src, tar, weights='exponential', max_length=8, normalized=False ): """Calculate the Hamming distance between the Eudex hashes of two terms. This is a wrapper for :py:meth:`Eudex.eudex_hamming`. Parameters ---------- src : str Source string for comparison tar : st...
python
{ "resource": "" }
q258254
dist_eudex
validation
def dist_eudex(src, tar, weights='exponential', max_length=8): """Return normalized Hamming distance between Eudex hashes of two terms. This is a wrapper for :py:meth:`Eudex.dist`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparis...
python
{ "resource": "" }
q258255
sim_eudex
validation
def sim_eudex(src, tar, weights='exponential', max_length=8): """Return normalized Hamming similarity between Eudex hashes of two terms. This is a wrapper for :py:meth:`Eudex.sim`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparis...
python
{ "resource": "" }
q258256
Eudex.gen_fibonacci
validation
def gen_fibonacci(): """Yield the next Fibonacci number. Based on https://www.python-course.eu/generators.php Starts at Fibonacci number 3 (the second 1) Yields ------ int The next Fibonacci number """ num_a, num_b = 1, 2 while True:...
python
{ "resource": "" }
q258257
Eudex.dist_abs
validation
def dist_abs( self, src, tar, weights='exponential', max_length=8, normalized=False ): """Calculate the distance between the Eudex hashes of two terms. Parameters ---------- src : str Source string for comparison tar : str Target string for co...
python
{ "resource": "" }
q258258
Eudex.dist
validation
def dist(self, src, tar, weights='exponential', max_length=8): """Return normalized distance between the Eudex hashes of two terms. This is Eudex distance normalized to [0, 1]. Parameters ---------- src : str Source string for comparison tar : str ...
python
{ "resource": "" }
q258259
euclidean
validation
def euclidean(src, tar, qval=2, normalized=False, alphabet=None): """Return the Euclidean distance between two strings. This is a wrapper for :py:meth:`Euclidean.dist_abs`. Parameters ---------- src : str Source string (or QGrams/Counter objects) for comparison tar : str Target...
python
{ "resource": "" }
q258260
dist_euclidean
validation
def dist_euclidean(src, tar, qval=2, alphabet=None): """Return the normalized Euclidean distance between two strings. This is a wrapper for :py:meth:`Euclidean.dist`. Parameters ---------- src : str Source string (or QGrams/Counter objects) for comparison tar : str Target strin...
python
{ "resource": "" }
q258261
sim_euclidean
validation
def sim_euclidean(src, tar, qval=2, alphabet=None): """Return the normalized Euclidean similarity of two strings. This is a wrapper for :py:meth:`Euclidean.sim`. Parameters ---------- src : str Source string (or QGrams/Counter objects) for comparison tar : str Target string (or...
python
{ "resource": "" }
q258262
Lovins._cond_k
validation
def _cond_k(self, word, suffix_len): """Return Lovins' condition K. Parameters ---------- word : str Word to check suffix_len : int Suffix length Returns ------- bool True if condition is met """ retur...
python
{ "resource": "" }
q258263
Lovins._cond_n
validation
def _cond_n(self, word, suffix_len): """Return Lovins' condition N. Parameters ---------- word : str Word to check suffix_len : int Suffix length Returns ------- bool True if condition is met """ if le...
python
{ "resource": "" }
q258264
Lovins._cond_s
validation
def _cond_s(self, word, suffix_len): """Return Lovins' condition S. Parameters ---------- word : str Word to check suffix_len : int Suffix length Returns ------- bool True if condition is met """ retur...
python
{ "resource": "" }
q258265
Lovins._cond_x
validation
def _cond_x(self, word, suffix_len): """Return Lovins' condition X. Parameters ---------- word : str Word to check suffix_len : int Suffix length Returns ------- bool True if condition is met """ retur...
python
{ "resource": "" }
q258266
Lovins._cond_bb
validation
def _cond_bb(self, word, suffix_len): """Return Lovins' condition BB. Parameters ---------- word : str Word to check suffix_len : int Suffix length Returns ------- bool True if condition is met """ ret...
python
{ "resource": "" }
q258267
Lovins.stem
validation
def stem(self, word): """Return Lovins stem. Parameters ---------- word : str The word to stem Returns ------- str Word stem Examples -------- >>> stmr = Lovins() >>> stmr.stem('reading') 'read' ...
python
{ "resource": "" }
q258268
NCDzlib.dist
validation
def dist(self, src, tar): """Return the NCD between two strings using zlib compression. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison Returns ------- float Compress...
python
{ "resource": "" }
q258269
pylint_color
validation
def pylint_color(score): """Return Pylint badge color. Parameters ---------- score : float A Pylint score Returns ------- str Badge color """ # These are the score cutoffs for each color above. # I.e. score==10 -> brightgreen, down to 7.5 > score >= 5 -> orange...
python
{ "resource": "" }
q258270
pydocstyle_color
validation
def pydocstyle_color(score): """Return pydocstyle badge color. Parameters ---------- score : float A pydocstyle score Returns ------- str Badge color """ # These are the score cutoffs for each color above. # I.e. score==0 -> brightgreen, down to 100 < score <= ...
python
{ "resource": "" }
q258271
flake8_color
validation
def flake8_color(score): """Return flake8 badge color. Parameters ---------- score : float A flake8 score Returns ------- str Badge color """ # These are the score cutoffs for each color above. # I.e. score==0 -> brightgreen, down to 100 < score <= 200 -> orang...
python
{ "resource": "" }
q258272
Bag.dist_abs
validation
def dist_abs(self, src, tar): """Return the bag distance between two strings. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison Returns ------- int Bag distance ...
python
{ "resource": "" }
q258273
Bag.dist
validation
def dist(self, src, tar): """Return the normalized bag distance between two strings. Bag distance is normalized by dividing by :math:`max( |src|, |tar| )`. Parameters ---------- src : str Source string for comparison tar : str Target string for c...
python
{ "resource": "" }
q258274
CLEFGermanPlus.stem
validation
def stem(self, word): """Return 'CLEF German stemmer plus' stem. Parameters ---------- word : str The word to stem Returns ------- str Word stem Examples -------- >>> stmr = CLEFGermanPlus() >>> clef_germa...
python
{ "resource": "" }
q258275
dist_mlipns
validation
def dist_mlipns(src, tar, threshold=0.25, max_mismatches=2): """Return the MLIPNS distance between two strings. This is a wrapper for :py:meth:`MLIPNS.dist`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison threshold : floa...
python
{ "resource": "" }
q258276
sim
validation
def sim(src, tar, method=sim_levenshtein): """Return a similarity of two strings. This is a generalized function for calling other similarity functions. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison method : function ...
python
{ "resource": "" }
q258277
dist
validation
def dist(src, tar, method=sim_levenshtein): """Return a distance between two strings. This is a generalized function for calling other distance functions. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison method : function ...
python
{ "resource": "" }
q258278
Porter._m_degree
validation
def _m_degree(self, term): """Return Porter helper function _m_degree value. m-degree is equal to the number of V to C transitions Parameters ---------- term : str The word for which to calculate the m-degree Returns ------- int ...
python
{ "resource": "" }
q258279
Porter._has_vowel
validation
def _has_vowel(self, term): """Return Porter helper function _has_vowel value. Parameters ---------- term : str The word to scan for vowels Returns ------- bool True iff a vowel exists in the term (as defined in the Porter ste...
python
{ "resource": "" }
q258280
Porter._ends_in_doubled_cons
validation
def _ends_in_doubled_cons(self, term): """Return Porter helper function _ends_in_doubled_cons value. Parameters ---------- term : str The word to check for a final doubled consonant Returns ------- bool True iff the stem ends in a doubled...
python
{ "resource": "" }
q258281
Porter._ends_in_cvc
validation
def _ends_in_cvc(self, term): """Return Porter helper function _ends_in_cvc value. Parameters ---------- term : str The word to scan for cvc Returns ------- bool True iff the stem ends in cvc (as defined in the Porter stemmer ...
python
{ "resource": "" }
q258282
filter_symlog
validation
def filter_symlog(y, base=10.0): """Symmetrical logarithmic scale. Optional arguments: *base*: The base of the logarithm. """ log_base = np.log(base) sign = np.sign(y) logs = np.log(np.abs(y) / log_base) return sign * logs
python
{ "resource": "" }
q258283
usage_function
validation
def usage_function(parser): """Show usage and available curve functions.""" parser.print_usage() print('') print('available functions:') for function in sorted(FUNCTION): doc = FUNCTION[function].__doc__.strip().splitlines()[0] print(' %-12s %s' % (function + ':', doc)) retur...
python
{ "resource": "" }
q258284
usage_palette
validation
def usage_palette(parser): """Show usage and available palettes.""" parser.print_usage() print('') print('available palettes:') for palette in sorted(PALETTE): print(' %-12s' % (palette,)) return 0
python
{ "resource": "" }
q258285
Terminal.size
validation
def size(self): """Get the current terminal size.""" for fd in range(3): cr = self._ioctl_GWINSZ(fd) if cr: break if not cr: try: fd = os.open(os.ctermid(), os.O_RDONLY) cr = self._ioctl_GWINSZ(fd) ...
python
{ "resource": "" }
q258286
Terminal.color
validation
def color(self, index): """Get the escape sequence for indexed color ``index``. The ``index`` is a color index in the 256 color space. The color space consists of: * 0x00-0x0f: default EGA colors * 0x10-0xe7: 6x6x6 RGB cubes * 0xe8-0xff: gray scale ramp """ ...
python
{ "resource": "" }
q258287
Terminal.csi
validation
def csi(self, capname, *args): """Return the escape sequence for the selected Control Sequence.""" value = curses.tigetstr(capname) if value is None: return b'' else: return curses.tparm(value, *args)
python
{ "resource": "" }
q258288
Terminal.csi_wrap
validation
def csi_wrap(self, value, capname, *args): """Return a value wrapped in the selected CSI and does a reset.""" if isinstance(value, str): value = value.encode('utf-8') return b''.join([ self.csi(capname, *args), value, self.csi('sgr0'), ])
python
{ "resource": "" }
q258289
Graph.consume
validation
def consume(self, istream, ostream, batch=False): """Read points from istream and output to ostream.""" datapoints = [] # List of 2-tuples if batch: sleep = max(0.01, self.option.sleep) fd = istream.fileno() while True: try: ...
python
{ "resource": "" }
q258290
Graph.consume_line
validation
def consume_line(self, line): """Consume data from a line.""" data = RE_VALUE_KEY.split(line.strip(), 1) if len(data) == 1: return float(data[0]), None else: return float(data[0]), data[1].strip()
python
{ "resource": "" }
q258291
Graph.update
validation
def update(self, points, values=None): """Add a set of data points.""" self.values = values or [None] * len(points) if np is None: if self.option.function: warnings.warn('numpy not available, function ignored') self.points = points self.minimu...
python
{ "resource": "" }
q258292
Graph.color_ramp
validation
def color_ramp(self, size): """Generate a color ramp for the current screen height.""" color = PALETTE.get(self.option.palette, {}) color = color.get(self.term.colors, None) color_ramp = [] if color is not None: ratio = len(color) / float(size) for i in ra...
python
{ "resource": "" }
q258293
Graph.human
validation
def human(self, size, base=1000, units=' kMGTZ'): """Convert the input ``size`` to human readable, short form.""" sign = '+' if size >= 0 else '-' size = abs(size) if size < 1000: return '%s%d' % (sign, size) for i, suffix in enumerate(units): unit = 1000 ...
python
{ "resource": "" }
q258294
Graph.apply_function
validation
def apply_function(self, points): """Run the filter function on the provided points.""" if not self.option.function: return points if np is None: raise ImportError('numpy is not available') if ':' in self.option.function: function, arguments = self.o...
python
{ "resource": "" }
q258295
Graph.line
validation
def line(self, p1, p2, resolution=1): """Resolve the points to make a line between two points.""" xdiff = max(p1.x, p2.x) - min(p1.x, p2.x) ydiff = max(p1.y, p2.y) - min(p1.y, p2.y) xdir = [-1, 1][int(p1.x <= p2.x)] ydir = [-1, 1][int(p1.y <= p2.y)] r = int(round(max(xdif...
python
{ "resource": "" }
q258296
Graph.set_text
validation
def set_text(self, point, text): """Set a text value in the screen canvas.""" if not self.option.legend: return if not isinstance(point, Point): point = Point(point) for offset, char in enumerate(str(text)): self.screen.canvas[point.y][point.x + offs...
python
{ "resource": "" }
q258297
AxisGraph.render
validation
def render(self, stream): """Render graph to stream.""" encoding = self.option.encoding or self.term.encoding or "utf8" if self.option.color: ramp = self.color_ramp(self.size.y)[::-1] else: ramp = None if self.cycle >= 1 and self.lines: strea...
python
{ "resource": "" }
q258298
AxisGraph._normalised_numpy
validation
def _normalised_numpy(self): """Normalised data points using numpy.""" dx = (self.screen.width / float(len(self.points))) oy = (self.screen.height) points = np.array(self.points) - self.minimum points = points * 4.0 / self.extents * self.size.y for x, y in enumerate(point...
python
{ "resource": "" }
q258299
AxisGraph._normalised_python
validation
def _normalised_python(self): """Normalised data points using pure Python.""" dx = (self.screen.width / float(len(self.points))) oy = (self.screen.height) for x, point in enumerate(self.points): y = (point - self.minimum) * 4.0 / self.extents * self.size.y yield P...
python
{ "resource": "" }