# Path: libeclectus/util.py
# def cachedproperty(fget):
#     def fget_wrapper(self):
#         try: return fget_wrapper._cached
#         except AttributeError:
#             fget_wrapper._cached = value = fget(self)
#             return value
#     def fdel(self):
#         try: del fget_wrapper._cached
#         except AttributeError: pass
#     return property(fget_wrapper, fdel=fdel, doc=fget.__doc__)
# 
# def getDatabaseConfiguration(databaseUrl=None):
#     configuration = {}
#     if databaseUrl:
#         configuration['sqlalchemy.url'] = databaseUrl
#         if databaseUrl.startswith('sqlite://'):
#             configuration['attach'] = ([getDatabaseUrl()]
#                 + getAttachableDatabases())
#     else:
#         configuration['sqlalchemy.url'] = getDatabaseUrl()
#         configuration['attach'] = getAttachableDatabases()
#     return configuration


import re
from sqlalchemy import select
from sqlalchemy.sql import and_, or_
from cjklib.dbconnector import getDBConnector
from cjklib.characterlookup import CharacterLookup
from cjklib import exception
from libeclectus.util import cachedproperty, getDatabaseConfiguration
    @classmethod
    def getSimilarPlainEntities(cls, plainEntity, reading):
        # TODO the following is not independent of reading and really slow
        similar = [plainEntity]
        if reading in cls.AMBIGUOUS_INITIALS:
            for key in cls.AMBIGUOUS_INITIALS[reading]:
                for tpl in cls.AMBIGUOUS_INITIALS[reading][key]:
                    a, b = tpl
                    if re.match(a + u'[aeiouü]', plainEntity):
                        similar.append(b + plainEntity[len(a):])
                    elif re.match(b + u'[aeiouü]', plainEntity):
                        similar.append(a + plainEntity[len(b):])
        # for all initial derived forms change final
        if reading in cls.AMBIGUOUS_FINALS:
            for modEntity in similar[:]:
                for key in cls.AMBIGUOUS_FINALS[reading]:
                    for tpl in cls.AMBIGUOUS_FINALS[reading][key]:
                        a, b = tpl
                        if re.search(u'[^aeiouü]' + a + '$',
                            modEntity):
                            similar.append(modEntity[:-len(a)] + b)
                        elif re.search(u'[^aeiouü]' + b + '$',
                            modEntity):
                            similar.append(modEntity[:-len(b)] + a)
        return similar

    def __init__(self, language, characterDomain=None, databaseUrl=None,
        dbConnectInst=None, ignoreIllegalSettings=False, **options):

        dbConnectInst = dbConnectInst or getDBConnector(

# Path: libeclectus/util.py
# def cachedproperty(fget):
#     def fget_wrapper(self):
#         try: return fget_wrapper._cached
#         except AttributeError:
#             fget_wrapper._cached = value = fget(self)
#             return value
#     def fdel(self):
#         try: del fget_wrapper._cached
#         except AttributeError: pass
#     return property(fget_wrapper, fdel=fdel, doc=fget.__doc__)
# 
# def getDatabaseConfiguration(databaseUrl=None):
#     configuration = {}
#     if databaseUrl:
#         configuration['sqlalchemy.url'] = databaseUrl
#         if databaseUrl.startswith('sqlite://'):
#             configuration['attach'] = ([getDatabaseUrl()]
#                 + getAttachableDatabases())
#     else:
#         configuration['sqlalchemy.url'] = getDatabaseUrl()
#         configuration['attach'] = getAttachableDatabases()
#     return configuration


# Path: libeclectus/chardb.py
import re
from sqlalchemy import select
from sqlalchemy.sql import and_, or_
from cjklib.dbconnector import getDBConnector
from cjklib.characterlookup import CharacterLookup
from cjklib import exception
from libeclectus.util import cachedproperty, getDatabaseConfiguration

    @classmethod
    def getSimilarPlainEntities(cls, plainEntity, reading):
        # TODO the following is not independent of reading and really slow
        similar = [plainEntity]
        if reading in cls.AMBIGUOUS_INITIALS:
            for key in cls.AMBIGUOUS_INITIALS[reading]:
                for tpl in cls.AMBIGUOUS_INITIALS[reading][key]:
                    a, b = tpl
                    if re.match(a + u'[aeiouü]', plainEntity):
                        similar.append(b + plainEntity[len(a):])
                    elif re.match(b + u'[aeiouü]', plainEntity):
                        similar.append(a + plainEntity[len(b):])
        # for all initial derived forms change final
        if reading in cls.AMBIGUOUS_FINALS:
            for modEntity in similar[:]:
                for key in cls.AMBIGUOUS_FINALS[reading]:
                    for tpl in cls.AMBIGUOUS_FINALS[reading][key]:
                        a, b = tpl
                        if re.search(u'[^aeiouü]' + a + '$',
                            modEntity):
                            similar.append(modEntity[:-len(a)] + b)
                        elif re.search(u'[^aeiouü]' + b + '$',
                            modEntity):
                            similar.append(modEntity[:-len(b)] + a)
        return similar

    def __init__(self, language, characterDomain=None, databaseUrl=None,
        dbConnectInst=None, ignoreIllegalSettings=False, **options):

        dbConnectInst = dbConnectInst or getDBConnector(

            getDatabaseConfiguration(databaseUrl))