146
146
__author_email__ = ('renato.ppontes@gmail.com, '
147
147
'feurerm@informatik.uni-freiburg.de, '
148
148
'joel.nothman@gmail.com' )
149
- __version__ = '2.3'
149
+ __version__ = '2.3.1 '
150
150
151
151
import re
152
152
import sys
171
171
172
172
173
173
def _build_re_values ():
174
- quoted_re = r'''(?x)
174
+ quoted_re = r'''
175
175
" # open quote followed by zero or more of:
176
176
(?:
177
177
(?<!\\) # no additional backslash
@@ -185,7 +185,7 @@ def _build_re_values():
185
185
" # close quote
186
186
'''
187
187
# a value is surrounded by " or by ' or contains no quotables
188
- value_re = r'''(?x)(? :
188
+ value_re = r'''(?:
189
189
%s| # a value may be surrounded by "
190
190
%s| # or by '
191
191
[^,\s"'{}]+ # or may contain no characters requiring quoting
@@ -253,7 +253,7 @@ def _parse_values(s):
253
253
for match in _RE_SPARSE_KEY_VALUES .finditer (s ):
254
254
if not match .group (1 ):
255
255
raise BadLayout ('Error parsing %r' % match .group ())
256
- raise
256
+ raise BadLayout ( 'Unknown parsing error' )
257
257
else :
258
258
# an ARFF syntax error
259
259
for match in _RE_DENSE_VALUES .finditer (s ):
@@ -310,7 +310,7 @@ def __init__(self, value):
310
310
)
311
311
312
312
class BadAttributeType (ArffException ):
313
- '''Error raised when some invalid type is provided into the attribute
313
+ '''Error raised when some invalid type is provided into the attribute
314
314
declaration.'''
315
315
message = 'Bad @ATTRIBUTE type, at line %d.'
316
316
@@ -327,7 +327,7 @@ def __init__(self, value, value2):
327
327
)
328
328
329
329
class BadNominalValue (ArffException ):
330
- '''Error raised when a value in used in some data instance but is not
330
+ '''Error raised when a value in used in some data instance but is not
331
331
declared into it respective attribute declaration.'''
332
332
333
333
def __init__ (self , value ):
@@ -347,7 +347,7 @@ def __init__(self, value):
347
347
)
348
348
349
349
class BadNumericalValue (ArffException ):
350
- '''Error raised when and invalid numerical value is used in some data
350
+ '''Error raised when and invalid numerical value is used in some data
351
351
instance.'''
352
352
message = 'Invalid numerical value, at line %d.'
353
353
@@ -365,14 +365,14 @@ def __init__(self, msg=''):
365
365
self .message = BadLayout .message + ' ' + msg .replace ('%' , '%%' )
366
366
367
367
class BadObject (ArffException ):
368
- '''Error raised when the object representing the ARFF file has something
368
+ '''Error raised when the object representing the ARFF file has something
369
369
wrong.'''
370
370
371
371
def __str__ (self ):
372
372
return 'Invalid object.'
373
373
374
374
class BadObject (ArffException ):
375
- '''Error raised when the object representing the ARFF file has something
375
+ '''Error raised when the object representing the ARFF file has something
376
376
wrong.'''
377
377
def __init__ (self , msg = '' ):
378
378
self .msg = msg
@@ -636,7 +636,7 @@ def _decode_comment(self, s):
636
636
characters.
637
637
638
638
This method must receive a normalized string, i.e., a string without
639
- padding, including the "\r \n " characters.
639
+ padding, including the "\r \n " characters.
640
640
641
641
:param s: a normalized string.
642
642
:return: a string with the decoded comment.
@@ -647,13 +647,13 @@ def _decode_comment(self, s):
647
647
def _decode_relation (self , s ):
648
648
'''(INTERNAL) Decodes a relation line.
649
649
650
- The relation declaration is a line with the format ``@RELATION
650
+ The relation declaration is a line with the format ``@RELATION
651
651
<relation-name>``, where ``relation-name`` is a string. The string must
652
652
start with alphabetic character and must be quoted if the name includes
653
653
spaces, otherwise this method will raise a `BadRelationFormat` exception.
654
654
655
655
This method must receive a normalized string, i.e., a string without
656
- padding, including the "\r \n " characters.
656
+ padding, including the "\r \n " characters.
657
657
658
658
:param s: a normalized string.
659
659
:return: a string with the decoded relation name.
@@ -670,26 +670,26 @@ def _decode_relation(self, s):
670
670
def _decode_attribute (self , s ):
671
671
'''(INTERNAL) Decodes an attribute line.
672
672
673
- The attribute is the most complex declaration in an arff file. All
673
+ The attribute is the most complex declaration in an arff file. All
674
674
attributes must follow the template::
675
675
676
676
@attribute <attribute-name> <datatype>
677
677
678
- where ``attribute-name`` is a string, quoted if the name contains any
678
+ where ``attribute-name`` is a string, quoted if the name contains any
679
679
whitespace, and ``datatype`` can be:
680
680
681
681
- Numerical attributes as ``NUMERIC``, ``INTEGER`` or ``REAL``.
682
682
- Strings as ``STRING``.
683
683
- Dates (NOT IMPLEMENTED).
684
684
- Nominal attributes with format:
685
685
686
- {<nominal-name1>, <nominal-name2>, <nominal-name3>, ...}
686
+ {<nominal-name1>, <nominal-name2>, <nominal-name3>, ...}
687
687
688
688
The nominal names follow the rules for the attribute names, i.e., they
689
689
must be quoted if the name contains whitespaces.
690
690
691
691
This method must receive a normalized string, i.e., a string without
692
- padding, including the "\r \n " characters.
692
+ padding, including the "\r \n " characters.
693
693
694
694
:param s: a normalized string.
695
695
:return: a tuple (ATTRIBUTE_NAME, TYPE_OR_VALUES).
@@ -874,8 +874,8 @@ def _encode_comment(self, s=''):
874
874
def _encode_relation (self , name ):
875
875
'''(INTERNAL) Decodes a relation line.
876
876
877
- The relation declaration is a line with the format ``@RELATION
878
- <relation-name>``, where ``relation-name`` is a string.
877
+ The relation declaration is a line with the format ``@RELATION
878
+ <relation-name>``, where ``relation-name`` is a string.
879
879
880
880
:param name: a string.
881
881
:return: a string with the encoded relation declaration.
@@ -901,7 +901,7 @@ def _encode_attribute(self, name, type_):
901
901
- Dates (NOT IMPLEMENTED).
902
902
- Nominal attributes with format:
903
903
904
- {<nominal-name1>, <nominal-name2>, <nominal-name3>, ...}
904
+ {<nominal-name1>, <nominal-name2>, <nominal-name3>, ...}
905
905
906
906
This method must receive a the name of the attribute and its type, if
907
907
the attribute type is nominal, ``type`` must be a list of values.
@@ -936,7 +936,7 @@ def encode(self, obj):
936
936
def iter_encode (self , obj ):
937
937
'''The iterative version of `arff.ArffEncoder.encode`.
938
938
939
- This encodes iteratively a given object and return, one-by-one, the
939
+ This encodes iteratively a given object and return, one-by-one, the
940
940
lines of the ARFF file.
941
941
942
942
:param obj: the object containing the ARFF information.
0 commit comments