php-extended / php-merge-object
An implementation of the php-merge-interface library
7.0.7
2024-12-08 16:38 UTC
Requires
- php: >=8.0
- php-extended/php-information-object: ^18
- php-extended/php-merge-interface: ^7
Requires (Dev)
- dev-master
- 7.0.7
- 7.0.6
- 7.0.5
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 6.1.4
- 6.1.3
- 6.1.2
- 6.1.1
- 6.1.0
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.0.1
- 5.0.0
- 4.0.1
- 4.0.0
- 3.2.20
- 3.2.19
- 3.2.18
- 3.2.17
- 3.2.16
- 3.2.15
- 3.2.14
- 3.2.13
- 3.2.12
- 3.2.11
- 3.2.10
- 3.2.9
- 3.2.8
- 3.2.7
- 3.2.6
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.0
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
This package is auto-updated.
Last update: 2024-12-08 15:38:58 UTC
README
An implementation of the php-merge-interface library.
Installation
The installation of this library is made via composer and the autoloading of all classes of this library is made through their autoloader.
- Download
composer.phar
from their website. - Then run the following command to install this library as dependency :
php composer.phar php-extended/php-merge-object ^7
Basic Usage
This library may be used the following way :
- First Step : to calculate the score of any data provider (such score may be interpreted as the accuracy of that data provider to be accurate for a given type of data) :
use PhpExtended\Merge\Scorer;
use PhpExtended\Merge\ScoreCalculationDefinitionList;
/* @var $source \PhpExtended\Record\RecordProviderInterface */
/* @var $srcNamespace string */
/* @var $srcClassname string */
/* @var $challenger \PhpExtended\Record\AssignableRecordProviderInterface */
/* @var $chlNamespace string */
/* @var $chlClassname string */
/* @var $scoreCollectionFactory \PhpExtended\Score\ScoreCollectionFactoryInterface */
/* @var $scoreFactory \PhpExtended\Score\ScoreFactory */
/* @var $scorePolicyFactory \PhpExtended\Score\ScorePolicyFactoryInterface */
$scoreCalculationDefinitionList = new ScoreCalculationDefinitionList();
foreach(['srcAttr1' => 'dstAttr1', 'srcAttr2' => 'dstAttr2'] as $srcAttr => $dstAttr)
{
$scoreCalculationDefinition = new ScoreCalculationDefinition(
$srcAttr,
$dstAttr,
$scoreCollectionFactory,
$scoreFactory, /* the score factory may differ for each field name, but not needed every time */
$scorePolicyFactory
);
$scoreCalculationDefinitionList->append($scoreCalculationDefinition);
}
$scorer = new Scorer();
$results = $scorer->calculateScore($source, $srcNamespace, $srcClassname, $challenger, $chlNamespace, $chlClassname, $scoreCaculationDefinitionList);
foreach($results as $result)
{
/* @var $result \PhpExtended\Merge\ScoreResultInterface */
// get namespace, classname, fieldname and score
// for each $chlNamespace, $chlClassname and $dstAttr
}
- Second Step : to assign records of a given data provider (record by record) to another source record provider. The best fit is given by the comparator which should give a perfect ordering of the records by measuring the distance between two records.
use PhpExtended\Merge\Assigner;
/* @var $source \PhpExtended\Record\RecordProviderInterface */
/* @var $srcNamespace string */
/* @var $srcClassname string */
/* @var $challenger \PhpExtended\Record\AssignableRecordProviderInterface */
/* @var $chlNamespace string */
/* @var $chlClassname string */
/* @var $comparator \PhpExtended\Record\CompatorInterface */
$assigner = new Assigner();
$assignments = $assigner->doAssignments($source, $srcNamespace, $srcClassname, $challenger, $chlNamespace, $chlClassname, $comparator);
// returns the number of records that were effectively assigned
- Third Step : merges the assigned record values into the main record, by giving individual informations to change to the main record. Note that this method will not create non-existent records only from the challenger sources, it must be created by another procedure.
use PhpExtended\Merge\Merger;
/* @var $source \PhpExtended\Record\RecordProviderInterface */
/* @var $srcNamespace string */
/* @var $srcClassname string */
/* @var $challengerList \PhpExtended\Record\AssignableRecordProviderListInterface */
// note that the challenger list must be created with all the available challengers
// to avoid at most the unsolvable elections
/* @var $chlNamespace string */
/* @var $chlClassname string */
// warning : the challengers should be normalized (via an interface if possible)
/* @var $votingMethodFactory \PhpExtended\Vote\VotingMethodFactoryInterface */
/* @var $citizenFactory \PhpExtended\Vote\CitizenFactoryInterface */
/* @var $candidateFactory \PhpExtended\Vote\CandidateFactoryInterface */
/* @var $argumentFactory \PhpExtended\Vote\ArgumentFactoryInterface */
/* @var $biasFactory \PhpExtended\Vote\BiasFactoryInterface */
/* @var $electionRunnerFactory \PhpExtended\Vote\ElectionRunnerFactoryInterface */
$mergeCalculationDefintitionList = new MergeCalculationDefinitionList();
foreach(['srcAttr1' => 'dstAttr1', 'srcAttr2' => 'dstAttr2'] as $srcAttr => $dstAttr)
{
$mergeCalculationDefinition = new MergeCalculationDefinition(
$srcAttr,
$dstAttr, // warning, should be the same for each challenger in the list
$votingMethodFactory,
$citizenFactory, // warning, should be the same for each challenger in the list
$candidateFactory,
$argumentFactory,
$biasFactory, // warning, should be the same for each challenger in the list
$electionRunnerFactory
);
$mergeCalculationDefinitionList->append($mergeCalculationDefinition);
}
$merger = new Merger();
$informations = $merger->doMerge($source, $srcNamespace, $srcClassname, $challengerList, $chlNamespace, $chlClassname, $mergeCalculationDefinitionList);
foreach($informations as $information)
{
/* @var $information \PhpExtended\Information\InformationInterface */
// get the $srcNamespace, $srcClassname, $sourceId and $srcFieldName
// alongside with the $value
}
License
MIT (See license file).