Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit e23a617

Browse files
author
Alex Walker
authored
BDD: Graql Steps (#156)
## What is the goal of this PR? We had Connection and Concept BDD implementations, but Graql steps were still not implemented. We added support for them. ## What are the changes implemented in this PR? - Implement all Graql Steps (BDD) - Fix bad IID format in `Thing` (no leading `0x`)
1 parent 16876e3 commit e23a617

File tree

27 files changed

+696
-80
lines changed

27 files changed

+696
-80
lines changed

grakn/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from grakn.rpc.transaction import TransactionType # noqa # pylint: disable=unused-import
3030

3131

32-
class GraknClient(object):
32+
class GraknClient:
3333
DEFAULT_URI = "localhost:1729"
3434

3535
def __init__(self, address=DEFAULT_URI):

grakn/concept/concept.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919

2020

21-
class Concept(object):
21+
class Concept:
2222

2323
def is_type(self):
2424
return False
@@ -54,7 +54,7 @@ def is_remote(self):
5454
return False
5555

5656

57-
class RemoteConcept(object):
57+
class RemoteConcept:
5858

5959
def is_remote(self):
6060
return True

grakn/concept/concept_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from grakn.concept.type.relation_type import RelationType
2626

2727

28-
class ConceptManager(object):
28+
class ConceptManager:
2929

3030
def __init__(self, transaction):
3131
self._transaction = transaction

grakn/concept/proto/concept_proto_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def value_type(value_type_: ValueType):
9696

9797

9898
def iid(iid_: str):
99-
return bytes.fromhex(iid_)
99+
return bytes.fromhex(iid_.lstrip("0x"))
100100

101101

102102
def thing_encoding(thing_):

grakn/concept/proto/concept_proto_reader.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
from grakn.concept.type.thing_type import ThingType
3434

3535

36+
def iid(iid_proto: bytes):
37+
return "0x" + iid_proto.hex()
38+
39+
3640
def concept(con_proto: concept_proto.Concept):
3741
if con_proto.HasField(ConceptMap._THING):
3842
concept = thing(con_proto.thing)

grakn/concept/thing/attribute.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import graknprotocol.protobuf.concept_pb2 as concept_proto
2323

24-
from grakn.concept.proto import concept_proto_builder
24+
from grakn.concept.proto import concept_proto_builder, concept_proto_reader
2525
from grakn.concept.thing.thing import Thing, RemoteThing
2626

2727

@@ -83,7 +83,7 @@ def __init__(self, iid: str, value: bool):
8383

8484
@staticmethod
8585
def _of(thing_proto: concept_proto.Thing):
86-
return BooleanAttribute(thing_proto.iid.hex(), thing_proto.value.boolean)
86+
return BooleanAttribute(concept_proto_reader.iid(thing_proto.iid), thing_proto.value.boolean)
8787

8888
def get_value(self):
8989
return self._value
@@ -119,7 +119,7 @@ def __init__(self, iid: str, value: int):
119119

120120
@staticmethod
121121
def _of(thing_proto: concept_proto.Thing):
122-
return LongAttribute(thing_proto.iid.hex(), thing_proto.value.long)
122+
return LongAttribute(concept_proto_reader.iid(thing_proto.iid), thing_proto.value.long)
123123

124124
def get_value(self):
125125
return self._value
@@ -155,7 +155,7 @@ def __init__(self, iid: str, value: float):
155155

156156
@staticmethod
157157
def _of(thing_proto: concept_proto.Thing):
158-
return DoubleAttribute(thing_proto.iid.hex(), thing_proto.value.double)
158+
return DoubleAttribute(concept_proto_reader.iid(thing_proto.iid), thing_proto.value.double)
159159

160160
def get_value(self):
161161
return self._value
@@ -191,7 +191,7 @@ def __init__(self, iid: str, value: str):
191191

192192
@staticmethod
193193
def _of(thing_proto: concept_proto.Thing):
194-
return StringAttribute(thing_proto.iid.hex(), thing_proto.value.string)
194+
return StringAttribute(concept_proto_reader.iid(thing_proto.iid), thing_proto.value.string)
195195

196196
def get_value(self):
197197
return self._value
@@ -227,7 +227,7 @@ def __init__(self, iid: str, value: datetime):
227227

228228
@staticmethod
229229
def _of(thing_proto: concept_proto.Thing):
230-
return DateTimeAttribute(thing_proto.iid.hex(), datetime.fromtimestamp(float(thing_proto.value.date_time) / 1000.0))
230+
return DateTimeAttribute(concept_proto_reader.iid(thing_proto.iid), datetime.fromtimestamp(float(thing_proto.value.date_time) / 1000.0))
231231

232232
def get_value(self):
233233
return self._value

grakn/concept/thing/entity.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919

2020
import graknprotocol.protobuf.concept_pb2 as concept_proto
2121

22+
from grakn.concept.proto import concept_proto_reader
2223
from grakn.concept.thing.thing import Thing, RemoteThing
2324

2425

2526
class Entity(Thing):
2627

2728
@staticmethod
2829
def _of(thing_proto: concept_proto.Thing):
29-
return Entity(thing_proto.iid.hex())
30+
return Entity(concept_proto_reader.iid(thing_proto.iid))
3031

3132
def as_remote(self, transaction):
3233
return RemoteEntity(transaction, self._iid)

grakn/concept/thing/relation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Relation(Thing):
2828

2929
@staticmethod
3030
def _of(thing_proto: concept_proto.Thing):
31-
return Relation(thing_proto.iid.hex())
31+
return Relation(concept_proto_reader.iid(thing_proto.iid))
3232

3333
def as_remote(self, transaction):
3434
return RemoteRelation(transaction, self.get_iid())

grakn/concept/type/value_type.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@
1919

2020
import enum
2121

22+
from datetime import datetime
23+
from typing import Union
24+
2225

23-
# This lives here to avoid circular imports.
2426
class ValueType(enum.Enum):
27+
# This lives here to avoid circular imports.
2528
OBJECT = 0
2629
BOOLEAN = 1
2730
LONG = 2
2831
DOUBLE = 3
2932
STRING = 4
3033
DATETIME = 5
34+
35+
36+
ValueClass = Union[bool, int, float, str, datetime]

grakn/logic/logic_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from grakn.logic.rule import Rule
2424

2525

26-
class LogicManager(object):
26+
class LogicManager:
2727

2828
def __init__(self, transaction):
2929
self._transaction = transaction

0 commit comments

Comments
 (0)