repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
MartinThoma/hwrt
hwrt/create_ffiles.py
training_set_multiplication
def training_set_multiplication(training_set, mult_queue): """ Multiply the training set by all methods listed in mult_queue. Parameters ---------- training_set : set of all recordings that will be used for training mult_queue : list of all algorithms that will take one recordin...
python
def training_set_multiplication(training_set, mult_queue): """ Multiply the training set by all methods listed in mult_queue. Parameters ---------- training_set : set of all recordings that will be used for training mult_queue : list of all algorithms that will take one recordin...
[ "def", "training_set_multiplication", "(", "training_set", ",", "mult_queue", ")", ":", "logging", ".", "info", "(", "\"Multiply data...\"", ")", "for", "algorithm", "in", "mult_queue", ":", "new_trning_set", "=", "[", "]", "for", "recording", "in", "training_set"...
Multiply the training set by all methods listed in mult_queue. Parameters ---------- training_set : set of all recordings that will be used for training mult_queue : list of all algorithms that will take one recording and generate more than one. Returns ------- mutl...
[ "Multiply", "the", "training", "set", "by", "all", "methods", "listed", "in", "mult_queue", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/create_ffiles.py#L163-L192
train
59,300
MartinThoma/hwrt
hwrt/create_ffiles.py
_calculate_feature_stats
def _calculate_feature_stats(feature_list, prepared, serialization_file): # pylint: disable=R0914 """Calculate min, max and mean for each feature. Store it in object.""" # Create feature only list feats = [x for x, _ in prepared] # Label is not necessary # Calculate all means / mins / maxs means ...
python
def _calculate_feature_stats(feature_list, prepared, serialization_file): # pylint: disable=R0914 """Calculate min, max and mean for each feature. Store it in object.""" # Create feature only list feats = [x for x, _ in prepared] # Label is not necessary # Calculate all means / mins / maxs means ...
[ "def", "_calculate_feature_stats", "(", "feature_list", ",", "prepared", ",", "serialization_file", ")", ":", "# pylint: disable=R0914", "# Create feature only list", "feats", "=", "[", "x", "for", "x", ",", "_", "in", "prepared", "]", "# Label is not necessary", "# C...
Calculate min, max and mean for each feature. Store it in object.
[ "Calculate", "min", "max", "and", "mean", "for", "each", "feature", ".", "Store", "it", "in", "object", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/create_ffiles.py#L267-L299
train
59,301
MartinThoma/hwrt
hwrt/create_ffiles.py
make_hdf5
def make_hdf5(dataset_name, feature_count, data, output_filename, create_learning_curve): """ Create the hdf5 file. Parameters ---------- filename : name of the file that hdf5_create will use to create the hdf5 file. feature_count : integer number of features d...
python
def make_hdf5(dataset_name, feature_count, data, output_filename, create_learning_curve): """ Create the hdf5 file. Parameters ---------- filename : name of the file that hdf5_create will use to create the hdf5 file. feature_count : integer number of features d...
[ "def", "make_hdf5", "(", "dataset_name", ",", "feature_count", ",", "data", ",", "output_filename", ",", "create_learning_curve", ")", ":", "# create raw data file for hdf5_create", "if", "dataset_name", "==", "\"traindata\"", "and", "create_learning_curve", ":", "max_tra...
Create the hdf5 file. Parameters ---------- filename : name of the file that hdf5_create will use to create the hdf5 file. feature_count : integer number of features data : list of tuples data format ('feature_string', 'label')
[ "Create", "the", "hdf5", "file", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/create_ffiles.py#L354-L390
train
59,302
MartinThoma/hwrt
hwrt/segmentation/segmentation.py
get_dataset
def get_dataset(): """Create a dataset for machine learning of segmentations. Returns ------- tuple : (X, y) where X is a list of tuples. Each tuple is a feature. y is a list of labels (0 for 'not in one symbol' and 1 for 'in symbol') """ seg_data = "segmentation-X.npy" seg_...
python
def get_dataset(): """Create a dataset for machine learning of segmentations. Returns ------- tuple : (X, y) where X is a list of tuples. Each tuple is a feature. y is a list of labels (0 for 'not in one symbol' and 1 for 'in symbol') """ seg_data = "segmentation-X.npy" seg_...
[ "def", "get_dataset", "(", ")", ":", "seg_data", "=", "\"segmentation-X.npy\"", "seg_labels", "=", "\"segmentation-y.npy\"", "# seg_ids = \"segmentation-ids.npy\"", "if", "os", ".", "path", ".", "isfile", "(", "seg_data", ")", "and", "os", ".", "path", ".", "isfil...
Create a dataset for machine learning of segmentations. Returns ------- tuple : (X, y) where X is a list of tuples. Each tuple is a feature. y is a list of labels (0 for 'not in one symbol' and 1 for 'in symbol')
[ "Create", "a", "dataset", "for", "machine", "learning", "of", "segmentations", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L169-L217
train
59,303
MartinThoma/hwrt
hwrt/segmentation/segmentation.py
get_segmented_raw_data
def get_segmented_raw_data(top_n=10000): """Fetch data from the server. Parameters ---------- top_n : int Number of data sets which get fetched from the server. """ cfg = utils.get_database_configuration() mysql = cfg['mysql_online'] connection = pymysql.connect(host=mysql['host...
python
def get_segmented_raw_data(top_n=10000): """Fetch data from the server. Parameters ---------- top_n : int Number of data sets which get fetched from the server. """ cfg = utils.get_database_configuration() mysql = cfg['mysql_online'] connection = pymysql.connect(host=mysql['host...
[ "def", "get_segmented_raw_data", "(", "top_n", "=", "10000", ")", ":", "cfg", "=", "utils", ".", "get_database_configuration", "(", ")", "mysql", "=", "cfg", "[", "'mysql_online'", "]", "connection", "=", "pymysql", ".", "connect", "(", "host", "=", "mysql",...
Fetch data from the server. Parameters ---------- top_n : int Number of data sets which get fetched from the server.
[ "Fetch", "data", "from", "the", "server", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L248-L282
train
59,304
MartinThoma/hwrt
hwrt/segmentation/segmentation.py
get_stroke_features
def get_stroke_features(recording, strokeid1, strokeid2): """Get the features used to decide if two strokes belong to the same symbol or not. Parameters ---------- recording : list A list of strokes strokeid1 : int strokeid2 : int Returns ------- list : A list o...
python
def get_stroke_features(recording, strokeid1, strokeid2): """Get the features used to decide if two strokes belong to the same symbol or not. Parameters ---------- recording : list A list of strokes strokeid1 : int strokeid2 : int Returns ------- list : A list o...
[ "def", "get_stroke_features", "(", "recording", ",", "strokeid1", ",", "strokeid2", ")", ":", "stroke1", "=", "recording", "[", "strokeid1", "]", "stroke2", "=", "recording", "[", "strokeid2", "]", "assert", "isinstance", "(", "stroke1", ",", "list", ")", ",...
Get the features used to decide if two strokes belong to the same symbol or not. Parameters ---------- recording : list A list of strokes strokeid1 : int strokeid2 : int Returns ------- list : A list of features which could be useful to decide if stroke1 and ...
[ "Get", "the", "features", "used", "to", "decide", "if", "two", "strokes", "belong", "to", "the", "same", "symbol", "or", "not", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L472-L505
train
59,305
MartinThoma/hwrt
hwrt/segmentation/segmentation.py
get_segmentation
def get_segmentation(recording, single_clf, single_stroke_clf, stroke_segmented_classifier): """ Get a list of segmentations of recording with the probability of the segmentation being correct. Parameters ---------- recording : A li...
python
def get_segmentation(recording, single_clf, single_stroke_clf, stroke_segmented_classifier): """ Get a list of segmentations of recording with the probability of the segmentation being correct. Parameters ---------- recording : A li...
[ "def", "get_segmentation", "(", "recording", ",", "single_clf", ",", "single_stroke_clf", ",", "stroke_segmented_classifier", ")", ":", "mst_wood", "=", "get_mst_wood", "(", "recording", ",", "single_clf", ")", "return", "[", "(", "normalize_segmentation", "(", "[",...
Get a list of segmentations of recording with the probability of the segmentation being correct. Parameters ---------- recording : A list of lists Each sublist represents a stroke single_clf : object A classifier for single symbols single_stroke_clf : object A classifier...
[ "Get", "a", "list", "of", "segmentations", "of", "recording", "with", "the", "probability", "of", "the", "segmentation", "being", "correct", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L574-L667
train
59,306
MartinThoma/hwrt
hwrt/segmentation/segmentation.py
break_mst
def break_mst(mst, i): """ Break mst into multiple MSTs by removing one node i. Parameters ---------- mst : symmetrical square matrix i : index of the mst where to break Returns ------- list of dictionarys ('mst' and 'strokes' are the keys) """ for j in range(len(mst['mst']...
python
def break_mst(mst, i): """ Break mst into multiple MSTs by removing one node i. Parameters ---------- mst : symmetrical square matrix i : index of the mst where to break Returns ------- list of dictionarys ('mst' and 'strokes' are the keys) """ for j in range(len(mst['mst']...
[ "def", "break_mst", "(", "mst", ",", "i", ")", ":", "for", "j", "in", "range", "(", "len", "(", "mst", "[", "'mst'", "]", ")", ")", ":", "mst", "[", "'mst'", "]", "[", "i", "]", "[", "j", "]", "=", "0", "mst", "[", "'mst'", "]", "[", "j",...
Break mst into multiple MSTs by removing one node i. Parameters ---------- mst : symmetrical square matrix i : index of the mst where to break Returns ------- list of dictionarys ('mst' and 'strokes' are the keys)
[ "Break", "mst", "into", "multiple", "MSTs", "by", "removing", "one", "node", "i", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L784-L832
train
59,307
MartinThoma/hwrt
hwrt/segmentation/segmentation.py
_is_out_of_order
def _is_out_of_order(segmentation): """ Check if a given segmentation is out of order. Examples -------- >>> _is_out_of_order([[0, 1, 2, 3]]) False >>> _is_out_of_order([[0, 1], [2, 3]]) False >>> _is_out_of_order([[0, 1, 3], [2]]) True """ last_stroke = -1 for symbo...
python
def _is_out_of_order(segmentation): """ Check if a given segmentation is out of order. Examples -------- >>> _is_out_of_order([[0, 1, 2, 3]]) False >>> _is_out_of_order([[0, 1], [2, 3]]) False >>> _is_out_of_order([[0, 1, 3], [2]]) True """ last_stroke = -1 for symbo...
[ "def", "_is_out_of_order", "(", "segmentation", ")", ":", "last_stroke", "=", "-", "1", "for", "symbol", "in", "segmentation", ":", "for", "stroke", "in", "symbol", ":", "if", "last_stroke", ">", "stroke", ":", "return", "True", "last_stroke", "=", "stroke",...
Check if a given segmentation is out of order. Examples -------- >>> _is_out_of_order([[0, 1, 2, 3]]) False >>> _is_out_of_order([[0, 1], [2, 3]]) False >>> _is_out_of_order([[0, 1, 3], [2]]) True
[ "Check", "if", "a", "given", "segmentation", "is", "out", "of", "order", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L835-L854
train
59,308
MartinThoma/hwrt
hwrt/segmentation/segmentation.py
get_bb_intersections
def get_bb_intersections(recording): """ Get all intersections of the bounding boxes of strokes. Parameters ---------- recording : list of lists of integers Returns ------- A symmetrical matrix which indicates if two bounding boxes intersect. """ intersections = numpy.zeros((le...
python
def get_bb_intersections(recording): """ Get all intersections of the bounding boxes of strokes. Parameters ---------- recording : list of lists of integers Returns ------- A symmetrical matrix which indicates if two bounding boxes intersect. """ intersections = numpy.zeros((le...
[ "def", "get_bb_intersections", "(", "recording", ")", ":", "intersections", "=", "numpy", ".", "zeros", "(", "(", "len", "(", "recording", ")", ",", "len", "(", "recording", ")", ")", ",", "dtype", "=", "bool", ")", "for", "i", "in", "range", "(", "l...
Get all intersections of the bounding boxes of strokes. Parameters ---------- recording : list of lists of integers Returns ------- A symmetrical matrix which indicates if two bounding boxes intersect.
[ "Get", "all", "intersections", "of", "the", "bounding", "boxes", "of", "strokes", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/segmentation.py#L1006-L1026
train
59,309
MartinThoma/hwrt
hwrt/segmentation/beam.py
p_strokes
def p_strokes(symbol, count): """ Get the probability of a written `symbol` having `count` strokes. Parameters ---------- symbol : str LaTeX command count : int, >= 1 Returns ------- float In [0.0, 1.0] """ global stroke_prob assert count >= 1 epsilo...
python
def p_strokes(symbol, count): """ Get the probability of a written `symbol` having `count` strokes. Parameters ---------- symbol : str LaTeX command count : int, >= 1 Returns ------- float In [0.0, 1.0] """ global stroke_prob assert count >= 1 epsilo...
[ "def", "p_strokes", "(", "symbol", ",", "count", ")", ":", "global", "stroke_prob", "assert", "count", ">=", "1", "epsilon", "=", "0.00000001", "if", "stroke_prob", "is", "None", ":", "misc_path", "=", "pkg_resources", ".", "resource_filename", "(", "'hwrt'", ...
Get the probability of a written `symbol` having `count` strokes. Parameters ---------- symbol : str LaTeX command count : int, >= 1 Returns ------- float In [0.0, 1.0]
[ "Get", "the", "probability", "of", "a", "written", "symbol", "having", "count", "strokes", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/beam.py#L32-L61
train
59,310
MartinThoma/hwrt
hwrt/segmentation/beam.py
Beam._add_hypotheses_assuming_new_stroke
def _add_hypotheses_assuming_new_stroke(self, new_stroke, stroke_nr, new_beam): """ Get new guesses by assuming new_stroke is a new symbol. Parameters ----...
python
def _add_hypotheses_assuming_new_stroke(self, new_stroke, stroke_nr, new_beam): """ Get new guesses by assuming new_stroke is a new symbol. Parameters ----...
[ "def", "_add_hypotheses_assuming_new_stroke", "(", "self", ",", "new_stroke", ",", "stroke_nr", ",", "new_beam", ")", ":", "guesses", "=", "single_clf", ".", "predict", "(", "{", "'data'", ":", "[", "new_stroke", "]", ",", "'id'", ":", "None", "}", ")", "[...
Get new guesses by assuming new_stroke is a new symbol. Parameters ---------- new_stroke : list of dicts A list of dicts [{'x': 12, 'y': 34, 'time': 56}, ...] which represent a point. stroke_nr : int Number of the stroke for segmentation new_b...
[ "Get", "new", "guesses", "by", "assuming", "new_stroke", "is", "a", "new", "symbol", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/beam.py#L137-L189
train
59,311
MartinThoma/hwrt
hwrt/segmentation/beam.py
Beam.add_stroke
def add_stroke(self, new_stroke): """ Update the beam so that it considers `new_stroke`. When a `new_stroke` comes, it can either belong to a symbol for which at least one other stroke was already made or belong to a symbol for which `new_stroke` is the first stroke. Th...
python
def add_stroke(self, new_stroke): """ Update the beam so that it considers `new_stroke`. When a `new_stroke` comes, it can either belong to a symbol for which at least one other stroke was already made or belong to a symbol for which `new_stroke` is the first stroke. Th...
[ "def", "add_stroke", "(", "self", ",", "new_stroke", ")", ":", "global", "single_clf", "if", "len", "(", "self", ".", "hypotheses", ")", "==", "0", ":", "# Don't put this in the constructor!", "self", ".", "hypotheses", "=", "[", "{", "'segmentation'", ":", ...
Update the beam so that it considers `new_stroke`. When a `new_stroke` comes, it can either belong to a symbol for which at least one other stroke was already made or belong to a symbol for which `new_stroke` is the first stroke. The number of hypotheses after q strokes without pruning...
[ "Update", "the", "beam", "so", "that", "it", "considers", "new_stroke", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/beam.py#L191-L295
train
59,312
MartinThoma/hwrt
hwrt/segmentation/beam.py
Beam._prune
def _prune(self): """Shorten hypotheses to the best k ones.""" self.hypotheses = sorted(self.hypotheses, key=lambda e: e['probability'], reverse=True)[:self.k]
python
def _prune(self): """Shorten hypotheses to the best k ones.""" self.hypotheses = sorted(self.hypotheses, key=lambda e: e['probability'], reverse=True)[:self.k]
[ "def", "_prune", "(", "self", ")", ":", "self", ".", "hypotheses", "=", "sorted", "(", "self", ".", "hypotheses", ",", "key", "=", "lambda", "e", ":", "e", "[", "'probability'", "]", ",", "reverse", "=", "True", ")", "[", ":", "self", ".", "k", "...
Shorten hypotheses to the best k ones.
[ "Shorten", "hypotheses", "to", "the", "best", "k", "ones", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/segmentation/beam.py#L297-L301
train
59,313
MartinThoma/hwrt
bin/convert_cuda2numpy.py
get_matrices
def get_matrices(): """ Get the matrices from a pickled files. Returns ------- list List of all matrices. """ with open('hwrt/misc/is_one_symbol_classifier.pickle', 'rb') as f: a = pickle.load(f) arrays = [] for el1 in a.input_storage: for el2 in el1.__dict_...
python
def get_matrices(): """ Get the matrices from a pickled files. Returns ------- list List of all matrices. """ with open('hwrt/misc/is_one_symbol_classifier.pickle', 'rb') as f: a = pickle.load(f) arrays = [] for el1 in a.input_storage: for el2 in el1.__dict_...
[ "def", "get_matrices", "(", ")", ":", "with", "open", "(", "'hwrt/misc/is_one_symbol_classifier.pickle'", ",", "'rb'", ")", "as", "f", ":", "a", "=", "pickle", ".", "load", "(", "f", ")", "arrays", "=", "[", "]", "for", "el1", "in", "a", ".", "input_st...
Get the matrices from a pickled files. Returns ------- list List of all matrices.
[ "Get", "the", "matrices", "from", "a", "pickled", "files", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/bin/convert_cuda2numpy.py#L32-L53
train
59,314
MartinThoma/hwrt
bin/convert_cuda2numpy.py
create_model_tar
def create_model_tar(matrices, tarname="model-cuda-converted.tar"): """ Create a tar file which contains the model. Parameters ---------- matrices : list tarname : str Target file which will be created. """ # Write layers filenames = [] for layer in range(len(matrices)):...
python
def create_model_tar(matrices, tarname="model-cuda-converted.tar"): """ Create a tar file which contains the model. Parameters ---------- matrices : list tarname : str Target file which will be created. """ # Write layers filenames = [] for layer in range(len(matrices)):...
[ "def", "create_model_tar", "(", "matrices", ",", "tarname", "=", "\"model-cuda-converted.tar\"", ")", ":", "# Write layers", "filenames", "=", "[", "]", "for", "layer", "in", "range", "(", "len", "(", "matrices", ")", ")", ":", "if", "matrices", "[", "layer"...
Create a tar file which contains the model. Parameters ---------- matrices : list tarname : str Target file which will be created.
[ "Create", "a", "tar", "file", "which", "contains", "the", "model", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/bin/convert_cuda2numpy.py#L56-L96
train
59,315
MartinThoma/hwrt
hwrt/selfcheck.py
check_python_version
def check_python_version(): """Check if the currently running Python version is new enough.""" # Required due to multiple with statements on one line req_version = (2, 7) cur_version = sys.version_info if cur_version >= req_version: print("Python version... %sOK%s (found %s, requires %s)" % ...
python
def check_python_version(): """Check if the currently running Python version is new enough.""" # Required due to multiple with statements on one line req_version = (2, 7) cur_version = sys.version_info if cur_version >= req_version: print("Python version... %sOK%s (found %s, requires %s)" % ...
[ "def", "check_python_version", "(", ")", ":", "# Required due to multiple with statements on one line", "req_version", "=", "(", "2", ",", "7", ")", "cur_version", "=", "sys", ".", "version_info", "if", "cur_version", ">=", "req_version", ":", "print", "(", "\"Pytho...
Check if the currently running Python version is new enough.
[ "Check", "if", "the", "currently", "running", "Python", "version", "is", "new", "enough", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/selfcheck.py#L48-L60
train
59,316
MartinThoma/hwrt
hwrt/selfcheck.py
main
def main(): """Execute all checks.""" check_python_version() check_python_modules() check_executables() home = os.path.expanduser("~") print("\033[1mCheck files\033[0m") rcfile = os.path.join(home, ".hwrtrc") if os.path.isfile(rcfile): print("~/.hwrtrc... %sFOUND%s" % ...
python
def main(): """Execute all checks.""" check_python_version() check_python_modules() check_executables() home = os.path.expanduser("~") print("\033[1mCheck files\033[0m") rcfile = os.path.join(home, ".hwrtrc") if os.path.isfile(rcfile): print("~/.hwrtrc... %sFOUND%s" % ...
[ "def", "main", "(", ")", ":", "check_python_version", "(", ")", "check_python_modules", "(", ")", "check_executables", "(", ")", "home", "=", "os", ".", "path", ".", "expanduser", "(", "\"~\"", ")", "print", "(", "\"\\033[1mCheck files\\033[0m\"", ")", "rcfile...
Execute all checks.
[ "Execute", "all", "checks", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/selfcheck.py#L136-L151
train
59,317
MartinThoma/hwrt
bin/merge.py
merge
def merge(d1, d2): """Merge two raw datasets into one. Parameters ---------- d1 : dict d2 : dict Returns ------- dict """ if d1['formula_id2latex'] is None: formula_id2latex = {} else: formula_id2latex = d1['formula_id2latex'].copy() formula_id2latex.upd...
python
def merge(d1, d2): """Merge two raw datasets into one. Parameters ---------- d1 : dict d2 : dict Returns ------- dict """ if d1['formula_id2latex'] is None: formula_id2latex = {} else: formula_id2latex = d1['formula_id2latex'].copy() formula_id2latex.upd...
[ "def", "merge", "(", "d1", ",", "d2", ")", ":", "if", "d1", "[", "'formula_id2latex'", "]", "is", "None", ":", "formula_id2latex", "=", "{", "}", "else", ":", "formula_id2latex", "=", "d1", "[", "'formula_id2latex'", "]", ".", "copy", "(", ")", "formul...
Merge two raw datasets into one. Parameters ---------- d1 : dict d2 : dict Returns ------- dict
[ "Merge", "two", "raw", "datasets", "into", "one", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/bin/merge.py#L37-L58
train
59,318
MartinThoma/hwrt
hwrt/download.py
is_file_consistent
def is_file_consistent(local_path_file, md5_hash): """Check if file is there and if the md5_hash is correct.""" return os.path.isfile(local_path_file) and \ hashlib.md5(open(local_path_file, 'rb').read()).hexdigest() == md5_hash
python
def is_file_consistent(local_path_file, md5_hash): """Check if file is there and if the md5_hash is correct.""" return os.path.isfile(local_path_file) and \ hashlib.md5(open(local_path_file, 'rb').read()).hexdigest() == md5_hash
[ "def", "is_file_consistent", "(", "local_path_file", ",", "md5_hash", ")", ":", "return", "os", ".", "path", ".", "isfile", "(", "local_path_file", ")", "and", "hashlib", ".", "md5", "(", "open", "(", "local_path_file", ",", "'rb'", ")", ".", "read", "(", ...
Check if file is there and if the md5_hash is correct.
[ "Check", "if", "file", "is", "there", "and", "if", "the", "md5_hash", "is", "correct", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/download.py#L18-L21
train
59,319
MartinThoma/hwrt
hwrt/download.py
main
def main(): """Main part of the download script.""" # Read config file. This has to get updated via git project_root = utils.get_project_root() infofile = os.path.join(project_root, "raw-datasets/info.yml") logging.info("Read '%s'...", infofile) with open(infofile, 'r') as ymlfile: datas...
python
def main(): """Main part of the download script.""" # Read config file. This has to get updated via git project_root = utils.get_project_root() infofile = os.path.join(project_root, "raw-datasets/info.yml") logging.info("Read '%s'...", infofile) with open(infofile, 'r') as ymlfile: datas...
[ "def", "main", "(", ")", ":", "# Read config file. This has to get updated via git", "project_root", "=", "utils", ".", "get_project_root", "(", ")", "infofile", "=", "os", ".", "path", ".", "join", "(", "project_root", ",", "\"raw-datasets/info.yml\"", ")", "loggin...
Main part of the download script.
[ "Main", "part", "of", "the", "download", "script", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/download.py#L32-L53
train
59,320
MartinThoma/hwrt
hwrt/language_model/language_model.py
load_model
def load_model(): """ Load a n-gram language model for mathematics in ARPA format which gets shipped with hwrt. Returns ------- A NgramLanguageModel object """ logging.info("Load language model...") ngram_arpa_t = pkg_resources.resource_filename('hwrt', ...
python
def load_model(): """ Load a n-gram language model for mathematics in ARPA format which gets shipped with hwrt. Returns ------- A NgramLanguageModel object """ logging.info("Load language model...") ngram_arpa_t = pkg_resources.resource_filename('hwrt', ...
[ "def", "load_model", "(", ")", ":", "logging", ".", "info", "(", "\"Load language model...\"", ")", "ngram_arpa_t", "=", "pkg_resources", ".", "resource_filename", "(", "'hwrt'", ",", "'misc/ngram.arpa.tar.bz2'", ")", "with", "tarfile", ".", "open", "(", "ngram_ar...
Load a n-gram language model for mathematics in ARPA format which gets shipped with hwrt. Returns ------- A NgramLanguageModel object
[ "Load", "a", "n", "-", "gram", "language", "model", "for", "mathematics", "in", "ARPA", "format", "which", "gets", "shipped", "with", "hwrt", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/language_model/language_model.py#L157-L177
train
59,321
MartinThoma/hwrt
hwrt/language_model/language_model.py
NgramLanguageModel.load_from_arpa_str
def load_from_arpa_str(self, arpa_str): """ Initialize N-gram model by reading an ARPA language model string. Parameters ---------- arpa_str : str A string in ARPA language model file format """ data_found = False end_found = False in_...
python
def load_from_arpa_str(self, arpa_str): """ Initialize N-gram model by reading an ARPA language model string. Parameters ---------- arpa_str : str A string in ARPA language model file format """ data_found = False end_found = False in_...
[ "def", "load_from_arpa_str", "(", "self", ",", "arpa_str", ")", ":", "data_found", "=", "False", "end_found", "=", "False", "in_ngram_block", "=", "0", "for", "i", ",", "line", "in", "enumerate", "(", "arpa_str", ".", "split", "(", "\"\\n\"", ")", ")", "...
Initialize N-gram model by reading an ARPA language model string. Parameters ---------- arpa_str : str A string in ARPA language model file format
[ "Initialize", "N", "-", "gram", "model", "by", "reading", "an", "ARPA", "language", "model", "string", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/language_model/language_model.py#L23-L84
train
59,322
MartinThoma/hwrt
hwrt/language_model/language_model.py
NgramLanguageModel.get_probability
def get_probability(self, sentence): """ Calculate the probability of a sentence, given this language model. Get P(sentence) = P(w1, w2, w3, ..., wn) = P(w1, w2, w3) * P(w2, w3, w4) *...* P(wn-2, wn-1, wn) Parameters ---------- sentence : list ...
python
def get_probability(self, sentence): """ Calculate the probability of a sentence, given this language model. Get P(sentence) = P(w1, w2, w3, ..., wn) = P(w1, w2, w3) * P(w2, w3, w4) *...* P(wn-2, wn-1, wn) Parameters ---------- sentence : list ...
[ "def", "get_probability", "(", "self", ",", "sentence", ")", ":", "if", "len", "(", "sentence", ")", "==", "1", ":", "return", "Decimal", "(", "10", ")", "**", "self", ".", "get_unigram_log_prob", "(", "sentence", ")", "elif", "len", "(", "sentence", "...
Calculate the probability of a sentence, given this language model. Get P(sentence) = P(w1, w2, w3, ..., wn) = P(w1, w2, w3) * P(w2, w3, w4) *...* P(wn-2, wn-1, wn) Parameters ---------- sentence : list A list of strings / tokens.
[ "Calculate", "the", "probability", "of", "a", "sentence", "given", "this", "language", "model", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/language_model/language_model.py#L128-L148
train
59,323
MartinThoma/hwrt
hwrt/datasets/crohme_eval.py
evaluate_dir
def evaluate_dir(sample_dir): """Evaluate all recordings in `sample_dir`. Parameters ---------- sample_dir : string The path to a directory with *.inkml files. Returns ------- list of dictionaries Each dictionary contains the keys 'filename' and 'results', where 're...
python
def evaluate_dir(sample_dir): """Evaluate all recordings in `sample_dir`. Parameters ---------- sample_dir : string The path to a directory with *.inkml files. Returns ------- list of dictionaries Each dictionary contains the keys 'filename' and 'results', where 're...
[ "def", "evaluate_dir", "(", "sample_dir", ")", ":", "results", "=", "[", "]", "if", "sample_dir", "[", "-", "1", "]", "==", "\"/\"", ":", "sample_dir", "=", "sample_dir", "[", ":", "-", "1", "]", "for", "filename", "in", "glob", ".", "glob", "(", "...
Evaluate all recordings in `sample_dir`. Parameters ---------- sample_dir : string The path to a directory with *.inkml files. Returns ------- list of dictionaries Each dictionary contains the keys 'filename' and 'results', where 'results' itself is a list of dictionari...
[ "Evaluate", "all", "recordings", "in", "sample_dir", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/datasets/crohme_eval.py#L21-L41
train
59,324
MartinThoma/hwrt
hwrt/datasets/crohme_eval.py
evaluate_inkml
def evaluate_inkml(inkml_file_path): """Evaluate an InkML file. Parameters ---------- inkml_file_path : string path to an InkML file Returns ------- dictionary The dictionary contains the keys 'filename' and 'results', where 'results' itself is a list of dictionarie...
python
def evaluate_inkml(inkml_file_path): """Evaluate an InkML file. Parameters ---------- inkml_file_path : string path to an InkML file Returns ------- dictionary The dictionary contains the keys 'filename' and 'results', where 'results' itself is a list of dictionarie...
[ "def", "evaluate_inkml", "(", "inkml_file_path", ")", ":", "logging", ".", "info", "(", "\"Start evaluating '%s'...\"", ",", "inkml_file_path", ")", "ret", "=", "{", "'filename'", ":", "inkml_file_path", "}", "recording", "=", "inkml", ".", "read", "(", "inkml_f...
Evaluate an InkML file. Parameters ---------- inkml_file_path : string path to an InkML file Returns ------- dictionary The dictionary contains the keys 'filename' and 'results', where 'results' itself is a list of dictionaries. Each of the results has the keys ...
[ "Evaluate", "an", "InkML", "file", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/datasets/crohme_eval.py#L44-L65
train
59,325
MartinThoma/hwrt
hwrt/datasets/crohme_eval.py
generate_output_csv
def generate_output_csv(evaluation_results, filename='results.csv'): """Generate the evaluation results in the format Parameters ---------- evaluation_results : list of dictionaries Each dictionary contains the keys 'filename' and 'results', where 'results' itself is a list of dictionar...
python
def generate_output_csv(evaluation_results, filename='results.csv'): """Generate the evaluation results in the format Parameters ---------- evaluation_results : list of dictionaries Each dictionary contains the keys 'filename' and 'results', where 'results' itself is a list of dictionar...
[ "def", "generate_output_csv", "(", "evaluation_results", ",", "filename", "=", "'results.csv'", ")", ":", "with", "open", "(", "filename", ",", "'w'", ")", "as", "f", ":", "for", "result", "in", "evaluation_results", ":", "for", "i", ",", "entry", "in", "e...
Generate the evaluation results in the format Parameters ---------- evaluation_results : list of dictionaries Each dictionary contains the keys 'filename' and 'results', where 'results' itself is a list of dictionaries. Each of the results has the keys 'latex' and 'probability' ...
[ "Generate", "the", "evaluation", "results", "in", "the", "format" ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/datasets/crohme_eval.py#L68-L95
train
59,326
MartinThoma/hwrt
hwrt/utils.py
get_project_configuration
def get_project_configuration(): """Get project configuration as dictionary.""" home = os.path.expanduser("~") rcfile = os.path.join(home, ".hwrtrc") if not os.path.isfile(rcfile): create_project_configuration(rcfile) with open(rcfile, 'r') as ymlfile: cfg = yaml.load(ymlfile) re...
python
def get_project_configuration(): """Get project configuration as dictionary.""" home = os.path.expanduser("~") rcfile = os.path.join(home, ".hwrtrc") if not os.path.isfile(rcfile): create_project_configuration(rcfile) with open(rcfile, 'r') as ymlfile: cfg = yaml.load(ymlfile) re...
[ "def", "get_project_configuration", "(", ")", ":", "home", "=", "os", ".", "path", ".", "expanduser", "(", "\"~\"", ")", "rcfile", "=", "os", ".", "path", ".", "join", "(", "home", ",", "\".hwrtrc\"", ")", "if", "not", "os", ".", "path", ".", "isfile...
Get project configuration as dictionary.
[ "Get", "project", "configuration", "as", "dictionary", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L73-L81
train
59,327
MartinThoma/hwrt
hwrt/utils.py
create_project_configuration
def create_project_configuration(filename): """Create a project configuration file which contains a configuration that might make sense.""" home = os.path.expanduser("~") project_root_folder = os.path.join(home, "hwr-experiments") config = {'root': project_root_folder, 'nntoolkit': ...
python
def create_project_configuration(filename): """Create a project configuration file which contains a configuration that might make sense.""" home = os.path.expanduser("~") project_root_folder = os.path.join(home, "hwr-experiments") config = {'root': project_root_folder, 'nntoolkit': ...
[ "def", "create_project_configuration", "(", "filename", ")", ":", "home", "=", "os", ".", "path", ".", "expanduser", "(", "\"~\"", ")", "project_root_folder", "=", "os", ".", "path", ".", "join", "(", "home", ",", "\"hwr-experiments\"", ")", "config", "=", ...
Create a project configuration file which contains a configuration that might make sense.
[ "Create", "a", "project", "configuration", "file", "which", "contains", "a", "configuration", "that", "might", "make", "sense", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L84-L98
train
59,328
MartinThoma/hwrt
hwrt/utils.py
get_project_root
def get_project_root(): """Get the project root folder as a string.""" cfg = get_project_configuration() # At this point it can be sure that the configuration file exists # Now make sure the project structure exists for dirname in ["raw-datasets", "preprocessed", ...
python
def get_project_root(): """Get the project root folder as a string.""" cfg = get_project_configuration() # At this point it can be sure that the configuration file exists # Now make sure the project structure exists for dirname in ["raw-datasets", "preprocessed", ...
[ "def", "get_project_root", "(", ")", ":", "cfg", "=", "get_project_configuration", "(", ")", "# At this point it can be sure that the configuration file exists", "# Now make sure the project structure exists", "for", "dirname", "in", "[", "\"raw-datasets\"", ",", "\"preprocessed\...
Get the project root folder as a string.
[ "Get", "the", "project", "root", "folder", "as", "a", "string", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L101-L140
train
59,329
MartinThoma/hwrt
hwrt/utils.py
get_template_folder
def get_template_folder(): """Get path to the folder where th HTML templates are.""" cfg = get_project_configuration() if 'templates' not in cfg: home = os.path.expanduser("~") rcfile = os.path.join(home, ".hwrtrc") cfg['templates'] = pkg_resources.resource_filename('hwrt', ...
python
def get_template_folder(): """Get path to the folder where th HTML templates are.""" cfg = get_project_configuration() if 'templates' not in cfg: home = os.path.expanduser("~") rcfile = os.path.join(home, ".hwrtrc") cfg['templates'] = pkg_resources.resource_filename('hwrt', ...
[ "def", "get_template_folder", "(", ")", ":", "cfg", "=", "get_project_configuration", "(", ")", "if", "'templates'", "not", "in", "cfg", ":", "home", "=", "os", ".", "path", ".", "expanduser", "(", "\"~\"", ")", "rcfile", "=", "os", ".", "path", ".", "...
Get path to the folder where th HTML templates are.
[ "Get", "path", "to", "the", "folder", "where", "th", "HTML", "templates", "are", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L143-L153
train
59,330
MartinThoma/hwrt
hwrt/utils.py
get_database_config_file
def get_database_config_file(): """Get the absolute path to the database configuration file.""" cfg = get_project_configuration() if 'dbconfig' in cfg: if os.path.isfile(cfg['dbconfig']): return cfg['dbconfig'] else: logging.info("File '%s' was not found. Adjust 'dbco...
python
def get_database_config_file(): """Get the absolute path to the database configuration file.""" cfg = get_project_configuration() if 'dbconfig' in cfg: if os.path.isfile(cfg['dbconfig']): return cfg['dbconfig'] else: logging.info("File '%s' was not found. Adjust 'dbco...
[ "def", "get_database_config_file", "(", ")", ":", "cfg", "=", "get_project_configuration", "(", ")", "if", "'dbconfig'", "in", "cfg", ":", "if", "os", ".", "path", ".", "isfile", "(", "cfg", "[", "'dbconfig'", "]", ")", ":", "return", "cfg", "[", "'dbcon...
Get the absolute path to the database configuration file.
[ "Get", "the", "absolute", "path", "to", "the", "database", "configuration", "file", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L192-L205
train
59,331
MartinThoma/hwrt
hwrt/utils.py
get_database_configuration
def get_database_configuration(): """Get database configuration as dictionary.""" db_config = get_database_config_file() if db_config is None: return None with open(db_config, 'r') as ymlfile: cfg = yaml.load(ymlfile) return cfg
python
def get_database_configuration(): """Get database configuration as dictionary.""" db_config = get_database_config_file() if db_config is None: return None with open(db_config, 'r') as ymlfile: cfg = yaml.load(ymlfile) return cfg
[ "def", "get_database_configuration", "(", ")", ":", "db_config", "=", "get_database_config_file", "(", ")", "if", "db_config", "is", "None", ":", "return", "None", "with", "open", "(", "db_config", ",", "'r'", ")", "as", "ymlfile", ":", "cfg", "=", "yaml", ...
Get database configuration as dictionary.
[ "Get", "database", "configuration", "as", "dictionary", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L208-L215
train
59,332
MartinThoma/hwrt
hwrt/utils.py
input_int_default
def input_int_default(question="", default=0): """A function that works for both, Python 2.x and Python 3.x. It asks the user for input and returns it as a string. """ answer = input_string(question) if answer == "" or answer == "yes": return default else: return int(answer)
python
def input_int_default(question="", default=0): """A function that works for both, Python 2.x and Python 3.x. It asks the user for input and returns it as a string. """ answer = input_string(question) if answer == "" or answer == "yes": return default else: return int(answer)
[ "def", "input_int_default", "(", "question", "=", "\"\"", ",", "default", "=", "0", ")", ":", "answer", "=", "input_string", "(", "question", ")", "if", "answer", "==", "\"\"", "or", "answer", "==", "\"yes\"", ":", "return", "default", "else", ":", "retu...
A function that works for both, Python 2.x and Python 3.x. It asks the user for input and returns it as a string.
[ "A", "function", "that", "works", "for", "both", "Python", "2", ".", "x", "and", "Python", "3", ".", "x", ".", "It", "asks", "the", "user", "for", "input", "and", "returns", "it", "as", "a", "string", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L236-L244
train
59,333
MartinThoma/hwrt
hwrt/utils.py
create_run_logfile
def create_run_logfile(folder): """Create a 'run.log' within folder. This file contains the time of the latest successful run. """ with open(os.path.join(folder, "run.log"), "w") as f: datestring = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") f.write("timestamp: '%s'" % da...
python
def create_run_logfile(folder): """Create a 'run.log' within folder. This file contains the time of the latest successful run. """ with open(os.path.join(folder, "run.log"), "w") as f: datestring = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") f.write("timestamp: '%s'" % da...
[ "def", "create_run_logfile", "(", "folder", ")", ":", "with", "open", "(", "os", ".", "path", ".", "join", "(", "folder", ",", "\"run.log\"", ")", ",", "\"w\"", ")", "as", "f", ":", "datestring", "=", "datetime", ".", "datetime", ".", "utcnow", "(", ...
Create a 'run.log' within folder. This file contains the time of the latest successful run.
[ "Create", "a", "run", ".", "log", "within", "folder", ".", "This", "file", "contains", "the", "time", "of", "the", "latest", "successful", "run", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L317-L323
train
59,334
MartinThoma/hwrt
hwrt/utils.py
choose_raw_dataset
def choose_raw_dataset(currently=""): """Let the user choose a raw dataset. Return the absolute path.""" folder = os.path.join(get_project_root(), "raw-datasets") files = [os.path.join(folder, name) for name in os.listdir(folder) if name.endswith(".pickle")] default = -1 for i, filename...
python
def choose_raw_dataset(currently=""): """Let the user choose a raw dataset. Return the absolute path.""" folder = os.path.join(get_project_root(), "raw-datasets") files = [os.path.join(folder, name) for name in os.listdir(folder) if name.endswith(".pickle")] default = -1 for i, filename...
[ "def", "choose_raw_dataset", "(", "currently", "=", "\"\"", ")", ":", "folder", "=", "os", ".", "path", ".", "join", "(", "get_project_root", "(", ")", ",", "\"raw-datasets\"", ")", "files", "=", "[", "os", ".", "path", ".", "join", "(", "folder", ",",...
Let the user choose a raw dataset. Return the absolute path.
[ "Let", "the", "user", "choose", "a", "raw", "dataset", ".", "Return", "the", "absolute", "path", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L326-L340
train
59,335
MartinThoma/hwrt
hwrt/utils.py
get_readable_time
def get_readable_time(t): """ Format the time to a readable format. Parameters ---------- t : int Time in ms Returns ------- string The time splitted to highest used time (minutes, hours, ...) """ ms = t % 1000 t -= ms t /= 1000 s = t % 60 t -= ...
python
def get_readable_time(t): """ Format the time to a readable format. Parameters ---------- t : int Time in ms Returns ------- string The time splitted to highest used time (minutes, hours, ...) """ ms = t % 1000 t -= ms t /= 1000 s = t % 60 t -= ...
[ "def", "get_readable_time", "(", "t", ")", ":", "ms", "=", "t", "%", "1000", "t", "-=", "ms", "t", "/=", "1000", "s", "=", "t", "%", "60", "t", "-=", "s", "t", "/=", "60", "minutes", "=", "t", "%", "60", "t", "-=", "minutes", "t", "/=", "60...
Format the time to a readable format. Parameters ---------- t : int Time in ms Returns ------- string The time splitted to highest used time (minutes, hours, ...)
[ "Format", "the", "time", "to", "a", "readable", "format", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L343-L376
train
59,336
MartinThoma/hwrt
hwrt/utils.py
default_model
def default_model(): """Get a path for a default value for the model. Start searching in the current directory.""" project_root = get_project_root() models_dir = os.path.join(project_root, "models") curr_dir = os.getcwd() if os.path.commonprefix([models_dir, curr_dir]) == models_dir and \ ...
python
def default_model(): """Get a path for a default value for the model. Start searching in the current directory.""" project_root = get_project_root() models_dir = os.path.join(project_root, "models") curr_dir = os.getcwd() if os.path.commonprefix([models_dir, curr_dir]) == models_dir and \ ...
[ "def", "default_model", "(", ")", ":", "project_root", "=", "get_project_root", "(", ")", "models_dir", "=", "os", ".", "path", ".", "join", "(", "project_root", ",", "\"models\"", ")", "curr_dir", "=", "os", ".", "getcwd", "(", ")", "if", "os", ".", "...
Get a path for a default value for the model. Start searching in the current directory.
[ "Get", "a", "path", "for", "a", "default", "value", "for", "the", "model", ".", "Start", "searching", "in", "the", "current", "directory", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L379-L390
train
59,337
MartinThoma/hwrt
hwrt/utils.py
create_adjusted_model_for_percentages
def create_adjusted_model_for_percentages(model_src, model_use): """Replace logreg layer by sigmoid to get probabilities.""" # Copy model file shutil.copyfile(model_src, model_use) # Adjust model file with open(model_src) as f: content = f.read() content = content.replace("logreg", "sigm...
python
def create_adjusted_model_for_percentages(model_src, model_use): """Replace logreg layer by sigmoid to get probabilities.""" # Copy model file shutil.copyfile(model_src, model_use) # Adjust model file with open(model_src) as f: content = f.read() content = content.replace("logreg", "sigm...
[ "def", "create_adjusted_model_for_percentages", "(", "model_src", ",", "model_use", ")", ":", "# Copy model file", "shutil", ".", "copyfile", "(", "model_src", ",", "model_use", ")", "# Adjust model file", "with", "open", "(", "model_src", ")", "as", "f", ":", "co...
Replace logreg layer by sigmoid to get probabilities.
[ "Replace", "logreg", "layer", "by", "sigmoid", "to", "get", "probabilities", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L393-L402
train
59,338
MartinThoma/hwrt
hwrt/utils.py
create_hdf5
def create_hdf5(output_filename, feature_count, data): """ Create a HDF5 feature files. Parameters ---------- output_filename : string name of the HDF5 file that will be created feature_count : int dimension of all features combined data : list of tuples list of (x, ...
python
def create_hdf5(output_filename, feature_count, data): """ Create a HDF5 feature files. Parameters ---------- output_filename : string name of the HDF5 file that will be created feature_count : int dimension of all features combined data : list of tuples list of (x, ...
[ "def", "create_hdf5", "(", "output_filename", ",", "feature_count", ",", "data", ")", ":", "import", "h5py", "logging", ".", "info", "(", "\"Start creating of %s hdf file\"", ",", "output_filename", ")", "x", "=", "[", "]", "y", "=", "[", "]", "for", "featur...
Create a HDF5 feature files. Parameters ---------- output_filename : string name of the HDF5 file that will be created feature_count : int dimension of all features combined data : list of tuples list of (x, y) tuples, where x is the feature vector of dimension ``fea...
[ "Create", "a", "HDF5", "feature", "files", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L405-L432
train
59,339
MartinThoma/hwrt
hwrt/utils.py
load_model
def load_model(model_file): """Load a model by its file. This includes the model itself, but also the preprocessing queue, the feature list and the output semantics. """ # Extract tar with tarfile.open(model_file) as tar: tarfolder = tempfile.mkdtemp() tar.extractall(path=tarfolde...
python
def load_model(model_file): """Load a model by its file. This includes the model itself, but also the preprocessing queue, the feature list and the output semantics. """ # Extract tar with tarfile.open(model_file) as tar: tarfolder = tempfile.mkdtemp() tar.extractall(path=tarfolde...
[ "def", "load_model", "(", "model_file", ")", ":", "# Extract tar", "with", "tarfile", ".", "open", "(", "model_file", ")", "as", "tar", ":", "tarfolder", "=", "tempfile", ".", "mkdtemp", "(", ")", "tar", ".", "extractall", "(", "path", "=", "tarfolder", ...
Load a model by its file. This includes the model itself, but also the preprocessing queue, the feature list and the output semantics.
[ "Load", "a", "model", "by", "its", "file", ".", "This", "includes", "the", "model", "itself", "but", "also", "the", "preprocessing", "queue", "the", "feature", "list", "and", "the", "output", "semantics", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L448-L482
train
59,340
MartinThoma/hwrt
hwrt/utils.py
evaluate_model_single_recording_preloaded
def evaluate_model_single_recording_preloaded(preprocessing_queue, feature_list, model, output_semantics, recording, ...
python
def evaluate_model_single_recording_preloaded(preprocessing_queue, feature_list, model, output_semantics, recording, ...
[ "def", "evaluate_model_single_recording_preloaded", "(", "preprocessing_queue", ",", "feature_list", ",", "model", ",", "output_semantics", ",", "recording", ",", "recording_id", "=", "None", ")", ":", "handwriting", "=", "handwritten_data", ".", "HandwrittenData", "(",...
Evaluate a model for a single recording, after everything has been loaded. Parameters ---------- preprocessing_queue : list List of all preprocessing objects. feature_list : list List of all feature objects. model : dict Neural network model. output_semantics : list ...
[ "Evaluate", "a", "model", "for", "a", "single", "recording", "after", "everything", "has", "been", "loaded", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L485-L515
train
59,341
MartinThoma/hwrt
hwrt/utils.py
evaluate_model_single_recording_preloaded_multisymbol
def evaluate_model_single_recording_preloaded_multisymbol(preprocessing_queue, feature_list, model, output_semantics, ...
python
def evaluate_model_single_recording_preloaded_multisymbol(preprocessing_queue, feature_list, model, output_semantics, ...
[ "def", "evaluate_model_single_recording_preloaded_multisymbol", "(", "preprocessing_queue", ",", "feature_list", ",", "model", ",", "output_semantics", ",", "recording", ")", ":", "import", "json", "import", "nntoolkit", ".", "evaluate", "recording", "=", "json", ".", ...
Evaluate a model for a single recording, after everything has been loaded. Multiple symbols are recognized. Parameters ---------- preprocessing_queue : list List of all preprocessing objects. feature_list : list List of all feature objects. model : dict Neural network mo...
[ "Evaluate", "a", "model", "for", "a", "single", "recording", "after", "everything", "has", "been", "loaded", ".", "Multiple", "symbols", "are", "recognized", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L551-L608
train
59,342
MartinThoma/hwrt
hwrt/utils.py
evaluate_model_single_recording_multisymbol
def evaluate_model_single_recording_multisymbol(model_file, recording): """ Evaluate a model for a single recording where possibly multiple symbols are. Parameters ---------- model_file : string Model file (.tar) recording : The handwritten recording. """ (preprocess...
python
def evaluate_model_single_recording_multisymbol(model_file, recording): """ Evaluate a model for a single recording where possibly multiple symbols are. Parameters ---------- model_file : string Model file (.tar) recording : The handwritten recording. """ (preprocess...
[ "def", "evaluate_model_single_recording_multisymbol", "(", "model_file", ",", "recording", ")", ":", "(", "preprocessing_queue", ",", "feature_list", ",", "model", ",", "output_semantics", ")", "=", "load_model", "(", "model_file", ")", "logging", ".", "info", "(", ...
Evaluate a model for a single recording where possibly multiple symbols are. Parameters ---------- model_file : string Model file (.tar) recording : The handwritten recording.
[ "Evaluate", "a", "model", "for", "a", "single", "recording", "where", "possibly", "multiple", "symbols", "are", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L611-L632
train
59,343
MartinThoma/hwrt
hwrt/utils.py
evaluate_model
def evaluate_model(recording, model_folder, verbose=False): """Evaluate model for a single recording.""" from . import preprocess_dataset from . import features for target_folder in get_recognizer_folders(model_folder): # The source is later than the target. That means we need to # refr...
python
def evaluate_model(recording, model_folder, verbose=False): """Evaluate model for a single recording.""" from . import preprocess_dataset from . import features for target_folder in get_recognizer_folders(model_folder): # The source is later than the target. That means we need to # refr...
[ "def", "evaluate_model", "(", "recording", ",", "model_folder", ",", "verbose", "=", "False", ")", ":", "from", ".", "import", "preprocess_dataset", "from", ".", "import", "features", "for", "target_folder", "in", "get_recognizer_folders", "(", "model_folder", ")"...
Evaluate model for a single recording.
[ "Evaluate", "model", "for", "a", "single", "recording", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L699-L740
train
59,344
MartinThoma/hwrt
hwrt/utils.py
get_index2latex
def get_index2latex(model_description): """ Get a dictionary that maps indices to LaTeX commands. Parameters ---------- model_description : string A model description file that points to a feature folder where an `index2formula_id.csv` has to be. Returns ------- diction...
python
def get_index2latex(model_description): """ Get a dictionary that maps indices to LaTeX commands. Parameters ---------- model_description : string A model description file that points to a feature folder where an `index2formula_id.csv` has to be. Returns ------- diction...
[ "def", "get_index2latex", "(", "model_description", ")", ":", "index2latex", "=", "{", "}", "translation_csv", "=", "os", ".", "path", ".", "join", "(", "get_project_root", "(", ")", ",", "model_description", "[", "\"data-source\"", "]", ",", "\"index2formula_id...
Get a dictionary that maps indices to LaTeX commands. Parameters ---------- model_description : string A model description file that points to a feature folder where an `index2formula_id.csv` has to be. Returns ------- dictionary : Maps indices to LaTeX commands
[ "Get", "a", "dictionary", "that", "maps", "indices", "to", "LaTeX", "commands", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L743-L766
train
59,345
MartinThoma/hwrt
hwrt/utils.py
get_online_symbol_data
def get_online_symbol_data(database_id): """Get from the server.""" import pymysql import pymysql.cursors cfg = get_database_configuration() mysql = cfg['mysql_online'] connection = pymysql.connect(host=mysql['host'], user=mysql['user'], ...
python
def get_online_symbol_data(database_id): """Get from the server.""" import pymysql import pymysql.cursors cfg = get_database_configuration() mysql = cfg['mysql_online'] connection = pymysql.connect(host=mysql['host'], user=mysql['user'], ...
[ "def", "get_online_symbol_data", "(", "database_id", ")", ":", "import", "pymysql", "import", "pymysql", ".", "cursors", "cfg", "=", "get_database_configuration", "(", ")", "mysql", "=", "cfg", "[", "'mysql_online'", "]", "connection", "=", "pymysql", ".", "conn...
Get from the server.
[ "Get", "from", "the", "server", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L811-L830
train
59,346
MartinThoma/hwrt
hwrt/utils.py
classify_single_recording
def classify_single_recording(raw_data_json, model_folder, verbose=False): """ Get the classification as a list of tuples. The first value is the LaTeX code, the second value is the probability. """ evaluation_file = evaluate_model(raw_data_json, model_folder, verbose) with open(os.path.join(mod...
python
def classify_single_recording(raw_data_json, model_folder, verbose=False): """ Get the classification as a list of tuples. The first value is the LaTeX code, the second value is the probability. """ evaluation_file = evaluate_model(raw_data_json, model_folder, verbose) with open(os.path.join(mod...
[ "def", "classify_single_recording", "(", "raw_data_json", ",", "model_folder", ",", "verbose", "=", "False", ")", ":", "evaluation_file", "=", "evaluate_model", "(", "raw_data_json", ",", "model_folder", ",", "verbose", ")", "with", "open", "(", "os", ".", "path...
Get the classification as a list of tuples. The first value is the LaTeX code, the second value is the probability.
[ "Get", "the", "classification", "as", "a", "list", "of", "tuples", ".", "The", "first", "value", "is", "the", "LaTeX", "code", "the", "second", "value", "is", "the", "probability", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L833-L852
train
59,347
MartinThoma/hwrt
hwrt/utils.py
get_objectlist
def get_objectlist(description, config_key, module): """ Take a description and return a list of classes. Parameters ---------- description : list of dictionaries Each dictionary has only one entry. The key is the name of a class. The value of that entry is a list of dictionaries ag...
python
def get_objectlist(description, config_key, module): """ Take a description and return a list of classes. Parameters ---------- description : list of dictionaries Each dictionary has only one entry. The key is the name of a class. The value of that entry is a list of dictionaries ag...
[ "def", "get_objectlist", "(", "description", ",", "config_key", ",", "module", ")", ":", "object_list", "=", "[", "]", "for", "feature", "in", "description", ":", "for", "feat", ",", "params", "in", "feature", ".", "items", "(", ")", ":", "feat", "=", ...
Take a description and return a list of classes. Parameters ---------- description : list of dictionaries Each dictionary has only one entry. The key is the name of a class. The value of that entry is a list of dictionaries again. Those dictionaries are paramters. Returns -...
[ "Take", "a", "description", "and", "return", "a", "list", "of", "classes", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L855-L882
train
59,348
MartinThoma/hwrt
hwrt/utils.py
get_class
def get_class(name, config_key, module): """Get the class by its name as a string.""" clsmembers = inspect.getmembers(module, inspect.isclass) for string_name, act_class in clsmembers: if string_name == name: return act_class # Check if the user has specified a plugin and if the cla...
python
def get_class(name, config_key, module): """Get the class by its name as a string.""" clsmembers = inspect.getmembers(module, inspect.isclass) for string_name, act_class in clsmembers: if string_name == name: return act_class # Check if the user has specified a plugin and if the cla...
[ "def", "get_class", "(", "name", ",", "config_key", ",", "module", ")", ":", "clsmembers", "=", "inspect", ".", "getmembers", "(", "module", ",", "inspect", ".", "isclass", ")", "for", "string_name", ",", "act_class", "in", "clsmembers", ":", "if", "string...
Get the class by its name as a string.
[ "Get", "the", "class", "by", "its", "name", "as", "a", "string", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L885-L907
train
59,349
MartinThoma/hwrt
hwrt/utils.py
get_mysql_cfg
def get_mysql_cfg(): """ Get the appropriate MySQL configuration """ environment = get_project_configuration()['environment'] cfg = get_database_configuration() if environment == 'production': mysql = cfg['mysql_online'] else: mysql = cfg['mysql_dev'] return mysql
python
def get_mysql_cfg(): """ Get the appropriate MySQL configuration """ environment = get_project_configuration()['environment'] cfg = get_database_configuration() if environment == 'production': mysql = cfg['mysql_online'] else: mysql = cfg['mysql_dev'] return mysql
[ "def", "get_mysql_cfg", "(", ")", ":", "environment", "=", "get_project_configuration", "(", ")", "[", "'environment'", "]", "cfg", "=", "get_database_configuration", "(", ")", "if", "environment", "==", "'production'", ":", "mysql", "=", "cfg", "[", "'mysql_onl...
Get the appropriate MySQL configuration
[ "Get", "the", "appropriate", "MySQL", "configuration" ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L926-L936
train
59,350
MartinThoma/hwrt
hwrt/utils.py
softmax
def softmax(w, t=1.0): """Calculate the softmax of a list of numbers w. Parameters ---------- w : list of numbers Returns ------- a list of the same length as w of non-negative numbers Examples -------- >>> softmax([0.1, 0.2]) array([ 0.47502081, 0.52497919]) >>> soft...
python
def softmax(w, t=1.0): """Calculate the softmax of a list of numbers w. Parameters ---------- w : list of numbers Returns ------- a list of the same length as w of non-negative numbers Examples -------- >>> softmax([0.1, 0.2]) array([ 0.47502081, 0.52497919]) >>> soft...
[ "def", "softmax", "(", "w", ",", "t", "=", "1.0", ")", ":", "w", "=", "[", "Decimal", "(", "el", ")", "for", "el", "in", "w", "]", "e", "=", "numpy", ".", "exp", "(", "numpy", ".", "array", "(", "w", ")", "/", "Decimal", "(", "t", ")", ")...
Calculate the softmax of a list of numbers w. Parameters ---------- w : list of numbers Returns ------- a list of the same length as w of non-negative numbers Examples -------- >>> softmax([0.1, 0.2]) array([ 0.47502081, 0.52497919]) >>> softmax([-0.1, 0.2]) array([ 0...
[ "Calculate", "the", "softmax", "of", "a", "list", "of", "numbers", "w", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L939-L964
train
59,351
MartinThoma/hwrt
hwrt/utils.py
get_beam_cache_directory
def get_beam_cache_directory(): """ Get a directory where pickled Beam Data can be stored. Create that directory, if it doesn't exist. Returns ------- str Path to the directory """ home = os.path.expanduser("~") cache_dir = os.path.join(home, '.hwrt-beam-cache') if not ...
python
def get_beam_cache_directory(): """ Get a directory where pickled Beam Data can be stored. Create that directory, if it doesn't exist. Returns ------- str Path to the directory """ home = os.path.expanduser("~") cache_dir = os.path.join(home, '.hwrt-beam-cache') if not ...
[ "def", "get_beam_cache_directory", "(", ")", ":", "home", "=", "os", ".", "path", ".", "expanduser", "(", "\"~\"", ")", "cache_dir", "=", "os", ".", "path", ".", "join", "(", "home", ",", "'.hwrt-beam-cache'", ")", "if", "not", "os", ".", "path", ".", ...
Get a directory where pickled Beam Data can be stored. Create that directory, if it doesn't exist. Returns ------- str Path to the directory
[ "Get", "a", "directory", "where", "pickled", "Beam", "Data", "can", "be", "stored", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L967-L982
train
59,352
MartinThoma/hwrt
hwrt/utils.py
get_beam
def get_beam(secret_uuid): """ Get a beam from the session with `secret_uuid`. Parameters ---------- secret_uuid : str Returns ------- The beam object if it exists, otherwise `None`. """ beam_dir = get_beam_cache_directory() beam_filename = os.path.join(beam_dir, secret_uui...
python
def get_beam(secret_uuid): """ Get a beam from the session with `secret_uuid`. Parameters ---------- secret_uuid : str Returns ------- The beam object if it exists, otherwise `None`. """ beam_dir = get_beam_cache_directory() beam_filename = os.path.join(beam_dir, secret_uui...
[ "def", "get_beam", "(", "secret_uuid", ")", ":", "beam_dir", "=", "get_beam_cache_directory", "(", ")", "beam_filename", "=", "os", ".", "path", ".", "join", "(", "beam_dir", ",", "secret_uuid", ")", "if", "os", ".", "path", ".", "isfile", "(", "beam_filen...
Get a beam from the session with `secret_uuid`. Parameters ---------- secret_uuid : str Returns ------- The beam object if it exists, otherwise `None`.
[ "Get", "a", "beam", "from", "the", "session", "with", "secret_uuid", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L985-L1004
train
59,353
MartinThoma/hwrt
hwrt/utils.py
is_valid_uuid
def is_valid_uuid(uuid_to_test, version=4): """ Check if uuid_to_test is a valid UUID. Parameters ---------- uuid_to_test : str version : {1, 2, 3, 4} Returns ------- `True` if uuid_to_test is a valid UUID, otherwise `False`. Examples -------- >>> is_valid_uuid('c9bf9e...
python
def is_valid_uuid(uuid_to_test, version=4): """ Check if uuid_to_test is a valid UUID. Parameters ---------- uuid_to_test : str version : {1, 2, 3, 4} Returns ------- `True` if uuid_to_test is a valid UUID, otherwise `False`. Examples -------- >>> is_valid_uuid('c9bf9e...
[ "def", "is_valid_uuid", "(", "uuid_to_test", ",", "version", "=", "4", ")", ":", "try", ":", "uuid_obj", "=", "UUID", "(", "uuid_to_test", ",", "version", "=", "version", ")", "except", "ValueError", ":", "return", "False", "return", "str", "(", "uuid_obj"...
Check if uuid_to_test is a valid UUID. Parameters ---------- uuid_to_test : str version : {1, 2, 3, 4} Returns ------- `True` if uuid_to_test is a valid UUID, otherwise `False`. Examples -------- >>> is_valid_uuid('c9bf9e57-1685-4c89-bafb-ff5af830be8a') True >>> is_val...
[ "Check", "if", "uuid_to_test", "is", "a", "valid", "UUID", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/utils.py#L1016-L1041
train
59,354
MartinThoma/hwrt
hwrt/partitions.py
prepare_table
def prepare_table(table): """Make the table 'symmetric' where the lower left part of the matrix is the reverse probability """ n = len(table) for i, row in enumerate(table): assert len(row) == n for j, el in enumerate(row): if i == j: table[i][i] = 0.0 ...
python
def prepare_table(table): """Make the table 'symmetric' where the lower left part of the matrix is the reverse probability """ n = len(table) for i, row in enumerate(table): assert len(row) == n for j, el in enumerate(row): if i == j: table[i][i] = 0.0 ...
[ "def", "prepare_table", "(", "table", ")", ":", "n", "=", "len", "(", "table", ")", "for", "i", ",", "row", "in", "enumerate", "(", "table", ")", ":", "assert", "len", "(", "row", ")", "==", "n", "for", "j", ",", "el", "in", "enumerate", "(", "...
Make the table 'symmetric' where the lower left part of the matrix is the reverse probability
[ "Make", "the", "table", "symmetric", "where", "the", "lower", "left", "part", "of", "the", "matrix", "is", "the", "reverse", "probability" ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/partitions.py#L20-L32
train
59,355
MartinThoma/hwrt
hwrt/partitions.py
neclusters
def neclusters(l, K): """Partition list ``l`` in ``K`` partitions, without empty parts. >>> l = [0, 1, 2] >>> list(neclusters(l, 2)) [[[0, 1], [2]], [[1], [0, 2]], [[0], [1, 2]]] >>> list(neclusters(l, 1)) [[[0, 1, 2]]] """ for c in clusters(l, K): if all(x for x in c): ...
python
def neclusters(l, K): """Partition list ``l`` in ``K`` partitions, without empty parts. >>> l = [0, 1, 2] >>> list(neclusters(l, 2)) [[[0, 1], [2]], [[1], [0, 2]], [[0], [1, 2]]] >>> list(neclusters(l, 1)) [[[0, 1, 2]]] """ for c in clusters(l, K): if all(x for x in c): ...
[ "def", "neclusters", "(", "l", ",", "K", ")", ":", "for", "c", "in", "clusters", "(", "l", ",", "K", ")", ":", "if", "all", "(", "x", "for", "x", "in", "c", ")", ":", "yield", "c" ]
Partition list ``l`` in ``K`` partitions, without empty parts. >>> l = [0, 1, 2] >>> list(neclusters(l, 2)) [[[0, 1], [2]], [[1], [0, 2]], [[0], [1, 2]]] >>> list(neclusters(l, 1)) [[[0, 1, 2]]]
[ "Partition", "list", "l", "in", "K", "partitions", "without", "empty", "parts", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/partitions.py#L57-L68
train
59,356
MartinThoma/hwrt
hwrt/partitions.py
all_segmentations
def all_segmentations(l): """Get all segmentations of a list ``l``. This gets bigger fast. See https://oeis.org/A000110 For len(l) = 14 it is 190,899,322 >>> list(all_segmentations([0, 1, 2])) [[[0, 1, 2]], [[0, 1], [2]], [[1], [0, 2]], [[0], [1, 2]], [[0], [1], [2]]] """ for K in range(1...
python
def all_segmentations(l): """Get all segmentations of a list ``l``. This gets bigger fast. See https://oeis.org/A000110 For len(l) = 14 it is 190,899,322 >>> list(all_segmentations([0, 1, 2])) [[[0, 1, 2]], [[0, 1], [2]], [[1], [0, 2]], [[0], [1, 2]], [[0], [1], [2]]] """ for K in range(1...
[ "def", "all_segmentations", "(", "l", ")", ":", "for", "K", "in", "range", "(", "1", ",", "len", "(", "l", ")", "+", "1", ")", ":", "gen", "=", "neclusters", "(", "l", ",", "K", ")", "for", "el", "in", "gen", ":", "yield", "el" ]
Get all segmentations of a list ``l``. This gets bigger fast. See https://oeis.org/A000110 For len(l) = 14 it is 190,899,322 >>> list(all_segmentations([0, 1, 2])) [[[0, 1, 2]], [[0, 1], [2]], [[1], [0, 2]], [[0], [1, 2]], [[0], [1], [2]]]
[ "Get", "all", "segmentations", "of", "a", "list", "l", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/partitions.py#L71-L84
train
59,357
MartinThoma/hwrt
hwrt/partitions.py
q
def q(segmentation, s1, s2): """Test if ``s1`` and ``s2`` are in the same symbol, given the ``segmentation``. """ index1 = find_index(segmentation, s1) index2 = find_index(segmentation, s2) return index1 == index2
python
def q(segmentation, s1, s2): """Test if ``s1`` and ``s2`` are in the same symbol, given the ``segmentation``. """ index1 = find_index(segmentation, s1) index2 = find_index(segmentation, s2) return index1 == index2
[ "def", "q", "(", "segmentation", ",", "s1", ",", "s2", ")", ":", "index1", "=", "find_index", "(", "segmentation", ",", "s1", ")", "index2", "=", "find_index", "(", "segmentation", ",", "s2", ")", "return", "index1", "==", "index2" ]
Test if ``s1`` and ``s2`` are in the same symbol, given the ``segmentation``.
[ "Test", "if", "s1", "and", "s2", "are", "in", "the", "same", "symbol", "given", "the", "segmentation", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/partitions.py#L105-L111
train
59,358
MartinThoma/hwrt
hwrt/partitions.py
score_segmentation
def score_segmentation(segmentation, table): """Get the score of a segmentation.""" stroke_nr = sum(1 for symbol in segmentation for stroke in symbol) score = 1 for i in range(stroke_nr): for j in range(i+1, stroke_nr): qval = q(segmentation, i, j) if qval: ...
python
def score_segmentation(segmentation, table): """Get the score of a segmentation.""" stroke_nr = sum(1 for symbol in segmentation for stroke in symbol) score = 1 for i in range(stroke_nr): for j in range(i+1, stroke_nr): qval = q(segmentation, i, j) if qval: ...
[ "def", "score_segmentation", "(", "segmentation", ",", "table", ")", ":", "stroke_nr", "=", "sum", "(", "1", "for", "symbol", "in", "segmentation", "for", "stroke", "in", "symbol", ")", "score", "=", "1", "for", "i", "in", "range", "(", "stroke_nr", ")",...
Get the score of a segmentation.
[ "Get", "the", "score", "of", "a", "segmentation", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/partitions.py#L140-L151
train
59,359
MartinThoma/hwrt
hwrt/partitions.py
TopFinder.push
def push(self, element, value): """Push an ``element`` into the datastrucutre together with its value and only save it if it currently is one of the top n elements. Drop elements if necessary. """ insert_pos = 0 for index, el in enumerate(self.tops): if...
python
def push(self, element, value): """Push an ``element`` into the datastrucutre together with its value and only save it if it currently is one of the top n elements. Drop elements if necessary. """ insert_pos = 0 for index, el in enumerate(self.tops): if...
[ "def", "push", "(", "self", ",", "element", ",", "value", ")", ":", "insert_pos", "=", "0", "for", "index", ",", "el", "in", "enumerate", "(", "self", ".", "tops", ")", ":", "if", "not", "self", ".", "find_min", "and", "el", "[", "1", "]", ">=", ...
Push an ``element`` into the datastrucutre together with its value and only save it if it currently is one of the top n elements. Drop elements if necessary.
[ "Push", "an", "element", "into", "the", "datastrucutre", "together", "with", "its", "value", "and", "only", "save", "it", "if", "it", "currently", "is", "one", "of", "the", "top", "n", "elements", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/partitions.py#L121-L134
train
59,360
MartinThoma/hwrt
bin/convert.py
_array2cstr
def _array2cstr(arr): """ Serializes a numpy array to a compressed base64 string """ out = StringIO() np.save(out, arr) return b64encode(out.getvalue())
python
def _array2cstr(arr): """ Serializes a numpy array to a compressed base64 string """ out = StringIO() np.save(out, arr) return b64encode(out.getvalue())
[ "def", "_array2cstr", "(", "arr", ")", ":", "out", "=", "StringIO", "(", ")", "np", ".", "save", "(", "out", ",", "arr", ")", "return", "b64encode", "(", "out", ".", "getvalue", "(", ")", ")" ]
Serializes a numpy array to a compressed base64 string
[ "Serializes", "a", "numpy", "array", "to", "a", "compressed", "base64", "string" ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/bin/convert.py#L21-L25
train
59,361
MartinThoma/hwrt
bin/convert.py
_str2array
def _str2array(d): """ Reconstructs a numpy array from a plain-text string """ if type(d) == list: return np.asarray([_str2array(s) for s in d]) ins = StringIO(d) return np.loadtxt(ins)
python
def _str2array(d): """ Reconstructs a numpy array from a plain-text string """ if type(d) == list: return np.asarray([_str2array(s) for s in d]) ins = StringIO(d) return np.loadtxt(ins)
[ "def", "_str2array", "(", "d", ")", ":", "if", "type", "(", "d", ")", "==", "list", ":", "return", "np", ".", "asarray", "(", "[", "_str2array", "(", "s", ")", "for", "s", "in", "d", "]", ")", "ins", "=", "StringIO", "(", "d", ")", "return", ...
Reconstructs a numpy array from a plain-text string
[ "Reconstructs", "a", "numpy", "array", "from", "a", "plain", "-", "text", "string" ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/bin/convert.py#L28-L33
train
59,362
MartinThoma/hwrt
bin/convert.py
create_output_semantics
def create_output_semantics(model_folder, outputs): """ Create a 'output_semantics.csv' file which contains information what the output of the single output neurons mean. Parameters ---------- model_folder : str folder where the model description file is outputs : int number...
python
def create_output_semantics(model_folder, outputs): """ Create a 'output_semantics.csv' file which contains information what the output of the single output neurons mean. Parameters ---------- model_folder : str folder where the model description file is outputs : int number...
[ "def", "create_output_semantics", "(", "model_folder", ",", "outputs", ")", ":", "with", "open", "(", "'output_semantics.csv'", ",", "'wb'", ")", "as", "csvfile", ":", "model_description_file", "=", "os", ".", "path", ".", "join", "(", "model_folder", ",", "\"...
Create a 'output_semantics.csv' file which contains information what the output of the single output neurons mean. Parameters ---------- model_folder : str folder where the model description file is outputs : int number of output neurons
[ "Create", "a", "output_semantics", ".", "csv", "file", "which", "contains", "information", "what", "the", "output", "of", "the", "single", "output", "neurons", "mean", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/bin/convert.py#L50-L82
train
59,363
MartinThoma/hwrt
hwrt/datasets/mfrdb.py
elementtree_to_dict
def elementtree_to_dict(element): """Convert an xml ElementTree to a dictionary.""" d = dict() if hasattr(element, 'text') and element.text is not None: d['text'] = element.text d.update(element.items()) # element's attributes for c in list(element): # element's children if c.tag...
python
def elementtree_to_dict(element): """Convert an xml ElementTree to a dictionary.""" d = dict() if hasattr(element, 'text') and element.text is not None: d['text'] = element.text d.update(element.items()) # element's attributes for c in list(element): # element's children if c.tag...
[ "def", "elementtree_to_dict", "(", "element", ")", ":", "d", "=", "dict", "(", ")", "if", "hasattr", "(", "element", ",", "'text'", ")", "and", "element", ".", "text", "is", "not", "None", ":", "d", "[", "'text'", "]", "=", "element", ".", "text", ...
Convert an xml ElementTree to a dictionary.
[ "Convert", "an", "xml", "ElementTree", "to", "a", "dictionary", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/datasets/mfrdb.py#L69-L88
train
59,364
MartinThoma/hwrt
hwrt/datasets/mfrdb.py
strip_end
def strip_end(text, suffix): """Strip `suffix` from the end of `text` if `text` has that suffix.""" if not text.endswith(suffix): return text return text[:len(text)-len(suffix)]
python
def strip_end(text, suffix): """Strip `suffix` from the end of `text` if `text` has that suffix.""" if not text.endswith(suffix): return text return text[:len(text)-len(suffix)]
[ "def", "strip_end", "(", "text", ",", "suffix", ")", ":", "if", "not", "text", ".", "endswith", "(", "suffix", ")", ":", "return", "text", "return", "text", "[", ":", "len", "(", "text", ")", "-", "len", "(", "suffix", ")", "]" ]
Strip `suffix` from the end of `text` if `text` has that suffix.
[ "Strip", "suffix", "from", "the", "end", "of", "text", "if", "text", "has", "that", "suffix", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/datasets/mfrdb.py#L91-L95
train
59,365
MartinThoma/hwrt
hwrt/datasets/__init__.py
formula_to_dbid
def formula_to_dbid(formula_str, backslash_fix=False): """ Convert a LaTeX formula to the database index. Parameters ---------- formula_str : string The formula as LaTeX code. backslash_fix : boolean If this is set to true, then it will be checked if the same formula exi...
python
def formula_to_dbid(formula_str, backslash_fix=False): """ Convert a LaTeX formula to the database index. Parameters ---------- formula_str : string The formula as LaTeX code. backslash_fix : boolean If this is set to true, then it will be checked if the same formula exi...
[ "def", "formula_to_dbid", "(", "formula_str", ",", "backslash_fix", "=", "False", ")", ":", "global", "__formula_to_dbid_cache", "if", "__formula_to_dbid_cache", "is", "None", ":", "mysql", "=", "utils", ".", "get_mysql_cfg", "(", ")", "connection", "=", "pymysql"...
Convert a LaTeX formula to the database index. Parameters ---------- formula_str : string The formula as LaTeX code. backslash_fix : boolean If this is set to true, then it will be checked if the same formula exists with a preceeding backslash. Returns ------- int :...
[ "Convert", "a", "LaTeX", "formula", "to", "the", "database", "index", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/datasets/__init__.py#L20-L79
train
59,366
MartinThoma/hwrt
hwrt/datasets/__init__.py
insert_recording
def insert_recording(hw): """Insert recording `hw` into database.""" mysql = utils.get_mysql_cfg() connection = pymysql.connect(host=mysql['host'], user=mysql['user'], passwd=mysql['passwd'], db=mysql['db'], ...
python
def insert_recording(hw): """Insert recording `hw` into database.""" mysql = utils.get_mysql_cfg() connection = pymysql.connect(host=mysql['host'], user=mysql['user'], passwd=mysql['passwd'], db=mysql['db'], ...
[ "def", "insert_recording", "(", "hw", ")", ":", "mysql", "=", "utils", ".", "get_mysql_cfg", "(", ")", "connection", "=", "pymysql", ".", "connect", "(", "host", "=", "mysql", "[", "'host'", "]", ",", "user", "=", "mysql", "[", "'user'", "]", ",", "p...
Insert recording `hw` into database.
[ "Insert", "recording", "hw", "into", "database", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/datasets/__init__.py#L137-L181
train
59,367
MartinThoma/hwrt
hwrt/datasets/__init__.py
insert_symbol_mapping
def insert_symbol_mapping(raw_data_id, symbol_id, user_id, strokes): """ Insert data into `wm_strokes_to_symbol`. Parameters ---------- raw_data_id : int user_id : int strokes: list of int """ mysql = utils.get_mysql_cfg() connection = pymysql.connect(host=mysql['host'], ...
python
def insert_symbol_mapping(raw_data_id, symbol_id, user_id, strokes): """ Insert data into `wm_strokes_to_symbol`. Parameters ---------- raw_data_id : int user_id : int strokes: list of int """ mysql = utils.get_mysql_cfg() connection = pymysql.connect(host=mysql['host'], ...
[ "def", "insert_symbol_mapping", "(", "raw_data_id", ",", "symbol_id", ",", "user_id", ",", "strokes", ")", ":", "mysql", "=", "utils", ".", "get_mysql_cfg", "(", ")", "connection", "=", "pymysql", ".", "connect", "(", "host", "=", "mysql", "[", "'host'", "...
Insert data into `wm_strokes_to_symbol`. Parameters ---------- raw_data_id : int user_id : int strokes: list of int
[ "Insert", "data", "into", "wm_strokes_to_symbol", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/datasets/__init__.py#L184-L211
train
59,368
MartinThoma/hwrt
hwrt/analyze_data.py
filter_label
def filter_label(label, replace_by_similar=True): """Some labels currently don't work together because of LaTeX naming clashes. Those will be replaced by simple strings. """ bad_names = ['celsius', 'degree', 'ohm', 'venus', 'mars', 'astrosun', 'fullmoon', 'leftmoon', 'female', 'male', 'c...
python
def filter_label(label, replace_by_similar=True): """Some labels currently don't work together because of LaTeX naming clashes. Those will be replaced by simple strings. """ bad_names = ['celsius', 'degree', 'ohm', 'venus', 'mars', 'astrosun', 'fullmoon', 'leftmoon', 'female', 'male', 'c...
[ "def", "filter_label", "(", "label", ",", "replace_by_similar", "=", "True", ")", ":", "bad_names", "=", "[", "'celsius'", ",", "'degree'", ",", "'ohm'", ",", "'venus'", ",", "'mars'", ",", "'astrosun'", ",", "'fullmoon'", ",", "'leftmoon'", ",", "'female'",...
Some labels currently don't work together because of LaTeX naming clashes. Those will be replaced by simple strings.
[ "Some", "labels", "currently", "don", "t", "work", "together", "because", "of", "LaTeX", "naming", "clashes", ".", "Those", "will", "be", "replaced", "by", "simple", "strings", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/analyze_data.py#L27-L42
train
59,369
MartinThoma/hwrt
hwrt/analyze_data.py
analyze_feature
def analyze_feature(raw_datasets, feature, basename="aspect_ratios"): """ Apply ``feature`` to all recordings in ``raw_datasets``. Store the results in two files. One file stores the raw result, the other one groups the results by symbols and stores the mean, standard deviation and the name of the s...
python
def analyze_feature(raw_datasets, feature, basename="aspect_ratios"): """ Apply ``feature`` to all recordings in ``raw_datasets``. Store the results in two files. One file stores the raw result, the other one groups the results by symbols and stores the mean, standard deviation and the name of the s...
[ "def", "analyze_feature", "(", "raw_datasets", ",", "feature", ",", "basename", "=", "\"aspect_ratios\"", ")", ":", "# Prepare files", "csv_file", "=", "dam", ".", "prepare_file", "(", "basename", "+", "'.csv'", ")", "raw_file", "=", "dam", ".", "prepare_file", ...
Apply ``feature`` to all recordings in ``raw_datasets``. Store the results in two files. One file stores the raw result, the other one groups the results by symbols and stores the mean, standard deviation and the name of the symbol as a csv file. Parameters ---------- raw_datasets : List of dic...
[ "Apply", "feature", "to", "all", "recordings", "in", "raw_datasets", ".", "Store", "the", "results", "in", "two", "files", ".", "One", "file", "stores", "the", "raw", "result", "the", "other", "one", "groups", "the", "results", "by", "symbols", "and", "sto...
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/analyze_data.py#L45-L90
train
59,370
MartinThoma/hwrt
hwrt/analyze_data.py
main
def main(handwriting_datasets_file, analyze_features): """Start the creation of the wanted metric.""" # Load from pickled file logging.info("Start loading data '%s' ...", handwriting_datasets_file) loaded = pickle.load(open(handwriting_datasets_file)) raw_datasets = loaded['handwriting_datasets'] ...
python
def main(handwriting_datasets_file, analyze_features): """Start the creation of the wanted metric.""" # Load from pickled file logging.info("Start loading data '%s' ...", handwriting_datasets_file) loaded = pickle.load(open(handwriting_datasets_file)) raw_datasets = loaded['handwriting_datasets'] ...
[ "def", "main", "(", "handwriting_datasets_file", ",", "analyze_features", ")", ":", "# Load from pickled file", "logging", ".", "info", "(", "\"Start loading data '%s' ...\"", ",", "handwriting_datasets_file", ")", "loaded", "=", "pickle", ".", "load", "(", "open", "(...
Start the creation of the wanted metric.
[ "Start", "the", "creation", "of", "the", "wanted", "metric", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/analyze_data.py#L93-L122
train
59,371
MartinThoma/hwrt
hwrt/datasets/mathbrush.py
remove_matching_braces
def remove_matching_braces(latex): """ If `latex` is surrounded by matching braces, remove them. They are not necessary. Parameters ---------- latex : string Returns ------- string Examples -------- >>> remove_matching_braces('{2+2}') '2+2' >>> remove_matching_...
python
def remove_matching_braces(latex): """ If `latex` is surrounded by matching braces, remove them. They are not necessary. Parameters ---------- latex : string Returns ------- string Examples -------- >>> remove_matching_braces('{2+2}') '2+2' >>> remove_matching_...
[ "def", "remove_matching_braces", "(", "latex", ")", ":", "if", "latex", ".", "startswith", "(", "'{'", ")", "and", "latex", ".", "endswith", "(", "'}'", ")", ":", "opened", "=", "1", "matches", "=", "True", "for", "char", "in", "latex", "[", "1", ":"...
If `latex` is surrounded by matching braces, remove them. They are not necessary. Parameters ---------- latex : string Returns ------- string Examples -------- >>> remove_matching_braces('{2+2}') '2+2' >>> remove_matching_braces('{2+2') '{2+2'
[ "If", "latex", "is", "surrounded", "by", "matching", "braces", "remove", "them", ".", "They", "are", "not", "necessary", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/datasets/mathbrush.py#L45-L77
train
59,372
MartinThoma/hwrt
hwrt/datasets/mathbrush.py
read_folder
def read_folder(folder): """Read all files of `folder` and return a list of HandwrittenData objects. Parameters ---------- folder : string Path to a folder Returns ------- list : A list of all .ink files in the given folder. """ recordings = [] for filename ...
python
def read_folder(folder): """Read all files of `folder` and return a list of HandwrittenData objects. Parameters ---------- folder : string Path to a folder Returns ------- list : A list of all .ink files in the given folder. """ recordings = [] for filename ...
[ "def", "read_folder", "(", "folder", ")", ":", "recordings", "=", "[", "]", "for", "filename", "in", "glob", ".", "glob", "(", "os", ".", "path", ".", "join", "(", "folder", ",", "'*.ink'", ")", ")", ":", "recording", "=", "parse_scg_ink_file", "(", ...
Read all files of `folder` and return a list of HandwrittenData objects. Parameters ---------- folder : string Path to a folder Returns ------- list : A list of all .ink files in the given folder.
[ "Read", "all", "files", "of", "folder", "and", "return", "a", "list", "of", "HandwrittenData", "objects", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/datasets/mathbrush.py#L250-L268
train
59,373
MartinThoma/hwrt
hwrt/handwritten_data.py
_get_colors
def _get_colors(segmentation): """Get a list of colors which is as long as the segmentation. Parameters ---------- segmentation : list of lists Returns ------- list A list of colors. """ symbol_count = len(segmentation) num_colors = symbol_count # See http://stacko...
python
def _get_colors(segmentation): """Get a list of colors which is as long as the segmentation. Parameters ---------- segmentation : list of lists Returns ------- list A list of colors. """ symbol_count = len(segmentation) num_colors = symbol_count # See http://stacko...
[ "def", "_get_colors", "(", "segmentation", ")", ":", "symbol_count", "=", "len", "(", "segmentation", ")", "num_colors", "=", "symbol_count", "# See http://stackoverflow.com/a/20298116/562769", "color_array", "=", "[", "\"#000000\"", ",", "\"#FFFF00\"", ",", "\"#1CE6FF\...
Get a list of colors which is as long as the segmentation. Parameters ---------- segmentation : list of lists Returns ------- list A list of colors.
[ "Get", "a", "list", "of", "colors", "which", "is", "as", "long", "as", "the", "segmentation", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/handwritten_data.py#L352-L401
train
59,374
MartinThoma/hwrt
hwrt/handwritten_data.py
HandwrittenData.fix_times
def fix_times(self): """ Some recordings have wrong times. Fix them so that nothing after loading a handwritten recording breaks. """ pointlist = self.get_pointlist() times = [point['time'] for stroke in pointlist for point in stroke] times_min = max(min(times), 0...
python
def fix_times(self): """ Some recordings have wrong times. Fix them so that nothing after loading a handwritten recording breaks. """ pointlist = self.get_pointlist() times = [point['time'] for stroke in pointlist for point in stroke] times_min = max(min(times), 0...
[ "def", "fix_times", "(", "self", ")", ":", "pointlist", "=", "self", ".", "get_pointlist", "(", ")", "times", "=", "[", "point", "[", "'time'", "]", "for", "stroke", "in", "pointlist", "for", "point", "in", "stroke", "]", "times_min", "=", "max", "(", ...
Some recordings have wrong times. Fix them so that nothing after loading a handwritten recording breaks.
[ "Some", "recordings", "have", "wrong", "times", ".", "Fix", "them", "so", "that", "nothing", "after", "loading", "a", "handwritten", "recording", "breaks", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/handwritten_data.py#L43-L57
train
59,375
MartinThoma/hwrt
hwrt/handwritten_data.py
HandwrittenData.get_pointlist
def get_pointlist(self): """ Get a list of lists of tuples from JSON raw data string. Those lists represent strokes with control points. Returns ------- list : A list of strokes. Each stroke is a list of dictionaries {'x': 123, 'y': 42, 'time': 13...
python
def get_pointlist(self): """ Get a list of lists of tuples from JSON raw data string. Those lists represent strokes with control points. Returns ------- list : A list of strokes. Each stroke is a list of dictionaries {'x': 123, 'y': 42, 'time': 13...
[ "def", "get_pointlist", "(", "self", ")", ":", "try", ":", "pointlist", "=", "json", ".", "loads", "(", "self", ".", "raw_data_json", ")", "except", "Exception", "as", "inst", ":", "logging", ".", "debug", "(", "\"pointStrokeList: strokelistP\"", ")", "loggi...
Get a list of lists of tuples from JSON raw data string. Those lists represent strokes with control points. Returns ------- list : A list of strokes. Each stroke is a list of dictionaries {'x': 123, 'y': 42, 'time': 1337}
[ "Get", "a", "list", "of", "lists", "of", "tuples", "from", "JSON", "raw", "data", "string", ".", "Those", "lists", "represent", "strokes", "with", "control", "points", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/handwritten_data.py#L59-L81
train
59,376
MartinThoma/hwrt
hwrt/handwritten_data.py
HandwrittenData.get_sorted_pointlist
def get_sorted_pointlist(self): """ Make sure that the points and strokes are in order. Returns ------- list A list of all strokes in the recording. Each stroke is represented as a list of dicts {'time': 123, 'x': 45, 'y': 67} """ pointlis...
python
def get_sorted_pointlist(self): """ Make sure that the points and strokes are in order. Returns ------- list A list of all strokes in the recording. Each stroke is represented as a list of dicts {'time': 123, 'x': 45, 'y': 67} """ pointlis...
[ "def", "get_sorted_pointlist", "(", "self", ")", ":", "pointlist", "=", "self", ".", "get_pointlist", "(", ")", "for", "i", "in", "range", "(", "len", "(", "pointlist", ")", ")", ":", "pointlist", "[", "i", "]", "=", "sorted", "(", "pointlist", "[", ...
Make sure that the points and strokes are in order. Returns ------- list A list of all strokes in the recording. Each stroke is represented as a list of dicts {'time': 123, 'x': 45, 'y': 67}
[ "Make", "sure", "that", "the", "points", "and", "strokes", "are", "in", "order", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/handwritten_data.py#L83-L97
train
59,377
MartinThoma/hwrt
hwrt/handwritten_data.py
HandwrittenData.set_pointlist
def set_pointlist(self, pointlist): """Overwrite pointlist. Parameters ---------- pointlist : a list of strokes; each stroke is a list of points The inner lists represent strokes. Every stroke consists of points. Every point is a dictinary with 'x', 'y', 'time'. ...
python
def set_pointlist(self, pointlist): """Overwrite pointlist. Parameters ---------- pointlist : a list of strokes; each stroke is a list of points The inner lists represent strokes. Every stroke consists of points. Every point is a dictinary with 'x', 'y', 'time'. ...
[ "def", "set_pointlist", "(", "self", ",", "pointlist", ")", ":", "assert", "type", "(", "pointlist", ")", "is", "list", ",", "\"pointlist is not of type list, but %r\"", "%", "type", "(", "pointlist", ")", "assert", "len", "(", "pointlist", ")", ">=", "1", "...
Overwrite pointlist. Parameters ---------- pointlist : a list of strokes; each stroke is a list of points The inner lists represent strokes. Every stroke consists of points. Every point is a dictinary with 'x', 'y', 'time'.
[ "Overwrite", "pointlist", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/handwritten_data.py#L99-L113
train
59,378
MartinThoma/hwrt
hwrt/handwritten_data.py
HandwrittenData.get_bounding_box
def get_bounding_box(self): """ Get the bounding box of a pointlist. """ pointlist = self.get_pointlist() # Initialize bounding box parameters to save values minx, maxx = pointlist[0][0]["x"], pointlist[0][0]["x"] miny, maxy = pointlist[0][0]["y"], pointlist[0][0]["y"] m...
python
def get_bounding_box(self): """ Get the bounding box of a pointlist. """ pointlist = self.get_pointlist() # Initialize bounding box parameters to save values minx, maxx = pointlist[0][0]["x"], pointlist[0][0]["x"] miny, maxy = pointlist[0][0]["y"], pointlist[0][0]["y"] m...
[ "def", "get_bounding_box", "(", "self", ")", ":", "pointlist", "=", "self", ".", "get_pointlist", "(", ")", "# Initialize bounding box parameters to save values", "minx", ",", "maxx", "=", "pointlist", "[", "0", "]", "[", "0", "]", "[", "\"x\"", "]", ",", "p...
Get the bounding box of a pointlist.
[ "Get", "the", "bounding", "box", "of", "a", "pointlist", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/handwritten_data.py#L115-L131
train
59,379
MartinThoma/hwrt
hwrt/handwritten_data.py
HandwrittenData.get_bitmap
def get_bitmap(self, time=None, size=32, store_path=None): """ Get a bitmap of the object at a given instance of time. If time is `None`,`then the bitmap is generated for the last point in time. Parameters ---------- time : int or None size : int Size...
python
def get_bitmap(self, time=None, size=32, store_path=None): """ Get a bitmap of the object at a given instance of time. If time is `None`,`then the bitmap is generated for the last point in time. Parameters ---------- time : int or None size : int Size...
[ "def", "get_bitmap", "(", "self", ",", "time", "=", "None", ",", "size", "=", "32", ",", "store_path", "=", "None", ")", ":", "# bitmap_width = int(self.get_width()*size) + 2", "# bitmap_height = int(self.get_height()*size) + 2", "img", "=", "Image", ".", "new", "("...
Get a bitmap of the object at a given instance of time. If time is `None`,`then the bitmap is generated for the last point in time. Parameters ---------- time : int or None size : int Size in pixels. The resulting bitmap will be (size x size). store_path : No...
[ "Get", "a", "bitmap", "of", "the", "object", "at", "a", "given", "instance", "of", "time", ".", "If", "time", "is", "None", "then", "the", "bitmap", "is", "generated", "for", "the", "last", "point", "in", "time", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/handwritten_data.py#L152-L194
train
59,380
MartinThoma/hwrt
hwrt/handwritten_data.py
HandwrittenData.preprocessing
def preprocessing(self, algorithms): """Apply preprocessing algorithms. Parameters ---------- algorithms : a list objects Preprocessing allgorithms which get applied in order. Examples -------- >>> import preprocessing >>> a = HandwrittenData...
python
def preprocessing(self, algorithms): """Apply preprocessing algorithms. Parameters ---------- algorithms : a list objects Preprocessing allgorithms which get applied in order. Examples -------- >>> import preprocessing >>> a = HandwrittenData...
[ "def", "preprocessing", "(", "self", ",", "algorithms", ")", ":", "assert", "type", "(", "algorithms", ")", "is", "list", "for", "algorithm", "in", "algorithms", ":", "algorithm", "(", "self", ")" ]
Apply preprocessing algorithms. Parameters ---------- algorithms : a list objects Preprocessing allgorithms which get applied in order. Examples -------- >>> import preprocessing >>> a = HandwrittenData(...) >>> preprocessing_queue = [(prepro...
[ "Apply", "preprocessing", "algorithms", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/handwritten_data.py#L196-L219
train
59,381
MartinThoma/hwrt
hwrt/handwritten_data.py
HandwrittenData.feature_extraction
def feature_extraction(self, algorithms): """Get a list of features. Every algorithm has to return the features as a list.""" assert type(algorithms) is list features = [] for algorithm in algorithms: new_features = algorithm(self) assert len(new_features...
python
def feature_extraction(self, algorithms): """Get a list of features. Every algorithm has to return the features as a list.""" assert type(algorithms) is list features = [] for algorithm in algorithms: new_features = algorithm(self) assert len(new_features...
[ "def", "feature_extraction", "(", "self", ",", "algorithms", ")", ":", "assert", "type", "(", "algorithms", ")", "is", "list", "features", "=", "[", "]", "for", "algorithm", "in", "algorithms", ":", "new_features", "=", "algorithm", "(", "self", ")", "asse...
Get a list of features. Every algorithm has to return the features as a list.
[ "Get", "a", "list", "of", "features", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/handwritten_data.py#L221-L233
train
59,382
MartinThoma/hwrt
hwrt/handwritten_data.py
HandwrittenData.show
def show(self): """Show the data graphically in a new pop-up window.""" # prevent the following error: # '_tkinter.TclError: no display name and no $DISPLAY environment # variable' # import matplotlib # matplotlib.use('GTK3Agg', warn=False) import matplotlib....
python
def show(self): """Show the data graphically in a new pop-up window.""" # prevent the following error: # '_tkinter.TclError: no display name and no $DISPLAY environment # variable' # import matplotlib # matplotlib.use('GTK3Agg', warn=False) import matplotlib....
[ "def", "show", "(", "self", ")", ":", "# prevent the following error:", "# '_tkinter.TclError: no display name and no $DISPLAY environment", "# variable'", "# import matplotlib", "# matplotlib.use('GTK3Agg', warn=False)", "import", "matplotlib", ".", "pyplot", "as", "plt", "poin...
Show the data graphically in a new pop-up window.
[ "Show", "the", "data", "graphically", "in", "a", "new", "pop", "-", "up", "window", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/handwritten_data.py#L235-L287
train
59,383
MartinThoma/hwrt
hwrt/handwritten_data.py
HandwrittenData.count_single_dots
def count_single_dots(self): """Count all strokes of this recording that have only a single dot. """ pointlist = self.get_pointlist() single_dots = 0 for stroke in pointlist: if len(stroke) == 1: single_dots += 1 return single_dots
python
def count_single_dots(self): """Count all strokes of this recording that have only a single dot. """ pointlist = self.get_pointlist() single_dots = 0 for stroke in pointlist: if len(stroke) == 1: single_dots += 1 return single_dots
[ "def", "count_single_dots", "(", "self", ")", ":", "pointlist", "=", "self", ".", "get_pointlist", "(", ")", "single_dots", "=", "0", "for", "stroke", "in", "pointlist", ":", "if", "len", "(", "stroke", ")", "==", "1", ":", "single_dots", "+=", "1", "r...
Count all strokes of this recording that have only a single dot.
[ "Count", "all", "strokes", "of", "this", "recording", "that", "have", "only", "a", "single", "dot", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/handwritten_data.py#L289-L297
train
59,384
MartinThoma/hwrt
hwrt/handwritten_data.py
HandwrittenData.to_single_symbol_list
def to_single_symbol_list(self): """ Convert this HandwrittenData object into a list of HandwrittenData objects. Each element of the list is a single symbol. Returns ------- list of HandwrittenData objects """ symbol_stream = getattr(self, ...
python
def to_single_symbol_list(self): """ Convert this HandwrittenData object into a list of HandwrittenData objects. Each element of the list is a single symbol. Returns ------- list of HandwrittenData objects """ symbol_stream = getattr(self, ...
[ "def", "to_single_symbol_list", "(", "self", ")", ":", "symbol_stream", "=", "getattr", "(", "self", ",", "'symbol_stream'", ",", "[", "None", "for", "symbol", "in", "self", ".", "segmentation", "]", ")", "single_symbols", "=", "[", "]", "pointlist", "=", ...
Convert this HandwrittenData object into a list of HandwrittenData objects. Each element of the list is a single symbol. Returns ------- list of HandwrittenData objects
[ "Convert", "this", "HandwrittenData", "object", "into", "a", "list", "of", "HandwrittenData", "objects", ".", "Each", "element", "of", "the", "list", "is", "a", "single", "symbol", "." ]
725c21a3d0f5a30b8492cbc184b3688ceb364e1c
https://github.com/MartinThoma/hwrt/blob/725c21a3d0f5a30b8492cbc184b3688ceb364e1c/hwrt/handwritten_data.py#L313-L333
train
59,385
acsone/setuptools-odoo
setuptools_odoo/git_postversion.py
get_git_postversion
def get_git_postversion(addon_dir): """ return the addon version number, with a developmental version increment if there were git commits in the addon_dir after the last version change. If the last change to the addon correspond to the version number in the manifest it is used as is for the python pack...
python
def get_git_postversion(addon_dir): """ return the addon version number, with a developmental version increment if there were git commits in the addon_dir after the last version change. If the last change to the addon correspond to the version number in the manifest it is used as is for the python pack...
[ "def", "get_git_postversion", "(", "addon_dir", ")", ":", "addon_dir", "=", "os", ".", "path", ".", "realpath", "(", "addon_dir", ")", "last_version", "=", "read_manifest", "(", "addon_dir", ")", ".", "get", "(", "'version'", ",", "'0.0.0'", ")", "last_versi...
return the addon version number, with a developmental version increment if there were git commits in the addon_dir after the last version change. If the last change to the addon correspond to the version number in the manifest it is used as is for the python package version. Otherwise a counter is incr...
[ "return", "the", "addon", "version", "number", "with", "a", "developmental", "version", "increment", "if", "there", "were", "git", "commits", "in", "the", "addon_dir", "after", "the", "last", "version", "change", "." ]
cc4d7a63cf99fb3651c8c92f66f7dd13bf2afe6b
https://github.com/acsone/setuptools-odoo/blob/cc4d7a63cf99fb3651c8c92f66f7dd13bf2afe6b/setuptools_odoo/git_postversion.py#L82-L134
train
59,386
acsone/setuptools-odoo
setuptools_odoo/core.py
_get_odoo_version_info
def _get_odoo_version_info(addons_dir, odoo_version_override=None): """ Detect Odoo version from an addons directory """ odoo_version_info = None addons = os.listdir(addons_dir) for addon in addons: addon_dir = os.path.join(addons_dir, addon) if is_installable_addon(addon_dir): ...
python
def _get_odoo_version_info(addons_dir, odoo_version_override=None): """ Detect Odoo version from an addons directory """ odoo_version_info = None addons = os.listdir(addons_dir) for addon in addons: addon_dir = os.path.join(addons_dir, addon) if is_installable_addon(addon_dir): ...
[ "def", "_get_odoo_version_info", "(", "addons_dir", ",", "odoo_version_override", "=", "None", ")", ":", "odoo_version_info", "=", "None", "addons", "=", "os", ".", "listdir", "(", "addons_dir", ")", "for", "addon", "in", "addons", ":", "addon_dir", "=", "os",...
Detect Odoo version from an addons directory
[ "Detect", "Odoo", "version", "from", "an", "addons", "directory" ]
cc4d7a63cf99fb3651c8c92f66f7dd13bf2afe6b
https://github.com/acsone/setuptools-odoo/blob/cc4d7a63cf99fb3651c8c92f66f7dd13bf2afe6b/setuptools_odoo/core.py#L78-L95
train
59,387
acsone/setuptools-odoo
setuptools_odoo/core.py
_get_version
def _get_version(addon_dir, manifest, odoo_version_override=None, git_post_version=True): """ Get addon version information from an addon directory """ version = manifest.get('version') if not version: warn("No version in manifest in %s" % addon_dir) version = '0.0.0' if...
python
def _get_version(addon_dir, manifest, odoo_version_override=None, git_post_version=True): """ Get addon version information from an addon directory """ version = manifest.get('version') if not version: warn("No version in manifest in %s" % addon_dir) version = '0.0.0' if...
[ "def", "_get_version", "(", "addon_dir", ",", "manifest", ",", "odoo_version_override", "=", "None", ",", "git_post_version", "=", "True", ")", ":", "version", "=", "manifest", ".", "get", "(", "'version'", ")", "if", "not", "version", ":", "warn", "(", "\...
Get addon version information from an addon directory
[ "Get", "addon", "version", "information", "from", "an", "addon", "directory" ]
cc4d7a63cf99fb3651c8c92f66f7dd13bf2afe6b
https://github.com/acsone/setuptools-odoo/blob/cc4d7a63cf99fb3651c8c92f66f7dd13bf2afe6b/setuptools_odoo/core.py#L98-L120
train
59,388
acsone/setuptools-odoo
setuptools_odoo/core.py
get_install_requires_odoo_addon
def get_install_requires_odoo_addon(addon_dir, no_depends=[], depends_override={}, external_dependencies_override={}, odoo_version_override=None): """ Get the list of requi...
python
def get_install_requires_odoo_addon(addon_dir, no_depends=[], depends_override={}, external_dependencies_override={}, odoo_version_override=None): """ Get the list of requi...
[ "def", "get_install_requires_odoo_addon", "(", "addon_dir", ",", "no_depends", "=", "[", "]", ",", "depends_override", "=", "{", "}", ",", "external_dependencies_override", "=", "{", "}", ",", "odoo_version_override", "=", "None", ")", ":", "manifest", "=", "rea...
Get the list of requirements for an addon
[ "Get", "the", "list", "of", "requirements", "for", "an", "addon" ]
cc4d7a63cf99fb3651c8c92f66f7dd13bf2afe6b
https://github.com/acsone/setuptools-odoo/blob/cc4d7a63cf99fb3651c8c92f66f7dd13bf2afe6b/setuptools_odoo/core.py#L193-L208
train
59,389
acsone/setuptools-odoo
setuptools_odoo/core.py
get_install_requires_odoo_addons
def get_install_requires_odoo_addons(addons_dir, depends_override={}, external_dependencies_override={}, odoo_version_override=None): """ Get the list of requirements for a directory containing addons """ ...
python
def get_install_requires_odoo_addons(addons_dir, depends_override={}, external_dependencies_override={}, odoo_version_override=None): """ Get the list of requirements for a directory containing addons """ ...
[ "def", "get_install_requires_odoo_addons", "(", "addons_dir", ",", "depends_override", "=", "{", "}", ",", "external_dependencies_override", "=", "{", "}", ",", "odoo_version_override", "=", "None", ")", ":", "addon_dirs", "=", "[", "]", "addons", "=", "os", "."...
Get the list of requirements for a directory containing addons
[ "Get", "the", "list", "of", "requirements", "for", "a", "directory", "containing", "addons" ]
cc4d7a63cf99fb3651c8c92f66f7dd13bf2afe6b
https://github.com/acsone/setuptools-odoo/blob/cc4d7a63cf99fb3651c8c92f66f7dd13bf2afe6b/setuptools_odoo/core.py#L211-L232
train
59,390
dgilland/flask-alchy
flask_alchy.py
Alchy.make_declarative_base
def make_declarative_base(self, metadata=None): """Override parent function with alchy's""" return make_declarative_base(self.session, Model=self.Model, metadata=metadata)
python
def make_declarative_base(self, metadata=None): """Override parent function with alchy's""" return make_declarative_base(self.session, Model=self.Model, metadata=metadata)
[ "def", "make_declarative_base", "(", "self", ",", "metadata", "=", "None", ")", ":", "return", "make_declarative_base", "(", "self", ".", "session", ",", "Model", "=", "self", ".", "Model", ",", "metadata", "=", "metadata", ")" ]
Override parent function with alchy's
[ "Override", "parent", "function", "with", "alchy", "s" ]
25795bb14513769105e1da419a8f7366040ade42
https://github.com/dgilland/flask-alchy/blob/25795bb14513769105e1da419a8f7366040ade42/flask_alchy.py#L33-L37
train
59,391
capless/kev
kev/backends/__init__.py
DocDB.prep_doc
def prep_doc(self, doc_obj): """ This method Validates, gets the Python value, checks unique indexes, gets the db value, and then returns the prepared doc dict object. Useful for save and backup functions. @param doc_obj: @return: """ doc = doc_obj._da...
python
def prep_doc(self, doc_obj): """ This method Validates, gets the Python value, checks unique indexes, gets the db value, and then returns the prepared doc dict object. Useful for save and backup functions. @param doc_obj: @return: """ doc = doc_obj._da...
[ "def", "prep_doc", "(", "self", ",", "doc_obj", ")", ":", "doc", "=", "doc_obj", ".", "_data", ".", "copy", "(", ")", "for", "key", ",", "prop", "in", "list", "(", "doc_obj", ".", "_base_properties", ".", "items", "(", ")", ")", ":", "prop", ".", ...
This method Validates, gets the Python value, checks unique indexes, gets the db value, and then returns the prepared doc dict object. Useful for save and backup functions. @param doc_obj: @return:
[ "This", "method", "Validates", "gets", "the", "Python", "value", "checks", "unique", "indexes", "gets", "the", "db", "value", "and", "then", "returns", "the", "prepared", "doc", "dict", "object", ".", "Useful", "for", "save", "and", "backup", "functions", "....
902f4d5d89482b2eedcf9a396d57be7083357024
https://github.com/capless/kev/blob/902f4d5d89482b2eedcf9a396d57be7083357024/kev/backends/__init__.py#L52-L70
train
59,392
Miserlou/flask-zappa
bin/client.py
apply_zappa_settings
def apply_zappa_settings(zappa_obj, zappa_settings, environment): '''Load Zappa settings, set defaults if needed, and apply to the Zappa object''' settings_all = json.load(zappa_settings) settings = settings_all[environment] # load defaults for missing options for key,value in DEFAULT_SETTINGS.ite...
python
def apply_zappa_settings(zappa_obj, zappa_settings, environment): '''Load Zappa settings, set defaults if needed, and apply to the Zappa object''' settings_all = json.load(zappa_settings) settings = settings_all[environment] # load defaults for missing options for key,value in DEFAULT_SETTINGS.ite...
[ "def", "apply_zappa_settings", "(", "zappa_obj", ",", "zappa_settings", ",", "environment", ")", ":", "settings_all", "=", "json", ".", "load", "(", "zappa_settings", ")", "settings", "=", "settings_all", "[", "environment", "]", "# load defaults for missing options",...
Load Zappa settings, set defaults if needed, and apply to the Zappa object
[ "Load", "Zappa", "settings", "set", "defaults", "if", "needed", "and", "apply", "to", "the", "Zappa", "object" ]
18af3c1ff3943d3c7b8b7f96d4ab5f147b9662f8
https://github.com/Miserlou/flask-zappa/blob/18af3c1ff3943d3c7b8b7f96d4ab5f147b9662f8/bin/client.py#L35-L55
train
59,393
Miserlou/flask-zappa
bin/client.py
deploy
def deploy(environment, zappa_settings): """ Package, create and deploy to Lambda.""" print(("Deploying " + environment)) zappa, settings, lambda_name, zip_path = \ _package(environment, zappa_settings) s3_bucket_name = settings['s3_bucket'] try: # Load your AWS credentials from ~...
python
def deploy(environment, zappa_settings): """ Package, create and deploy to Lambda.""" print(("Deploying " + environment)) zappa, settings, lambda_name, zip_path = \ _package(environment, zappa_settings) s3_bucket_name = settings['s3_bucket'] try: # Load your AWS credentials from ~...
[ "def", "deploy", "(", "environment", ",", "zappa_settings", ")", ":", "print", "(", "(", "\"Deploying \"", "+", "environment", ")", ")", "zappa", ",", "settings", ",", "lambda_name", ",", "zip_path", "=", "_package", "(", "environment", ",", "zappa_settings", ...
Package, create and deploy to Lambda.
[ "Package", "create", "and", "deploy", "to", "Lambda", "." ]
18af3c1ff3943d3c7b8b7f96d4ab5f147b9662f8
https://github.com/Miserlou/flask-zappa/blob/18af3c1ff3943d3c7b8b7f96d4ab5f147b9662f8/bin/client.py#L128-L175
train
59,394
Miserlou/flask-zappa
bin/client.py
update
def update(environment, zappa_settings): """ Update an existing deployment.""" print(("Updating " + environment)) # Package dependencies, and the source code into a zip zappa, settings, lambda_name, zip_path = \ _package(environment, zappa_settings) s3_bucket_name = settings['s3_bucket'] ...
python
def update(environment, zappa_settings): """ Update an existing deployment.""" print(("Updating " + environment)) # Package dependencies, and the source code into a zip zappa, settings, lambda_name, zip_path = \ _package(environment, zappa_settings) s3_bucket_name = settings['s3_bucket'] ...
[ "def", "update", "(", "environment", ",", "zappa_settings", ")", ":", "print", "(", "(", "\"Updating \"", "+", "environment", ")", ")", "# Package dependencies, and the source code into a zip", "zappa", ",", "settings", ",", "lambda_name", ",", "zip_path", "=", "_pa...
Update an existing deployment.
[ "Update", "an", "existing", "deployment", "." ]
18af3c1ff3943d3c7b8b7f96d4ab5f147b9662f8
https://github.com/Miserlou/flask-zappa/blob/18af3c1ff3943d3c7b8b7f96d4ab5f147b9662f8/bin/client.py#L181-L218
train
59,395
Miserlou/flask-zappa
flask_zappa/handler.py
lambda_handler
def lambda_handler(event, context, settings_name="zappa_settings"): """ An AWS Lambda function which parses specific API Gateway input into a WSGI request, feeds it to Flask, procceses the Flask response, and returns that back to the API Gateway. """ # Loading settings from a python module setti...
python
def lambda_handler(event, context, settings_name="zappa_settings"): """ An AWS Lambda function which parses specific API Gateway input into a WSGI request, feeds it to Flask, procceses the Flask response, and returns that back to the API Gateway. """ # Loading settings from a python module setti...
[ "def", "lambda_handler", "(", "event", ",", "context", ",", "settings_name", "=", "\"zappa_settings\"", ")", ":", "# Loading settings from a python module", "settings", "=", "importlib", ".", "import_module", "(", "settings_name", ")", "# The flask-app module", "app_modul...
An AWS Lambda function which parses specific API Gateway input into a WSGI request, feeds it to Flask, procceses the Flask response, and returns that back to the API Gateway.
[ "An", "AWS", "Lambda", "function", "which", "parses", "specific", "API", "Gateway", "input", "into", "a", "WSGI", "request", "feeds", "it", "to", "Flask", "procceses", "the", "Flask", "response", "and", "returns", "that", "back", "to", "the", "API", "Gateway...
18af3c1ff3943d3c7b8b7f96d4ab5f147b9662f8
https://github.com/Miserlou/flask-zappa/blob/18af3c1ff3943d3c7b8b7f96d4ab5f147b9662f8/flask_zappa/handler.py#L15-L106
train
59,396
frankban/django-endless-pagination
endless_pagination/views.py
MultipleObjectMixin.get_context_data
def get_context_data(self, **kwargs): """Get the context for this view. Also adds the *page_template* variable in the context. If the *page_template* is not given as a kwarg of the *as_view* method then it is generated using app label, model name (obviously if the list is a que...
python
def get_context_data(self, **kwargs): """Get the context for this view. Also adds the *page_template* variable in the context. If the *page_template* is not given as a kwarg of the *as_view* method then it is generated using app label, model name (obviously if the list is a que...
[ "def", "get_context_data", "(", "self", ",", "*", "*", "kwargs", ")", ":", "queryset", "=", "kwargs", ".", "pop", "(", "'object_list'", ")", "page_template", "=", "kwargs", ".", "pop", "(", "'page_template'", ",", "None", ")", "context_object_name", "=", "...
Get the context for this view. Also adds the *page_template* variable in the context. If the *page_template* is not given as a kwarg of the *as_view* method then it is generated using app label, model name (obviously if the list is a queryset), *self.template_name_suffix* and *...
[ "Get", "the", "context", "for", "this", "view", "." ]
4814fe7cf81277efe35e96b88f57cc260a771255
https://github.com/frankban/django-endless-pagination/blob/4814fe7cf81277efe35e96b88f57cc260a771255/endless_pagination/views.py#L63-L93
train
59,397
SpockBotMC/SpockBot
spockbot/mcdata/utils.py
clean_var
def clean_var(text): """Turn text into a valid python classname or variable""" text = re_invalid_var.sub('', text) text = re_invalid_start.sub('', text) return text
python
def clean_var(text): """Turn text into a valid python classname or variable""" text = re_invalid_var.sub('', text) text = re_invalid_start.sub('', text) return text
[ "def", "clean_var", "(", "text", ")", ":", "text", "=", "re_invalid_var", ".", "sub", "(", "''", ",", "text", ")", "text", "=", "re_invalid_start", ".", "sub", "(", "''", ",", "text", ")", "return", "text" ]
Turn text into a valid python classname or variable
[ "Turn", "text", "into", "a", "valid", "python", "classname", "or", "variable" ]
f89911551f18357720034fbaa52837a0d09f66ea
https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/mcdata/utils.py#L65-L69
train
59,398
SpockBotMC/SpockBot
spockbot/plugins/tools/task.py
TaskFailed.full_tasktrace
def full_tasktrace(self): """ List of all failed tasks caused by this and all previous errors. Returns: List[Task] """ if self.prev_error: return self.prev_error.tasktrace + self.tasktrace else: return self.tasktrace
python
def full_tasktrace(self): """ List of all failed tasks caused by this and all previous errors. Returns: List[Task] """ if self.prev_error: return self.prev_error.tasktrace + self.tasktrace else: return self.tasktrace
[ "def", "full_tasktrace", "(", "self", ")", ":", "if", "self", ".", "prev_error", ":", "return", "self", ".", "prev_error", ".", "tasktrace", "+", "self", ".", "tasktrace", "else", ":", "return", "self", ".", "tasktrace" ]
List of all failed tasks caused by this and all previous errors. Returns: List[Task]
[ "List", "of", "all", "failed", "tasks", "caused", "by", "this", "and", "all", "previous", "errors", "." ]
f89911551f18357720034fbaa52837a0d09f66ea
https://github.com/SpockBotMC/SpockBot/blob/f89911551f18357720034fbaa52837a0d09f66ea/spockbot/plugins/tools/task.py#L70-L80
train
59,399