Skip to content
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

Equals method for all fact classes #110

Open
manusimidt opened this issue Mar 19, 2023 · 1 comment
Open

Equals method for all fact classes #110

manusimidt opened this issue Mar 19, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@manusimidt
Copy link
Owner

Add an eq() method to all fact classes to test for equality

@manusimidt manusimidt self-assigned this Mar 19, 2023
@manusimidt manusimidt added the enhancement New feature or request label Mar 19, 2023
@stkerr
Copy link
Contributor

stkerr commented Mar 19, 2023

If it helps, I've been using the code below to check for fact equality:

def fact_compare(first:AbstractFact, second:AbstractFact):
    if type(first) != type(second):
        return False

    if first.value != second.value:
        return False

    if first.xml_id != second.xml_id:
        return False

    if first.footnote != second.footnote:
        return False

    if isinstance(first, NumericFact):
        first:NumericFact = first
        second:NumericFact = second

        if first.decimals != second.decimals:
            return False

        if first.unit != second.unit:
            return False

    else:
        first:TextFact = first
        second:TextFact = second

    if not context_compare(first.context, second.context):
        return False

    if not concept_compare(first.concept, second.concept):
        return False

    return True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants