<commit_before>(function(){
  'use strict';
  angular.module('fsCloneShared')
    .directive('fsFamilyMembersSection', function (_, $rootScope, fsApi, fsUtils) {

      function getSpouseFamilies(pwr, self) {
        // first gather all of the couple relationships
        var families = _.map(pwr.getSpouseRelationships(), function(couple) {
          var spouseId = couple.$getHusbandId() === self.id ? couple.$getWifeId() : couple.$getHusbandId();
          return {
            husband: pwr.getPerson(couple.$getHusbandId()),
            wife: pwr.getPerson(couple.$getWifeId()),
            relationshipId: couple.id,
            couple: couple,
            children: fsUtils.getChildrenWithParentsId(pwr.getChildrenOf(spouseId), pwr.getChildRelationshipsOf(spouseId))
          };
        });
        // next add families with children but no couple relationship
        return families.concat(
          _(pwr.getChildRelationships())
            .map(function(cap) {
              return {
                fatherId: cap.$getFatherId(),
                motherId: cap.$getMotherId()
              };
            })
            .reject(function(parentIds) {
              return !(parentIds.fatherId === self.id || parentIds.motherId === self.id) || // just in case there are other children for some reason?
                _.contains(families, function(family) {
                  return family.husband.id === parentIds.fatherId && family.wife.id === parentIds.motherId;
                });
            })
            .uniq(function(parentIds) {
              return (parentIds.fatherId || '_') + ':' + (parentIds.motherId || '_');
            })
            .map(function(parentIds) {
              var spouseId = (self.id === parentIds.fatherId ? parentIds.motherId : parentIds.fatherId) || null; // ensure undefined becomes null
              return {
                husband: parentIds.fatherId ? pwr.getPerson(parentIds.fatherId) : null,
                wife: parentIds.motherId ? pwr.getPerson(parentIds.motherId) : null,
                children: fsUtils.getChildrenWithParentsId(pwr.getChildrenOf(spouseId), pwr.getChildRelationshipsOf(spouseId))
              };
            })
            .valueOf());
      }

      function getParentFamilies(pwr) {
        return _.map(pwr.getParentRelationships(), function(cap) {
          return {
            husband: cap.$getFatherId() ? pwr.getPerson(cap.$getFatherId()) : null,
            wife: cap.$getMotherId() ? pwr.getPerson(cap.$getMotherId()) : null,
            relationshipId: cap.id
          };
        });
      }

      return {
        templateUrl: 'fsCloneShared/fsFamilyMembersSection/fsFamilyMembersSection.tpl.html',
        scope: {
          state: '=',
          person: '='
        },
        link: function(scope) {

          fsApi.getPersonWithRelationships(scope.person.id, {persons: true}).then(function(response) {
            scope.spouseFamilies = getSpouseFamilies(response, scope.person);
            scope.parentFamilies = getParentFamilies(response);
          });
<commit_msg>shorten getSpouseFamilies a bit<commit_after>(function(){
  'use strict';
  angular.module('fsCloneShared')
    .directive('fsFamilyMembersSection', function (_, $rootScope, fsApi, fsUtils) {

      function getSpouseFamilies(pwr, self) {
        // first gather all of the couple relationships
        var families = _.map(pwr.getSpouseRelationships(), function(couple) {
          var spouseId = couple.$getHusbandId() === self.id ? couple.$getWifeId() : couple.$getHusbandId();
          return {
            husband: pwr.getPerson(couple.$getHusbandId()),
            wife: pwr.getPerson(couple.$getWifeId()),
            relationshipId: couple.id,
            couple: couple,
            children: fsUtils.getChildrenWithParentsId(pwr.getChildrenOf(spouseId), pwr.getChildRelationshipsOf(spouseId))
          };
        });
        // next add families with children but no couple relationship
        return families.concat(
          _(pwr.getChildRelationships())
            // one per father+mother combination
            .uniq(function(cap) {
              return (cap.$getFatherId() || '_') + ':' + (cap.$getMotherId() || '_');
            })
            // reject father+mother combinations for which we already have families
            .reject(function(cap) {
              return !(cap.$getFatherId() === self.id || cap.$getMotherId() === self.id) || // just in case there are other children for some reason?
                _.contains(families, function(family) {
                  return family.husband.id === cap.$getFatherId() && family.wife.id === cap.$getMotherId();
                });
            })
            // map to family structure
            .map(function(cap) {
              var spouseId = (self.id === cap.$getFatherId() ? cap.$getMotherId() : cap.$getFatherId()) || null; // ensure undefined becomes null
              return {
                husband: cap.$getFatherId() ? pwr.getPerson(cap.$getFatherId()) : null,
                wife: cap.$getMotherId() ? pwr.getPerson(cap.$getMotherId()) : null,
                children: fsUtils.getChildrenWithParentsId(pwr.getChildrenOf(spouseId), pwr.getChildRelationshipsOf(spouseId))
              };
            })
            .valueOf());
      }

      function getParentFamilies(pwr) {
        return _.map(pwr.getParentRelationships(), function(cap) {
          return {
            husband: cap.$getFatherId() ? pwr.getPerson(cap.$getFatherId()) : null,
            wife: cap.$getMotherId() ? pwr.getPerson(cap.$getMotherId()) : null,
            relationshipId: cap.id
          };
        });
      }

      return {
        templateUrl: 'fsCloneShared/fsFamilyMembersSection/fsFamilyMembersSection.tpl.html',
        scope: {
          state: '=',
          person: '='
        },
        link: function(scope) {

          fsApi.getPersonWithRelationships(scope.person.id, {persons: true}).then(function(response) {
            scope.spouseFamilies = getSpouseFamilies(response, scope.person);
            scope.parentFamilies = getParentFamilies(response);
          });

{'fraction_non_alphanumeric': 0.12779136104319477, 'fraction_numerical': 0.0, 'mean_word_length': 2.174340403517848, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6016201', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1670, 'n_words': 300}