Skip to content

Commit

Permalink
one test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
sierra-moxon committed Aug 10, 2022
1 parent 811a14b commit a46016a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
4 changes: 4 additions & 0 deletions kgx/cli/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def _process_knowledge_source(ksf: str, spec: str) -> Union[str, bool, Tuple]:
if spec.lower() == "true":
return True
elif spec.lower() == "false":
print("returning false")
return False
else:
# If a Tuple, expect a comma-delimited string?
Expand Down Expand Up @@ -520,6 +521,7 @@ def transform(
pool.join()
graphs = [r.get() for r in results]
else:
print("no transform config")
source_dict: Dict = {
"input": {
"format": input_format,
Expand Down Expand Up @@ -555,7 +557,9 @@ def transform(
+ "' are all rewrite specifications!"
)
else:
print("not a tuple")
source_dict["input"][ksf] = ksf_spec
print(source_dict)

name = os.path.basename(inputs[0])
transform_source(
Expand Down
2 changes: 1 addition & 1 deletion kgx/source/json_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ def read_edges(self, filename: str) -> Generator:
FH = gzip.open(filename, "rb")
else:
FH = open(filename, "rb")
for e in ijson.items(FH, "edges.item"):
for e in ijson.items(FH, "edges.item", use_float=True):
yield self.read_edge(e)
2 changes: 1 addition & 1 deletion kgx/source/tsv_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,5 @@ def read_edge(self, edge: Dict) -> Optional[Tuple]:
key = generate_edge_key(s, edge_data["predicate"], o)
self.edge_properties.update(list(edge_data.keys()))
if self.check_edge_filter(edge_data):
self.node_properties.update(edge_data.keys())
self.edge_properties.update(edge_data.keys())
return s, o, key, edge_data
18 changes: 9 additions & 9 deletions kgx/utils/infores.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,13 @@ def set_provenance_map(self, kwargs: Dict):
"""
if "default_provenance" in kwargs:
self.default_provenance = kwargs.pop("default_provenance")
print(self.default_provenance)

# Biolink 2.0 knowledge_source 'knowledge_source' derived fields
ksf_found = False
ksf_found = []
for ksf in knowledge_provenance_properties:
if ksf in kwargs:
if not ksf_found:
ksf_found = ksf # save the first one found, for later
ksf_found.append(ksf)
ksf_value = kwargs.pop(ksf)
# Check if the ksf_value is a multi-valued catalog of patterns for a
# given knowledge graph field, indexed on each distinct regex pattern
if isinstance(ksf_value, dict):
for ksf_pattern in ksf_value.keys():
if ksf not in self.mapping:
Expand All @@ -357,7 +354,9 @@ def set_provenance_map(self, kwargs: Dict):
)
else:
ir = self.get_mapping(ksf)
print(ir)
self.mapping[ksf] = ir.set_provenance_map_entry(ksf_value)
print("mapping", self.mapping)

# if none specified, add at least one generic 'knowledge_source'
if not ksf_found:
Expand All @@ -368,9 +367,8 @@ def set_provenance_map(self, kwargs: Dict):
else:
self.mapping["knowledge_source"] = ir.default(self.default_provenance)

# TODO: better to lobby the team to totally deprecated this, even for Nodes?
if "provided_by" not in self.mapping:
self.mapping["provided_by"] = self.mapping[ksf_found]
self.mapping["provided_by"] = ir.default(self.default_provenance)

def set_provenance(self, ksf: str, data: Dict):
"""
Expand All @@ -386,6 +384,7 @@ def set_provenance(self, ksf: str, data: Dict):
"""
if ksf not in data.keys():
print(data.keys())
if ksf in self.mapping and not isinstance(self.mapping[ksf], dict):
data[ksf] = self.mapping[ksf]() # get default ksf value?
else:
Expand All @@ -396,6 +395,7 @@ def set_provenance(self, ksf: str, data: Dict):
# If data is s a non-string iterable
# then, coerce into a simple list of sources
if isinstance(data[ksf], (list, set, tuple)):
print("is a tuple???")
sources = list(data[ksf])
else:
# Otherwise, just assumed to be a scalar
Expand Down Expand Up @@ -442,7 +442,7 @@ def set_node_provenance(self, node_data: Dict):
def set_edge_provenance(self, edge_data: Dict):
"""
Sets the node knowledge_source value for the current node. Edge knowledge_source properties
include the full Biolink 2.0 'knowledge_source' related properties.
include the 'knowledge_source' related properties.
Parameters
----------
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ def test_transform_error():
except ValueError:
assert ValueError


def test_transform_knowledge_source_suppression():
"""
Transform graph from TSV to JSON.
Expand Down

0 comments on commit a46016a

Please sign in to comment.