Fix bugs to pass compaction tests.

This commit is contained in:
Dave Longley 2013-02-07 23:47:55 -05:00
parent a8ce5ba4a2
commit 3831d5336a

View file

@ -449,14 +449,18 @@ class JsonLdProcessor {
// do compaction // do compaction
$compacted = $this->_compact($active_ctx, null, $expanded, $options); $compacted = $this->_compact($active_ctx, null, $expanded, $options);
// if compacted is an array with 1 entry, remove array unless if(!$options['graph'] && is_array($compacted)) {
// graph option is set // simplify to a single item
if($options['graph'] !== true && if(count($compacted) === 1) {
is_array($compacted) && count($compacted) === 1) {
$compacted = $compacted[0]; $compacted = $compacted[0];
} }
// simplify to an empty object
else if(count($compacted) === 0) {
$compacted = new stdClass();
}
}
// always use array if graph option is on // always use array if graph option is on
else if($options['graph'] === true) { else if($options['graph']) {
$compacted = self::arrayify($compacted); $compacted = self::arrayify($compacted);
} }
@ -1535,13 +1539,13 @@ class JsonLdProcessor {
// handle @list // handle @list
if($is_list) { if($is_list) {
// ensure $list value is an array // ensure @list value is an array
$compacted_item = self::arrayify($compacted_item); $compacted_item = self::arrayify($compacted_item);
if($container !== '@list') { if($container !== '@list') {
// wrap using @list alias // wrap using @list alias
$compacted_item = (object)array( $compacted_item = (object)array(
$this->_compactIri($active_ctx, '@list'), $compacted_item); $this->_compactIri($active_ctx, '@list') => $compacted_item);
// include @index from expanded @list, if any // include @index from expanded @list, if any
if(property_exists($expanded_item, '@index')) { if(property_exists($expanded_item, '@index')) {
@ -3739,8 +3743,12 @@ class JsonLdProcessor {
break; break;
} }
} }
$common_language = $common_language || '@none'; if($common_language === null) {
$common_type = $common_type || '@none'; $common_language = '@none';
}
if($common_type === null) {
$common_type = '@none';
}
if($common_type !== '@none') { if($common_type !== '@none') {
$type_or_language = '@type'; $type_or_language = '@type';
$type_or_language_value = $common_type; $type_or_language_value = $common_type;