Exemplo n.º 1
0
 def NLURecall(self, request, context):
     result = mem(request)
     go = result[0] if result else None
     if isinstance(result, GraphNode):
         dctgn = convert_graphobj_to_dict(result)
         gop = nlm_pb2.GraphNode(**dctgn)
     elif isinstance(go, GraphRelation):
         dctgr = convert_graphobj_to_dict(result)
         gop = nlm_pb2.GraphRelation(**dctgr)
     else:
         gop = nlm_pb2.GraphNode(**{})
     return nlm_pb2.GraphOutput(gn=gop)
Exemplo n.º 2
0
def test_recall_relation_start_not_exist2(grpc_stub):
    start = nlm_pb2.GraphNode(label="Person",
                              name="AliceThreeNotExist",
                              props=json.dumps({}))
    end = nlm_pb2.GraphNode(label="Person",
                            name="AliceOne",
                            props=json.dumps({}))
    kind = "LIKES"
    props = {}
    request = nlm_pb2.GraphRelation(start=start,
                                    end=end,
                                    kind=kind,
                                    props=json.dumps(props))
    response = grpc_stub.RelationRecall(request)
    assert isinstance(response, nlm_pb2.GraphRelation)
    assert response.start.name == "AliceSeven"
    assert response.end != end
    assert response.kind == kind
    assert isinstance(response.props, str)
    assert json.loads(response.props) != props
Exemplo n.º 3
0
def test_recall_relation_exist_only_props2(grpc_stub):
    start = nlm_pb2.GraphNode(label="Person",
                              name="AliceThree",
                              props=json.dumps({}))
    end = nlm_pb2.GraphNode(label="Person",
                            name="AliceOne",
                            props=json.dumps({}))
    props = {"from": 2009}
    request = nlm_pb2.GraphRelation(start=start,
                                    end=end,
                                    kind=None,
                                    props=json.dumps(props))
    response = grpc_stub.RelationRecall(request)
    assert isinstance(response, nlm_pb2.GraphRelation)
    assert response.start != start
    assert response.end != end
    assert response.start.name == start.name
    assert response.end.label == end.label
    assert response.kind == "WORK_WITH"
    assert isinstance(response.props, str)
    assert json.loads(response.props) != props
Exemplo n.º 4
0
def test_recall_relation_exist_fuzzy_kind(grpc_stub):
    start = nlm_pb2.GraphNode(label="Person",
                              name="AliceThree",
                              props=json.dumps({}))
    end = nlm_pb2.GraphNode(label="Person",
                            name="AliceOne",
                            props=json.dumps({}))
    kind = "LOVEING"
    props = {"roles": "husband"}
    request = nlm_pb2.GraphRelation(start=start,
                                    end=end,
                                    kind=kind,
                                    props=json.dumps(props))
    response = grpc_stub.RelationRecall(request)
    assert isinstance(response, nlm_pb2.GraphRelation)
    assert response.start != start
    assert response.end != end
    assert response.start.name == start.name
    assert response.end.label == end.label
    assert response.kind == "LOVES"
    assert isinstance(response.props, str)
    assert json.loads(response.props) != props
Exemplo n.º 5
0
 def recall_relation(self, start: nlm_pb2.GraphNode, end: nlm_pb2.GraphNode,
                     kind: str, props: dict = {}):
     request = nlm_pb2.GraphRelation(
         start=start, end=end, kind=kind, props=json.dumps(props))
     response = self.stub.RelationRecall(request)
     return response
Exemplo n.º 6
0
 def RelationRecall(self, request, context):
     result = mem(request)
     gr = result[0] if result else request
     dctgr = convert_graphobj_to_dict(gr)
     return nlm_pb2.GraphRelation(**dctgr)