bool support for csv2rdf
@@ -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,
}
