UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

93 lines (92 loc) 3.87 kB
/** * As other project partners want the produced data structures as rdf quads, this module provides * serialization capabilities for this purpose. * <p> * At the time of writing this module I am unaware of any sophisticated rdf library for typescript which allows to serialize objects * directly as rdf quads. Therefore, this module provides a simple serialization mechanism based on the popular n3.js library. * * @module */ import type { MergeableRecord } from './objects'; import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id'; type RecordForQuad = Record<string, unknown>; type DataForQuad = Record<string, unknown> | ArrayLike<unknown>; type ContextForQuad = string; /** * Predicate that allows you to ignore given elements based on their key/value * * @returns true if the given key/value should be ignored, false otherwise */ export type QuadIgnoreIf = (key: string, value: unknown) => boolean; /** * Deterministically retrieve a unique id for a given object. * @param obj - The object to retrieve the id for * @param context - to provide unique ids even for different contexts, we add the context to the id. */ export type QuadIdRetriever = (obj: unknown, context: ContextForQuad) => string; /** * Either a constant string or a supplier depending on the object in question */ export type QuadContextRetriever = ContextForQuad | ((obj: DataForQuad) => ContextForQuad); /** * A deterministic counting id generator for quads. */ export declare function defaultQuadIdGenerator(): QuadIdRetriever; export declare function defaultQuadIgnoreIf(): QuadIgnoreIf; /** * See {@link DefaultQuadSerializationConfiguration} for defaults. */ export interface QuadSerializationConfiguration extends MergeableRecord { /** * Ignore certain keys or values when serializing to quads. * @see defaultQuadIgnoreIf */ ignore?: QuadIgnoreIf; /** * Retrieve a unique id for a given object. * @see defaultQuadIdGenerator */ getId?: QuadIdRetriever; /** * The context of the serialized quads, probably the file-name (constant) or whatever is desired. */ context: QuadContextRetriever; /** * The basic domain name to use for the quads. */ domain?: string; } export declare const DefaultQuadSerializationConfiguration: Required<QuadSerializationConfiguration>; /** * Serializes the given object or array to rdf quads. * * @param obj - The object to serialize (must be a Record and no array etc.) * @param config - Further configuration options * * @returns the serialized quads * * @see graph2quads */ export declare function serialize2quads(obj: RecordForQuad, config: QuadSerializationConfiguration): string; export type VertexInformationForQuad<AdditionalInformation extends MergeableRecord> = MergeableRecord & AdditionalInformation & { id: NodeId; }; export type EdgeInformationForQuad<AdditionalInformation extends MergeableRecord> = MergeableRecord & AdditionalInformation & { from: NodeId; type: NodeId | NodeId[]; to: NodeId; }; export interface GraphInformationForQuad<AdditionalVertexInformation extends MergeableRecord, AdditionalEdgeInformation extends MergeableRecord> extends MergeableRecord { rootIds: NodeId[]; vertices: VertexInformationForQuad<AdditionalVertexInformation>[]; edges: EdgeInformationForQuad<AdditionalEdgeInformation>[]; additional?: DataForQuad; } /** * Serializes the given directed graph to rdf quads. * This is a mere (type-)convenience wrapper for {@link serialize2quads}. * * @see serialize2quads */ export declare function graph2quads<AdditionalVertexInformation extends MergeableRecord, AdditionalEdgeInformation extends MergeableRecord>(graph: GraphInformationForQuad<AdditionalVertexInformation, AdditionalEdgeInformation>, config: QuadSerializationConfiguration): string; export {};