# Path: epitator/annotator.py
# class Annotator(object):
#     def annotate(self, doc):
# 
# Path: epitator/species_annotator.py
# class SpeciesAnnotator(Annotator):
#     def annotate(self, doc):
#         named_entities = doc.require_tiers('spacy.nes', via=SpacyAnnotator)
#         geonames = doc.require_tiers('geonames', via=GeonameAnnotator)
#         resolved_keywords = doc.require_tiers('resolved_keywords', via=ResolvedKeywordAnnotator)
#         species_list = []
#         for kw_span in resolved_keywords:
#             first_resolution = kw_span.metadata['resolutions'][0]
#             if first_resolution['entity']['type'] == 'species':
#                 species_list.append(AnnoSpan(kw_span.start, kw_span.end, kw_span.doc, metadata={
#                     'species': {
#                         'id': first_resolution['entity']['id'],
#                         'label': first_resolution['entity']['label'],
#                     }
#                 }))
#         species_tier = AnnoTier(species_list, presorted=True)
#         return {
#             'species': species_tier.without_overlaps(geonames).without_overlaps(named_entities)
#         }


import unittest
from . import test_utils
from epitator.annotator import AnnoDoc
from epitator.species_annotator import SpeciesAnnotator
#!/usr/bin/env python
from __future__ import absolute_import


class SpeciesAnnotatorTest(unittest.TestCase):
    def setUp(self):
        self.annotator = SpeciesAnnotator()

    def test_species(self):
        doc = AnnoDoc("His illness was caused by cattle")
        doc.add_tier(self.annotator)
        test_utils.assertHasProps(doc.tiers['species'].spans[-1].metadata, {
            'species': {
                'id': 'tsn:180704',
                'label': 'Bovidae'}
        })

    def test_species_false_positive(self):
        # Sierra wil be detected as a species if using naive ontology keyword
        # matching.

# Path: epitator/annotator.py
# class Annotator(object):
#     def annotate(self, doc):
# 
# Path: epitator/species_annotator.py
# class SpeciesAnnotator(Annotator):
#     def annotate(self, doc):
#         named_entities = doc.require_tiers('spacy.nes', via=SpacyAnnotator)
#         geonames = doc.require_tiers('geonames', via=GeonameAnnotator)
#         resolved_keywords = doc.require_tiers('resolved_keywords', via=ResolvedKeywordAnnotator)
#         species_list = []
#         for kw_span in resolved_keywords:
#             first_resolution = kw_span.metadata['resolutions'][0]
#             if first_resolution['entity']['type'] == 'species':
#                 species_list.append(AnnoSpan(kw_span.start, kw_span.end, kw_span.doc, metadata={
#                     'species': {
#                         'id': first_resolution['entity']['id'],
#                         'label': first_resolution['entity']['label'],
#                     }
#                 }))
#         species_tier = AnnoTier(species_list, presorted=True)
#         return {
#             'species': species_tier.without_overlaps(geonames).without_overlaps(named_entities)
#         }


# Path: tests/annotator/test_species_annotator.py
import unittest
from . import test_utils
from epitator.annotator import AnnoDoc
from epitator.species_annotator import SpeciesAnnotator

#!/usr/bin/env python
from __future__ import absolute_import


class SpeciesAnnotatorTest(unittest.TestCase):
    def setUp(self):
        self.annotator = SpeciesAnnotator()

    def test_species(self):
        doc = AnnoDoc("His illness was caused by cattle")
        doc.add_tier(self.annotator)
        test_utils.assertHasProps(doc.tiers['species'].spans[-1].metadata, {
            'species': {
                'id': 'tsn:180704',
                'label': 'Bovidae'}
        })

    def test_species_false_positive(self):
        # Sierra wil be detected as a species if using naive ontology keyword
        # matching.

        doc = AnnoDoc("""