"""
Description: This module is the manually starting point our Tutti Salesman application.
Author: Josef Sertl
Copyright: SERTL Analytics, https://sertl-analytics.com
Date: 2019-04-02
"""

from salesman_tutti.tutti import Tutti
from time import sleep
from salesman_system_configuration import SystemConfiguration
from salesman_search import SalesmanSearchApi
from sertl_analytics.constants.salesman_constants import REGION
from salesman_tutti.tutti_constants import PRSUBCAT, PRCAT
from salesman_nlp.salesman_spacy import SalesmanSpacy
from spacy import displacy

my_spacy = SalesmanSpacy()
doc = my_spacy.nlp('Das ist ein Satz')
doc = my_spacy.nlp(
    'Leder schwarz. Den Widerstand der Rückenlehne kann man noch einstellen. '
    'Untergestell hat leichte Kratzspuren. Leder ist aber wie neu.')
displacy.serve(doc, style='dep')
"""
Using the 'dep' visualizer
Serving on http://0.0.0.0:5000 ...
NOW: open http://localhost:5000/
"""
class Test4SalesmanSpacy:
    def __init__(self):
        self._salesman_spacy = SalesmanSpacy(load_sm=True)

    def run_test(self, print_token=False):
        test_case_dict = self.__get_test_case_dict__()
        tc_handler = MyTestCaseHandler('Testing "{}":'.format(
            self.__class__.__name__))
        api = SalesmanSearchApi('')
        for key, test_case_list in test_case_dict.items():
            for tc in test_case_list:
                doc = self._salesman_spacy.nlp(tc[0])
                expected = tc[1]
                self._salesman_spacy.print_entities_for_doc(doc)
                if print_token:
                    self._salesman_spacy.print_tokens_for_doc(doc)
                result = self._salesman_spacy.get_entity_list(doc)
                tc_handler.add_test_case(MyTestCase(key, tc, expected, result))
        tc_handler.print_result()

    def __get_test_case_dict__(self):
        return {
            'REPLACEMENT': [
                [
                    'Das ist ein Text mit GoreTex und goretex und Goretex und nochmals Gore-Tex',
                    'Goretex (MATERIAL)'
                ],
            ],
            'COMPANY': [
                [
                    'BMW und Apple sind beides tolle Firmen',
                    'Apple (COMPANY), BMW (COMPANY)'
                ],
            ],
            'PRODUCT': [
                [
                    'Die Serie 7 ist gut. Das beste an der Serie 7 ist der Preis',
                    'Serie 7 (PRODUCT)'
                ],
                [
                    'Vitra Aluminium Chair EA107 oder EA 108 oder MacBook',
                    'Aluminium (MATERIAL), EA 108 (PRODUCT), EA107 (PRODUCT), MacBook (PRODUCT), Vitra (COMPANY)'
                ],
                [
                    'Vitra Bürostuhl EA108 günstig',
                    'Bürostuhl (OBJECT), EA108 (PRODUCT), Vitra (COMPANY)'
                ],
            ],
            'UNKNOWN_ORG': [
                [
                    'Audi und Volvo bauen die sichersten Autos.',
                    'Audi (COMPANY), Volvo (COMPANY)'
                ],
                [
                    'Im Dow Jones sind u.a. Travelers Companies und Verizon enthalten',
                    'Dow Jones (LOC), Travelers Companies (COMPANY), Verizon (COMPANY)'
                ],
            ],
            'TEST': [
                [
                    'Winterschuhe Kinder, Lowa, Rufus III GTX, Gr. 37, Goretex Sommerhut, Strohhut',
                    'Dow Jones (LOC), Travelers Companies (COMPANY), Verizon (COMPANY)'
                ],
            ]
        }