Passed
Branch master (ea367e)
by Osma
02:12
created

SubjectDirectory.__init__()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
1
"""A directory of files as a subject corpus"""
2
3
4
import glob
5
import os.path
6
import re
0 ignored issues
show
Unused Code introduced by
The import re seems to be unused.
Loading history...
7
8
9
class Subject:
1 ignored issue
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
10
    def __init__(self, uri, label, text):
11
        self.uri = uri
12
        self.label = label
13
        self.text = text
14
15
16
class SubjectDirectory:
1 ignored issue
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
17
    def __init__(self, path):
18
        self.path = path
19
20
    def __iter__(self):
21
        """Iterate through the directory, yielding Subject objects."""
22
23
        for filename in glob.glob(os.path.join(self.path, '*.txt')):
24
            with open(filename) as subjfile:
25
                uri, label = subjfile.readline().strip().split(' ', 1)
26
                text = ' '.join(subjfile.readlines())
27
                yield Subject(uri, label, text)
28