# Path: bionlp/data/token.py
# class Token:
#     def __init__(self,value,id=-1,document=-1,offset=-1):
#         self.id=id
#         self.attr={}
#         self.attr['offset']=offset
#         self.attr['length']=value.__len__()
#         self.attr['document']=document
#         self.value=value
# 
#     def __str__(self):
#         s ="id: {0}, value: {1}, attributes: {2}".format(self.id,self.value,self.attr)
#         return s
# 
# Path: bionlp/data/sentence.py
# class Sentence:
#     def __init__(self,TokenList,id=-1):
#         self.id=id
#         self.attr={}
#         self.attr['document']=TokenList[0].attr['document']
#         self.value=TokenList
# 
#     def get_text(self):
#         return ' '.join(token.value for token in self.value)
# 
#     def get_list(self):
#         return [token.value for token in self.value]
# 
# 
#     def __str__(self):
#         s ="Sentence id: {0}, value: {1}, attributes: {2}".format(self.id,self.get_text(),self.attr)
#         return s
# 
# Path: bionlp/data/document.py
# class Document:
#     def __init__(self,SentenceList,id=-1):
#         self.id=id
#         self.value=SentenceList
#         self.attr={}
# 
#     def __str__(self):
#         s ="Document id: {0}, value: {1}, attributes: {2}".format(self.id,self.value,self.attr)
#         return s
# 
# Path: bionlp/data/dataset.py
# class Dataset:
#     def __init__(self,DocumentList,desc="None"):
#         self.description=desc
#         self.value=DocumentList
#         self.active=[]          #set of active attributes used for Machine Learning
#         self.passive=[]       #set of passive attributes not used for trainig. e.g. gold-label, char offsets.
#         self.delayed=[]       #set of active attributes which require too much memory. So they are only computed in the tagger section.
#         self.attr={}
# 
#     def __str__(self):
#         s="Dataset description = {0}\n active Attributes {1}, passive Attributes {2}, delayed attributes {3} , Number of Documents {4}".format(self.description,self.active,self.passive,self.delayed,self.value.__len__())
#         return s


import logging
from tqdm import tqdm
from bionlp.data.token import Token as Token
from bionlp.data.sentence import Sentence as Sentence
from bionlp.data.document import Document as Document
from bionlp.data.dataset import Dataset as Dataset
from __future__ import print_function

logging.basicConfig(level=logging.INFO)
logger=logging.getLogger(__name__)


def encode_data_format(documents,raw_text,umls_params):
    logger.info('Encoding dataset into data format')
    document_dict={did_:(dtext_,metamap_) for (did_,dtext_,metamap_) in raw_text}
    documentList=[]
    for did,document in tqdm(documents):
        sentenceList=[]
        for sid,sent in enumerate(document):
            tid=0
            tokenList=[]
            for token in sent:
                newToken=Token(token[0],tid)
                newToken.attr['Annotation']=token[2]
                newToken.attr['offset']=token[1]
                newToken.attr['document']=did
                tokenList.append(newToken)
                tid+=1
            newSentence=Sentence(tokenList,sid)
            sentenceList.append(newSentence)

# Path: bionlp/data/token.py
# class Token:
#     def __init__(self,value,id=-1,document=-1,offset=-1):
#         self.id=id
#         self.attr={}
#         self.attr['offset']=offset
#         self.attr['length']=value.__len__()
#         self.attr['document']=document
#         self.value=value
# 
#     def __str__(self):
#         s ="id: {0}, value: {1}, attributes: {2}".format(self.id,self.value,self.attr)
#         return s
# 
# Path: bionlp/data/sentence.py
# class Sentence:
#     def __init__(self,TokenList,id=-1):
#         self.id=id
#         self.attr={}
#         self.attr['document']=TokenList[0].attr['document']
#         self.value=TokenList
# 
#     def get_text(self):
#         return ' '.join(token.value for token in self.value)
# 
#     def get_list(self):
#         return [token.value for token in self.value]
# 
# 
#     def __str__(self):
#         s ="Sentence id: {0}, value: {1}, attributes: {2}".format(self.id,self.get_text(),self.attr)
#         return s
# 
# Path: bionlp/data/document.py
# class Document:
#     def __init__(self,SentenceList,id=-1):
#         self.id=id
#         self.value=SentenceList
#         self.attr={}
# 
#     def __str__(self):
#         s ="Document id: {0}, value: {1}, attributes: {2}".format(self.id,self.value,self.attr)
#         return s
# 
# Path: bionlp/data/dataset.py
# class Dataset:
#     def __init__(self,DocumentList,desc="None"):
#         self.description=desc
#         self.value=DocumentList
#         self.active=[]          #set of active attributes used for Machine Learning
#         self.passive=[]       #set of passive attributes not used for trainig. e.g. gold-label, char offsets.
#         self.delayed=[]       #set of active attributes which require too much memory. So they are only computed in the tagger section.
#         self.attr={}
# 
#     def __str__(self):
#         s="Dataset description = {0}\n active Attributes {1}, passive Attributes {2}, delayed attributes {3} , Number of Documents {4}".format(self.description,self.active,self.passive,self.delayed,self.value.__len__())
#         return s


# Path: bionlp/preprocess/dataset_preprocess.py
import logging
from tqdm import tqdm
from bionlp.data.token import Token as Token
from bionlp.data.sentence import Sentence as Sentence
from bionlp.data.document import Document as Document
from bionlp.data.dataset import Dataset as Dataset

from __future__ import print_function

logging.basicConfig(level=logging.INFO)
logger=logging.getLogger(__name__)


def encode_data_format(documents,raw_text,umls_params):
    logger.info('Encoding dataset into data format')
    document_dict={did_:(dtext_,metamap_) for (did_,dtext_,metamap_) in raw_text}
    documentList=[]
    for did,document in tqdm(documents):
        sentenceList=[]
        for sid,sent in enumerate(document):
            tid=0
            tokenList=[]
            for token in sent:
                newToken=Token(token[0],tid)
                newToken.attr['Annotation']=token[2]
                newToken.attr['offset']=token[1]
                newToken.attr['document']=did
                tokenList.append(newToken)
                tid+=1
            newSentence=Sentence(tokenList,sid)
            sentenceList.append(newSentence)

        newDocument=Document(sentenceList,did)