Skip to content

Commit 22d7842

Browse files
authored
Merge pull request #30 from goldenrecursion/sc-18884/disambiguate-triple
Add disambiguate triple query
2 parents fe72957 + d681dae commit 22d7842

File tree

6 files changed

+221
-10
lines changed

6 files changed

+221
-10
lines changed

src/godel/api.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def get_authentication_token(
210210
## Queries ##
211211
#############
212212

213-
# Entities
213+
# Entities and Disambiguation
214214

215215
def entity_by_name(self, name: str, first: int = 10, **kwargs) -> dict:
216216
"""Retrieve entity by name
@@ -322,6 +322,39 @@ def entity_with_triples(self, id: str) -> dict:
322322
data = self.endpoint(query, variables)
323323
return data
324324

325+
def disambiguate_triples(self, predicate: str, object: str, validation_status: str, **kwargs) -> dict:
326+
"""Disambiguate entities given the predicate and object value or entity ID
327+
328+
Args:
329+
predicate (str): predicate name i.e. CEO of
330+
object (str): Either a string value or object entity ID
331+
validation_status:
332+
333+
Returns:
334+
dict: Entities with details
335+
"""
336+
query = f"""query MyQuery {{
337+
disambiguateTriples(
338+
payload: {{
339+
triples: {{
340+
predicate: "{predicate}"
341+
object: "{object}"
342+
}}
343+
validationStatus: {validation_status}
344+
}}
345+
) {{
346+
errors
347+
entities {{
348+
distance
349+
id
350+
reputation
351+
}}
352+
}}
353+
}}"""
354+
variables = {}
355+
data = self.endpoint(query, variables)
356+
return data
357+
325358
# Predicates
326359

327360
def predicate_by_name(self, name: str, **kwargs) -> dict:
@@ -447,7 +480,7 @@ def unvalidated_triple(self) -> dict:
447480
)
448481
return assign_validation
449482

450-
# TODO: Replaec once sgqlc supports GetTripleForValidation nested fragment
483+
# TODO: Replace once sgqlc supports GetTripleForValidation nested fragment
451484
query = """query GetTripleForValidation($id: UUID!) {
452485
triple(id: $id) {
453486
... on Statement {

src/godel/queries/CurrentUserLedgerRecords.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def query_current_user_ledger_records():
1212
_op = sgqlc.operation.Operation(_schema_root.query_type, name='CurrentUserLedgerRecords', variables=dict(after=sgqlc.types.Arg(_schema.Cursor, default=None), condition=sgqlc.types.Arg(sgqlc.types.non_null(_schema.LedgerRecordCondition))))
1313
_op_current_user = _op.current_user()
1414
_op_current_user_ledger_records = _op_current_user.ledger_records(first=20, after=sgqlc.types.Variable('after'), order_by='CREATED_AT_DESC', condition=sgqlc.types.Variable('condition'))
15+
_op_current_user_ledger_records.total_count()
1516
_op_current_user_ledger_records_page_info = _op_current_user_ledger_records.page_info()
1617
_op_current_user_ledger_records_page_info.has_next_page()
1718
_op_current_user_ledger_records_page_info.end_cursor()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sgqlc.types
2+
import sgqlc.operation
3+
import godel.schema
4+
5+
_schema = godel.schema
6+
_schema_root = _schema.schema
7+
8+
__all__ = ('Operations',)
9+
10+
11+
def query_entity_contributors():
12+
_op = sgqlc.operation.Operation(_schema_root.query_type, name='EntityContributors', variables=dict(id=sgqlc.types.Arg(sgqlc.types.non_null(_schema.UUID)), after=sgqlc.types.Arg(_schema.Cursor, default=None)))
13+
_op_entity = _op.entity(id=sgqlc.types.Variable('id'))
14+
_op_entity.id()
15+
_op_entity_nft_requests = _op_entity.nft_requests(first=5, after=sgqlc.types.Variable('after'))
16+
_op_entity_nft_requests_page_info = _op_entity_nft_requests.page_info()
17+
_op_entity_nft_requests_page_info.has_next_page()
18+
_op_entity_nft_requests_page_info.end_cursor()
19+
_op_entity_nft_requests_nodes = _op_entity_nft_requests.nodes()
20+
_op_entity_nft_requests_nodes.user_id()
21+
_op_entity_nft_requests_nodes.ledger_record_amount_sum()
22+
_op_entity_nft_requests_nodes.ownership_percent()
23+
return _op
24+
25+
26+
class Query:
27+
entity_contributors = query_entity_contributors()
28+
29+
30+
class Operations:
31+
query = Query

src/godel/queries/GetTripleForValidation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212

1313
def query_get_triple_for_validation():
14-
_op = sgqlc.operation.Operation(_schema_root.query_type, name='GetTripleForValidation')
15-
_op_unvalidated_triple = _op.unvalidated_triple()
16-
_op_unvalidated_triple__as__Statement = _op_unvalidated_triple.__as__(_schema.Statement)
17-
_op_unvalidated_triple__as__Statement.__fragment__(fragment_triple_widget())
18-
_op_unvalidated_triple__as__Statement_subject = _op_unvalidated_triple__as__Statement.subject()
19-
_op_unvalidated_triple__as__Statement_subject.__fragment__(fragment_entity_summary())
20-
_op_unvalidated_triple__as__Statement_object_entity = _op_unvalidated_triple__as__Statement.object_entity()
21-
_op_unvalidated_triple__as__Statement_object_entity.__fragment__(fragment_entity_summary())
14+
_op = sgqlc.operation.Operation(_schema_root.query_type, name='GetTripleForValidation', variables=dict(id=sgqlc.types.Arg(sgqlc.types.non_null(_schema.UUID))))
15+
_op_triple = _op.triple(id=sgqlc.types.Variable('id'))
16+
_op_triple__as__Statement = _op_triple.__as__(_schema.Statement)
17+
_op_triple__as__Statement.__fragment__(fragment_triple_widget())
18+
_op_triple__as__Statement_subject = _op_triple__as__Statement.subject()
19+
_op_triple__as__Statement_subject.__fragment__(fragment_entity_summary())
20+
_op_triple__as__Statement_object_entity = _op_triple__as__Statement.object_entity()
21+
_op_triple__as__Statement_object_entity.__fragment__(fragment_entity_summary())
2222
_op_current_user = _op.current_user()
2323
_op_current_user.remaining_skips()
2424
_op_current_user_user_flags = _op_current_user.user_flags()

src/godel/queries/WalletNfts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def query_wallet_nfts():
2020
_op_eligible_nfts_nodes_entity.__fragment__(fragment_entity_link())
2121
_op_eligible_nfts_nodes.ledger_record_amount_sum()
2222
_op_eligible_nfts_nodes.entity_ledger_record_amount_sum()
23+
_op_eligible_nfts_nodes.ownership_percent()
2324
return _op
2425

2526

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "28cb6338-0997-46f9-bf71-31ccfc71a976",
6+
"metadata": {},
7+
"source": [
8+
"# Disambiguate Triple\n",
9+
"\n",
10+
"Here is a short guide to disambiguating triples on the Golden protocol. Disambiguating triples is a core step in the data submission process. Before submitting any triples, you should disambiguate against any pre-existing triples that are similar if not identical to what you are submitting. This prevents duplicates from being submitted."
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"id": "f7598da8-46d9-421e-a861-60e88c42c42a",
16+
"metadata": {},
17+
"source": [
18+
"## Prerequisite\n",
19+
"\n",
20+
"[Authentication](https://docs.golden.xyz/guides/authentication)\n",
21+
"\n",
22+
"[Godel Authentication](https://docs.golden.xyz/godel-python-sdk/authentication)"
23+
]
24+
},
25+
{
26+
"cell_type": "markdown",
27+
"id": "bee98a0e-31e7-40cc-88ab-5164413c17dc",
28+
"metadata": {},
29+
"source": [
30+
"### 1. Connect to Golden Web3 API\n",
31+
"\n",
32+
"Let's connect the python wrapper to the Golden GraphQL API.\n",
33+
"\n",
34+
"Make sure you ran through the prerequisites for this guide and have learned to authenticate and retrieve your JWT token in Godel."
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 1,
40+
"id": "1311f6af-03c5-4067-9bf1-c1667813e611",
41+
"metadata": {},
42+
"outputs": [],
43+
"source": [
44+
"from godel import GoldenAPI\n",
45+
"\n",
46+
"JWT_TOKEN = \"ey098sd908v79899789877986567967845jh567hj5679568df678678daf6786789s569ghm567457hm8g567n8678fb8790678sd56756n456h8d4f5gn865648\"\n",
47+
"JWT_TOKEN = \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMHhkODZiNTM0QzAyOUFhZjg0MjcyYTNjNzI1Rjk0MDhlMDNERUY0YjgwIiwicm9sZSI6InVzZXJfcm9sZSIsImF1ZCI6InBvc3RncmFwaGlsZSIsImlhdCI6MTY2NjIxODM1NX0.TdXheV61u-yYTTcl2Pcp945dUWxMxuDMXeN8v6A9P8o\"\n",
48+
"goldapi = GoldenAPI(jwt_token=JWT_TOKEN)"
49+
]
50+
},
51+
{
52+
"cell_type": "markdown",
53+
"id": "5b3ee311-36e2-4ebf-9b99-e6a01ffe0df6",
54+
"metadata": {},
55+
"source": [
56+
"### 2. Disambiguate triple\n",
57+
"\n",
58+
"In order to disambiguate a triple, you'll need a specify a the predicate and object value or entityID you'd like to add to your own subject."
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": 2,
64+
"id": "f994e866-764f-467c-813c-cb533493bc32",
65+
"metadata": {},
66+
"outputs": [],
67+
"source": [
68+
"predicate = \"Website\"\n",
69+
"object = \"https://golden.com\""
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": 3,
75+
"id": "115e6fa1-0261-4811-87dd-f6fb266a87ab",
76+
"metadata": {},
77+
"outputs": [],
78+
"source": [
79+
"# Get disambiguated triple\n",
80+
"data = goldapi.disambiguate_triples(\n",
81+
" predicate=predicate,\n",
82+
" object=object,\n",
83+
" validation_status=\"ACCEPTED\"\n",
84+
")"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": 4,
90+
"id": "36bb6806-b858-4c5c-abca-1570a41bede9",
91+
"metadata": {},
92+
"outputs": [
93+
{
94+
"data": {
95+
"text/plain": [
96+
"{'data': {'disambiguateTriples': {'errors': None,\n",
97+
" 'entities': [{'distance': 0,\n",
98+
" 'id': '07c8ce4d-a5db-44af-9ffe-2ea137725488',\n",
99+
" 'reputation': 0},\n",
100+
" {'distance': 0,\n",
101+
" 'id': '88e5cf8e-c0bf-4e11-addf-27d54260a93e',\n",
102+
" 'reputation': 0},\n",
103+
" {'distance': 0,\n",
104+
" 'id': '378b1487-041e-4c1c-8c21-9cbf359d2d61',\n",
105+
" 'reputation': 0},\n",
106+
" {'distance': 0,\n",
107+
" 'id': '2e05170c-b044-4d4d-90a1-bca3769a7c9e',\n",
108+
" 'reputation': 0},\n",
109+
" {'distance': 0,\n",
110+
" 'id': '5c0d11ad-b6e7-4d08-a0f1-6a224d93f3a1',\n",
111+
" 'reputation': 0}]}}}"
112+
]
113+
},
114+
"execution_count": 4,
115+
"metadata": {},
116+
"output_type": "execute_result"
117+
}
118+
],
119+
"source": [
120+
"data"
121+
]
122+
}
123+
],
124+
"metadata": {
125+
"kernelspec": {
126+
"display_name": "Python 3 (ipykernel)",
127+
"language": "python",
128+
"name": "python3"
129+
},
130+
"language_info": {
131+
"codemirror_mode": {
132+
"name": "ipython",
133+
"version": 3
134+
},
135+
"file_extension": ".py",
136+
"mimetype": "text/x-python",
137+
"name": "python",
138+
"nbconvert_exporter": "python",
139+
"pygments_lexer": "ipython3",
140+
"version": "3.9.5"
141+
}
142+
},
143+
"nbformat": 4,
144+
"nbformat_minor": 5
145+
}

0 commit comments

Comments
 (0)