Generic Transformers
dict2graph comes with a lot of predefined transformers. For a basic concepts of a dict2Graph transformers have a look at How to use Transformers
Generic Transformers List¶
This is a list if transformers that can be applied to nodes and relationships
AddProperty
¶
Bases: _RelationTransformerBase
, _NodeTransformerBase
Add a property to a node Usage:
from dict2graph import Dict2graph, Transformer, NodeTrans
from neo4j import GraphDatabase
NEO4J_DRIVER = GraphDatabase.driver("neo4j://localhost")
dic = {"person": {"name": "Camina"}}
d2g = Dict2graph()
d2g.add_node_transformation(
Transformer.match_nodes("person").do(NodeTrans.AddProperty({"my_new_prop_key":"my_new_prop_value_1111"}))
)
d2g.parse(dic)
d2g.create(NEO4J_DRIVER)
(:Person{name:'Camina',my_new_prop_key:"my_new_prop_value_1111"})
.
Source code in dict2graph/transformers/generic_transformers.py
__init__(properties)
¶
summary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
properties |
Union[str, List[str]]
|
A property key or a list of property keys as strings that should be removed |
required |
Source code in dict2graph/transformers/generic_transformers.py
EscapeInvalidNamesForNeo4JCompatibility
¶
Bases: _RelationTransformerBase
, _NodeTransformerBase
Non destructive escaping of labels and property keys to be valid with Neo4j rules
https://neo4j.com/docs/cypher-manual/current/syntax/naming/¶
Source code in dict2graph/transformers/generic_transformers.py
OverridePropertyName
¶
Bases: _RelationTransformerBase
, _NodeTransformerBase
Replace a property name/key with a new string of your choice. Usage:
from dict2graph import Dict2graph, Transformer, NodeTrans
from neo4j import GraphDatabase
NEO4J_DRIVER = GraphDatabase.driver("neo4j://localhost")
dic = {"person": {"name": "Camina Drummer"}}
d2g = Dict2graph()
d2g.add_node_transformation(
Transformer.match_nodes("person").do(NodeTrans.OverridePropertyName("name","fullname"))
)
d2g.parse(dic)
d2g.create(NEO4J_DRIVER)
(:Person{fullname:'Camina Drummer'})
Source code in dict2graph/transformers/generic_transformers.py
__init__(source_property_name, target_property_name)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_property_name |
str
|
The property key you want to be replaced. |
required |
target_property_name |
str
|
The The new name of the property. |
required |
Source code in dict2graph/transformers/generic_transformers.py
RemoveProperty
¶
Bases: _RelationTransformerBase
, _NodeTransformerBase
Remove a property from a node Usage:
from dict2graph import Dict2graph, Transformer, NodeTrans
from neo4j import GraphDatabase
NEO4J_DRIVER = GraphDatabase.driver("neo4j://localhost")
dic = {"person": {"name": "Camina", "id":"sdf343"}}
d2g = Dict2graph()
d2g.add_node_transformation(
Transformer.match_nodes("person").do(NodeTrans.RemoveProperty(id))
)
d2g.parse(dic)
d2g.create(NEO4J_DRIVER)
(:Person{name:'Camina'})
. the id
property will be thrown away.
Source code in dict2graph/transformers/generic_transformers.py
__init__(property_keys)
¶
summary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
property_keys |
Union[str, List[str]]
|
A property key or a list of property keys as strings that should be removed |
required |
Source code in dict2graph/transformers/generic_transformers.py
SanitizeInvalidNamesForNeo4JCompatibility
¶
Bases: _RelationTransformerBase
, _NodeTransformerBase
Destructive renaming of labels and property keys to be valid with Neo4j rules
https://neo4j.com/docs/cypher-manual/current/syntax/naming/
Usage:
from dict2graph import Dict2graph, Transformer, NodeTrans
from neo4j import GraphDatabase
NEO4J_DRIVER = GraphDatabase.driver("neo4j://localhost")
dic = {"$person": {"1name": "Camina Drummer"}}
d2g = Dict2graph()
d2g.add_node_transformation(
Transformer.match_nodes().do(NodeTrans.SanitizeInvalidNamesForNeo4JCompatibility("name","fullname"))
)
d2g.parse(dic)
d2g.create(NEO4J_DRIVER)
(:Person{name:'Camina Drummer'})
Source code in dict2graph/transformers/generic_transformers.py
TypeCastProperty
¶
Bases: _RelationTransformerBase
, _NodeTransformerBase
change the type of property values. Usage:
from dict2graph import Dict2graph, Transformer, NodeTrans
from neo4j import GraphDatabase
NEO4J_DRIVER = GraphDatabase.driver("neo4j://localhost")
dic = {"person": {"name": "Camina", "captain":"true", "age":"39"}}
d2g = Dict2graph()
d2g.add_node_transformation([
Transformer.match_nodes("person").do(NodeTrans.TypeCastProperty("captain",bool)),
Transformer.match_nodes("person").do(NodeTrans.TypeCastProperty("age",int)),
])
d2g.parse(dic)
d2g.create(NEO4J_DRIVER)
(:Person{name:'Camina',captain:true,age:27})
Source code in dict2graph/transformers/generic_transformers.py
__init__(property_name, target_type)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
property_name |
str
|
The property key that should be changed |
required |
target_type |
Union[str, int, float, bool]
|
The type that should result |
required |