# Path: coolisf/common.py
# def read_file(file_path, mode='rt'):
#     file_path = FileHelper.abspath(file_path)  # normalize path
#     if not os.path.isfile(file_path):
#         raise Exception("Input file not found: {}".format(file_path))
#     if file_path.endswith('.gz'):
#         with gzip.open(file_path, mode) as infile:
#             return infile.read()
#     else:
#         return FileHelper.read(file_path, mode)
# 
# def overlap(cfrom1, cto1, cfrom2, cto2):
#     if cfrom1 is None or cto1 is None or cfrom2 is None or cto2 is None:
#         raise ValueError("cfrom:cto must be numbers")
#     return (cfrom1 <= cfrom2 < cto1) or (cfrom2 <= cfrom1 < cto2)


import os
import logging
import json
from collections import defaultdict as dd
from lxml import etree
from lelesk.util import ptpos_to_wn
from chirptext import TextReport, Counter, piter
from chirptext.cli import CLIApp, setup_logging
from chirptext.leutile import StringTool
from chirptext import chio
from chirptext.chio import CSV
from chirptext import texttaglib as ttl
from yawlib import SynsetID
from yawlib.helpers import get_omw, get_wn
from coolisf.common import read_file, overlap
        for tag in s.tags:
            cfrom = int(tag.cfrom)
            cto = int(tag.cto)
            if tag.tagtype in ('WN', 'EXTRA', 'OMW'):
                # ignore nonsense
                if not nonsense and tag.label in NONSENSES:
                    ignored += 1
                    continue
                tags[s.ID][tag.label].add((cfrom, cto))
                tagcount += 1
            else:
                ignored += 1
                if args and not args.quiet:
                    getLogger().warning("Unknown label: {} in sentence #{}".format(tag.tagtype, s.ID))
    return tags, tagcount, ignored


def score(gold_tags, profile_tags, args=None):
    matched = set()
    notmatched = set()  # false negative
    for sid in gold_tags.keys():
        gstags = gold_tags[sid]  # gold tags of this sent
        pstags = profile_tags[sid]  # profile tags of this sent
        for gstag in gstags.keys():  # gstag = synsetID
            glocs = gstags[gstag]
            plocs = set(pstags[gstag]) if gstag in pstags else []
            for gfrom, gto in glocs:
                tag = (sid, gfrom, gto, gstag)  # sentID, gfrom, gto, synsetID
                for pfrom, pto in plocs:
                    getLogger().debug("Checking {}:{} againts {}:{}".format(gfrom, gto, pfrom, pto))

# Path: coolisf/common.py
# def read_file(file_path, mode='rt'):
#     file_path = FileHelper.abspath(file_path)  # normalize path
#     if not os.path.isfile(file_path):
#         raise Exception("Input file not found: {}".format(file_path))
#     if file_path.endswith('.gz'):
#         with gzip.open(file_path, mode) as infile:
#             return infile.read()
#     else:
#         return FileHelper.read(file_path, mode)
# 
# def overlap(cfrom1, cto1, cfrom2, cto2):
#     if cfrom1 is None or cto1 is None or cfrom2 is None or cto2 is None:
#         raise ValueError("cfrom:cto must be numbers")
#     return (cfrom1 <= cfrom2 < cto1) or (cfrom2 <= cfrom1 < cto2)


# Path: isftk/ttl.py
import os
import logging
import json
from collections import defaultdict as dd
from lxml import etree
from lelesk.util import ptpos_to_wn
from chirptext import TextReport, Counter, piter
from chirptext.cli import CLIApp, setup_logging
from chirptext.leutile import StringTool
from chirptext import chio
from chirptext.chio import CSV
from chirptext import texttaglib as ttl
from yawlib import SynsetID
from yawlib.helpers import get_omw, get_wn
from coolisf.common import read_file, overlap

        for tag in s.tags:
            cfrom = int(tag.cfrom)
            cto = int(tag.cto)
            if tag.tagtype in ('WN', 'EXTRA', 'OMW'):
                # ignore nonsense
                if not nonsense and tag.label in NONSENSES:
                    ignored += 1
                    continue
                tags[s.ID][tag.label].add((cfrom, cto))
                tagcount += 1
            else:
                ignored += 1
                if args and not args.quiet:
                    getLogger().warning("Unknown label: {} in sentence #{}".format(tag.tagtype, s.ID))
    return tags, tagcount, ignored


def score(gold_tags, profile_tags, args=None):
    matched = set()
    notmatched = set()  # false negative
    for sid in gold_tags.keys():
        gstags = gold_tags[sid]  # gold tags of this sent
        pstags = profile_tags[sid]  # profile tags of this sent
        for gstag in gstags.keys():  # gstag = synsetID
            glocs = gstags[gstag]
            plocs = set(pstags[gstag]) if gstag in pstags else []
            for gfrom, gto in glocs:
                tag = (sid, gfrom, gto, gstag)  # sentID, gfrom, gto, synsetID
                for pfrom, pto in plocs:
                    getLogger().debug("Checking {}:{} againts {}:{}".format(gfrom, gto, pfrom, pto))

                    if overlap(pfrom, pto, gfrom, gto):