Module: Transformer
Transformer
A module to transform records in the record layer/subgraphs of the semantic layer into a semantic layer using the semantic header
- Nodes on the semantic layer are created based on records or a subgraph of the semantic layer
- Relationships on the semantic layer are created based on records or a subgraph of the semantic layer
Examples:
>>> from promg.modules.transformer import Transformer
>>> from promg import SemanticHeader
>>> semantic_header_path = Path(f'json_files/{dataset_name}.json')
>>> semantic_header = SemanticHeader.create_semantic_header(semantic_header_path)
>>> transformer = Transformer()
Returns the transformer module
create_nodes_by_records(node_types)
Create nodes with node types using records. If no node types are defined, then all nodes types specified in the semantic header get created if they are created using records
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_types |
Optional[List[str]]
|
An optional list of strings with the node types to be created If the given node type is not constructed using a record, then it is ignored. |
required |
Examples:
Create nodes for a specific list of node types
>>> transformer.create_nodes_by_records(["Event", "Activity", "Book"])
The transformer creates the nodes with the types Event, Activity and Book
as specified in semantic header in the Event Knowledge graph.
Create nodes for all node types specified in the semantic header
create_relations_using_records(relation_types)
Create relationships with relation types using records. That is two nodes related to the same (:Record) node get a relation in between as specified in the semantic header. If no relation types are defined, then all relation types specified in the semantic header get created if they are created using records
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relation_types |
Optional[List[str]]
|
An optional list of strings with the relation types to be created If the given relation type is not constructed using a record, then it is ignored. |
required |
Examples:
Create nodes for a specific list of relation types
>>> transformer.create_relations_using_records(["MEMBER_OF"])
The transformer creates the relationships between two nodes with the type MEMBER_OF
as specified in semantic header in the Event Knowledge graph.
More specifically, a (:Member) node is related to a (:Library) node with a [:MEMBER_OF] relation
when the (:Member) and (:Library) node are related to the same (:Record) node as specified in
the semantic header
Create nodes for all relationship types specified in the semantic header
create_relations_using_relations(relation_types)
Create relations with relation types using subgraph of semantic layer (relations). If no relation types are defined, then all relation types specified in the semantic header get created if they are created using a subgraph
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relation_types |
Optional[List[str]]
|
An optional list of strings with the relation types to be created. If the given relation type is not constructed using a subgraph, then it is ignored. |
required |
Examples:
Create nodes for a specific list of node types
>>> transformer.create_relations_using_relations(["BORROWED"])
The transformer creates the relationship with the types BORROWED
as specified in semantic header in the Event Knowledge graph.
Create nodes for all node types specified in the semantic header
create_df_edges(entity_types=None, event_label='Event')
For all nodes (nodes or reified relationship nodes) with entity_types create DF edges between (:Event) nodes matching event_label
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_types |
List[str]
|
Optional list of types for which we want to create the DF edges. If none, then we create DF edges for all nodes as specified in the semantic header. If for the given entity types the infer_df is False (or not specified) in the semantic header, then it is ignored (i.e. no DF edges are created) |
None
|
event_label |
str
|
The label of the event nodes used to create the DF edges |
'Event'
|
Examples:
merge_duplicate_df()
Merge duplicate DF edges between the same nodes Only do this for the (reified) nodes in semantic header with merge_duplicate_df = true