mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-22 03:31:02 +02:00
Fixing query stuff
This commit is contained in:
parent
179285e186
commit
8c38dc30ff
8 changed files with 27 additions and 33 deletions
|
|
@ -4,8 +4,8 @@ from .. schema import GraphEmbeddingsRequest, GraphEmbeddingsResponse
|
|||
from .. knowledge import Uri, Literal
|
||||
|
||||
def to_value(x):
|
||||
if x.e: return Uri(x.v)
|
||||
return Literal(x.v)
|
||||
if x.is_uri: return Uri(x.value)
|
||||
return Literal(x.value)
|
||||
|
||||
class GraphEmbeddingsClient(RequestResponse):
|
||||
async def query(self, vectors, limit=20, user="trustgraph",
|
||||
|
|
@ -21,6 +21,8 @@ class GraphEmbeddingsClient(RequestResponse):
|
|||
timeout=timeout
|
||||
)
|
||||
|
||||
print(resp, flush=True)
|
||||
|
||||
if resp.error:
|
||||
raise RuntimeError(resp.error.message)
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class GraphEmbeddingsQueryService(FlowProcessor):
|
|||
|
||||
print(f"Handling input {id}...", flush=True)
|
||||
|
||||
entities = self.query_graph_embeddings(request)
|
||||
entities = await self.query_graph_embeddings(request)
|
||||
|
||||
print("Send response...", flush=True)
|
||||
r = GraphEmbeddingsResponse(entities=entities, error=None)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
from . request_response_spec import RequestResponse, RequestResponseSpec
|
||||
from .. schema import TriplesQueryRequest, TriplesQueryResponse, Value
|
||||
from .. knowledge import Uri, Literal
|
||||
from .. knowledge import Uri, Literal, Triple
|
||||
|
||||
def to_value(x):
|
||||
if x.e: return Uri(x.v)
|
||||
return Literal(x.v)
|
||||
if x.is_uri: return Uri(x.value)
|
||||
return Literal(x.value)
|
||||
|
||||
def from_value(x):
|
||||
if x is None: return None
|
||||
|
|
@ -35,7 +35,7 @@ class TriplesClient(RequestResponse):
|
|||
raise RuntimeError(resp.error.message)
|
||||
|
||||
return [
|
||||
to_value(v)
|
||||
Triple(to_value(v.s), to_value(v.p), to_value(v.o))
|
||||
for v in resp.triples
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class TriplesQueryService(FlowProcessor):
|
|||
|
||||
id = params.get("id")
|
||||
|
||||
super(TriplesStoreService, self).__init__(**params | { "id": id })
|
||||
super(TriplesQueryService, self).__init__(**params | { "id": id })
|
||||
|
||||
self.register_specification(
|
||||
ConsumerSpec(
|
||||
|
|
@ -47,7 +47,7 @@ class TriplesQueryService(FlowProcessor):
|
|||
|
||||
print(f"Handling input {id}...", flush=True)
|
||||
|
||||
triples = self.query_triples(request)
|
||||
triples = await self.query_triples(request)
|
||||
|
||||
print("Send response...", flush=True)
|
||||
r = TriplesQueryResponse(triples=triples, error=None)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ URL = 'https://schema.org/url'
|
|||
IDENTIFIER = 'https://schema.org/identifier'
|
||||
KEYWORD = 'https://schema.org/keywords'
|
||||
|
||||
class Triple:
|
||||
def __init__(self, s, p, o):
|
||||
self.s, self.p, self.o = s, p, o
|
||||
|
||||
class Uri(str):
|
||||
def is_uri(self): return True
|
||||
def is_literal(self): return False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue