# Path: beancount_import/matching.py
# def is_unknown_account(account: str):
#     return account == FIXME_ACCOUNT or account.startswith(
#         MERGEABLE_FIXME_ACCOUNT_PREFIX)
# 
# FIXME_ACCOUNT = 'Expenses:FIXME'
# 
# Path: beancount_import/posting_date.py
# def get_posting_date(entry, posting):
#     """Returns the date associated with a posting."""
#     return ((posting.meta and (posting.meta.get(POSTING_DATE_KEY) or
#                                posting.meta.get(POSTING_TRANSACTION_DATE_KEY))) or entry.date)


import collections
import datetime
import functools
import itertools
import re
from typing import Callable, Any, Dict, Iterable, List, NamedTuple, Sequence, Union, Optional, Tuple, Set
from beancount.core.data import Directive, Entries, Transaction, Posting
from beancount.core.amount import Amount
from .matching import is_unknown_account, FIXME_ACCOUNT
from .posting_date import get_posting_date
    from .source import Source  # For typing only.
                        PredictionInput(
                            source_account='',
                            amount=posting.units,
                            date=entry.date,
                            key_value_pairs=key_value_pairs),
                        target_account=posting.account,
                    )
            if got_example: continue

            # Otherwise use the metadata values directly, as long as there
            # are only two postings. Two postings are a requirement to have
            # a source account and a target account.
            non_ignored_postings = self.get_postings_for_automatic_classification(
                entry.postings)
            if len(non_ignored_postings) != 2: continue
            for posting_i, posting in enumerate(non_ignored_postings):
                if posting.meta is None: continue
                target_account = non_ignored_postings[1 - posting_i].account
                if is_unknown_account(target_account): continue
                source = self.account_source_map.get(posting.account)
                if source is None: continue
                key_value_pairs = source.get_example_key_value_pairs(
                    entry, posting)
                if not key_value_pairs: continue
                key_value_pairs = dict(transaction_key_value_pairs,
                                       **key_value_pairs)
                training_examples.add(
                    PredictionInput(
                        source_account=posting.account,
                        key_value_pairs=key_value_pairs,

# Path: beancount_import/matching.py
# def is_unknown_account(account: str):
#     return account == FIXME_ACCOUNT or account.startswith(
#         MERGEABLE_FIXME_ACCOUNT_PREFIX)
# 
# FIXME_ACCOUNT = 'Expenses:FIXME'
# 
# Path: beancount_import/posting_date.py
# def get_posting_date(entry, posting):
#     """Returns the date associated with a posting."""
#     return ((posting.meta and (posting.meta.get(POSTING_DATE_KEY) or
#                                posting.meta.get(POSTING_TRANSACTION_DATE_KEY))) or entry.date)


# Path: beancount_import/training.py
import collections
import datetime
import functools
import itertools
import re
from typing import Callable, Any, Dict, Iterable, List, NamedTuple, Sequence, Union, Optional, Tuple, Set
from beancount.core.data import Directive, Entries, Transaction, Posting
from beancount.core.amount import Amount
from .matching import is_unknown_account, FIXME_ACCOUNT
from .posting_date import get_posting_date
    from .source import Source  # For typing only.

                        PredictionInput(
                            source_account='',
                            amount=posting.units,
                            date=entry.date,
                            key_value_pairs=key_value_pairs),
                        target_account=posting.account,
                    )
            if got_example: continue

            # Otherwise use the metadata values directly, as long as there
            # are only two postings. Two postings are a requirement to have
            # a source account and a target account.
            non_ignored_postings = self.get_postings_for_automatic_classification(
                entry.postings)
            if len(non_ignored_postings) != 2: continue
            for posting_i, posting in enumerate(non_ignored_postings):
                if posting.meta is None: continue
                target_account = non_ignored_postings[1 - posting_i].account
                if is_unknown_account(target_account): continue
                source = self.account_source_map.get(posting.account)
                if source is None: continue
                key_value_pairs = source.get_example_key_value_pairs(
                    entry, posting)
                if not key_value_pairs: continue
                key_value_pairs = dict(transaction_key_value_pairs,
                                       **key_value_pairs)
                training_examples.add(
                    PredictionInput(
                        source_account=posting.account,
                        key_value_pairs=key_value_pairs,

                        date=get_posting_date(entry, posting),