summaryrefslogtreecommitdiff
path: root/rdflib/tools
diff options
context:
space:
mode:
authorGunnar Aastrand Grimnes <gromgull@gmail.com>2017-04-11 10:51:47 +0200
committerGunnar Aastrand Grimnes <gromgull@gmail.com>2017-04-11 10:51:54 +0200
commit95a0491071b18148424ee071305cdddf7f36f7de (patch)
tree9464c96d8dad24b46126dcef271f03d5272e38fb /rdflib/tools
parent8788cc603b1ffee58bf4f0c08b783d32e37ca472 (diff)
downloadrdflib-95a0491071b18148424ee071305cdddf7f36f7de.tar.gz
bool support for csv2rdf
Diffstat (limited to 'rdflib/tools')
-rw-r--r--rdflib/tools/csv2rdf.py17
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,
}