@@ -78,12 +78,14 @@ The basic API of the `DatasetReader` is just that we need to instantiate the obj
78
78
79
79
``` python
80
80
from allennlp.common.testing import AllenNlpTestCase
81
+ from allennlp.common.util import ensure_list
82
+
81
83
from my_library.dataset_readers import SemanticScholarDatasetReader
82
84
83
85
class TestSemanticScholarDatasetReader (AllenNlpTestCase ):
84
86
def test_read_from_file (self ):
85
87
reader = SemanticScholarDatasetReader()
86
- dataset = reader.read(' tests/fixtures/s2_papers.jsonl' )
88
+ instances = ensure_list( reader.read(' tests/fixtures/s2_papers.jsonl' ) )
87
89
```
88
90
89
91
Then we just want to make sure that the resulting dataset looks like we expect. We'll refer you to
@@ -112,16 +114,16 @@ are given as `Lists` here, but other than that, this just mimics the relevant fi
112
114
blobs in the data file. We'll have our test make sure that what we read matches this:
113
115
114
116
``` python
115
- assert len (dataset. instances) == 10
116
- fields = dataset. instances[0 ].fields
117
+ assert len (instances) == 10
118
+ fields = instances[0 ].fields
117
119
assert [t.text for t in fields[" title" ].tokens] == instance1[" title" ]
118
120
assert [t.text for t in fields[" abstract" ].tokens[:5 ]] == instance1[" abstract" ]
119
121
assert fields[" label" ].label == instance1[" venue" ]
120
- fields = dataset. instances[1 ].fields
122
+ fields = instances[1 ].fields
121
123
assert [t.text for t in fields[" title" ].tokens] == instance2[" title" ]
122
124
assert [t.text for t in fields[" abstract" ].tokens[:5 ]] == instance2[" abstract" ]
123
125
assert fields[" label" ].label == instance2[" venue" ]
124
- fields = dataset. instances[2 ].fields
126
+ fields = instances[2 ].fields
125
127
assert [t.text for t in fields[" title" ].tokens] == instance3[" title" ]
126
128
assert [t.text for t in fields[" abstract" ].tokens[:5 ]] == instance3[" abstract" ]
127
129
assert fields[" label" ].label == instance3[" venue" ]
0 commit comments