Simplify keyword alias handling.

This commit is contained in:
Dave Longley 2013-03-11 17:04:24 -04:00
parent 5cf9a5c133
commit 896842b107

View file

@ -3952,11 +3952,9 @@ class JsonLdProcessor {
return $iri; return $iri;
} }
// term is a keyword // term is a keyword, default vocab to true
if(self::_isKeyword($iri)) { if(self::_isKeyword($iri)) {
// return alias if available $relative_to['vocab'] = true;
$aliases = $active_ctx->keywords->{$iri};
return (count($aliases) > 0) ? $aliases[0] : $iri;
} }
// use inverse context to pick a term if iri is relative to vocab // use inverse context to pick a term if iri is relative to vocab
@ -4253,14 +4251,9 @@ class JsonLdProcessor {
'jsonld.SyntaxError', array('context' => $local_ctx)); 'jsonld.SyntaxError', array('context' => $local_ctx));
} }
if(property_exists($active_ctx->mappings, $term) && // remove old mapping
$active_ctx->mappings->{$term} !== null) { if(property_exists($active_ctx->mappings, $term)) {
// if term is a keyword alias, remove it unset($active_ctx->mappings->{$term});
$kw = $active_ctx->mappings->{$term}->{'@id'};
if(self::_isKeyword($kw)) {
array_splice($active_ctx->keywords->{$kw},
array_search($term, $active_ctx->keywords->{$kw}), 1);
}
} }
// get context term value // get context term value
@ -4287,16 +4280,9 @@ class JsonLdProcessor {
'Invalid JSON-LD syntax; @context and @preserve cannot be aliased.', 'Invalid JSON-LD syntax; @context and @preserve cannot be aliased.',
'jsonld.SyntaxError'); 'jsonld.SyntaxError');
} }
// uniquely add term as a keyword alias and resort
if(!in_array($term, $active_ctx->keywords->{$value})) {
$active_ctx->keywords->{$value}[] = $term;
usort($active_ctx->keywords->{$value},
array($this, '_compareShortestLeast'));
}
} }
// define/redefine term to expanded IRI/keyword // define term to expanded IRI/keyword
$active_ctx->mappings->{$term} = (object)array('@id' => $id); $active_ctx->mappings->{$term} = (object)array('@id' => $id);
$defined->{$term} = true; $defined->{$term} = true;
return; return;
@ -4710,23 +4696,6 @@ class JsonLdProcessor {
return (object)array( return (object)array(
'@base' => jsonld_parse_url($options['base']), '@base' => jsonld_parse_url($options['base']),
'mappings' => new stdClass(), 'mappings' => new stdClass(),
'keywords' => (object)array(
'@context' => array(),
'@container' => array(),
'@default' => array(),
'@embed' => array(),
'@explicit' => array(),
'@graph' => array(),
'@id' => array(),
'@index' => array(),
'@language' => array(),
'@list' => array(),
'@omitDefault' => array(),
'@preserve' => array(),
'@set' => array(),
'@type' => array(),
'@value' => array(),
'@vocab' => array()),
'namer' => $namer, 'namer' => $namer,
'inverse' => null); 'inverse' => null);
} }
@ -4844,7 +4813,6 @@ class JsonLdProcessor {
protected function _cloneActiveContext($active_ctx) { protected function _cloneActiveContext($active_ctx) {
$child = new stdClass(); $child = new stdClass();
$child->{'@base'} = $active_ctx->{'@base'}; $child->{'@base'} = $active_ctx->{'@base'};
$child->keywords = self::copy($active_ctx->keywords);
$child->mappings = self::copy($active_ctx->mappings); $child->mappings = self::copy($active_ctx->mappings);
$child->namer = $active_ctx->namer; $child->namer = $active_ctx->namer;
$child->inverse = null; $child->inverse = null;
@ -4869,7 +4837,6 @@ class JsonLdProcessor {
public function _shareActiveContext($active_ctx) { public function _shareActiveContext($active_ctx) {
$rval = new stdClass(); $rval = new stdClass();
$rval->{'@base'} = $active_ctx->{'@base'}; $rval->{'@base'} = $active_ctx->{'@base'};
$rval->keywords = $active_ctx->keywords;
$rval->mappings = $active_ctx->mappings; $rval->mappings = $active_ctx->mappings;
if($active_ctx->namer !== null) { if($active_ctx->namer !== null) {
$rval->namer = new UniqueNamer('_:b'); $rval->namer = new UniqueNamer('_:b');
@ -4909,6 +4876,7 @@ class JsonLdProcessor {
case '@list': case '@list':
case '@omitDefault': case '@omitDefault':
case '@preserve': case '@preserve':
case '@reverse':
case '@set': case '@set':
case '@type': case '@type':
case '@value': case '@value':