fredericd / marcjs

Node.js module for manipulating MARC bibliographic records
59 stars 26 forks source link

Can marc.Iso2709Reader consume a String? #17

Closed philgooch closed 8 years ago

philgooch commented 8 years ago

Node newbie here! Is it possible to have marc.Iso2709Reader read the contents of a string variable?

I've not been successful so far, even trying to create a stream from the string, e.g.

   var strm = new Readable;
    strm._read = function noop() {}; 
    strm.push(data);  // var data contains my MARC record as a string
    strm.push(null);

    var reader = new marc.Iso2709Reader(strm);
    reader.on('data', function(record) {
        console.log("HERE");
        console.log(record);
    });

   // nothing happens ...

I should note that my MARC data looks like this (seems to be the most common format although different to your examples)

LEADER 00000cam a2200361 i 4500 
001    GR111154 
008    780609s1975    nyuaf    b    00110 eng u 
010    78102239 
020    0156309351 :|c$3.75 
035    (CaOTULAS)154869186 
035    (UtOrBLW)b10796848 
041 1  eng|hrus 
082 0  791.45/01 
090    PN1995|b.E52 1975 
100 1  Eisenstein, Sergei,|d1898-1948 
245 14 The film sense /|cby Sergei M. Eisenstein ; translated and
       edited by Jay Leyda 
250    [Rev. ed.] 
260    New York :|bHarcourt Brace Jovanovich,|cc1975 
300    x, 288 p., [2] leaves of plates :|bill. ;|c21 cm 
336    text|btxt|2rdacontent 
337    unmediated|bn|2rdamedia 
338    volume|bnc|2rdacarrier 
500    Includes index 
504    "Bibliography of Eisenstein's writings availabe in 
       English": p. 269-276 
650  0 Motion pictures|xAesthetics 
700 1  Leyda, Jay,|d1910-1988 
900    unlv|lmain 
910    rdae 
949 0  UNLM|p31147002913863 
989    unlv*PN1995 .E52 1975 
999    UNLM 
fredericd commented 8 years ago

Your MARC data isn't in ISO2709. It is a text format, commonly used for display. Two solutions: (1) you write a specific parser for this format, (2) you try to get your data in another format...

Where do the data come from.

philgooch commented 8 years ago

Hi @fredericd, thanks for the info. I'll write a specific parser based on your existing ones and submit a PR.

The data comes from library catalogues, e.g.

http://webpac.library.unlv.edu/search~S1?/XFilm+sense&searchscope=1&SORT=D/XFilm+sense&searchscope=1&SORT=D&SUBKEY=Film+sense/1%2C139%2C139%2CE/marc&FF=XFilm+sense&searchscope=1&SORT=D&1%2C1%2C

philgooch commented 8 years ago

The format is called MARC 21 I believe

http://www.loc.gov/marc/bibliographic/

or UNIMARC

http://www.ifla.org/publications/unimarc-formats-and-related-documentation

fredericd commented 8 years ago

OK it's MARC21. But it's for display not to be parsed. With this interface, I see that you can save biblio records into a list. And then you can view the list, and export it in MARC. You get this way a true ISO2709 file of biblio records which can be parsed by marcjs.