Exemplo n.º 1
0
 def create(cls, guide_id, file_name, **kwargs):
     print(guide_id)
     node = Node(cls.__name__,
                 id=UUID(),
                 guide_id=guide_id,
                 file_name=file_name,
                 **kwargs)
     graph_.create(node)
     return node["id"]
Exemplo n.º 2
0
 def create(cls, policy_id, file_name, **kwargs):
     # kwargs["id"]=
     node = Node("Policy",
                 id=UUID(),
                 policy_id=policy_id,
                 file_name=file_name,
                 **kwargs)
     graph_.create(node)
     return node["id"]
Exemplo n.º 3
0
 def add_boons(cls, id_, boons=None):
     if boons is None:
         boons = []
     _, _, guide = Guide.find_by_id(id_)
     boon_list = list(
         NodeMatcher(graph_).match("Boon").where(f"_.id in {boons}"))
     relationships = []
     for boon in boon_list:
         relationships.append(Relationship(guide, "HAS_BOON", boon))
     sub_graph = Subgraph(boon_list + [guide], relationships)
     graph_.create(sub_graph)
Exemplo n.º 4
0
 def set_object(cls, id_, object_id):
     _, _, node = cls.find_by_id(id_)
     _, _, object_node = BaseInterface.find_by_id_in_graph(object_id)
     if "Subject" not in object_node.labels:
         object_node.add_label("Subject")
     relationship = RelationshipMatcher(graph_).match((node, ),
                                                      "HAS_OBJECT").first()
     if relationship is not None:
         graph_.separate(relationship)
     relationship = Relationship(node, "HAS_OBJECT", object_node)
     graph_.create(relationship)
Exemplo n.º 5
0
 def set_predicate(cls, id_, predicate_id):
     _, _, node = cls.find_by_id(id_)
     _, _, predicate_node = Predicate.find_by_id(predicate_id)
     relationship = RelationshipMatcher(graph_).match(
         (node, ), "HAS_PREDICATE").first()
     if relationship is not None:
         old_node = relationship.end_node()
         graph_.separate(relationship)
         graph_.delete(old_node)
     relationship = Relationship(node, "HAS_PREDICATE", predicate_node)
     graph_.create(relationship)
Exemplo n.º 6
0
 def set_alia(cls, id_, alia):
     """
     给字段设置别名,如果遇到重复的忽略
     :param id_:
     :param alia: 别名
     :return:
     """
     _, _, node = cls.find_by_id(id_)
     if NodeMatcher(graph_).match("Alia", cls.__name__,
                                  name=alia).first() is None:
         _, alia_node = cls.create("Alia", alia)
         relationship = Relationship(node, "HAS_ALIA", alia_node)
         graph_.create(relationship)
Exemplo n.º 7
0
 def create(cls, type_, name, field=None, **kwargs):
     """
     往数据库中添加一个字段信息,现在允许重复
     :param type_: Field 或者 Alia
     :param field: 字段名
     :param name: 字段中文
     :param kwargs:
     :return:
     """
     if type_ == "Field":
         node = Node(cls.__name__,
                     type_,
                     id=UUID(),
                     name=name,
                     field=field,
                     **kwargs)
     else:  # Alia
         node = Node(cls.__name__, type_, id=UUID(), name=name, **kwargs)
     graph_.create(node)
     return node["id"], node
Exemplo n.º 8
0
 def create(cls, **kwargs):
     node = Node(cls.__name__, id=UUID(), **kwargs)
     graph_.create(node)
     return node["id"]
Exemplo n.º 9
0
 def add_requirement(cls, id_, requirement_id):
     _, _, boon_node = Boon.find_by_id(id_)
     _, _, requirement_node = Requirement.find_by_id(requirement_id)
     relationship = Relationship(boon_node, "HAS_REQUIREMENT",
                                 requirement_node)
     graph_.create(relationship)
Exemplo n.º 10
0
 def create(cls, **kwargs):
     # if kwargs.get("value", None) not in PredicateValue:
     #     raise Exception(f"predicate value must in {PredicateValue}")
     node = Node(cls.__name__, id=UUID(), **kwargs)
     graph_.create(node)
     return node["id"]
Exemplo n.º 11
0
 def create(cls, object_type, **kwargs):
     if object_type not in ObjectType:
         raise Exception(f"object_type must in {ObjectType}")
     node = Node(cls.__name__, object_type, id=UUID(), **kwargs)
     graph_.create(node)
     return node["id"]
Exemplo n.º 12
0
 def link_to_policy(cls, guide_id, policy_id):
     _, _, guide_node = Guide.find_by_guide_id(guide_id)
     _, _, policy_node = Policy.find_by_policy_id(policy_id)
     relationship = Relationship(guide_node, "BASE_ON", policy_node)
     sub_graph = Subgraph([guide_node, policy_node], [relationship])
     graph_.create(sub_graph)