LISTSERV mailing list manager LISTSERV 16.5

Help for CODE4LIB Archives


CODE4LIB Archives

CODE4LIB Archives


CODE4LIB@LISTS.CLIR.ORG


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

CODE4LIB Home

CODE4LIB Home

CODE4LIB  March 2012

CODE4LIB March 2012

Subject:

Re: Q.: MARC8 vs. MARC/Unicode and pymarc and misencoded III records

From:

Jonathan Rochkind <[log in to unmask]>

Reply-To:

Code for Libraries <[log in to unmask]>

Date:

Thu, 8 Mar 2012 15:45:15 -0500

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (88 lines)

a) Mis-characterized MARC char encodings are common amongst many of our 
corpuses and ILS's. It is a common problem. It can be very inconvenient. 
Not only Marc8 that says it's UTF8 and vice versa, but something that 
says it's MARC8 or UTF8 but is actually neither.

b) While one solution would be having the marc tool pass the char stream 
through as is without complaining like Godmar suggested; and another 
solution would be trying to heuristically guess the 'real' solution like 
Gabe suggests;  personally I favor a different solution:

The thing that's encoding as unicode on the way out?  Instead of raising 
on an invalid char, it should have the option of silently eating it, 
replacing it with either empty string or the unicode "replacement 
character" ( "used to replace an incoming character whose value is 
unknown or unrepresentable in Unicode" 
[http://www.fileformat.info/info/unicode/char/fffd/index.htm] )

I have worked with character encoding libraries before that have this 
option, replace messed up bytes with unicode replacement char. I don't 
know what's avail in Python though.

Jonathan

On 3/8/2012 3:19 PM, Gabriel Farrell wrote:
> Sounds like what you do, Terry, and what we need in PyMARC, is
> something like UnicodeDammit [0]. Actually handling all of these
> esoteric encodings would be quite the chore, though.
>
> I also used to think it would be cool if we could get MARC8
> encoding/decoding into the Python standard library, but then I
> realized I'd rather work on other stuff while MARC8 withers and dies.
>
>
> [0] https://github.com/bdoms/beautifulsoup/blob/master/BeautifulSoup.py#L1753
>
> On Thu, Mar 8, 2012 at 2:36 PM, Reese, Terry
> <[log in to unmask]>  wrote:
>> This is one of the reasons you really can't trust the information found in position 9.  This is one of the reasons why when I wrote MarcEdit, I utilize a mixed process when working with data and determining characterset -- a process that reads this byte and takes the information under advisement, but in the end treats it more as a suggestion and one part of a larger heuristic analysis of the record data to determine whether the information is in UTF8 or not.  Fortunately, determining if a set of data is in UTF8 or something else, is a fairly easy process.  Determining the something else is much more difficult, but generally not necessary.
>>
>> For that reason, if I was advising other people working on MARC processing libraries, I'd advocate having a process for recognizing that certain informational data may not be set correctly, and essentially utilize a compatibility process to read and correct them.  Because unfortunately, while the number of vendors and systems that set this encoding byte correctly has increased dramatically (it used to be pretty much no one) -- but it's still so uneven, I generally consider this information unreliable.
>>
>> --TR
>>
>> -----Original Message-----
>> From: Code for Libraries [mailto:[log in to unmask]] On Behalf Of Godmar Back
>> Sent: Thursday, March 08, 2012 11:01 AM
>> To: [log in to unmask]
>> Subject: Re: [CODE4LIB] Q.: MARC8 vs. MARC/Unicode and pymarc and misencoded III records
>>
>> On Thu, Mar 8, 2012 at 1:46 PM, Terray, James<[log in to unmask]>  wrote:
>>
>>> Hi Godmar,
>>>
>>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 9:
>>> ordinal not in range(128)
>>>
>>> Having seen my fair share of these kinds of encoding errors in Python,
>>> I can speculate (without seeing the pymarc source code, so please
>>> don't hold me to this) that it's the Python code that's not set up to
>>> handle the UTF-8 strings from your data source. In fact, the error
>>> indicates it's using the default 'ascii' codec rather than 'utf-8'. If
>>> it said "'utf-8' codec can't decode...", then I'd suspect a problem with the data.
>>>
>>> If you were to send the full traceback (all the gobbledy-gook that
>>> Python spews when it encounters an error) and the version of pymarc
>>> you're using to the program's author(s), they may be able to help you out further.
>>>
>>>
>> My question is less about the Python error, which I understand, than about the MARC record causing the error and about how others deal with this issue (if it's a common issue, which I do not know.)
>>
>> But, here's the long story from pymarc's perspective.
>>
>> The record has leader[9] == 'a', but really, truly contains ANSEL-encoded data.  When reading the record with a MARCReader(to_unicode = False) instance, the record reads ok since no decoding is attempted, but attempts at writing the record fail with the above error since pymarc attempts to
>> utf8 encode the ANSEL-encoded string which contains non-ascii chars such as
>> 0xe8 (the ANSEL Umlaut prefix). It does so because leader[9] == 'a' (see [1]).
>>
>> When reading the record with a MARCReader(to_unicode=True) instance, it'll throw an exception during marc_decode when trying to utf8-decode the ANSEL-encoded string. Rightly so.
>>
>> I don't blame pymarc for this behavior; to me, the record looks wrong.
>>
>>   - Godmar
>>
>> (ps: that said, what pymarc does fails in different circumstances - from what I can see, pymarc shouldn't assume that it's ok to utf8-encode the field data if leader[9] is 'a'.  For instance, this would double-encode correctly encoded Marc/Unicode records that were read with a
>> MARCReader(to_unicode=False) instance. But that's a separate issue that is not my immediate concern. pymarc should probably remember if a record needs or does not need encoding when writing it, rather than consulting the leader[9] field.)
>>
>>
>> (*)
>> https://github.com/mbklein/pymarc/commit/ff312861096ecaa527d210836dbef904c24baee6

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

January 2020
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
January 2004
December 2003
November 2003

ATOM RSS1 RSS2



LISTS.CLIR.ORG

CataList Email List Search Powered by the LISTSERV Email List Manager