words.py
def most_common(word_pos_path: Text,
                word_regex=".*",
                pos_regex=".*",
                n=10) -> List[Tuple[Text, int]]:
    """Finds the most common words and/or parts of speech in a file.

    :param word_pos_path: The path of a file containing part-of-speech tagged
    text. The file should be formatted as a sequence of tokens separated by
    whitespace. Each token should be a word and a part-of-speech tag, separated
    by a slash. For example: "The/at Hartsfield/np home/nr is/bez at/in 637/cd
    E./np Pelham/np Rd./nn-tl Aj/nn ./."

    :param word_regex: If None, do not include words in the output. If a regular
    expression string, all words included in the output must match the regular
    expression.

    :param pos_regex: If None, do not include part-of-speech tags in the output.
    If a regular expression string, all part-of-speech tags included in the
    output must match the regular expression.

    :param n: The number of most common words and/or parts of speech to return.

    :return: A list of (token, count) tuples for the most frequent words and/or
    parts-of-speech in the file. Note that, depending on word_regex and
    pos_regex (as described above), the returned tokens will contain either
    words, part-of-speech tags, or both.
    """

    with open(word_pos_path) as f:
        data = f.read()
        line = data.split()

        if pos_regex is not None and word_regex is None:
            line = [item.rsplit('/', 1)[1] for item in line]
            line = [item for item in line if re.match(pos_regex, item) is not  None]
        
        elif pos_regex is None and word_regex is not None:
            line = [item.rsplit('/', 1)[0] for item in line]
            line = [item for item in line if re.match(word_regex, item) is not  None]

        else:
            line = [item for item in line if re.match(word_regex, item.rsplit('/', 1)[0]) is not  None]
            line = [item for item in line if re.match(pos_regex, item.rsplit('/', 1)[1]) is not  None]
 
        common = Counter(line).most_common(n)
        return common
Finds the most common words and/or parts of speech in a file.

    :param word_pos_path: The path of a file containing part-of-speech tagged
    text. The file should be formatted as a sequence of tokens separated by
    whitespace. Each token should be a word and a part-of-speech tag, separated
    by a slash. For example: "The/at Hartsfield/np home/nr is/bez at/in 637/cd
    E./np Pelham/np Rd./nn-tl Aj/nn ./."

    :param word_regex: If None, do not include words in the output. If a regular
    expression string, all words included in the output must match the regular
    expression.

    :param pos_regex: If None, do not include part-of-speech tags in the output.
    If a regular expression string, all part-of-speech tags included in the
    output must match the regular expression.

    :param n: The number of most common words and/or parts of speech to return.

    :return: A list of (token, count) tuples for the most frequent words and/or
    parts-of-speech in the file. Note that, depending on word_regex and
    pos_regex (as described above), the returned tokens will contain either
    words, part-of-speech tags, or both.
    
Finds the most common words and/or parts of speech in a file.
Finds the most common words and / or parts of speech in a file .
def most_common(word_pos_path: Text,
                word_regex=".*",
                pos_regex=".*",
                n=10) -> List[Tuple[Text, int]]:
    with open(word_pos_path) as f:
        data = f.read()
        line = data.split()
        if pos_regex is not None and word_regex is None:
            line = [item.rsplit('/', 1)[1] for item in line]
            line = [item for item in line if re.match(pos_regex, item) is not  None]
        elif pos_regex is None and word_regex is not None:
            line = [item.rsplit('/', 1)[0] for item in line]
            line = [item for item in line if re.match(word_regex, item) is not  None]
        else:
            line = [item for item in line if re.match(word_regex, item.rsplit('/', 1)[0]) is not  None]
            line = [item for item in line if re.match(pos_regex, item.rsplit('/', 1)[1]) is not  None]
        common = Counter(line).most_common(n)
        return common
def most_common ( word_pos_path : Text , word_regex = ".*" , pos_regex = ".*" , n = 10 ) -> List [ Tuple [ Text , int ] ] : with open ( word_pos_path ) as f : data = f . read ( ) line = data . split ( ) if pos_regex is not None and word_regex is None : line = [ item . rsplit ( '/' , 1 ) [ 1 ] for item in line ] line = [ item for item in line if re . match ( pos_regex , item ) is not None ] elif pos_regex is None and word_regex is not None : line = [ item . rsplit ( '/' , 1 ) [ 0 ] for item in line ] line = [ item for item in line if re . match ( word_regex , item ) is not None ] else : line = [ item for item in line if re . match ( word_regex , item . rsplit ( '/' , 1 ) [ 0 ] ) is not None ] line = [ item for item in line if re . match ( pos_regex , item . rsplit ( '/' , 1 ) [ 1 ] ) is not None ] common = Counter ( line ) . most_common ( n ) return common
Finds the most common words and/or parts of speech in a file.
Finds the most common words and / or parts of speech in a file .
"""Finds the most common words and/or parts of speech in a file.

    :param word_pos_path: The path of a file containing part-of-speech tagged
    text. The file should be formatted as a sequence of tokens separated by
    whitespace. Each token should be a word and a part-of-speech tag, separated
    by a slash. For example: "The/at Hartsfield/np home/nr is/bez at/in 637/cd
    E./np Pelham/np Rd./nn-tl Aj/nn ./."

    :param word_regex: If None, do not include words in the output. If a regular
    expression string, all words included in the output must match the regular
    expression.

    :param pos_regex: If None, do not include part-of-speech tags in the output.
    If a regular expression string, all part-of-speech tags included in the
    output must match the regular expression.

    :param n: The number of most common words and/or parts of speech to return.

    :return: A list of (token, count) tuples for the most frequent words and/or
    parts-of-speech in the file. Note that, depending on word_regex and
    pos_regex (as described above), the returned tokens will contain either
    words, part-of-speech tags, or both.
    """
A list of (token, count) tuples for the most frequent words and/or
parts-of-speech in the file. Note that, depending on word_regex and
pos_regex (as described above), the returned tokens will contain either
words, part-of-speech tags, or both.
A list of ( token count ) tuples for the most frequent words and / or parts - of - speech in the file . Note that depending on word_regex and pos_regex ( as described above ) the returned tokens will contain either words part - of - speech tags or both .
word_pos_path
Text
The path of a file containing part-of-speech tagged
text. The file should be formatted as a sequence of tokens separated by
whitespace. Each token should be a word and a part-of-speech tag, separated
by a slash. For example: "The/at Hartsfield/np home/nr is/bez at/in 637/cd
E./np Pelham/np Rd./nn-tl Aj/nn ./."
The path of a file containing part - of - speech tagged text . The file should be formatted as a sequence of tokens separated by whitespace . Each token should be a word and a part - of - speech tag separated by a slash . For example : " The / at Hartsfield / np home / nr is / bez at / in 637 / cd E . / np Pelham / np Rd . / nn - tl Aj / nn . / . "
word_regex
If None, do not include words in the output. If a regular
expression string, all words included in the output must match the regular
expression.
If None do not include words in the output . If a regular expression string all words included in the output must match the regular expression .
pos_regex
If None, do not include part-of-speech tags in the output.
If a regular expression string, all part-of-speech tags included in the
output must match the regular expression.
If None do not include part - of - speech tags in the output . If a regular expression string all part - of - speech tags included in the output must match the regular expression .
n
The number of most common words and/or parts of speech to return.
The number of most common words and / or parts of speech to return .