algebraixlib.io.rdf module

Import and export facilities for RDF data.

algebraixlib.io.rdf.import_graph(input_file=None, input_data: str=None, rdf_format: str=None) → 'PP(A x A)'[source]

Return an absolute graph into which the RDF graph input_file has been imported.

  • The left components are ‘s’ (subject), ‘p’ (predicate) and ‘o’ (object) (see triple).
  • Blank nodes are converted to IRIs (skolemization).
  • URI references are represented as rdflib.URIRef instances (embedded in an Atom).
  • Literals are converted to intuitive native Python types (embedded in an Atom).
Parameters:
  • input_file – A string that is a path (relative or absolute) to the file to be imported, or a StringIO instance. Exactly one of input_file and input_data must be given.
  • input_data – The input data as string. Exactly one of input_file and input_data must be given.
  • rdf_format – The format of the RDF graph that is being imported. See Pluginparsers for a list of supported formats and their corresponding strings. If none is given, the file name’s extension is used to guess a format. If that fails, Turtle is used as default.
Returns:

An absolute graph with the data from the RDF graph that has been imported.

algebraixlib.io.rdf.export_table(file_or_path, lefts: 'P( A )', table: 'PP(A x A)', out_format: str='csv')[source]

Return a serialized table as string in a supported RDF format for table serialization.

Limitations: - Leading ‘?’ and ‘$’ are not stripped from lefts (variable names). - Non-printable characters are backslash-escaped. - table must be an absolute graph.

Parameters:
  • file_or_path – Either a file path (in this case the data is written to a file at this location) or a file object (in this case the data is written to its .write() function).
  • lefts – The set of the left components in table that is exported.
  • table – A clan that contains the data to be exported.
  • out_format – A supported RDF table format. Supported are 'csv' (SPARQL1.1QueryResultsCSVandTSVFormats) and 'json' (SPARQL1.1QueryResultsJSONFormat).