Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename Keynodes to KeynodeNames
  • Loading branch information
deniskoronchik committed Oct 25, 2021
commit 0459d412164964da27de2b6f75a1f422d6fbc353
4 changes: 4 additions & 0 deletions db/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- Create configuration file `config.ini`. See [config.ini](db/config.ini)

## Codestlye

- Please style your code aacording to [PEP8](https://www.python.org/dev/peps/pep-0008/) rules

## Regenerate ANTLR parser

- [Download](https://www.antlr.org/download.html) antlr generator.
Expand Down
38 changes: 37 additions & 1 deletion db/sc/core/keynodes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
class Keynodes:
class KeynodeNames:
SC_NODE = "sc_node"
SC_LINK = "sc_link"
SC_EDGE = "sc_edge"
SC_ARC = "sc_arc"

CORE_TYPES = [SC_NODE, SC_LINK, SC_EDGE, SC_ARC]

SC_CONST = "sc_const"
SC_VAR = "sc_var"

CONST_TYPES = [SC_CONST, SC_VAR]

SC_NODE_STRUCT = "sc_node_struct"
SC_NODE_TUPLE = "sc_node_tuple"
SC_NODE_ROLE = "sc_node_role"
SC_NODE_NO_ROLE = "sc_node_no_role"
SC_NODE_CLASS = "sc_node_class"
SC_NODE_ABSTRACT = "sc_node_abstract"
SC_NODE_MATERIAL = "sc_node_material"

NODE_TYPES = [
SC_NODE_STRUCT, SC_NODE_TUPLE, SC_NODE_ROLE,
SC_NODE_NO_ROLE, SC_NODE_CLASS, SC_NODE_ABSTRACT,
SC_NODE_MATERIAL]

SC_ARC_PERM = "sc_arc_perm"
SC_ARC_TEMP = "sc_arc_temp"

ARC_PERM_TYPES = [SC_ARC_PERM, SC_ARC_TEMP]

SC_ARC_POS = "sc_arc_pos"
SC_ARC_NEG = "sc_arc_neg"
SC_ARC_FUZ = "sc_arc_fuz"

ARC_POS_TYPES = [SC_ARC_POS, SC_ARC_NEG, SC_ARC_FUZ]

# common keynodes
NREL_SYS_IDTF = "nrel_system_identifier"
10 changes: 5 additions & 5 deletions db/sc/core/transaction/names.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sc.core.element import Element
from sc.core.keynodes import Keynodes
from sc.core.keynodes import KeynodeNames
from sc.core.keywords import Labels, TypeAttrs
from sc.core.transaction.utils import _parse_output_element, _get_label_from_type

Expand Down Expand Up @@ -32,7 +32,7 @@ class TransactionNamesWrite:

def __init__(self,
driver: neo4j.Driver,
nrel_sys_idtf: str = Keynodes.NREL_SYS_IDTF) -> None:
nrel_sys_idtf: str = KeynodeNames.NREL_SYS_IDTF) -> None:
self._driver = driver
self._sys_idtfs = set()
self._tasks = []
Expand All @@ -58,7 +58,7 @@ def _is_empty(self) -> bool:
return len(self._sys_idtfs) == 0

def _make_query(self) -> str:
query = (f"MATCH (l:{Labels.SC_LINK} {{content: '{Keynodes.NREL_SYS_IDTF}', {_const_attr()} }})"
query = (f"MATCH (l:{Labels.SC_LINK} {{content: '{KeynodeNames.NREL_SYS_IDTF}', {_const_attr()} }})"
f"<-[__idtf_edge:{Labels.SC_ARC} {{ {TypeAttrs.CONST}: 'CONST' }}]"
f"-(__sys_idtf:{Labels.SC_NODE}), \n"
f"(:{Labels.SC_EDGE_SOCK} {{edge_id: id(__idtf_edge)}})"
Expand Down Expand Up @@ -136,7 +136,7 @@ class TransactionNamesRead:

def __init__(self,
driver: neo4j.Driver,
nrel_sys_idtf: str = Keynodes.NREL_SYS_IDTF) -> None:
nrel_sys_idtf: str = KeynodeNames.NREL_SYS_IDTF) -> None:
self._driver = driver
self._sys_idtfs = set()

Expand All @@ -161,7 +161,7 @@ def _is_empty(self) -> bool:

def _make_query(self) -> str:

query = (f"MATCH (l:{Labels.SC_LINK} {{ content: '{Keynodes.NREL_SYS_IDTF}', {_const_attr()} }})"
query = (f"MATCH (l:{Labels.SC_LINK} {{ content: '{KeynodeNames.NREL_SYS_IDTF}', {_const_attr()} }})"
f"<-[edge:{Labels.SC_ARC} {{ {_const_attr()} }}]"
f"-(__sys_idtf:{Labels.SC_NODE}), \n"
f"(edge_sock:{Labels.SC_EDGE_SOCK} {{edge_id: id(edge)}})"
Expand Down
4 changes: 2 additions & 2 deletions db/tools/bootstrap/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import neo4j

from sc.core.keywords import Labels, TypeAttrs
from sc.core.keynodes import Keynodes
from sc.core.keynodes import KeynodeNames
from sc.core.config import Config

from typing import Union
Expand Down Expand Up @@ -31,7 +31,7 @@ def wrap_enum(e) -> object:
return result

return templ.render(
Keynodes=Keynodes,
KeynodeNames=KeynodeNames,
Labels=Labels,
TypeConst=wrap_enum(TypeConst),
TypeNodeStruct=wrap_enum(TypeNodeStruct),
Expand Down
2 changes: 1 addition & 1 deletion db/tools/bootstrap/steps/0001-sys_idtf.cypher.jinja
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% import 'lib/types.cypher.jinja' as types with context %}

CREATE
(link:{{Labels.SC_LINK}} {content: "{{Keynodes.NREL_SYS_IDTF}}", is_url: false, type: "str", {{ types.const_attr(TypeConst.CONST) }} }),
(link:{{Labels.SC_LINK}} {content: "{{KeynodeNames.NREL_SYS_IDTF}}", is_url: false, type: "str", {{ types.const_attr(TypeConst.CONST) }} }),
(node:{{Labels.SC_NODE}} { {{ types.node_const_no_role_attrs() }} }),
(node)-[edge:{{Labels.SC_ARC}} { {{ types.const_attr(TypeConst.CONST) }} }]->(link)
WITH edge, node
Expand Down
12 changes: 5 additions & 7 deletions db/tools/bootstrap/steps/0010-types.cypher.jinja
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{% import 'lib/names.cypher.jinja' as names with context %}
{% import 'lib/types.cypher.jinja' as types with context %}

{% set keynodes_list = [
'sc_node', 'sc_link', 'sc_edge', 'sc_arc', 'sc_arc_member',
'sc_const', 'sc_var',
'sc_node_struct', 'sc_node_tuple', 'sc_node_role', 'sc_node_no_role', 'sc_node_class', 'sc_node_abstract', 'sc_node_material',
'sc_edge_perm', 'sc_edge_temp',
'sc_edge_pos', 'sc_edge_neg', 'sc_edge_fuz'
]%}
{% set keynodes_list = KeynodeNames.CORE_TYPES
+ KeynodeNames.CONST_TYPES
+ KeynodeNames.NODE_TYPES
+ KeynodeNames.ARC_PERM_TYPES
+ KeynodeNames.ARC_POS_TYPES %}

{# find system identifier keynode #}
{{ names.find_sys_idtf_rel(found_name="found_nrel_sys_idtf") }}
Expand Down
2 changes: 1 addition & 1 deletion db/tools/bootstrap/steps/lib/names.cypher.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MATCH
-[:{{Labels.SC_ARC}} { {{ types.arc_member_const_pos_perm() }} }]->
(edge_sock_{{found_name}})
WHERE
(link_{{found_name}}.content = '{{Keynodes.NREL_SYS_IDTF}}') AND
(link_{{found_name}}.content = '{{KeynodeNames.NREL_SYS_IDTF}}') AND
edge_sock_{{found_name}}.edge_id = id(edge_{{found_name}})
{%- endmacro %}

Expand Down