(filename=None, separator=',', pathFrequency = False, maxlines=_sys.maxsize, maxN=_sys.maxsize, expandSubPaths = True)
return p
Reads path data from a file containing multiple lines of n-grams of the 
        form "a,b,c,d,frequency" (where frequency is optional). The default separating 
        character ',' can be changed. Each n-gram will be interpreted as a path of length n-1, 
        i.e. bigrams a,b are considered as path of length one, trigrams a,b,c as path of length two, etc.
        In order to calculate the statistics of paths of any length, by default all subpaths of 
        length k < n-1 contained in an n-gram will be considered. I.e. for n=4 the four-gram a,b,c,d 
        will be considered as a single (longest) path of length n-1 = 3 and three subpaths 
        a->b, b->c, c->d of length k=1 and two subpaths a->b->c amd b->c->d of length k=2 will be 
        additionally counted.

        @param filename: name of the n-gram file to read data from

        @param separator: the character used to separate nodes on the path, i.e. using a 
            separator character of ';' n-grams are represented as a;b;c;...

        @param pathFrequency: if set to true, the last entry in each n-gram will be interpreted as 
            weight (i.e. frequency of the path), e.g. a,b,c,d,4 means that four-gram a,b,c,d has weight four.
            False by default, which means each path occurrence is assigned a default weight of one (adding weights 
            of multiple occurrences).

        @param maxlines: The maximum number of lines (i.e. ngrams) to read from the input file

        @param maxN: The maximum n for the n-grams to read, i.e. setting maxN to 15 will ignore all n-grams of length 
            16 and longer, which means that only paths up to length n-1 are considered.

        @param expandSubPaths: by default all subpaths of the given ngrams are generated, i.e. 
            for an input file with a single trigram a;b;c a path a->b->c of length two will be generated
            as well as two subpaths a->b and b->c of length one
Reads path data from a file containing multiple lines of n-grams of the 
        form "a,b,c,d,frequency" (where frequency is optional). The default separating 
        character ',' can be changed. Each n-gram will be interpreted as a path of length n-1, 
        i.e. bigrams a,b are considered as path of length one, trigrams a,b,c as path of length two, etc.
        In order to calculate the statistics of paths of any length, by default all subpaths of 
        length k < n-1 contained in an n-gram will be considered. I.e. for n=4 the four-gram a,b,c,d 
        will be considered as a single (longest) path of length n-1 = 3 and three subpaths 
        a->b, b->c, c->d of length k=1 and two subpaths a->b->c amd b->c->d of length k=2 will be 
        additionally counted.
Reads path data from a file containing multiple lines of n - grams of the form a b c d frequency ( where frequency is optional ) . The default separating character can be changed . Each n - gram will be interpreted as a path of length n - 1 i . e . bigrams a b are considered as path of length one trigrams a b c as path of length two etc . In order to calculate the statistics of paths of any length by default all subpaths of length k < n - 1 contained in an n - gram will be considered . I . e . for n = 4 the four - gram a b c d will be considered as a single ( longest ) path of length n - 1 = 3 and three subpaths a - > b b - > c c - > d of length k = 1 and two subpaths a - > b - > c amd b - > c - > d of length k = 2 will be additionally counted .
def readFile(filename=None, separator=',', pathFrequency = False, maxlines=_sys.maxsize, maxN=_sys.maxsize, expandSubPaths = True):
        """ 
        Reads path data from a file containing multiple lines of n-grams of the 
        form "a,b,c,d,frequency" (where frequency is optional). The default separating 
        character ',' can be changed. Each n-gram will be interpreted as a path of length n-1, 
        i.e. bigrams a,b are considered as path of length one, trigrams a,b,c as path of length two, etc.
        In order to calculate the statistics of paths of any length, by default all subpaths of 
        length k < n-1 contained in an n-gram will be considered. I.e. for n=4 the four-gram a,b,c,d 
        will be considered as a single (longest) path of length n-1 = 3 and three subpaths 
        a->b, b->c, c->d of length k=1 and two subpaths a->b->c amd b->c->d of length k=2 will be 
        additionally counted.

        @param filename: name of the n-gram file to read data from

        @param separator: the character used to separate nodes on the path, i.e. using a 
            separator character of ';' n-grams are represented as a;b;c;...

        @param pathFrequency: if set to true, the last entry in each n-gram will be interpreted as 
            weight (i.e. frequency of the path), e.g. a,b,c,d,4 means that four-gram a,b,c,d has weight four.
            False by default, which means each path occurrence is assigned a default weight of one (adding weights 
            of multiple occurrences).

        @param maxlines: The maximum number of lines (i.e. ngrams) to read from the input file

        @param maxN: The maximum n for the n-grams to read, i.e. setting maxN to 15 will ignore all n-grams of length 
            16 and longer, which means that only paths up to length n-1 are considered.

        @param expandSubPaths: by default all subpaths of the given ngrams are generated, i.e. 
            for an input file with a single trigram a;b;c a path a->b->c of length two will be generated
            as well as two subpaths a->b and b->c of length one
        """
        assert filename is not "", 'Empty filename given'
    
        # If subpath expansion is applied, we keep the information how many times a path 
        # has been observed as a subpath, and how many times as a "real" path        

        p = Paths()

        p.separator = separator
        maxL = 0 

        with open(filename, 'r') as f:
            Log.add('Reading ngram data ... ')
            line = f.readline()
            n = 1 
            while line and n <= maxlines:
                fields = line.rstrip().split(separator)
                path = ()
                # Add frequency of "real" path to second component of occurrence counter
                if pathFrequency:
                    for i in range(0, len(fields)-1):
                        # Omit empty fields
                        v = fields[i].strip()
                        if len(v)>0:
                            path += (v,)
                    frequency = int(fields[len(fields)-1])
                    if len(path) <= maxN:
                        p.paths[len(path)-1][path] += (0,frequency)
                        maxL = max(maxL, len(path)-1)
                    else: # cut path at maxN
                        p.paths[maxN-1][path[:maxN]] += (0,frequency)
                        maxL = max(maxL, maxN-1)
                else:
                    for i in range(0, len(fields)):
                        # Omit empty fields
                        v = fields[i].strip()
                        if len(v)>0:
                            path += (v,)
                    if len(path) <= maxN:
                        p.paths[len(path)-1][path] += (0,1)
                        maxL = max(maxL, len(path)-1)
                    else: # cut path at maxN
                        p.paths[maxN-1][path[:maxN]] += (0,1)
                        maxL = max(maxL, maxN-1)
                line = f.readline()
                n += 1                
        # end of with open()
        Log.add('finished. Read ' + str(n-1) + ' paths with maximum length ' + str(maxL))
        
        if expandSubPaths:
            p.expandSubPaths()
        Log.add('finished.')

        return p
def readFile ( filename = None , separator = ',' , pathFrequency = False , maxlines = _sys . maxsize , maxN = _sys . maxsize , expandSubPaths = True ) : assert filename is not "" , 'Empty filename given' # If subpath expansion is applied, we keep the information how many times a path  # has been observed as a subpath, and how many times as a "real" path         p = Paths ( ) p . separator = separator maxL = 0 with open ( filename , 'r' ) as f : Log . add ( 'Reading ngram data ... ' ) line = f . readline ( ) n = 1 while line and n <= maxlines : fields = line . rstrip ( ) . split ( separator ) path = ( ) # Add frequency of "real" path to second component of occurrence counter if pathFrequency : for i in range ( 0 , len ( fields ) - 1 ) : # Omit empty fields v = fields [ i ] . strip ( ) if len ( v ) > 0 : path += ( v , ) frequency = int ( fields [ len ( fields ) - 1 ] ) if len ( path ) <= maxN : p . paths [ len ( path ) - 1 ] [ path ] += ( 0 , frequency ) maxL = max ( maxL , len ( path ) - 1 ) else : # cut path at maxN p . paths [ maxN - 1 ] [ path [ : maxN ] ] += ( 0 , frequency ) maxL = max ( maxL , maxN - 1 ) else : for i in range ( 0 , len ( fields ) ) : # Omit empty fields v = fields [ i ] . strip ( ) if len ( v ) > 0 : path += ( v , ) if len ( path ) <= maxN : p . paths [ len ( path ) - 1 ] [ path ] += ( 0 , 1 ) maxL = max ( maxL , len ( path ) - 1 ) else : # cut path at maxN p . paths [ maxN - 1 ] [ path [ : maxN ] ] += ( 0 , 1 ) maxL = max ( maxL , maxN - 1 ) line = f . readline ( ) n += 1 # end of with open() Log . add ( 'finished. Read ' + str ( n - 1 ) + ' paths with maximum length ' + str ( maxL ) ) if expandSubPaths : p . expandSubPaths ( ) Log . add ( 'finished.' ) return p