-
Notifications
You must be signed in to change notification settings - Fork 201
Graph id type maps #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graph id type maps #212
Conversation
lib/graphTypes.js
Outdated
// 3. It may have '@id' or '@index' | ||
return types.isObject(v) && | ||
'@graph' in v && | ||
Object.keys(v).filter(key => key != '@id' && key != '@index').length === 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use !==
.
lib/expand.js
Outdated
// and value is not, itself, a graph | ||
// index cases handled above | ||
if(container.includes('@graph') && | ||
!container.some(key => key == '@id' || key == '@index') && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ===
.
51cf8fb
to
22ec6b1
Compare
22ec6b1
to
00e321c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nits mostly. Then LGTM.
lib/compact.js
Outdated
// add compactedItem to map, using value of `@index` or `@none` | ||
_addValue( | ||
mapObject, (expandedItem['@index'] || '@none'), compactedItem, | ||
{propertyIsArray: (!options.compactArrays || container.includes('@set'))}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code in these first two cases is really similar and could potentially be combined -- but that can wait until we do some clean up later. Just making a note of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the code is the same for the cases where @index
and where @id
are present other than the second parameter to _addValue
.
lib/compact.js
Outdated
// get or create the map object | ||
let mapObject; | ||
let mapObject, key; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declare vars on new lines:
let mapObject;
let key;
But the key
declaration should really be moved down to where it's immediately relevant, so right above its first use.
lib/compact.js
Outdated
delete compactedItem[idKey]; | ||
} else if(container.includes('@type')) { | ||
const typeKey = api.compactIri({activeCtx, iri: '@type', vocab: true}); | ||
var types; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use let types
, not var
.
lib/compact.js
Outdated
switch(types.length) { | ||
case 0: delete compactedItem[typeKey]; break; | ||
case 1: compactedItem[typeKey] = types[0]; break; | ||
default: compactedItem[typeKey] = types; break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use line breaks:
switch(types.length) {
case 0:
delete compactedItem[typeKey];
break;
case 1:
compactedItem[typeKey] = types[0];
break;
default:
compactedItem[typeKey] = types;
break;
}
Or shorten to if/else:
if(types.length === 0) {
delete compactedItem[typeKey];
} else if(types.length === 1) {
compactedItem[typeKey] = types[0];
} else {
compactedItem[typeKey] = types;
}
lib/compact.js
Outdated
} | ||
|
||
// add compact value to map object using key from expanded value | ||
// based on the container type | ||
const c = container.includes('@language') ? '@language' : '@index'; | ||
_addValue(mapObject, expandedItem[c], compactedItem); | ||
_addValue(mapObject, key, compactedItem, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our coding style rule for long parameter lists is:
When moving any function parameters down a line, move them all down a line (and then add new lines as needed to fit within 80-chars, but do not leave any on the same line as the function as it improves readability):
_addValue(
mapObject, key, compactedItem, {propertyIsArray: container.includes('@set')});
lib/context.js
Outdated
{code: 'invalid container mapping', context: localCtx}); | ||
} | ||
} else if(container.includes('@graph')) { | ||
if(container.some(key => key != '@graph' && key != '@id' && key != '@index' && key != '@set')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use triple equals.
I made the requested changes. Note that this will need a rebase to fit with the other two PRs. |
lib/compact.js
Outdated
} else if(_isObject(value) && !_isValue(value)) { | ||
containers.push('@id@set'); | ||
containers.push('@id'); | ||
containers.push('@type@set'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flipped order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be @set@type
, and can push
can take multiple arguments.
Based on json-ld/json-ld.org#569 it's even more complicated, if we want to prioritize order based on the actual value, and allow @none
to be used. The work's not all done fo this yet, but may as well get this in order.
More container checking for specifics of `@list` and `@graph`. Don't expand values of graph container properties which are already graphs.
- adds a BNode issuer to compact to generate identifiers, if necessary.
ee9a13b
to
5bb6924
Compare
This adds support for graph indexing on
@id
and@index
, as well as id maps and type maps.It is based on the
processingMode
branch, but is targeted for 0.6.x. The 0.6.x branch will require rebasing from 0.5.x until that branch is completed.