# -*- coding: utf-8 -*-
"""
Created on Sun Dec  9 19:25:17 2018

@author: VeNoMzZxHD
"""

import re
import tkinter
from tkinter.filedialog import askopenfilename, askdirectory
import glob
import os
import sys
from nltk.tag import StanfordNERTagger
from nltk.tokenize import word_tokenize

def main():
    pTags = ['Dr.', 'Dr\s' , 'Prof.', 'Prof ', 'Professor']
    
    ### Neccessary to define directory of java executbale to use Stanford NER Jar
    java_path = "C:/Program Files/Java/jdk1.8.0_162/bin/java.exe"
    os.environ['JAVAHOME'] = java_path
    
    NERTagger = StanfordNERTagger('C:/Users/iujej_000/git/nlp1/stanford-ner-2018-10-16/classifiers/english.muc.7class.distsim.crf.ser.gz',
                              'C:/Users/iujej_000/git/nlp1/stanford-ner-2018-10-16/stanford-ner.jar', encoding = 'utf8')
    '''
    tkinter.Tk().withdraw()
    datasetDir = askdirectory()
    '''
    datasetDir = "C:\\Users\\iujej_000\\git\\nlp1\\UntaggedData"
    files = glob.glob(datasetDir + "\*.txt") ##returns list of filepath strings for each file in chosen dir
    
    file_dict = {}
    for file in files[1:-1]:              ##Iterates through every file in directory
        with open (file) as inFile: 
            print(os.path.basename(inFile.name))
            inString = inFile.read()
            topic = re.search('Topic: (.*?)\n', inString).group()
            
            tTags = NERTagger.tag(word_tokenize(topic))
            matches = []
            for tag in tTags:
                if tag[1] == 'PERSON':
                    matches.append(tag[0])
            
          
if __name__ == "__main__":
    main()
              