paddlenlp/metrics/rouge.py
def lcs(self, string, sub):
        """
        Calculate the length of longest common subsequence of string and sub.

        Args:
            string (str):
                The string to be calculated, usually longer the sub string.
            sub (str):
                The sub string to be calculated.

        Returns:
            float: Returns the length of the longest common subsequence of string and sub.
        """
        if len(string) < len(sub):
            sub, string = string, sub
        lengths = np.zeros((len(string) + 1, len(sub) + 1))
        for j in range(1, len(sub) + 1):
            for i in range(1, len(string) + 1):
                if string[i - 1] == sub[j - 1]:
                    lengths[i][j] = lengths[i - 1][j - 1] + 1
                else:
                    lengths[i][j] = max(lengths[i - 1][j], lengths[i][j - 1])
        return lengths[len(string)][len(sub)]

        Calculate the length of longest common subsequence of string and sub.

        Args:
            string (str):
                The string to be calculated, usually longer the sub string.
            sub (str):
                The sub string to be calculated.

        Returns:
            float: Returns the length of the longest common subsequence of string and sub.
        
Calculate the length of longest common subsequence of string and sub.
Calculate the length of longest common subsequence of string and sub .
def lcs(self, string, sub):
        if len(string) < len(sub):
            sub, string = string, sub
        lengths = np.zeros((len(string) + 1, len(sub) + 1))
        for j in range(1, len(sub) + 1):
            for i in range(1, len(string) + 1):
                if string[i - 1] == sub[j - 1]:
                    lengths[i][j] = lengths[i - 1][j - 1] + 1
                else:
                    lengths[i][j] = max(lengths[i - 1][j], lengths[i][j - 1])
        return lengths[len(string)][len(sub)]
def lcs ( self , string , sub ) : if len ( string ) < len ( sub ) : sub , string = string , sub lengths = np . zeros ( ( len ( string ) + 1 , len ( sub ) + 1 ) ) for j in range ( 1 , len ( sub ) + 1 ) : for i in range ( 1 , len ( string ) + 1 ) : if string [ i - 1 ] == sub [ j - 1 ] : lengths [ i ] [ j ] = lengths [ i - 1 ] [ j - 1 ] + 1 else : lengths [ i ] [ j ] = max ( lengths [ i - 1 ] [ j ] , lengths [ i ] [ j - 1 ] ) return lengths [ len ( string ) ] [ len ( sub ) ]
Calculate the length of longest common subsequence of string and sub.
Calculate the length of longest common subsequence of string and sub .
"""
        Calculate the length of longest common subsequence of string and sub.

        Args:
            string (str):
                The string to be calculated, usually longer the sub string.
            sub (str):
                The sub string to be calculated.

        Returns:
            float: Returns the length of the longest common subsequence of string and sub.
        """
Returns the length of the longest common subsequence of string and sub.
Returns the length of the longest common subsequence of string and sub .
float
self
string
The string to be calculated, usually longer the sub string.
The string to be calculated usually longer the sub string .
sub
The sub string to be calculated.
The sub string to be calculated .