pick_parallel_docs
Pick out parallel files to prestable/converted inside a corpus directory.
ParallelPicker
Pick valid parallel files from converted xml files.
Attributes:
Name | Type | Description |
---|---|---|
vcs |
versioncontrol.vcs
|
version control client for the corpus directory |
language1_dir |
str
|
the directory where converted files of language1 are found |
parallel_language |
str
|
three character long language code |
minratio |
float
|
the lowest diff in percent between wordcount in the language1 and parallel document that is accepted |
maxratio |
float
|
the highest diff in percent between wordcount in the language1 and parallel document that is accepted |
poor_ratio |
list of tuple
|
each tuple contains a pair of filename paths and the word count ratio of this pair. |
counter |
defaultdict(int
|
count various things. |
Source code in /home/anders/projects/CorpusTools/corpustools/pick_parallel_docs.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
__init__(language1_dir, parallel_language, minratio, maxratio)
Initialise the ParallelPicker class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
language1_dir |
str
|
the directory where the lang1 files exist. |
required |
parallel_language |
str
|
the parallel language where the lang2 files exist. |
required |
minratio |
int
|
the minimum acceptable ratio of sentences between two parallel documents |
required |
maxratio |
int
|
the maximum acceptable ratio of sentences between two parallel documents |
required |
Source code in /home/anders/projects/CorpusTools/corpustools/pick_parallel_docs.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
calculate_language1(language1_dir)
The language is the part after 'converted/'.
Source code in /home/anders/projects/CorpusTools/corpustools/pick_parallel_docs.py
75 76 77 78 79 80 81 82 83 |
|
copy_file(xml_file)
Copy xml_file to prestable/converted.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml_file |
corpusxmlfile.CorpusXMLFile
|
the file that should be copied to prestable/converted. |
required |
Source code in /home/anders/projects/CorpusTools/corpustools/pick_parallel_docs.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
copy_valid_parallels()
Copy valid parallel files from converted to prestable/converted.
Source code in /home/anders/projects/CorpusTools/corpustools/pick_parallel_docs.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
find_lang1_files()
Find the language1 files.
Yields:
Type | Description |
---|---|
corpusxmlfile.CorpusXMLFile
|
Language files |
Source code in /home/anders/projects/CorpusTools/corpustools/pick_parallel_docs.py
85 86 87 88 89 90 91 92 93 94 |
|
has_parallel(language1_file)
Check if the given file has a parallel file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
language1_file |
corpusxmlfile.CorpusXMLFile
|
The first file of a parallel pair. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if there is a parallel file, False otherwise |
Source code in /home/anders/projects/CorpusTools/corpustools/pick_parallel_docs.py
96 97 98 99 100 101 102 103 104 105 106 107 |
|
has_sufficient_ratio(file1, file2)
See if the ratio of words is good enough.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file1 |
corpusxmlfile.CorpusXMLFile
|
The first file of a parallel pair. |
required |
file2 |
corpusxmlfile.CorpusXMLFile
|
The second file of a parallel pair. |
required |
Returns:
Type | Description |
---|---|
True | None
|
True if good enough, None if not |
Source code in /home/anders/projects/CorpusTools/corpustools/pick_parallel_docs.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
has_sufficient_words(file1, file2)
staticmethod
Check if the given file contains more words than the threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file1 |
corpusxmlfile.CorpusXMLFile
|
The first file of a parallel pair. |
required |
file2 |
corpusxmlfile.CorpusXMLFile
|
The second file of a parallel pair. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if true, False if not |
Source code in /home/anders/projects/CorpusTools/corpustools/pick_parallel_docs.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
is_valid_pair(file1, file2)
Check if file1 and file2 is a valid parallel pair.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file1 |
corpusxmlfile.CorpusXMLFile
|
The first file of a parallel pair. |
required |
file2 |
corpusxmlfile.CorpusXMLFile
|
The second file of a parallel pair. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if valid, False if not |
Source code in /home/anders/projects/CorpusTools/corpustools/pick_parallel_docs.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
valid_parallels()
Pick valid parallel file pairs.
Yields:
Type | Description |
---|---|
tuple[corpusxmlfile.CorpusXMLFile]
|
valid file pairs |
Source code in /home/anders/projects/CorpusTools/corpustools/pick_parallel_docs.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
main()
Copy valid parallel pairs from converted to prestable/converted.
Source code in /home/anders/projects/CorpusTools/corpustools/pick_parallel_docs.py
259 260 261 262 263 264 265 266 267 |
|
parse_options()
Parse the commandline options.
Returns:
Type | Description |
---|---|
argparse.Namespace
|
the parsed commandline arguments |
Source code in /home/anders/projects/CorpusTools/corpustools/pick_parallel_docs.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|