diff options
author | Gunnar Aastrand Grimnes <gromgull@gmail.com> | 2017-04-11 10:51:47 +0200 |
---|---|---|
committer | Gunnar Aastrand Grimnes <gromgull@gmail.com> | 2017-04-11 10:51:54 +0200 |
commit | 95a0491071b18148424ee071305cdddf7f36f7de (patch) | |
tree | 9464c96d8dad24b46126dcef271f03d5272e38fb /rdflib/tools | |
parent | 8788cc603b1ffee58bf4f0c08b783d32e37ca472 (diff) | |
download | rdflib-95a0491071b18148424ee071305cdddf7f36f7de.tar.gz |
bool support for csv2rdf
Diffstat (limited to 'rdflib/tools')
-rw-r--r-- | rdflib/tools/csv2rdf.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/rdflib/tools/csv2rdf.py b/rdflib/tools/csv2rdf.py index 4e02f9ca..8d5b06b2 100644 --- a/rdflib/tools/csv2rdf.py +++ b/rdflib/tools/csv2rdf.py @@ -198,6 +198,17 @@ class NodeInt(NodeLiteral): def range(self): return rdflib.XSD.int +class NodeBool(NodeLiteral): + def __call__(self, x): + if not self.f: + return rdflib.Literal(bool(x)) + if callable(self.f): + return rdflib.Literal(bool(self.f(x))) + raise Exception("Function passed to bool is not callable") + + def range(self): + return rdflib.XSD.bool + class NodeReplace(NodeMaker): def __init__(self, a, b): @@ -260,6 +271,9 @@ def _config_replace(a, b): def _config_int(f=None): return NodeInt(f) +def _config_bool(f=None): + return NodeBool(f) + def _config_date(format_): return NodeDate(format_) @@ -275,7 +289,8 @@ config_functions = {"ignore": _config_ignore, "int": _config_int, "date": _config_date, "split": _config_split, - "replace": _config_replace + "replace": _config_replace, + "bool": _config_bool, } |