diff --git a/kgtk/__init__.py b/kgtk/__init__.py index 0bb84ff29..c24ed73be 100644 --- a/kgtk/__init__.py +++ b/kgtk/__init__.py @@ -1 +1 @@ -__version__ = '1.5.3' +__version__ = '1.5.4' diff --git a/kgtk/cli/calc.py b/kgtk/cli/calc.py index bf2d737b7..36d222fdc 100644 --- a/kgtk/cli/calc.py +++ b/kgtk/cli/calc.py @@ -76,6 +76,7 @@ def parser(): MIN_OP: str = "min" MINUS_OP: str = "minus" # (column1 - column2) or (column - value) MOD_OP: str = "mod" # (column mod column) or (column mod value) +MULTIPLY_OP: str = "multiply" # (column x column) or (column x value) NEGATE_OP: str = "negate" # (column, ...) NUMBER_OP: str = "number" # Get a number or the numeric part of a quantity. PERCENTAGE_OP: str = "percentage" @@ -1855,6 +1856,27 @@ def mod_op()->bool: return True opfunc = mod_op + elif operation == MULTIPLY_OP: + if not ((len(sources) == 2 and len(values) == 0) or (len(sources) == 1 and len(values) == 1)): + raise KGTKException("Multiply needs two sources or one source and one value, got %d sources and %d values" % (len(sources), len(values))) + if len(into_column_idxs) != 1: + raise KGTKException("Multiply needs 1 destination columns, got %d" % len(into_column_idxs)) + + def multiply_2_op()->bool: + # TODO: support quantities. + output_row[into_column_idx] = str(float(row[sources[0]]) * float(row[sources[1]])) + return True + + def multiply_1op()->bool: + # TODO: support quantities. + output_row[into_column_idx] = str(float(row[sources[0]]) * float(values[0])) + return True + + if len(sources) == 2: + opfunc = multiply_2_op + else: + opfunc = multiply_1_op + elif operation == NAND_OP: if len(sources) == 0: raise KGTKException("Nand needs at least one source, got %d" % len(sources)) diff --git a/requirements.txt b/requirements.txt index e0aae13e0..fd5f8520e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ rdflib==6.1.1 rdflib-jsonld==0.6.2 pyshacl>=0.19.0 rfc3986 -thinc==7.4.0 +thinc plac==1.1.3 parsley>=1.3 peewee>=3.14.10