mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-16 16:51:02 +02:00
Change API to deliver a boolean e if value is an entity
This commit is contained in:
parent
c83bbe173e
commit
483f761e15
5 changed files with 71 additions and 58 deletions
|
|
@ -213,9 +213,16 @@ class Api:
|
||||||
"limit": limit
|
"limit": limit
|
||||||
}
|
}
|
||||||
|
|
||||||
if s: input["s"] = s
|
if not isinstance(s, Uri):
|
||||||
if p: input["p"] = p
|
raise RuntimeError("s must be Uri")
|
||||||
if o: input["o"] = o
|
if not isinstance(p, Uri):
|
||||||
|
raise RuntimeError("p must be Uri")
|
||||||
|
if not isinstance(o, Uri) and not isinstance(o, Literal):
|
||||||
|
raise RuntimeError("o must be Uri or Literal")
|
||||||
|
|
||||||
|
if s: input["s"] = { "v": str(s), "e": isinstance(s, Uri), }
|
||||||
|
if p: input["p"] = { "v": str(p), "e": isinstance(p, Uri), }
|
||||||
|
if o: input["o"] = { "v": str(o), "e": isinstance(o, Uri), }
|
||||||
|
|
||||||
url = f"{self.url}triples-query"
|
url = f"{self.url}triples-query"
|
||||||
|
|
||||||
|
|
@ -272,10 +279,10 @@ class Api:
|
||||||
|
|
||||||
if metadata:
|
if metadata:
|
||||||
metadata.emit(
|
metadata.emit(
|
||||||
lambda t: triples.append({
|
lambda t: triples.append(
|
||||||
"s": t.s.value,
|
"s": { "v": t.s, "e": isinstance(t.s, Uri) }
|
||||||
"p": t.p.value,
|
"p": { "v": t.p, "e": isinstance(t.p, Uri) }
|
||||||
"o": t.o.value
|
"o": { "v": t.o, "e": isinstance(t.o, Uri) }
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -312,9 +319,9 @@ class Api:
|
||||||
if metadata:
|
if metadata:
|
||||||
metadata.emit(
|
metadata.emit(
|
||||||
lambda t: triples.append({
|
lambda t: triples.append({
|
||||||
"s": t.s.value,
|
"s": { "v": t.s, "e": isinstance(t.s, Uri),
|
||||||
"p": t.p.value,
|
"p": { "v": t.p, "e": isinstance(t.p, Uri),
|
||||||
"o": t.o.value
|
"o": { "v": t.o, "e": isinstance(t.o, Uri),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,15 @@
|
||||||
|
|
||||||
from . defs import *
|
from . defs import *
|
||||||
from .. schema import Triple, Value
|
|
||||||
|
def Value(value, is_uri):
|
||||||
|
return {
|
||||||
|
"v": value, "e": is_uri,
|
||||||
|
}
|
||||||
|
|
||||||
|
def Triple(s, p, o):
|
||||||
|
return {
|
||||||
|
"s": s, "p": p, "o": o,
|
||||||
|
}
|
||||||
|
|
||||||
class DigitalDocument:
|
class DigitalDocument:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,15 @@
|
||||||
|
|
||||||
from . defs import *
|
from . defs import *
|
||||||
from .. schema import Triple, Value
|
|
||||||
|
def Value(value, is_uri):
|
||||||
|
return {
|
||||||
|
"v": value, "e": is_uri,
|
||||||
|
}
|
||||||
|
|
||||||
|
def Triple(s, p, o):
|
||||||
|
return {
|
||||||
|
"s": s, "p": p, "o": o,
|
||||||
|
}
|
||||||
|
|
||||||
class Organization:
|
class Organization:
|
||||||
def __init__(self, id, name=None, description=None):
|
def __init__(self, id, name=None, description=None):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,15 @@
|
||||||
|
|
||||||
from . defs import *
|
from . defs import *
|
||||||
from .. schema import Triple, Value
|
|
||||||
|
def Value(value, is_uri):
|
||||||
|
return {
|
||||||
|
"v": value, "e": is_uri,
|
||||||
|
}
|
||||||
|
|
||||||
|
def Triple(s, p, o):
|
||||||
|
return {
|
||||||
|
"s": s, "p": p, "o": o,
|
||||||
|
}
|
||||||
|
|
||||||
class PublicationEvent:
|
class PublicationEvent:
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
|
||||||
|
|
@ -73,10 +73,7 @@ default_timeout = 600
|
||||||
default_port = 8088
|
default_port = 8088
|
||||||
|
|
||||||
def to_value(x):
|
def to_value(x):
|
||||||
if x.startswith("http:") or x.startswith("https:"):
|
return Value(value=x["v"], is_uri=x["e"])
|
||||||
return Value(value=x, is_uri=True)
|
|
||||||
else:
|
|
||||||
return Value(value=x, is_uri=False)
|
|
||||||
|
|
||||||
def to_subgraph(x):
|
def to_subgraph(x):
|
||||||
return [
|
return [
|
||||||
|
|
@ -195,43 +192,41 @@ class Subscriber:
|
||||||
if id in self.full:
|
if id in self.full:
|
||||||
del self.full[id]
|
del self.full[id]
|
||||||
|
|
||||||
|
def serialize_value(v):
|
||||||
|
return {
|
||||||
|
"v": v.value,
|
||||||
|
"e": v.is_uri,
|
||||||
|
}
|
||||||
|
|
||||||
|
def serialize_triple(t):
|
||||||
|
return {
|
||||||
|
"s": serialize_value(t.s),
|
||||||
|
"p": serialize_value(t.p),
|
||||||
|
"o": serialize_value(t.o)
|
||||||
|
}
|
||||||
|
|
||||||
|
def serialize_subgraph(sg):
|
||||||
|
return [
|
||||||
|
serialize_triple(t)
|
||||||
|
for t in sg
|
||||||
|
]
|
||||||
|
|
||||||
def serialize_triples(message):
|
def serialize_triples(message):
|
||||||
return {
|
return {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": message.metadata.id,
|
"id": message.metadata.id,
|
||||||
"metadata": [
|
"metadata": serialize_subgraph(message.metadata.metadata),
|
||||||
{
|
|
||||||
"s": t.s.value,
|
|
||||||
"p": t.p.value,
|
|
||||||
"o": t.o.value,
|
|
||||||
}
|
|
||||||
for t in message.metadata.metadata
|
|
||||||
],
|
|
||||||
"user": message.metadata.user,
|
"user": message.metadata.user,
|
||||||
"collection": message.metadata.collection,
|
"collection": message.metadata.collection,
|
||||||
},
|
},
|
||||||
"triples": [
|
"triples": serialize_subgraph(message.triples),
|
||||||
{
|
|
||||||
"s": t.s.value,
|
|
||||||
"p": t.p.value,
|
|
||||||
"o": t.o.value,
|
|
||||||
}
|
|
||||||
for t in message.triples
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def serialize_graph_embeddings(message):
|
def serialize_graph_embeddings(message):
|
||||||
return {
|
return {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": message.metadata.id,
|
"id": message.metadata.id,
|
||||||
"metadata": [
|
"metadata": serialize_subgraph(message.metadata.metadata),
|
||||||
{
|
|
||||||
"s": t.s.value,
|
|
||||||
"p": t.p.value,
|
|
||||||
"o": t.o.value,
|
|
||||||
}
|
|
||||||
for t in message.metadata.metadata
|
|
||||||
],
|
|
||||||
"user": message.metadata.user,
|
"user": message.metadata.user,
|
||||||
"collection": message.metadata.collection,
|
"collection": message.metadata.collection,
|
||||||
},
|
},
|
||||||
|
|
@ -563,23 +558,7 @@ class Api:
|
||||||
|
|
||||||
return web.json_response(
|
return web.json_response(
|
||||||
{
|
{
|
||||||
"response": [
|
"response": serialize_subgraph(resp.triples),
|
||||||
{
|
|
||||||
"s": {
|
|
||||||
"v": t.s.value,
|
|
||||||
"e": t.s.is_uri,
|
|
||||||
},
|
|
||||||
"p": {
|
|
||||||
"v": t.p.value,
|
|
||||||
"e": t.p.is_uri,
|
|
||||||
},
|
|
||||||
"o": {
|
|
||||||
"v": t.o.value,
|
|
||||||
"e": t.o.is_uri,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for t in resp.triples
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue