# -*- coding: utf-8 -*-
"""
Created on Wed Aug  2 13:27:20 2017

@author: SANDIPAN
"""
import nltk
import tensorflow as tf
import random
import pickle
import numpy as np
import os
from nltk.tokenize import word_tokenize
from nltk.tag.stanford import StanfordPOSTagger as POS_Tag
java_path = "C:/Program Files/Java/jdk1.8.0_121/bin/java.exe"
os.environ['JAVAHOME'] = java_path

max_length_cmd = []
featureset = []
global count


home = 'F:/Projects II/speech'
_path_to_model = home + '/stanford-postagger/models/english-bidirectional-distsim.tagger' 
_path_to_jar = home + '/stanford-postagger/stanford-postagger.jar'
st = POS_Tag(model_filename=_path_to_model, path_to_jar=_path_to_jar)


cmd = open('command.txt','r')
non_cmd = open('non_command.txt','r')

for line in cmd:
    max_length_cmd.append(len(line.split()))
    
for line in non_cmd:
    max_length_cmd.append(len(line.split()))
    
max_length = max(max_length_cmd)


wh_words = ['how', 'what', 'who', 'when', 'whether', 'why', 'which', 'where']
noun_tags = ['NN', 'NNP', 'PRP', 'PRP$']
verb_tags = ['VB', 'VBD', 'VBG', 'VBN', 'VBP', 'VBZ']
adverb_tags = ['RB', 'RBR', 'RBS']

def create_features(features, words):
    for i in range(0,len(words)):
        
        if  words[i][0] in wh_words:
            features[i] = 10
        elif words[i][1] in noun_tags:
            features[i] = 20
        elif words[i][1] in verb_tags:
            features[i] = 30  
        elif words[i][1] in adverb_tags:
            features[i] = 40    
        elif words[i][1] not in wh_words and words[i][1] not in noun_tags and words[i][1] not in verb_tags and words[i][1] not in adverb_tags:
            features[i] = 50
        
    return features
            
def make_featuresets(file, classification):
    
  with open(file,'r') as f:
    contents = f.readlines()
    count = 0
    for line in contents:
        current_words = word_tokenize(line)
        count = count+1
        print(count)
        tagged_words = st.tag(current_words)
        features = [0]*(max_length)
        features_in_line = create_features(features, tagged_words)