# Path: props/applications/run.py
# def parseSentences(sent, HOME_DIR = BASE_PATH, stanford_json_sent = None):
#     resetCounter()
#     if stanford_json_sent:
#         # Use Stanford json notation
#         result = sent['parse'].replace("\n","") + "\n"
#     else:
#         # Use default berkeley parser
#         from BerkeleyInterface import parseInput
#         orig_Stdin = sys.stdin
#         strIn = StringIO(sent)
#         sys.stdin = strIn
#         strOut = StringIO()
#         parseInput(parser, opts, outputFile=strOut)
#         sys.stdin = orig_Stdin
#         result = strOut.getvalue()
# 
#     tmp_fn = "./tmp.parse"
#     fout = open(tmp_fn,'w')
#     fout.write(result)
#     fout.close()
#     graphs = read_dep_graphs_file(tmp_fn,
#                                   False,
#                                   HOME_DIR,
#                                   stanford_json_sent = sent \
#                                   if stanford_json_sent \
#                                   else False)
#     ret = []
#     for graph in graphs:        
#         g = convert(graph)
#         ret.append((g,g.tree_str))
# 
#     if not graphs:#Berkley bug?
#         ret.append((GraphWrapper("",HOME_DIR),""))
# 
#     if (not stanford_json_sent):
#         strIn.close()
#         strOut.close()
#     return ret
# 
# Path: props/applications/run.py
# def load_berkeley(tokenize=True,
#                   path_to_berkeley = os.path.join(BASE_PATH, 'berkeleyparser/')):
# 
#     from BerkeleyInterface import startup, getOpts, loadGrammar, dictToArgs
#     # This should be the path to the Berkeley Parser jar file
# 
#     cp = os.path.join(path_to_berkeley, "BerkeleyParser-1.7.jar")
#     logging.info("Starting Berkeley parser from {0}".format(cp))
#     startup(cp)
#     
#     gr = os.path.join(path_to_berkeley, 'eng_sm6.gr')
#     args = {"gr":gr, "tokenize":tokenize}
#     
#     # Convert args from a dict to the appropriate Java class
#     global opts
#     opts = getOpts(dictToArgs(args))
#     
#     # Load the grammar file and initialize the parser with our options
#     global parser
#     parser = loadGrammar(opts)


import unittest
import logging
from props.applications.run import parseSentences
from props.applications.run import load_berkeley
from _jpype import shutdown


class PropsTest(unittest.TestCase):
    ''' Super class for all PropS tests '''
    
    def setUp(self):
        ''' takes care of the needed initializations '''
        logging.info("running tests")

# Path: props/applications/run.py
# def parseSentences(sent, HOME_DIR = BASE_PATH, stanford_json_sent = None):
#     resetCounter()
#     if stanford_json_sent:
#         # Use Stanford json notation
#         result = sent['parse'].replace("\n","") + "\n"
#     else:
#         # Use default berkeley parser
#         from BerkeleyInterface import parseInput
#         orig_Stdin = sys.stdin
#         strIn = StringIO(sent)
#         sys.stdin = strIn
#         strOut = StringIO()
#         parseInput(parser, opts, outputFile=strOut)
#         sys.stdin = orig_Stdin
#         result = strOut.getvalue()
# 
#     tmp_fn = "./tmp.parse"
#     fout = open(tmp_fn,'w')
#     fout.write(result)
#     fout.close()
#     graphs = read_dep_graphs_file(tmp_fn,
#                                   False,
#                                   HOME_DIR,
#                                   stanford_json_sent = sent \
#                                   if stanford_json_sent \
#                                   else False)
#     ret = []
#     for graph in graphs:        
#         g = convert(graph)
#         ret.append((g,g.tree_str))
# 
#     if not graphs:#Berkley bug?
#         ret.append((GraphWrapper("",HOME_DIR),""))
# 
#     if (not stanford_json_sent):
#         strIn.close()
#         strOut.close()
#     return ret
# 
# Path: props/applications/run.py
# def load_berkeley(tokenize=True,
#                   path_to_berkeley = os.path.join(BASE_PATH, 'berkeleyparser/')):
# 
#     from BerkeleyInterface import startup, getOpts, loadGrammar, dictToArgs
#     # This should be the path to the Berkeley Parser jar file
# 
#     cp = os.path.join(path_to_berkeley, "BerkeleyParser-1.7.jar")
#     logging.info("Starting Berkeley parser from {0}".format(cp))
#     startup(cp)
#     
#     gr = os.path.join(path_to_berkeley, 'eng_sm6.gr')
#     args = {"gr":gr, "tokenize":tokenize}
#     
#     # Convert args from a dict to the appropriate Java class
#     global opts
#     opts = getOpts(dictToArgs(args))
#     
#     # Load the grammar file and initialize the parser with our options
#     global parser
#     parser = loadGrammar(opts)


# Path: props/unit_tests/props_test.py
import unittest
import logging
from props.applications.run import parseSentences
from props.applications.run import load_berkeley
from _jpype import shutdown



class PropsTest(unittest.TestCase):
    ''' Super class for all PropS tests '''
    
    def setUp(self):
        ''' takes care of the needed initializations '''
        logging.info("running tests")

        load_berkeley(tokenize = True)