コード例 #1
0
 def __setitem__(self, key, value):
     from process import makesafe, is_number
     if key.startswith('c') and len(key) > 1 and all(
             is_number(x) for x in key[1:]):
         self.__setattr__(key.lstrip('c'), value)
     else:
         self.__setattr__(key, value)
コード例 #2
0
ファイル: process.py プロジェクト: nkhuyu/corpkit
def makesafe(variabletext):
    import re
    from process import is_number
    variable_safe_r = re.compile('[\W_]+', re.UNICODE)
    try:
        txt = variabletext.name.split('.')[0].replace('-parsed', '')
    except AttributeError:
        txt = variabletext.split('.')[0].replace('-parsed', '')
    variable_safe = re.sub(variable_safe_r, '', txt)
    if is_number(variable_safe):
        variable_safe = 'c' + variable_safe
    return variable_safe
コード例 #3
0
def makesafe(variabletext):
    import re
    from process import is_number
    variable_safe_r = re.compile(r'[^A-Za-z0-9_]+', re.UNICODE)
    try:
        txt = variabletext.name.split('.')[0].replace('-parsed', '')
    except AttributeError:
        txt = variabletext.split('.')[0].replace('-parsed', '')
    txt = txt.replace(' ', '_')
    variable_safe = re.sub(variable_safe_r, '', txt)
    if is_number(variable_safe):
        variable_safe = 'c' + variable_safe
    return variable_safe
コード例 #4
0
ファイル: corpus.py プロジェクト: xuanhan863/corpkit
 def __getitem__(self, key):
     from process import makesafe
     if isinstance( key, slice ) :
         #Get the start, stop, and step from the slice
         return Datalist([self[ii] for ii in range(*key.indices(len(self.subcorpora)))])
     elif type(key) == int:
         return self.subcorpora.__getitem__(makesafe(self.subcorpora[key]))
     else:
         try:
             return self.subcorpora.__getattribute__(key)
         except:
             from process import is_number
             if is_number(key):
                 return self.__getattribute__('c' + key)
コード例 #5
0
 def __getitem__(self, key):
     """allow slicing, indexing"""
     from process import makesafe
     if isinstance(key, slice):
         #Get the start, stop, and step from the slice
         return Corpora([self[ii] for ii in range(*key.indices(len(self)))])
     elif type(key) == int:
         return self.__getitem__(makesafe(self.data[key]))
     else:
         try:
             return self.__getattribute__(key)
         except:
             from process import is_number
             if is_number(key):
                 return self.__getattribute__('c' + key)
コード例 #6
0
ファイル: corpus.py プロジェクト: nkhuyu/corpkit
    def __getitem__(self, key):
        """allow slicing, indexing"""
        from process import makesafe

        if isinstance(key, slice):
            # Get the start, stop, and step from the slice
            return Corpora([self[ii] for ii in range(*key.indices(len(self)))])
        elif type(key) == int:
            return self.__getitem__(makesafe(self.data[key]))
        else:
            try:
                return self.__getattribute__(key)
            except:
                from process import is_number

                if is_number(key):
                    return self.__getattribute__("c" + key)
コード例 #7
0
    def __getitem__(self, key):

        from process import makesafe

        if isinstance(key, slice):
            #Get the start, stop, and step from the slice
            return Datalist(
                [self[ii] for ii in range(*key.indices(len(self.files)))])
        elif type(key) == int:
            return self.files.__getitem__(makesafe(self.files[key]))
        else:
            try:
                return self.files.__getattribute__(key)
            except:
                from process import is_number
                if is_number(key):
                    return self.__getattribute__('c' + key)
コード例 #8
0
ファイル: interrogation.py プロジェクト: maxdesp/corpkit
 def __getitem__(self, key):
     """allow slicing, indexing"""
     from collections import OrderedDict
     from process import makesafe
     # allow slicing
     if isinstance( key, slice ) :
         n = OrderedDict()
         for ii in range(*key.indices(len(self))):
             n[self.keys()[ii]] = self[ii]
         return Interrodict(n) 
         return Interrodict([self[ii] for ii in range(*key.indices(len(self)))])
     # allow integer index
     elif type(key) == int:
         return next(v for i, (k, v) in enumerate(self.items()) if i == key)
         #return self.subcorpora.__getitem__(makesafe(self.subcorpora[key]))
     # dict key access
     else:
         try:
             return OrderedDict.__getitem__(self, key)
         except:
             from process import is_number
             if is_number(key):
                 return self.__getattribute__('c' + key)
コード例 #9
0
 def __getitem__(self, key):
     """allow slicing, indexing"""
     from collections import OrderedDict
     from process import makesafe
     # allow slicing
     if isinstance(key, slice):
         n = OrderedDict()
         for ii in range(*key.indices(len(self))):
             n[self.keys()[ii]] = self[ii]
         return Interrodict(n)
         return Interrodict(
             [self[ii] for ii in range(*key.indices(len(self)))])
     # allow integer index
     elif type(key) == int:
         return next(v for i, (k, v) in enumerate(self.items()) if i == key)
         #return self.subcorpora.__getitem__(makesafe(self.subcorpora[key]))
     # dict key access
     else:
         try:
             return OrderedDict.__getitem__(self, key)
         except:
             from process import is_number
             if is_number(key):
                 return self.__getattribute__('c' + key)
コード例 #10
0
ファイル: corpus.py プロジェクト: maxdesp/corpkit
 def __setitem__(self, key, value):
     from process import makesafe, is_number
     if key.startswith('c') and len(key) > 1 and all(is_number(x) for x in key[1:]):
         self.__setattr__(key.lstrip('c'), value)
     else:
         self.__setattr__(key, value)