@@ -25,59 +25,38 @@ module.exports = api;
25
25
*
26
26
* @return the framed output.
27
27
*/
28
- api . frameMerged = ( input , frame , options ) => {
28
+ api . frameMergedOrDefault = ( input , frame , options ) => {
29
29
// create framing state
30
30
const state = {
31
31
options : options ,
32
- graph : '@merged ' ,
32
+ graph : '@default ' ,
33
33
graphMap : { '@default' : { } } ,
34
34
graphStack : [ ] ,
35
35
subjectStack : [ ] ,
36
- link : { }
36
+ link : { } ,
37
+ bnodeMap : { }
37
38
} ;
38
39
39
40
// produce a map of all graphs and name each bnode
40
41
// FIXME: currently uses subjects from @merged graph only
41
42
const issuer = new util . IdentifierIssuer ( '_:b' ) ;
42
43
_createNodeMap ( input , state . graphMap , '@default' , issuer ) ;
43
- state . graphMap [ '@merged' ] = _mergeNodeMapGraphs ( state . graphMap ) ;
44
- state . subjects = state . graphMap [ '@merged' ] ;
44
+ if ( options . merged ) {
45
+ state . graphMap [ '@merged' ] = _mergeNodeMapGraphs ( state . graphMap ) ;
46
+ state . graph = '@merged'
47
+ }
48
+ state . subjects = state . graphMap [ state . graph ] ;
45
49
46
50
// frame the subjects
47
51
const framed = [ ] ;
48
52
api . frame ( state , Object . keys ( state . subjects ) . sort ( ) , frame , framed ) ;
49
- return framed ;
50
- } ;
51
53
52
- /**
53
- * Performs JSON-LD `default` framing.
54
- * FIXME: maybe just rename frameMerged and perform selection logic in one place
55
- *
56
- * @param input the expanded JSON-LD to frame.
57
- * @param frame the expanded JSON-LD frame to use.
58
- * @param options the framing options.
59
- *
60
- * @return the framed output.
61
- */
62
- api . frameDefault = ( input , frame , options ) => {
63
- // create framing state
64
- const state = {
65
- options : options ,
66
- graph : '@default' ,
67
- graphMap : { '@default' : { } } ,
68
- graphStack : [ ] ,
69
- subjectStack : [ ] ,
70
- link : { }
71
- } ;
72
-
73
- // produce a map of all graphs and name each bnode
74
- const issuer = new util . IdentifierIssuer ( '_:b' ) ;
75
- _createNodeMap ( input , state . graphMap , '@default' , issuer ) ;
76
- state . subjects = state . graphMap [ '@default' ] ;
54
+ // If pruning blank nodes, find those to prune
55
+ if ( options . pruneBlankNodeIdentifiers ) {
56
+ // remove all blank nodes appearing only once, done in compaction
57
+ options . bnodesToClear = Object . keys ( state . bnodeMap ) . filter ( id => state . bnodeMap [ id ] . length === 1 ) ;
58
+ }
77
59
78
- // frame the subjects
79
- const framed = [ ] ;
80
- api . frame ( state , Object . keys ( state . subjects ) . sort ( ) , frame , framed ) ;
81
60
return framed ;
82
61
} ;
83
62
@@ -133,6 +112,9 @@ api.frame = (state, subjects, frame, parent, property = null) => {
133
112
// start output for subject
134
113
const output = { } ;
135
114
output [ '@id' ] = id ;
115
+ if ( id . indexOf ( '_:' ) === 0 ) {
116
+ util . addValue ( state . bnodeMap , id , output , { propertyIsArray : true } ) ;
117
+ }
136
118
state . link [ id ] = output ;
137
119
138
120
// if embed is @never or if a circular reference would be created by an
0 commit comments