From ac36e56b2a01dac1283122c7be7e7a6651a935ae Mon Sep 17 00:00:00 2001 From: Craig Milo Rogers Date: Mon, 24 Apr 2023 22:55:50 -0700 Subject: [PATCH 1/3] Add support for multiplication in kgtk calc. --- kgtk/cli/calc.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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)) From 8c1e4efa3e421cd5ea140c2e1b624f512a4a7cbd Mon Sep 17 00:00:00 2001 From: saggu Date: Thu, 29 Jun 2023 11:45:10 -0700 Subject: [PATCH 2/3] remove version from thinc requirement --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 61dfa5657929e15d5cfebf8168183c63c98c3be6 Mon Sep 17 00:00:00 2001 From: saggu Date: Thu, 29 Jun 2023 11:45:31 -0700 Subject: [PATCH 3/3] update version for release --- kgtk/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'