-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation, diff table headers, implement #324, and refactor logic into function #325
base: master
Are you sure you want to change the base?
Conversation
Fixes #324 |
The diff table headers add column labels, showing which file is associated with which column, and assigning the title "Similarity score" to the middle column. |
simple_node.go
Outdated
//if both Ancestry sources, only check if their _APID is the same | ||
if node.Tag().String() == "Source" && tag.String() == "Source" { | ||
found := false | ||
ancestry: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be below the loop? Otherwise a match would cause an infinite loop. This is so fundamental it will need some unit tests for this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? This equality check is only true for sources, so there is no need to run a loop if it is not a source. Hand-checked this on my gedcom and it works great. Looking back, not sure why I didn't just return true in the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to pass a command line param to SimpleNode.Equals() to toggle on and off the ancestry source matching. How should I pass it to Equals(), other than flags.Lookup("ancestry-source-matching"), which indexes a map every time equals is called... (presumably bad performance)?
@shmueldabomb441 just waiting for your code update to rereview |
Ok. |
I realized that in my GoLand, settings, it runs |
…t check 2. Make table responsive by setting viewport to device width and adding table class `table-responsive` (elliotchance#327) 3. Add GEDCOM paths to DiffPage 4. Add how many are only in the right, left, and both GEDCOMs (elliotchance#327) 5. Fix error in node_diff.go documentation 6. Optimize Ancestry source matching and test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in d2dc486
@elliotchance do I need to do anything like create another pull request for you to approve d2dc486 ? |
I think there's come confusion here between the comments, so I'll clarify:
|
I made it a separate test because I couldn't figure out how to integrate it in the already existing function (I tried for a very long time). This is my first time ever being exposed to Go (I think I did pretty well though), and so I did not know how to resolve the errors I was getting. I also didn't 100% understand the logic of the function (I got most of it), which contributed to making it hard to add another case in that function for the Ancestry case. I can add a call in I agree it makes most sense to have it in the test of the equals method, but because of the above challenges, I would just copy paste it in. Though, I can hear an argument why it may be slightly better to have a separate function for this edge case (I am quite familiar with regression testing, TDD, etc.). |
I would like to add a flag to ignore sources altogether in If I add this, will you accept a PR? |
@@ -64,6 +64,51 @@ func TestSimpleNode_Equals(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestAncestryNode_Equals(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This test name implies that there is a type called AncestryNode
with a method called Equals
. So, its easy to miss when jumping between production code and tests. It's best that you move this test to a subtest to the function above:
func TestSimpleNode_Equals(t *testing.T) {
// ...
t.Run("AncestryNode", func(t *testing.T) {
//test when source ids are the same
original := GetAncestryIndividual("@S291470533@", "@S291470520@", "@S291470520@", "@S291470520@", "@S291470520@")
assert.True(t, gedcom.DeepEqualNodes(gedcom.newDocumentFromString(original).Nodes(), gedcom.newDocumentFromString(original).Nodes()))
//test when source ids are different, but _apid stays the same
left := gedcom.newDocumentFromString(GetAncestryIndividual("@S222222222@", "@S444444444@", "@S666666666@", "@S888888888@", "@S111111111@"))
right := gedcom.newDocumentFromString(GetAncestryIndividual("@S333333333@", "@S555555555@", "@S777777777@", "@S999999999@", "@S000000000@"))
assert.True(t, gedcom.DeepEqualNodes(left.Nodes(), right.Nodes()))
})
}
@@ -88,6 +89,22 @@ func (node *SimpleNode) Equals(node2 Node) bool { | |||
return false | |||
} | |||
|
|||
useAncestrySourceMatching := flag.Lookup("ancestry-source-matching").Value.String() //indexes a map CommandLine.formal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot lookup flags like this. While this might work when using it through the CLI, this can also be used a library. It's also just a leaky abstraction to write it this way. You have three choices:
- Make the extra comparison logic permanent. I'm fine with that - but there are still caveats to consider below.
- If you want/need to control the logic you will need to provide that through another Equals method with options, for example:
type SimpleNodeEqualsOptions struct {
// UseAncestrySourceMatching ...
UseAncestrySourceMatching bool
}
func (node *SimpleNode) Equals(node2 Node) bool {
return node.EqualsOptions(node2, SimpleNodeEqualsOptions{})
}
func (node *SimpleNode) EqualsOptions(node2 Node, o SimpleNodeEqualsOptions) bool {
// ...
if o.UseAncestrySourceMatching && node.Tag().String() == "Source" && tag.String() == "Source" {
}
}
- This is probably the best option for you, use a
FilterFunction
(Line 36 in 9061dca
type FilterFunction func(node Node) (newNode Node, traverseChildren bool)
SimpleNode.Equals
only will only apply to nodes that do not have a custom type with an Equals
method of their own. This is an important consideration because this is generic logic that you may want to apply to all nodes on top of any logic.
If you want this to apply globally (and be controlled from the CLI) you might find it easier to do preprocessing first instead. That is, based on a CLI flag, you preprocess the files so when the comparison happens the logic has already been normalized.
We do in this already using FilterFunctions. For example the -only-official
CLI flag (https://github.com/elliotchance/gedcom/blob/master/filter_flags.go#L57-L58) triggers the files to remove non-official GEDCOM tags so they don't exist for the comparison:
Line 143 in 9061dca
func OfficialTagFilter() FilterFunction { |
This change is