Ensure property generator values are compared during term selection.
- Reuse find property generator duplicates function.
This commit is contained in:
parent
7c2aceed28
commit
31dafae2ec
66
jsonld.php
66
jsonld.php
|
@ -1071,7 +1071,7 @@ class JsonLdProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. equal @values
|
// 2. equal @values
|
||||||
if(self::_isValue($v1) || self::_isValue($v2)) {
|
if(self::_isValue($v1) && self::_isValue($v2)) {
|
||||||
return (
|
return (
|
||||||
self::_compareKeyValues($v1, $v2, '@value') &&
|
self::_compareKeyValues($v1, $v2, '@value') &&
|
||||||
self::_compareKeyValues($v1, $v2, '@type') &&
|
self::_compareKeyValues($v1, $v2, '@type') &&
|
||||||
|
@ -1538,9 +1538,9 @@ class JsonLdProcessor {
|
||||||
if(property_exists($active_ctx->mappings, $active_property)) {
|
if(property_exists($active_ctx->mappings, $active_property)) {
|
||||||
$mapping = $active_ctx->mappings->{$active_property};
|
$mapping = $active_ctx->mappings->{$active_property};
|
||||||
if($mapping && $mapping->propertyGenerator) {
|
if($mapping && $mapping->propertyGenerator) {
|
||||||
$this->_findAndRemovePropertyGeneratorDuplicates(
|
$this->_findPropertyGeneratorDuplicates(
|
||||||
$active_ctx, $element, $expanded_property, $expanded_item,
|
$active_ctx, $element, $expanded_property, $expanded_item,
|
||||||
$active_property);
|
$active_property, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3647,14 +3647,8 @@ class JsonLdProcessor {
|
||||||
// see if a property generator matches
|
// see if a property generator matches
|
||||||
if(is_object($parent)) {
|
if(is_object($parent)) {
|
||||||
foreach($term_info->propertyGenerators as $property_generator) {
|
foreach($term_info->propertyGenerators as $property_generator) {
|
||||||
$iris = $active_ctx->mappings->{$property_generator}->{'@id'};
|
$match = $this->_findPropertyGeneratorDuplicates(
|
||||||
$match = true;
|
$active_ctx, $parent, $iri, $value, $property_generator, false);
|
||||||
foreach($iris as $iri_) {
|
|
||||||
if(!property_exists($parent, $iri_)) {
|
|
||||||
$match = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if($match) {
|
if($match) {
|
||||||
$term = $property_generator;
|
$term = $property_generator;
|
||||||
break;
|
break;
|
||||||
|
@ -3952,8 +3946,8 @@ class JsonLdProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and removes any duplicate values that were presumably generated by
|
* Finds and, if specified, removes any duplicate values that were
|
||||||
* a property generator in the given element.
|
* presumably generated by a property generator in the given element.
|
||||||
*
|
*
|
||||||
* @param stdClass $active_ctx the active context.
|
* @param stdClass $active_ctx the active context.
|
||||||
* @param stdClass $element the element to remove duplicates from.
|
* @param stdClass $element the element to remove duplicates from.
|
||||||
|
@ -3961,30 +3955,64 @@ class JsonLdProcessor {
|
||||||
* generator.
|
* generator.
|
||||||
* @param mixed $value the value to compare against when duplicate checking.
|
* @param mixed $value the value to compare against when duplicate checking.
|
||||||
* @param string $active_property the property generator term.
|
* @param string $active_property the property generator term.
|
||||||
|
* @param bool $remove true to remove the duplicates found, false not to.
|
||||||
|
*
|
||||||
|
* @return bool true if duplicates were found for every IRI.
|
||||||
*/
|
*/
|
||||||
protected function _findAndRemovePropertyGeneratorDuplicates(
|
protected function _findPropertyGeneratorDuplicates(
|
||||||
$active_ctx, $element, $expanded_property, $value, $active_property) {
|
$active_ctx, $element, $expanded_property, $value, $active_property,
|
||||||
|
$remove) {
|
||||||
|
$rval = true;
|
||||||
|
|
||||||
// get property generator IRIs
|
// get property generator IRIs
|
||||||
$iris = $active_ctx->mappings->{$active_property}->{'@id'};
|
$iris = $active_ctx->mappings->{$active_property}->{'@id'};
|
||||||
|
|
||||||
// for each IRI that isn't 'expandedProperty', remove a single duplicate
|
// for each IRI that isn't 'expandedProperty', remove a single duplicate
|
||||||
// from element, if found
|
// from element, if found
|
||||||
foreach($iris as $iri) {
|
foreach($iris as $iri) {
|
||||||
|
if($rval === false) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if($iri === $expanded_property) {
|
if($iri === $expanded_property) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$rval = false;
|
||||||
|
if(!property_exists($element, $iri)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
$length = count($element->{$iri});
|
$length = count($element->{$iri});
|
||||||
|
|
||||||
|
// handle empty array case
|
||||||
|
if($length === 0 && is_array($value) && count($value) === 0) {
|
||||||
|
$rval = true;
|
||||||
|
if($remove) {
|
||||||
|
unset($element->{$iri});
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle other cases
|
||||||
for($pi = 0; $pi < $length; ++$pi) {
|
for($pi = 0; $pi < $length; ++$pi) {
|
||||||
if(self::compareValues($element->{$iri}[$pi], $value)) {
|
if(self::compareValues($element->{$iri}[$pi], $value)) {
|
||||||
// duplicate found, remove it in place
|
// duplicate found
|
||||||
array_splice($element->{$iri}, $pi, 1);
|
$rval = true;
|
||||||
if(count($element->{$iri}) === 0) {
|
|
||||||
unset($element->{$iri});
|
if($remove) {
|
||||||
|
// remove it in place
|
||||||
|
array_splice($element->{$iri}, $pi, 1);
|
||||||
|
if(count($element->{$iri}) === 0) {
|
||||||
|
unset($element->{$iri});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue