aboutsummaryrefslogtreecommitdiffstats
path: root/bsfs
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2023-01-30 09:52:18 +0100
committerMatthias Baumgartner <dev@igsor.net>2023-01-30 09:52:18 +0100
commit72e0bd78dc9cc1d74c3061b028040b64c0efcf9f (patch)
tree8a9fdfb7b441fa0d25e14c638c02389a214a7982 /bsfs
parent1392951dfc82af05e7a5999baa1c0a4fc72083b8 (diff)
downloadbsfs-72e0bd78dc9cc1d74c3061b028040b64c0efcf9f.tar.gz
bsfs-72e0bd78dc9cc1d74c3061b028040b64c0efcf9f.tar.bz2
bsfs-72e0bd78dc9cc1d74c3061b028040b64c0efcf9f.zip
flip graph fethc result flags
Diffstat (limited to 'bsfs')
-rw-r--r--bsfs/graph/nodes.py6
-rw-r--r--bsfs/graph/result.py29
2 files changed, 20 insertions, 15 deletions
diff --git a/bsfs/graph/nodes.py b/bsfs/graph/nodes.py
index 85e5fdb..9990714 100644
--- a/bsfs/graph/nodes.py
+++ b/bsfs/graph/nodes.py
@@ -277,9 +277,9 @@ class Nodes():
yield node, path, value
# simplify by default
- view_kwargs['node'] = view_kwargs.get('node', len(self._guids) == 1)
- view_kwargs['path'] = view_kwargs.get('path', len(paths) == 1)
- view_kwargs['value'] = view_kwargs.get('value', True)
+ view_kwargs['node'] = view_kwargs.get('node', len(self._guids) != 1)
+ view_kwargs['path'] = view_kwargs.get('path', len(paths) != 1)
+ view_kwargs['value'] = view_kwargs.get('value', False)
# return results view
if view == list:
diff --git a/bsfs/graph/result.py b/bsfs/graph/result.py
index 688929b..00607f4 100644
--- a/bsfs/graph/result.py
+++ b/bsfs/graph/result.py
@@ -38,11 +38,11 @@ def to_list_view(
the respective component is omitted.
"""
- if node and path:
+ if not node and not path:
return iter(val for _, _, val in triples)
- if node:
+ if not node:
return iter((pred, val) for _, pred, val in triples)
- if path:
+ if not path:
return iter((subj, val) for subj, _, val in triples)
return iter((subj, pred, val) for subj, pred, val in triples)
@@ -57,6 +57,7 @@ def to_dict_view(
node: bool,
path: bool,
value: bool,
+ default: typing.Optional[typing.Any] = None,
) -> typing.Any:
"""Return a dict of results.
@@ -74,7 +75,7 @@ def to_dict_view(
# FIXME: type of data can be overwritten later on (if value)
- if node and path:
+ if not node and not path:
data = set()
elif node ^ path:
data = defaultdict(set)
@@ -83,24 +84,24 @@ def to_dict_view(
for subj, pred, val in triples:
unique = pred in unique_paths
- if node and path:
- if value and unique and one_node and one_path:
+ if not node and not path:
+ if not value and unique and one_node and one_path:
return val
data.add(val)
- elif node:
+ elif not node:
# remove node from result, group by predicate
- if value and unique and one_node:
+ if not value and unique and one_node:
data[pred] = val
else:
data[pred].add(val)
- elif path:
+ elif not path:
# remove predicate from result, group by node
- if value and unique and one_path:
+ if not value and unique and one_path:
data[subj] = val
else:
data[subj].add(val)
else:
- if value and unique:
+ if not value and unique:
data[subj][pred] = val
else:
data[subj][pred].add(val)
@@ -108,7 +109,11 @@ def to_dict_view(
# FIXME: Combine multiple Nodes instances into one?
# convert defaultdict to ordinary dict
- if node and path:
+ if not node and not path and not value \
+ and len(unique_paths) > 0 and one_node and one_path \
+ and len(data) == 0:
+ return default
+ if not node and not path:
return data
if node ^ path:
return dict(data)