From 839ec29752562dc81dc4ea7c998f491bb279cd24 Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Wed, 23 Oct 2024 17:36:52 +0100 Subject: [PATCH] Added subject-of links --- trustgraph-base/trustgraph/rdf.py | 1 + .../extract/kg/definitions/extract.py | 16 +++++++++++++++- .../extract/kg/relationships/extract.py | 19 ++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/trustgraph-base/trustgraph/rdf.py b/trustgraph-base/trustgraph/rdf.py index b65d9c29..ef1da183 100644 --- a/trustgraph-base/trustgraph/rdf.py +++ b/trustgraph-base/trustgraph/rdf.py @@ -1,6 +1,7 @@ RDF_LABEL = "http://www.w3.org/2000/01/rdf-schema#label" DEFINITION = "http://www.w3.org/2004/02/skos/core#definition" +SUBJECT_OF = "https://schema.org/subjectOf" TRUSTGRAPH_ENTITIES = "http://trustgraph.ai/e/" diff --git a/trustgraph-flow/trustgraph/extract/kg/definitions/extract.py b/trustgraph-flow/trustgraph/extract/kg/definitions/extract.py index f7cdea99..eed34574 100755 --- a/trustgraph-flow/trustgraph/extract/kg/definitions/extract.py +++ b/trustgraph-flow/trustgraph/extract/kg/definitions/extract.py @@ -13,10 +13,12 @@ from .... schema import prompt_request_queue from .... schema import prompt_response_queue from .... log_level import LogLevel from .... clients.prompt_client import PromptClient -from .... rdf import TRUSTGRAPH_ENTITIES, DEFINITION +from .... rdf import TRUSTGRAPH_ENTITIES, DEFINITION, RDF_LABEL, SUBJECT_OF from .... base import ConsumerProducer DEFINITION_VALUE = Value(value=DEFINITION, is_uri=True) +RDF_LABEL_VALUE = Value(value=RDF_LABEL, is_uri=True) +SUBJECT_OF_VALUE = Value(value=SUBJECT_OF, is_uri=True) module = ".".join(__name__.split(".")[1:-1]) @@ -111,10 +113,22 @@ class Processor(ConsumerProducer): s_value = Value(value=str(s_uri), is_uri=True) o_value = Value(value=str(o), is_uri=False) + triples.append(Triple( + s=s_value, + p=RDF_LABEL_VALUE, + o=Value(value=s, is_uri=False), + )) + triples.append(Triple( s=s_value, p=DEFINITION_VALUE, o=o_value )) + triples.append(Triple( + s=s_value, + p=SUBJECT_OF_VALUE, + o=Value(value=v.metadata.id, is_uri=True) + )) + self.emit_edges( Metadata( id=v.metadata.id, diff --git a/trustgraph-flow/trustgraph/extract/kg/relationships/extract.py b/trustgraph-flow/trustgraph/extract/kg/relationships/extract.py index d63549e2..4daf6859 100755 --- a/trustgraph-flow/trustgraph/extract/kg/relationships/extract.py +++ b/trustgraph-flow/trustgraph/extract/kg/relationships/extract.py @@ -17,10 +17,11 @@ from .... schema import prompt_request_queue from .... schema import prompt_response_queue from .... log_level import LogLevel from .... clients.prompt_client import PromptClient -from .... rdf import RDF_LABEL, TRUSTGRAPH_ENTITIES +from .... rdf import RDF_LABEL, TRUSTGRAPH_ENTITIES, SUBJECT_OF from .... base import ConsumerProducer RDF_LABEL_VALUE = Value(value=RDF_LABEL, is_uri=True) +SUBJECT_OF_VALUE = Value(value=SUBJECT_OF, is_uri=True) module = ".".join(__name__.split(".")[1:-1]) @@ -177,8 +178,24 @@ class Processor(ConsumerProducer): o=Value(value=str(o), is_uri=False) )) + # 'Subject of' for s + triples.append(Triple( + s=s_value, + p=SUBJECT_OF_VALUE, + o=Value(value=v.metadata.id, is_uri=True) + )) + + if rel.o_entity: + # 'Subject of' for o + triples.append(Triple( + s=o_value, + p=RDF_LABEL_VALUE, + o=Value(value=v.metadata.id, is_uri=True) + )) + self.emit_vec(v.metadata, s_value, v.vectors) self.emit_vec(v.metadata, p_value, v.vectors) + if rel.o_entity: self.emit_vec(v.metadata, o_value, v.vectors)