# 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/evaluate.py
# class StrictMetricWarning(Warning):
# class Evaluate(object):
# class Matrix(object):
# METRICS = [
#     'ptp',
#     'fp',
#     'rtp',
#     'fn',
#     'precision',
#     'recall',
#     'fscore',
# ]
#     FMTS = {
#         'tab': tab_format,
#         'json': json_format,
#         'none': no_format,
#     }
#     def __init__(self, system, gold=None,
#                  measures=DEFAULT_MEASURE_SET,
#                  fmt='none', group_by=None, overall=False,
#                  type_weights=None):
#     def iter_pairs(self, system, gold):
#     def __call__(self, measures=None):
#     def add_arguments(cls, p):
#     def count_all(cls, doc_pairs, measures, weighting=None):
#     def count(cls, measure, doc_pairs, weighting=None):
#     def tab_format(self, results, num_fmt='{:.3f}', delimiter='\t'):
#     def _header(delimiter='\t'):
#     def row(self, results, measure_str, num_fmt):
#     def read_tab_format(cls, file):
#     def json_format(self, results):
#     def no_format(self, results):
#     def __init__(self, ptp=0, fp=0, rtp=0, fn=0):
#     def __str__(self):
#     def __add__(self, other):
#     def __iadd__(self, other):
#     def results(self):
#     def precision(self):
#     def recall(self):
#     def div(self, n, d):
#     def fscore(self):
# def macro_average(results_iter):
# 
# Path: neleval/utils.py
# WIKI_PREFIX = re.compile('^http://[^.]+.wikipedia.org/wiki/')
# def normalise_link(l):
# def utf8_open(path, mode='r'):
# def json_dumps(obj, sort_keys=True, indent=4):
#     def default(o):


from collections import Counter
from collections import namedtuple
from .document import Reader
from .evaluate import get_measure, Evaluate
from .utils import utf8_open, unicode
        if self.gold is None:
            return 'nil-as-link'
        if self.system is None:
            return 'link-as-nil'
        return 'wrong-link'

    @staticmethod
    def _str(val, pre):
        if val is MISSING:
            return u''
        elif val is None:
            return u'{}NIL'.format(pre)
        return u'{}"{}"'.format(pre, val)

    @property
    def _system_str(self):
        return self._str(self.system, 's')

    @property
    def _gold_str(self):
        return self._str(self.gold, 'g')

    def __str__(self):
        return u'{0.label}\t{0.doc_id}\t{0._gold_str}\t{0._system_str}'.format(self)


class Analyze(object):
    """Analyze errors"""
    def __init__(self, system, gold=None, unique=False, summary=False, with_correct=False):
        self.system = list(Reader(utf8_open(system)))

# 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/evaluate.py
# class StrictMetricWarning(Warning):
# class Evaluate(object):
# class Matrix(object):
# METRICS = [
#     'ptp',
#     'fp',
#     'rtp',
#     'fn',
#     'precision',
#     'recall',
#     'fscore',
# ]
#     FMTS = {
#         'tab': tab_format,
#         'json': json_format,
#         'none': no_format,
#     }
#     def __init__(self, system, gold=None,
#                  measures=DEFAULT_MEASURE_SET,
#                  fmt='none', group_by=None, overall=False,
#                  type_weights=None):
#     def iter_pairs(self, system, gold):
#     def __call__(self, measures=None):
#     def add_arguments(cls, p):
#     def count_all(cls, doc_pairs, measures, weighting=None):
#     def count(cls, measure, doc_pairs, weighting=None):
#     def tab_format(self, results, num_fmt='{:.3f}', delimiter='\t'):
#     def _header(delimiter='\t'):
#     def row(self, results, measure_str, num_fmt):
#     def read_tab_format(cls, file):
#     def json_format(self, results):
#     def no_format(self, results):
#     def __init__(self, ptp=0, fp=0, rtp=0, fn=0):
#     def __str__(self):
#     def __add__(self, other):
#     def __iadd__(self, other):
#     def results(self):
#     def precision(self):
#     def recall(self):
#     def div(self, n, d):
#     def fscore(self):
# def macro_average(results_iter):
# 
# Path: neleval/utils.py
# WIKI_PREFIX = re.compile('^http://[^.]+.wikipedia.org/wiki/')
# def normalise_link(l):
# def utf8_open(path, mode='r'):
# def json_dumps(obj, sort_keys=True, indent=4):
#     def default(o):


# Path: neleval/analyze.py
from collections import Counter
from collections import namedtuple
from .document import Reader
from .evaluate import get_measure, Evaluate
from .utils import utf8_open, unicode

        if self.gold is None:
            return 'nil-as-link'
        if self.system is None:
            return 'link-as-nil'
        return 'wrong-link'

    @staticmethod
    def _str(val, pre):
        if val is MISSING:
            return u''
        elif val is None:
            return u'{}NIL'.format(pre)
        return u'{}"{}"'.format(pre, val)

    @property
    def _system_str(self):
        return self._str(self.system, 's')

    @property
    def _gold_str(self):
        return self._str(self.gold, 'g')

    def __str__(self):
        return u'{0.label}\t{0.doc_id}\t{0._gold_str}\t{0._system_str}'.format(self)


class Analyze(object):
    """Analyze errors"""
    def __init__(self, system, gold=None, unique=False, summary=False, with_correct=False):
        self.system = list(Reader(utf8_open(system)))

        self.gold = list(Reader(utf8_open(gold)))