# Path: coolisf/ghub.py
# class GrammarHub:
# 
#     def __init__(self):
#         self.read_config()
#         self.grammars = {}
#         if self.cache_path:
#             temp_folder = os.path.dirname(self.cache_path)
#             if not os.path.exists(temp_folder):
#                 os.makedirs(temp_folder)
#             self.cache = ISFCache(self.cache_path)
#         else:
#             self.cache = None
#         self.preps = ProcessorManager.from_json(self.cfg["preprocessors"])
#         self.posts = ProcessorManager.from_json(self.cfg["postprocessors"])
# 
#     def read_config(self):
#         self.cfg = read_config()
#         if not self.cfg:
#             raise Exception("Application configuration could not be read")
#         if 'cache' in self.cfg:
#             self.cache_path = self.to_path(self.cfg['cache'])
#         else:
#             self.cache_path = None
#         getLogger().info("ISF Cache DB: {o} => {c}".format(o=self.cfg['cache'], c=self.cache_path))
#         return self.cfg
# 
#     def to_path(self, path):
#         return FileHelper.abspath(path.format(data_root=self.cfg['data_root']))
# 
#     @property
#     def names(self):
#         return tuple(self.cfg['grammars'].keys())
# 
#     @property
#     def available(self):
#         """ Available grammars and their friendly names """
#         return {k: g['name'] for k, g in self.cfg['grammars'].items()}
# 
#     def __getattr__(self, name):
#         return self.get_grammar(name)
# 
#     def __getitem__(self, grm):
#         return self.get_grammar(grm)
# 
#     def get_grammar(self, grm):
#         if grm not in self.cfg['grammars']:
#             raise LookupError("Unknown grammar ({})".format(grm))
#         if grm not in self.grammars:
#             ginfo = self.cfg['grammars'][grm]
#             ace_bin = ginfo['ace'] if 'ace' in ginfo else self.cfg['ace']
#             if 'acecache' in ginfo:
#                 cache_loc = self.to_path(ginfo['acecache'])
#             elif 'acecache' in self.cfg:
#                 cache_loc = self.to_path(self.cfg['acecache'])
#             else:
#                 cache_loc = None
#             preps = self.lookup_preps(ginfo)
#             posts = self.lookup_posts(ginfo)
#             grm_path = self.to_path(ginfo['path'])
#             self.grammars[grm] = Grammar(grm, grm_path, ginfo['args'], ace_bin, cache_loc, preps=preps, posts=posts)
#         # done creating grammar
#         return self.grammars[grm]
# 
#     def lookup_preps(self, gcfg):
#         if 'preps' not in gcfg:
#             return None
#         else:
#             return [self.preps[pname] for pname in gcfg['preps']]
# 
#     def lookup_posts(self, gcfg):
#         if 'posts' not in gcfg:
#             return None
#         else:
#             return [self.posts[pname] for pname in gcfg['posts']]
# 
#     def parse_json(self, txt, grm, pc=None, tagger=None, ignore_cache=False):
#         # validation
#         if not txt:
#             raise ValueError('Sentence cannot be empty')
#         # look up from cache first
#         if not ignore_cache and self.cache:
#             s = self.cache.load(txt, grm, pc, tagger)
#             if s is not None:
#                 getLogger().debug("Retrieved {} parse(s) from cache for sent: {}".format(len(s['parses']), s['sent']))
#                 return s
#         # else parse it ...
#         sent = self.parse(txt, grm, pc, tagger, ignore_cache)
#         # cache sent if possible
#         if self.cache and not ignore_cache:
#             self.cache.save(txt, grm, pc, tagger, sent)
#         # make it JSON
#         return sent2json(sent, txt, pc, tagger, grm)
# 
#     def parse(self, txt, grm, pc=None, tagger=None, ignore_cache=False, wsd=None, ctx=None):
#         """ Parse a sentence using ISF """
#         # validation
#         if not txt:
#             raise ValueError('Sentence cannot be empty')
#         # Parse sentence
#         getLogger().debug("Parsing sentence: {}".format(txt))
#         sent = self[grm].parse(txt, parse_count=pc, ignore_cache=ignore_cache)
#         if tagger:
#             getLogger().debug("Sense-tagging sentence using {}".format(tagger))
#             sent.tag_xml(method=tagger, wsd=wsd, ctx=ctx)
#         return sent


import unittest
import logging
from coolisf import GrammarHub
# -*- coding: utf-8 -*-

"""
Test script for coolisf/jacy
"""

# This code is a part of coolisf library: https://github.com/letuananh/intsem.fx
# :copyright: (c) 2014 Le Tuan Anh <tuananh.ke@gmail.com>
# :license: MIT, see LICENSE for more details.



# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------

txt = '雨 が 降る 。'
txt2 = '猫が好きです。'


def getLogger():
    return logging.getLogger(__name__)


# ------------------------------------------------------------------------------
# Test cases
# ------------------------------------------------------------------------------

class TestJacy(unittest.TestCase):


# Path: coolisf/ghub.py
# class GrammarHub:
# 
#     def __init__(self):
#         self.read_config()
#         self.grammars = {}
#         if self.cache_path:
#             temp_folder = os.path.dirname(self.cache_path)
#             if not os.path.exists(temp_folder):
#                 os.makedirs(temp_folder)
#             self.cache = ISFCache(self.cache_path)
#         else:
#             self.cache = None
#         self.preps = ProcessorManager.from_json(self.cfg["preprocessors"])
#         self.posts = ProcessorManager.from_json(self.cfg["postprocessors"])
# 
#     def read_config(self):
#         self.cfg = read_config()
#         if not self.cfg:
#             raise Exception("Application configuration could not be read")
#         if 'cache' in self.cfg:
#             self.cache_path = self.to_path(self.cfg['cache'])
#         else:
#             self.cache_path = None
#         getLogger().info("ISF Cache DB: {o} => {c}".format(o=self.cfg['cache'], c=self.cache_path))
#         return self.cfg
# 
#     def to_path(self, path):
#         return FileHelper.abspath(path.format(data_root=self.cfg['data_root']))
# 
#     @property
#     def names(self):
#         return tuple(self.cfg['grammars'].keys())
# 
#     @property
#     def available(self):
#         """ Available grammars and their friendly names """
#         return {k: g['name'] for k, g in self.cfg['grammars'].items()}
# 
#     def __getattr__(self, name):
#         return self.get_grammar(name)
# 
#     def __getitem__(self, grm):
#         return self.get_grammar(grm)
# 
#     def get_grammar(self, grm):
#         if grm not in self.cfg['grammars']:
#             raise LookupError("Unknown grammar ({})".format(grm))
#         if grm not in self.grammars:
#             ginfo = self.cfg['grammars'][grm]
#             ace_bin = ginfo['ace'] if 'ace' in ginfo else self.cfg['ace']
#             if 'acecache' in ginfo:
#                 cache_loc = self.to_path(ginfo['acecache'])
#             elif 'acecache' in self.cfg:
#                 cache_loc = self.to_path(self.cfg['acecache'])
#             else:
#                 cache_loc = None
#             preps = self.lookup_preps(ginfo)
#             posts = self.lookup_posts(ginfo)
#             grm_path = self.to_path(ginfo['path'])
#             self.grammars[grm] = Grammar(grm, grm_path, ginfo['args'], ace_bin, cache_loc, preps=preps, posts=posts)
#         # done creating grammar
#         return self.grammars[grm]
# 
#     def lookup_preps(self, gcfg):
#         if 'preps' not in gcfg:
#             return None
#         else:
#             return [self.preps[pname] for pname in gcfg['preps']]
# 
#     def lookup_posts(self, gcfg):
#         if 'posts' not in gcfg:
#             return None
#         else:
#             return [self.posts[pname] for pname in gcfg['posts']]
# 
#     def parse_json(self, txt, grm, pc=None, tagger=None, ignore_cache=False):
#         # validation
#         if not txt:
#             raise ValueError('Sentence cannot be empty')
#         # look up from cache first
#         if not ignore_cache and self.cache:
#             s = self.cache.load(txt, grm, pc, tagger)
#             if s is not None:
#                 getLogger().debug("Retrieved {} parse(s) from cache for sent: {}".format(len(s['parses']), s['sent']))
#                 return s
#         # else parse it ...
#         sent = self.parse(txt, grm, pc, tagger, ignore_cache)
#         # cache sent if possible
#         if self.cache and not ignore_cache:
#             self.cache.save(txt, grm, pc, tagger, sent)
#         # make it JSON
#         return sent2json(sent, txt, pc, tagger, grm)
# 
#     def parse(self, txt, grm, pc=None, tagger=None, ignore_cache=False, wsd=None, ctx=None):
#         """ Parse a sentence using ISF """
#         # validation
#         if not txt:
#             raise ValueError('Sentence cannot be empty')
#         # Parse sentence
#         getLogger().debug("Parsing sentence: {}".format(txt))
#         sent = self[grm].parse(txt, parse_count=pc, ignore_cache=ignore_cache)
#         if tagger:
#             getLogger().debug("Sense-tagging sentence using {}".format(tagger))
#             sent.tag_xml(method=tagger, wsd=wsd, ctx=ctx)
#         return sent


# Path: test/test_jacy.py
import unittest
import logging
from coolisf import GrammarHub

# -*- coding: utf-8 -*-

"""
Test script for coolisf/jacy
"""

# This code is a part of coolisf library: https://github.com/letuananh/intsem.fx
# :copyright: (c) 2014 Le Tuan Anh <tuananh.ke@gmail.com>
# :license: MIT, see LICENSE for more details.



# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------

txt = '雨 が 降る 。'
txt2 = '猫が好きです。'


def getLogger():
    return logging.getLogger(__name__)


# ------------------------------------------------------------------------------
# Test cases
# ------------------------------------------------------------------------------

class TestJacy(unittest.TestCase):


    ghub = GrammarHub()