Reorganize and simplify value expansion.

This commit is contained in:
Dave Longley 2013-02-13 20:08:53 -05:00
parent 447aa88d61
commit 6d5934398d

View file

@ -4285,19 +4285,12 @@ class JsonLdProcessor {
$this->_createTermDefinition($active_ctx, $local_ctx, $value, $defined); $this->_createTermDefinition($active_ctx, $local_ctx, $value, $defined);
} }
$rval = null;
if(isset($relative_to['vocab']) && $relative_to['vocab']) {
if(property_exists($active_ctx->mappings, $value)) { if(property_exists($active_ctx->mappings, $value)) {
$mapping = $active_ctx->mappings->{$value};
// value is explicitly ignored with a null mapping
if($mapping === null) {
return null;
}
}
else {
$mapping = null;
}
// term dependency cannot be a property generator // term dependency cannot be a property generator
$mapping = $active_ctx->mappings->{$value};
if($local_ctx !== null && $mapping && $mapping->propertyGenerator) { if($local_ctx !== null && $mapping && $mapping->propertyGenerator) {
throw new JsonLdException( throw new JsonLdException(
'Invalid JSON-LD syntax; a term definition cannot have a property ' . 'Invalid JSON-LD syntax; a term definition cannot have a property ' .
@ -4306,35 +4299,30 @@ class JsonLdProcessor {
array('context' => $local_ctx, 'value' => $value)); array('context' => $local_ctx, 'value' => $value));
} }
$is_absolute = false; // value is explicitly ignored with a null mapping
$rval = $value; if($mapping === null) {
return null;
}
// value is a term // value is a term
if(isset($relative_to['vocab']) && $relative_to['vocab'] && if(!$mapping->propertyGenerator) {
$mapping && !$mapping->propertyGenerator) {
$is_absolute = true;
$rval = $mapping->{'@id'}; $rval = $mapping->{'@id'};
} }
}
// keywords need no expanding (aliasing already handled by now)
if(self::_isKeyword($rval)) {
return $rval;
} }
if(!$is_absolute) { if($rval === null) {
// split value into prefix:suffix // split value into prefix:suffix
$colon = strpos($rval, ':'); $colon = strpos($value, ':');
if($colon !== false) { if($colon !== false) {
$is_absolute = true; $prefix = substr($value, 0, $colon);
$prefix = substr($rval, 0, $colon); $suffix = substr($value, $colon + 1);
$suffix = substr($rval, $colon + 1);
// do not expand blank nodes (prefix of '_') or already-absolute // do not expand blank nodes (prefix of '_') or already-absolute
// IRIs (suffix of '//') // IRIs (suffix of '//')
if($prefix !== '_' && strpos($suffix, '//') !== 0) { if($prefix !== '_' && strpos($suffix, '//') !== 0) {
// prefix dependency not defined, define it // prefix dependency not defined, define it
if($local_ctx !== null && property_exists($local_ctx, $prefix) && if($local_ctx !== null && property_exists($local_ctx, $prefix)) {
!self::_hasKeyValue($defined, $prefix, true)) {
$this->_createTermDefinition( $this->_createTermDefinition(
$active_ctx, $local_ctx, $prefix, $defined); $active_ctx, $local_ctx, $prefix, $defined);
} }
@ -4350,7 +4338,16 @@ class JsonLdProcessor {
} }
} }
if($is_absolute) { if($rval === null) {
$rval = $value;
}
// keywords need no expanding (aliasing already handled by now)
if(self::_isKeyword($rval)) {
return $rval;
}
if(self::_isAbsoluteIri($rval)) {
// rename blank node if requested // rename blank node if requested
if(!$local_ctx && strpos($rval, '_:') === 0 && if(!$local_ctx && strpos($rval, '_:') === 0 &&
$active_ctx->namer !== null) { $active_ctx->namer !== null) {