UNPKG

metagraph

Version:

A framework for building higher-order graph data structures

129 lines (124 loc) 4.83 kB
/*! * metagraph.js <%= conf.pkg.version %> * http://gordonwoodhull.github.io/metagraph.js/ * Copyright 2019 AT&T Intellectual Property * * Licensed under the MIT License * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ import { output, subset, input } from './dataflow_calcs.js'; import { lookupArg, subgraph } from './interface.js'; const graph_options = (opts) => Object.assign({ nodeKey: (kv) => kv.key, edgeKey: (kv) => kv.key, nodeValue: (kv) => kv.value, edgeValue: (kv) => kv.value, edgeSource: (kv) => kv.value.source, edgeTarget: (kv) => kv.value.target }, opts || {}); /** * Creates a subgraph pattern specification for filtering parent graphs. * Enables creation of subgraphs by selecting subsets of nodes and edges from parent graphs. * * @param opts - Optional graph options for customizing node/edge accessors * @returns A pattern specification for creating subgraph functionality * * @example * ```typescript * // Used in composed patterns to enable subgraph operations * const subPat = subgraph_pattern(); * // Results in parent.subgraph(['nodeA', 'nodeB'], ['edge1'], data) * ``` */ const subgraph_pattern = (opts) => { graph_options(opts); return { dataflow: { incidences: { parent_nodes: { node: input('parent.nodes') }, parent_edges: { node: input('parent.edges') }, node_keys: { node: input('nodeKeys') }, edge_keys: { node: input('edgeKeys') }, subset_nodes: { node: subset(), refs: 'child.Node', ins: ['parent_nodes', 'node_keys'] }, subset_edges: { node: subset(), refs: 'child.Edge', ins: ['parent_edges', 'edge_keys'] }, nodes: { node: output(), ins: 'subset_nodes' }, edges: { node: output(), ins: 'subset_edges' } } }, interface: { nodes: { ParentGraph: 'parent.Graph', ChildGraph: 'child.Graph' }, edges: { subgraph: { name: 'subgraph', source: 'ParentGraph', target: 'ChildGraph', member: subgraph() }, subnode: { name: 'subnode', source: 'ParentGraph', target: 'ChildGraph', deps: 'parent.node_by_key', member: lookupArg() }, subedge: { name: 'subedge', source: 'ParentGraph', target: 'ChildGraph', deps: 'parent.edge_by_key', flow: lookupArg() }, subgraphS: { name: 'subgraph', source: 'ChildGraph', target: 'ParentGraph', member: subgraph() }, subnodeS: { name: 'subnode', source: 'ChildGraph', target: 'ParentGraph', deps: 'node_by_key', // should be child: member: lookupArg((x) => x.key()) }, subedgeS: { name: 'subedge', source: 'ChildGraph', target: 'ParentGraph', deps: 'edge_by_key', // should be child: flow: lookupArg((x) => x.key()) } } } }; }; export { subgraph_pattern }; //# sourceMappingURL=subgraph_pattern.js.map