# Path: neleval/document.py
# class Reader(object):
#     "Read annotations, grouped into documents"
#     def __init__(self, fh, group=by_document, cls=Document):
#         self.fh = fh
#         self.group = group
#         self.cls = cls
# 
#     def __iter__(self):
#         return self.read()
# 
#     def read(self):
#         try:
#             for groupid, annots in self.group(self.annotations()):
#                 yield self.cls(groupid, annots)
#         except Exception:
#             print('ERROR while processing', self.fh, file=sys.stderr)
#             raise
# 
#     def annotations(self):
#         "Yield Annotation objects"
#         for line in self.fh:
#             yield Annotation.from_string(line.rstrip('\n'))
# 
# Path: neleval/utils.py
# def utf8_open(path, mode='r'):
#     return open(path, mode, encoding='utf8')


from collections import defaultdict
from .document import Reader
from .utils import utf8_open
import json
    ambiguity:

        * attempt to match it to the top candidate for that span
        * attempt to match it to the top candidate for any span in that
          document
        * attempt to match it to the top candidate for any span in the
          collection
        * default to select the first listed candidate

    The altered gold standard will be output.
    """

    def __init__(self, system, gold, fields='eid'):
        self.system = system
        self.gold = gold
        self.fields = fields.split(',') if fields != '*' else '*'

    def _get_key(self, candidate):
        if self.fields == '*':
            # avoid comparing on score
            return (candidate.eid, candidate.__dict__)
        return tuple(getattr(candidate, field, None)
                     for field in self.fields)

    def __call__(self):
        system = self.system
        if not isinstance(system, list):
            system = Reader(utf8_open(system))
        gold = self.gold
        if not isinstance(gold, list):

# Path: neleval/document.py
# class Reader(object):
#     "Read annotations, grouped into documents"
#     def __init__(self, fh, group=by_document, cls=Document):
#         self.fh = fh
#         self.group = group
#         self.cls = cls
# 
#     def __iter__(self):
#         return self.read()
# 
#     def read(self):
#         try:
#             for groupid, annots in self.group(self.annotations()):
#                 yield self.cls(groupid, annots)
#         except Exception:
#             print('ERROR while processing', self.fh, file=sys.stderr)
#             raise
# 
#     def annotations(self):
#         "Yield Annotation objects"
#         for line in self.fh:
#             yield Annotation.from_string(line.rstrip('\n'))
# 
# Path: neleval/utils.py
# def utf8_open(path, mode='r'):
#     return open(path, mode, encoding='utf8')


# Path: neleval/prepare.py
from collections import defaultdict
from .document import Reader
from .utils import utf8_open
import json

    ambiguity:

        * attempt to match it to the top candidate for that span
        * attempt to match it to the top candidate for any span in that
          document
        * attempt to match it to the top candidate for any span in the
          collection
        * default to select the first listed candidate

    The altered gold standard will be output.
    """

    def __init__(self, system, gold, fields='eid'):
        self.system = system
        self.gold = gold
        self.fields = fields.split(',') if fields != '*' else '*'

    def _get_key(self, candidate):
        if self.fields == '*':
            # avoid comparing on score
            return (candidate.eid, candidate.__dict__)
        return tuple(getattr(candidate, field, None)
                     for field in self.fields)

    def __call__(self):
        system = self.system
        if not isinstance(system, list):
            system = Reader(utf8_open(system))
        gold = self.gold
        if not isinstance(gold, list):

            gold = Reader(utf8_open(gold))