Skip to content

Commit

Permalink
Further work on #36
Browse files Browse the repository at this point in the history
  • Loading branch information
ric2016 committed Apr 10, 2021
1 parent 6d1dbbc commit 77f932b
Show file tree
Hide file tree
Showing 17 changed files with 642 additions and 215 deletions.
9 changes: 9 additions & 0 deletions ExtendedRelationshipModuleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ protected function createPrefs() {
null,
'CHART_SHOW_CAS',
'1')));

$chartSub[] = new ControlPanelSubsection(
/* I18N: Module Configuration */I18N::translate('Debugging'),
array(new ControlPanelCheckbox(
/* I18N: Module Configuration */I18N::translate('Show legacy relationship path names'),
null,
'CHART_SHOW_LEGACY',
'1')));

$chartSub[] = new ControlPanelSubsection(
/* I18N: Module Configuration */I18N::translate('Options to show in the chart'),
array(new ControlPanelCheckbox(
Expand Down
16 changes: 14 additions & 2 deletions ExtendedRelationshipsChartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,20 @@ public function chart(
// Cannot see one of the families/individuals, due to privacy;
continue;
}
echo '<h3>', I18N::translate('Relationship: %s', FunctionsExt::getRelationshipNameFromPath(implode('', $relationships), $individual1, $individual2)), '</h3>';
echo '<h3>', I18N::translate('Relationship: %s', RelationshipUtils::getRelationshipName(RelationshipPath::create($tree, $path))), '</h3>';

$rel = RelationshipUtils::getRelationshipName(RelationshipPath::create($tree, $path));
echo '<h3>', I18N::translate('Relationship: %s', $rel), '</h3>';

$debugWebtreesRel = $showCa = boolval($this->module->getPreference('CHART_SHOW_LEGACY', '1'));
if ($debugWebtreesRel) {
$webtreesRel = FunctionsExt::getRelationshipNameFromPath(implode('', $relationships), $individual1, $individual2);
if ($rel !== $webtreesRel) {
echo '<h4>', '(', I18N::translate('via legacy algorithm: %s', $webtreesRel), ')';
echo FunctionsPrintExtHelpLink::helpLink($this->module->name(), 'Legacy Algorithm');
echo '</h4>';
}
}

$num_paths++;

//[RC] added
Expand Down
8 changes: 8 additions & 0 deletions HelpTexts.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public static function helpText($help) {
'</p>';
break;

case 'Legacy Algorithm':
$title = I18N::translate('Legacy algorithm for Relationship path names');
$text = '<p>' .
I18N::translate('You can disable this via the module preferences, it\'s mainly intended for debugging.') . ' ' .
I18N::translate('And hopefully it shows how much better the new algorithm works ...') .
'</p>';
break;

default:
$title = MoreI18N::xlate('Help');
$text = MoreI18N::xlate('The help text has not been written for this item.');
Expand Down
18 changes: 18 additions & 0 deletions patchedWebtrees/Modules/LanguageGermanExt.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public function getRelationshipName(

public static function defs(): RelDefs {

//documentation:

//only add customary terms here - do not use this to control how complex rels are generated.
//use RelAlgorithm for that!

//order is relevant

//see RelDefBuilder*Axis for available methods
//(split into 4 interfaces because not all combinations are required)

$defs = [];

$defs []= RelPath::any()->father()->is('Vater', 'des Vaters');
Expand All @@ -37,6 +47,14 @@ public static function defs(): RelDefs {
$defs []= RelPath::any()->husband()->is('Ehemann', 'des Ehemannes');
$defs []= RelPath::any()->wife()->is('Ehefrau', 'der Ehefrau');
$defs []= RelPath::any()->spouse()->is('Ehepartner', 'des Ehepartners');

$defs []= RelPath::any()->exHusband()->is('Ex-Ehemann', 'des Ex-Ehemannes');
$defs []= RelPath::any()->exWife()->is('Ex-Ehefrau', 'der Ex-Ehefrau');
$defs []= RelPath::any()->exSpouse()->is('Ex-Ehepartner', 'des Ex-Ehepartners');

$defs []= RelPath::any()->malePartner()->is('Partner', 'des Partners');
$defs []= RelPath::any()->femalePartner()->is('Partnerin', 'der Partnerin');
$defs []= RelPath::any()->partner()->is('Partner/Partnerin', 'des Partner/der Partnerin');

$defs []= RelPath::any()->son()->is('Sohn', 'des Sohnes');
$defs []= RelPath::any()->daughter()->is('Tochter', 'der Tochter');
Expand Down
26 changes: 16 additions & 10 deletions patchedWebtrees/Modules/LanguageSlovakExt.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public static function defs(): RelDefs {
$defs []= RelPath::any()->wife()->is('manželka', 'manželky');
$defs []= RelPath::any()->spouse()->is('manžel/manželka', 'manžela/manželky');

//$defs []= RelPath::any()->partner(sex::'M')->is('partner', 'partnera');
//$defs []= RelPath::any()->partner(sex::'F')->is('partnerka', 'partnerky');
$defs []= RelPath::any()->malePartner()->is('partner', 'partnera');
$defs []= RelPath::any()->femalePartner()->is('partnerka', 'partnerky');

$defs []= RelPath::any()->son()->is('syn', 'syna');
$defs []= RelPath::any()->daughter()->is('dcéra', 'dcéry');
Expand Down Expand Up @@ -76,7 +76,7 @@ public static function defs(): RelDefs {
////////

$defs []= RelPath::any()->parent()->father()->is('starý otec', 'starého otca');
$defs []= RelPath::any()->parent(Times::fixed(2))->father()->is('prastarý otec', 'prastarý otec');
$defs []= RelPath::any()->parent(Times::fixed(2))->father()->is('prastarý otec', 'prastarého otca');
$defs []= RelPath::any()->parent(Times::min(2))->parent()->father()->is('%s×prastarý otec', '%s×prastarého otca');

$defs []= RelPath::any()->parent()->mother()->is('stará matka', 'starej matky');
Expand Down Expand Up @@ -104,27 +104,27 @@ public static function defs(): RelDefs {
////////

$defs []= RelPath::any()->father()->brother()->is('strýko', 'strýka');
$defs []= RelPath::any()->father()->brother()->wife()->is('stryná', 'stranej');
$defs []= RelPath::any()->father()->brother()->wife()->is('stryná', 'strynej');
$defs []= RelPath::any()->mother()->brother()->is('ujo', 'uja');
$defs []= RelPath::any()->mother()->brother()->wife()->is('ujčiná', 'ujčinej');
$defs []= RelPath::any()->parent()->brother()->is('strýko', 'strýka');

$defs []= RelPath::any()->parent(Times::fixed(2))->brother()->is('prastrýko', 'prastrýka');
$defs []= RelPath::any()->parent(Times::fixed(3))->brother()->is('pra-prastrýko', 'pra-prastrýka');
$defs []= RelPath::any()->parent(Times::min(4, -2))->brother()->is('%s×prastrýko', '%s×prastrýka');
// $defs []= RelPath::any()->parent(Times::fixed(3))->brother()->is('pra-prastrýko', 'pra-prastrýka');
// $defs []= RelPath::any()->parent(Times::min(4, -2))->brother()->is('%s× prastrýko', '%s× prastrýka');
$defs []= RelPath::any()->parent()->sister()->is('teta', 'tety');
$defs []= RelPath::any()->parent(Times::fixed(2))->sister()->is('prateta', 'pratety');
$defs []= RelPath::any()->parent(Times::fixed(3))->sister()->is('pra-prateta', 'pra-pratety');
$defs []= RelPath::any()->parent(Times::min(4, -2))->sister()->is('%s×prateta', '%s×pratety');
// $defs []= RelPath::any()->parent(Times::fixed(3))->sister()->is('pra-prateta', 'pra-pratety');
// $defs []= RelPath::any()->parent(Times::min(4, -2))->sister()->is('%s× prateta', '%s× pratety');

////////

$defs []= RelPath::any()->sibling()->son()->is('synovec', 'synovca');
$defs []= RelPath::any()->sibling()->child()->son()->is('prasynovec', 'prasynovca');
$defs []= RelPath::any()->sibling()->child(Times::min(2, -1))->son()->is('%s×prasynovec', '%s×prasynovca');
// $defs []= RelPath::any()->sibling()->child(Times::min(2, -1))->son()->is('%s× prasynovec', '%s× prasynovca');
$defs []= RelPath::any()->sibling()->daughter()->is('neter', 'netere');
$defs []= RelPath::any()->sibling()->child()->daughter()->is('praneter', 'pranetere');
$defs []= RelPath::any()->sibling()->child(Times::min(2, -1))->daughter()->is('%s×praneter', '%s×pranetere');
// $defs []= RelPath::any()->sibling()->child(Times::min(2, -1))->daughter()->is('%s× praneter', '%s× pranetere');

////////

Expand All @@ -133,6 +133,9 @@ public static function defs(): RelDefs {
$defs []= RelPath::any()->parent()->parent(Times::fixed(3))->sibling()->child(Times::fixed(3))->son()->is('bratranec zo 4. kolena', 'bratranca zo 4. kolena');
$defs []= RelPath::any()->parent()->parent(Times::fixed(5))->sibling()->child(Times::fixed(5))->son()->is('bratranec zo 6. kolena', 'bratranca zo 6. kolena');
$defs []= RelPath::any()->parent()->parent(Times::fixed(6))->sibling()->child(Times::fixed(6))->son()->is('bratranec zo 7. kolena', 'bratranca zo 7. kolena');
$defs []= RelPath::any()->parent()->parent(Times::fixed(13))->sibling()->child(Times::fixed(3))->son()->is('bratranec zo 14. kolena', 'bratranca zo 14. kolena');
$defs []= RelPath::any()->parent()->parent(Times::fixed(15))->sibling()->child(Times::fixed(5))->son()->is('bratranec zo 16. kolena', 'bratranca zo 16. kolena');
$defs []= RelPath::any()->parent()->parent(Times::fixed(16))->sibling()->child(Times::fixed(6))->son()->is('bratranec zo 17. kolena', 'bratranca zo 17. kolena');

//IMPL NOTE: used as back-reference (i.e. count must match in '->child($ref)')
$ref = Times::min(1, 1);
Expand All @@ -143,6 +146,9 @@ public static function defs(): RelDefs {
$defs []= RelPath::any()->parent()->parent(Times::fixed(3))->sibling()->child(Times::fixed(3))->daughter()->is('sesternica zo 4. kolena', 'sesternice zo 4. kolena');
$defs []= RelPath::any()->parent()->parent(Times::fixed(5))->sibling()->child(Times::fixed(5))->daughter()->is('sesternica zo 6. kolena', 'sesternice zo 6. kolena');
$defs []= RelPath::any()->parent()->parent(Times::fixed(6))->sibling()->child(Times::fixed(6))->daughter()->is('sesternica zo 7. kolena', 'sesternice zo 7. kolena');
$defs []= RelPath::any()->parent()->parent(Times::fixed(13))->sibling()->child(Times::fixed(3))->daughter()->is('sesternica zo 14. kolena', 'sesternice zo 14. kolena');
$defs []= RelPath::any()->parent()->parent(Times::fixed(15))->sibling()->child(Times::fixed(5))->daughter()->is('sesternica zo 16. kolena', 'sesternice zo 16. kolena');
$defs []= RelPath::any()->parent()->parent(Times::fixed(16))->sibling()->child(Times::fixed(6))->daughter()->is('sesternica zo 17. kolena', 'sesternice zo 17. kolena');

$defs []= RelPath::any()->parent()->parent($ref)->sibling()->child($ref)->daughter()->is('sesternica z %s. kolena', 'sesternice z %s. kolena');

Expand Down
2 changes: 2 additions & 0 deletions patchedWebtrees/Modules/RelationshipUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static function getRelationshipName(
$end = hrtime(true);
$time1 = ($end - $start) / 1000000;

/*
error_log("--------");
$start = hrtime(true);
Expand All @@ -31,6 +32,7 @@ public static function getRelationshipName(
error_log("orig time: " . $time2);
error_log("new time: " . $time1);
*/

return $ret;
}
Expand Down
20 changes: 6 additions & 14 deletions patchedWebtrees/Relationships/RelDef.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class RelDef {

protected $sex;
protected $from;
protected $elements;
protected $nominative;
protected $genitive;
Expand All @@ -31,17 +31,17 @@ public function maxTimes(): int {

/**
*
* @param string $sex
* @param RelPathFrom $from
* @param Collection<RelPathElement> $elements
* @param string $nominative
*/
public function __construct(
string $sex,
RelPathFrom $from,
Collection $elements,
string $nominative,
?string $genitive) {

$this->sex = $sex;
$this->from = $from;
$this->elements = $elements;
$this->nominative = $nominative;
$this->genitive = $genitive;
Expand Down Expand Up @@ -79,16 +79,8 @@ public function matchPath(
return null;
}

//TODO expand this
switch ($this->sex) {
case "M":
case "F":
case "U":
if ($path->from->sex() !== $this->sex) {
return null;
}
default:
break;
if (!$this->from->matchFrom($path->sex(), $path->from())) {
return null;
}

$currentMatchedPaths = [];
Expand Down
7 changes: 7 additions & 0 deletions patchedWebtrees/Relationships/RelDefBuilderAncestorAxis.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ public function father(): RelDefBuilderAncestor;
public function mother(): RelDefBuilderAncestor;

public function parent(?Times $times = null): RelDefBuilderAncestor;

/**
*
* @param RelPathElement $element match dynamically (you may evaluate INDI and FAM facts of the current as well as preceding path elements)
* @return RelDefBuilderSpouse
*/
public function ancestorAxisVia(RelPathElement $element): RelDefBuilderAncestor;
}
7 changes: 7 additions & 0 deletions patchedWebtrees/Relationships/RelDefBuilderDescendantAxis.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ public function son(): RelDefBuilderDescendant;
public function daughter(): RelDefBuilderDescendant;

public function child(?Times $times = null): RelDefBuilderDescendant;

/**
*
* @param RelPathElement $element match dynamically (you may evaluate INDI and FAM facts of the current as well as preceding path elements)
* @return RelDefBuilderSpouse
*/
public function descendantAxisVia(RelPathElement $element): RelDefBuilderDescendant;
}
7 changes: 7 additions & 0 deletions patchedWebtrees/Relationships/RelDefBuilderSiblingAxis.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ public function brother(): RelDefBuilderSibling;
public function sister(): RelDefBuilderSibling;

public function sibling(): RelDefBuilderSibling;

/**
*
* @param RelPathElement $element match dynamically (you may evaluate INDI and FAM facts of the current as well as preceding path elements)
* @return RelDefBuilderSpouse
*/
public function siblingAxisVia(RelPathElement $element): RelDefBuilderSibling;
}
102 changes: 102 additions & 0 deletions patchedWebtrees/Relationships/RelDefBuilderSpouseAxis.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,111 @@

interface RelDefBuilderSpouseAxis {

/**
* family has a marriage event as last event relevant in this context
*
* @return RelDefBuilderSpouse
*/
public function husband(): RelDefBuilderSpouse;

/**
* family has a marriage event as last event relevant in this context
* (relevant events are: ['ANUL', 'DIV', 'ENGA', 'MARR', '_NMR'])
*
* @return RelDefBuilderSpouse
*/
public function wife(): RelDefBuilderSpouse;

/**
* family has a marriage event as last event relevant in this context
* (relevant events are: ['ANUL', 'DIV', 'ENGA', 'MARR', '_NMR'])
*
* @return RelDefBuilderSpouse
*/
public function spouse(): RelDefBuilderSpouse;

/**
* family has an engagement event as last event relevant in this context
* (relevant events are: ['ANUL', 'DIV', 'ENGA', 'MARR', '_NMR'])
*
* @return RelDefBuilderSpouse
*/
public function fiance(): RelDefBuilderSpouse;

/**
* family has an engagement event as last event relevant in this context
* (relevant events are: ['ANUL', 'DIV', 'ENGA', 'MARR', '_NMR'])
*
* @return RelDefBuilderSpouse
*/
public function fiancee(): RelDefBuilderSpouse;

/**
* family has an engagement event as last event relevant in this context
* (relevant events are: ['ANUL', 'DIV', 'ENGA', 'MARR', '_NMR'])
*
* @return RelDefBuilderSpouse
*/
public function betrothed(): RelDefBuilderSpouse;

/**
* family has a divorce event as last event relevant in this context
* (relevant events are: ['ANUL', 'DIV', 'ENGA', 'MARR', '_NMR'])
*
* @return RelDefBuilderSpouse
*/
public function exHusband(): RelDefBuilderSpouse;

/**
* family has a divorce event as last event relevant in this context
* (relevant events are: ['ANUL', 'DIV', 'ENGA', 'MARR', '_NMR'])
*
* @return RelDefBuilderSpouse
*/
public function exWife(): RelDefBuilderSpouse;

/**
* family has a divorce event as last event relevant in this context
* (relevant events are: ['ANUL', 'DIV', 'ENGA', 'MARR', '_NMR'])
*
* @return RelDefBuilderSpouse
*/
public function exSpouse(): RelDefBuilderSpouse;

/**
* family has a 'not married' (_NMR) event as last event relevant in this context
* (relevant events are: ['ANUL', 'DIV', 'ENGA', 'MARR', '_NMR'])
*
* @return RelDefBuilderSpouse
*/
public function nonMarriedMalePartner(): RelDefBuilderSpouse;

/**
* family has a 'not married' (_NMR) event as last event relevant in this context
* (relevant events are: ['ANUL', 'DIV', 'ENGA', 'MARR', '_NMR'])
*
* @return RelDefBuilderSpouse
*/
public function nonMarriedFemalePartner(): RelDefBuilderSpouse;

/**
* family has a 'not married' (_NMR) event as last event relevant in this context
* (relevant events are: ['ANUL', 'DIV', 'ENGA', 'MARR', '_NMR'])
*
* @return RelDefBuilderSpouse
*/
public function nonMarriedPartner(): RelDefBuilderSpouse;

public function malePartner(): RelDefBuilderSpouse;

public function femalePartner(): RelDefBuilderSpouse;

public function partner(): RelDefBuilderSpouse;

/**
*
* @param RelPathElement $element match dynamically (you may evaluate INDI and FAM facts of the current as well as preceding path elements)
* @return RelDefBuilderSpouse
*/
public function spouseAxisVia(RelPathElement $element): RelDefBuilderSpouse;
}
Loading

0 comments on commit 77f932b

Please sign in to comment.