rdf_writer module

class py_amr2fred.rdf_writer.RdfWriter

Bases: object

A class for converting a hierarchical structure of nodes into an RDF graph using rdflib.

This class manages RDF graph construction, namespace binding, serialization, and visibility handling.

get_prefixes() list[str]

Retrieves the list of namespace prefixes bound to the RDF graph.

Returns:

A list of tuples containing (prefix, namespace URI).

Return type:

list[str]

static get_uri(var: str) str

Resolves a variable name into a full URI based on predefined namespaces.

Parameters:

var (str) – The variable name to be converted into a URI.

Returns:

The corresponding URI.

Return type:

str

new_graph()

Creates a new RDF graph and a secondary graph for non-visible triples. Also, assigns the namespace manager to both graphs.

serialize(rdf_format: RdflibMode) str

Serializes the RDF graph into the specified format.

Parameters:

rdf_format (Glossary.RdflibMode) – The format in which to serialize the RDF graph.

Returns:

The serialized RDF data as a string.

Return type:

str

to_rdf(root: Node)

Converts a hierarchical structure of Node objects into an RDF graph.

Parameters:

root (Node) – The root node of the structure to be transformed into RDF.