Skip to content

Commit

Permalink
fixed bug in config parser that created parse error with spaces after…
Browse files Browse the repository at this point in the history
… wrappers of dynamic attributes
  • Loading branch information
jkminder committed Mar 7, 2022
1 parent 2325143 commit 050a4df
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 12 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ The library is built specifically for converting data into a [neo4j](https://neo

Note: The [py2neo](https://py2neo.org/2021.1/index.html) library does not support parallel relations of the same type (same source, same target and same type). If your graph requires such parallel relations please checkout the provided [py2neo extensions](/docs/documentation.md#py2neo-extensions).
## Installation
If you have setup a private ssh key for your github, copy-paste the command below to install the latest version ([v0.4.3][latest_tag]):
If you have setup a private ssh key for your github, copy-paste the command below to install the latest version ([v0.4.4][latest_tag]):
```
$ pip install git+ssh://[email protected]/sg-dev/[email protected].3
$ pip install git+ssh://[email protected]/sg-dev/[email protected].4
```

If you don't have ssh set up, download the latest wheel [here][latest_wheel] and install the wheel with:
Expand Down Expand Up @@ -85,7 +85,7 @@ converter()
# Known issues
If you encounter a bug or an unexplainable behavior, please check the [known issues](https://github.com/sg-dev/rel2graph/labels/bug) list. If your issue is not found, submit a new one.

[latest_version]: v0.4.3
[latest_tag]: https://github.com/sg-dev/rel2graph/releases/tag/v0.4.3
[latest_wheel]: https://github.com/sg-dev/rel2graph/releases/download/v0.4.3/rel2graph-0.4.3-py3-none-any.whl
[latest_version]: v0.4.4
[latest_tag]: https://github.com/sg-dev/rel2graph/releases/tag/v0.4.4
[latest_wheel]: https://github.com/sg-dev/rel2graph/releases/download/v0.4.4/rel2graph-0.4.4-py3-none-any.whl
[wiki]: docs/documentation.md
13 changes: 9 additions & 4 deletions rel2graph/core/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,22 @@ def _string_to_instructions(config_str: str) -> List[Any]:
end_e = config_str[end_e+1:].find("[")
if end_e >= 0 and end > end_e:
# unpack list
args = _split_arguments(config_str[end_e+1:-1]) # because we need to remove the closing bracket
args = _split_arguments(config_str.strip()[end_e+1:-1]) # because we need to remove the closing bracket
arg_instructions = []
for arg in args:
arg_instructions.append(_string_to_instructions(arg))
instructions.extend(arg_instructions)
elif end > 0:
instructions.append(config_str[:end])
args = _split_arguments(config_str[end+1:-1]) # because we need to remove the closing bracket
args = _split_arguments(config_str.strip()[end+1:-1]) # because we need to remove the closing bracket

arg_instructions = []
for arg in args:
arg_instructions.append(_string_to_instructions(arg))
instructions.append(arg_instructions)
elif end_e >= 0 and len(config_str) == 2:
# Handle empty list of args
args = _split_arguments(config_str[end_e+1:-1]) # because we need to remove the closing bracket
args = _split_arguments(config_str.strip()[end_e+1:-1]) # because we need to remove the closing bracket
instructions.extend(args)
else: # static argument -> parse to type
if config_str == "None":
Expand Down Expand Up @@ -298,7 +298,9 @@ def _precompile_dynamic_nokey_arguments(self, config_str: str, allowed_presymbol
# Parse Dynamic Entity Attributes without key
for match in re.finditer(f"(?!\"=)([{allowed_presymbols}])\s*(\w+)(?!&)[.](?!&)(\w+)", config_str):
if match.group(2) == self._entity_type:
config_str = re.sub(match.group(0), _convert(match, "{0}AttributeFactory(&None,\"{2}\",&None)"), config_str)
tmp = match.groups()
null = match.groups(0)
config_str = re.sub(_escape(match.group(0)), _convert(match, "{0}AttributeFactory(&None,\"{2}\",&None)"), config_str)
else:
# TODO: Inefficient since dynamic attributes are recomputed and not extracted
# Need structure to dynamically extract information from an existing node
Expand All @@ -316,6 +318,9 @@ def _precompile_entity_type(self, config_str: str) -> str:

def _precompile_graph_element(self, config_str: str) -> str:
"""Precompiles a graph element (Node or Relation)"""
# Remove identity
config_str = config_str[:_index_of_closing_bracket(config_str, 0)+1]

# Convert ids into Matchers
for id in self._ids:
# The first lookahead makes sure that an even amount of \" are after the match -> the id is not in a string
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
setup(
name = "rel2graph",
packages = find_packages(),
version = "0.4.3",
version = "0.4.4",
description = "Library for converting relational data into graph data (neo4j)",
author = "Julian Minder",
author_email = "[email protected]",
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/core/resources/dynamic_keys.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ENTITY("entity"):
NODE(entity.dynamic_key) node:
+ attr = entity.dynamic_key
- attr = WRAPPER(entity.dynamic_key)
NODE(WRAPPER(entity.dynamic_key)) node:
+ attr = entity.dynamic_key
NODE(entity.dynamic_key, WRAPPER(entity.dynamic_key)) node:
+ attr = entity.dynamic_key
NODE(entity.dynamic_key , WRAPPER(entity.dynamic_key) ) node:
NODE(WRAPPER(entity.dynamic_key), entity.dynamic_key) node:
+ attr = entity.dynamic_key
RELATION(node, entity.dynamic_key, node):
+ attr = entity.dynamic_key
RELATION(node, WRAPPER(entity.dynamic_key), node):
RELATION(node, WRAPPER(entity.dynamic_key) , node):
RELATION(node, WRAPPER( entity.dynamic_key ) , node):
1 change: 0 additions & 1 deletion tests/unit/core/resources/typing_exceptions1.yaml

This file was deleted.

1 change: 0 additions & 1 deletion tests/unit/core/resources/typing_exceptions2.yaml

This file was deleted.

18 changes: 18 additions & 0 deletions tests/unit/core/test_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
import pytest

from rel2graph.core.config_parser import parse
from rel2graph import register_attribute_preprocessor

@register_attribute_preprocessor
def WRAPPER(resource):
return resource

def get_rel_type(relation_factory):
return relation_factory._type.static_attribute_value
Expand Down Expand Up @@ -103,3 +108,16 @@ def test_typing():
conditions = af2str(fm._conditions)
check_types(conditions)

def test_dynkeys():
node_supplychain, relation_supplychain = parse(get_filepath("dynamic_keys"))["entity"]

for nf in node_supplychain.factories:
for label in nf._labels:
assert(label._entity_attribute == "dynamic_key")
for attr in nf._attributes:
assert(attr._entity_attribute == "dynamic_key")

for rf in relation_supplychain.factories:
assert(rf._type._entity_attribute == "dynamic_key")
for attr in nf._attributes:
assert(attr._entity_attribute == "dynamic_key")

0 comments on commit 050a4df

Please sign in to comment.