跳过或删除“镜像”数据的算法

huangapple go评论50阅读模式
英文:

Algorithm for skipping or deleting "mirror" data

问题

以下是您要翻译的内容:

"I am reading in a file that looks like this:

As you see in this data, line 5 is a "mirror" of line 1 (same values but flip-flopped). I want to skip one of these rows, not both. Either the first 2942 - 3911 (line 1) can be retained, or 3911 - 2942 (5) can be retained. I'd kind of prefer the "mirror" line 5 to stay but it's not that important.

I tried this algorithm below, but it deletes/skips over all the rows - the pair and its mirror - rather than just skipping one of them.

Any thoughts?? I will keep working on this, but I'm stumped and would love some clever ideas.

The output would look like this:"

英文:

I am reading in a file that looks like this:


line#        person-pin   reciprocal-person-pin  relationship   reciprocal-relationship
1             2942         3911                   son            mother                     
2             3911         2560                   client         financial advisor
3             3911         1195                   employee       employer
4             3911         1190                   church member  church
5             3911         2942                   mother         son
6             3911         3910                   mother         daughter
7             3911         3912                   mother         daughter
8             3911         5062                   wife           husband

As you see in this data, line 5 is a "mirror" of line 1 (same values but flip-flopped). I want to skip one of these rows, not both. Either the first 2942 - 3911 (line 1) can be retained, or 3911 - 2942 (5) can be retained. I'd kind of prefer the "mirror" line 5 to stay but it's not that important.

I tried this algorithm below, but it deletes/skips over all the rows - the pair and its mirror - rather than just skipping one of them.

Any thoughts?? I will keep working on this, but I'm stumped and would love some clever ideas.

FOR EACH ttRelationshipData:

    FIND FIRST ttRelationshipData2 WHERE ttRelationshipData.person-pin EQ ttRelationshipData2.reciprocal-person-pin
                                     AND ttRelationshipData.reciprocal-person-pin EQ ttRelationshipData2.person-pin NO-LOCK NO-ERROR.

    IF AVAILABLE ttRelationshipData2 THEN NEXT.
    ELSE DO:
        CREATE ttRelationship.
        ASSIGN
            ttRelationship.alpha-pin = ttRelationshipData.constituent-pin
            ttRelationship.alpha-role = ttRelationshipData.constituent-relationship-name
            ttRelationship.bravo-pin =  ttRelationshipData.related-constituent-pin
            ttRelationship.bravo-role = ttRelationshipData.relatedconstituent-rel-name.
    END.
END.

The output would look like this:


line#        person-pin   reciprocal-person-pin  relationship   reciprocal-relationship
                  
1             3911         2560                   client         financial advisor
2             3911         1195                   employee       employer
3             3911         1190                   church member  church
4             3911         2942                   mother         son
5             3911         3910                   mother         daughter
6             3911         3912                   mother         daughter
7             3911         5062                   wife           husband

答案1

得分: 1

以下是翻译好的部分:

你的测试对于第1行和第5行都会返回true,因此这两行都会被跳过,而是测试ttRelationShip表。

我对你的代码进行了一些其他更改:

  • NO-LOCK不适用于临时表
  • 使用替代样式以避免水平滚动条
  • 在“然后下一个”之后,不需要else块
  • 使用标签来执行下一个
CreateLoop:
对于每个ttRelationshipData:

    查找ttRelationship
        其中ttRelationship.alpha-pin = ttRelationshipData.related-constituent-pin
          和ttRelationship.bravo-pin = ttRelationshipData.constituent-pin
        无错误。

    如果ttRelationship可用,则继续CreateLoop。

    创建ttRelationship。
    分配
        ttRelationship.alpha-pin = ttRelationshipData.constituent-pin
        ttRelationship.alpha-role = ttRelationshipData.constituent-relationship-name
        ttRelationship.bravo-pin =  ttRelationshipData.related-constituent-pin
        ttRelationship.bravo-role = ttRelationshipData.relatedconstituent-rel-name。

结束。
英文:

Your test will be true for both rows 1 and 5, so both are skipped, test for the ttRelationShip table instead.

I made some other changes to your code

  • NO-LOCK does not apply to temp-tables
  • alternate styling to avoid horizontal scrollbars
  • after then next you don't need the else block
  • use labels on next
CreateLoop:
FOR EACH ttRelationshipData:

    FIND ttRelationship
        WHERE ttRelationship.alpha-pin = ttRelationshipData.related-constituent-pin
          AND ttRelationship.bravo-pin = ttRelationshipData.constituent-pin
        NO-ERROR.

    IF AVAILABLE ttRelationship THEN NEXT CreateLoop.

    CREATE ttRelationship.
    ASSIGN
        ttRelationship.alpha-pin = ttRelationshipData.constituent-pin
        ttRelationship.alpha-role = ttRelationshipData.constituent-relationship-name
        ttRelationship.bravo-pin =  ttRelationshipData.related-constituent-pin
        ttRelationship.bravo-role = ttRelationshipData.relatedconstituent-rel-name.

END.

huangapple
  • 本文由 发表于 2023年5月8日 00:56:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76195208.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定