Skip to content

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

Merged
merged 14 commits into from
Jan 20, 2018
Merged

Graph id type maps #212

merged 14 commits into from
Jan 20, 2018

Conversation

gkellogg
Copy link
Collaborator

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.

// 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;
Copy link
Member

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') &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ===.

Copy link
Member

@dlongley dlongley left a 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'))});
Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This better?

Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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,
Copy link
Member

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')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use triple equals.

@gkellogg
Copy link
Collaborator Author

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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flipped order?

Copy link
Collaborator Author

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.

@gkellogg gkellogg merged commit b7318d7 into 0.6.x Jan 20, 2018
@gkellogg gkellogg deleted the graph-id-type-maps branch January 20, 2018 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants