[Phpmylibrary-developers] phpmylibrary developer
Status: Beta
Brought to you by:
polerio
From: Polerio B. <pt...@ho...> - 2002-10-17 12:26:06
|
Hello Sash, Please browse through this mail as I answer your question one by one. By the way thanks for the different ideas you've shared. Also, It would be helpful if you could register at sourceforge.net so that I can now add you in the phpmylibrary as official developer. Please email me the username you will use in sourceforge.net. In addition, I will be activating the mailing lists for developers so that our mail can be archived for future reference. For a start I will add this mail in there. Thanks. You will be the first official phpmylibrary developer. I hope we could make the coding successful. >From: Sascha Herpers <s.h...@br...> >To: Polerio Babao <pt...@ho...> >Subject: Csv to Marc Converter >Date: 14 Oct 2002 19:52:15 +0200 > >Hi Polerio, > >take your time, I come to think, that this mail will we a little >longer... > > > You sounds well-versed programmer to me. >I know my way around ;o) > > > I started to think that if the CSV > > to MARC has been approved I will not be alone creating that new module. > > Perhaps if you would like, you could join me in enhancing the >PhpMyLibrary, > > there's much to be added in there. >Yes, I agree. For starters I created a CSVImport Class. Nothing fancy, >but it works and should serve our needs. Nice idea. > >Take a look at the attached zip an put it in a server directory with php >support and rights for direct file access. Open the index.php. you >should see a bulleted list with one item 'music.csv' (how about that: i >call one item a list ;o) > >Click on it. Then you see a table with songtitles and artists. This >table is generated from a csv file (the one you clicked on). > >Here are the function of the CSVImport class: > > // Reads the contents of the csvFile > function ReadFile($fileName, $seperator="|") > > // checks if the bookmark reached the end of the csvFile > function Eof() > > // checks if the bookmark reached the beginning of the csvFile > function Bof() > > // advances the bookmark by 1 > function MoveNext() > > // advances the bookmark by -1 > function MovePrevious() > > // moves the bookmark to the first line > function MoveFirst() > > // moves the bookmark to the last line > function MoveLast() > > // returns the array with the fieldNames > function FieldNames() > > // checks the integrety of the current line > function IsCurrentLineValid() > > // retrives the specified field value > function Value($key, $default="") > >What I would suggest now is, you write the following class: >Class CSVtoMarc // or however you want to call it >{ > function SetOutputFile($outputFileName) > { > } > > function SetCsvFile($csvFileName) > { > // initilize my CSVImport Class here > } > > function Open() > { > // open the output file and write a header or whatever > // the start of a marc file is (don't know) > } > > function ProcessCurrentLine(&$errString) > { > // take the current csvline and parse it into the marc format > // the return should be either null, if an error occured setting > // the $errString to an appropriate value > // or the return is a valid marc blob > } > > > function WriteMarcBlob($marcBlob) > { > // write the marc blob returned from ProccessCurrentLine to the file > } > > function Eof() > { > return($this->csvfile->Eof()); > } > > function MoveNext() > { > $this->csvfile->MoveNext(); > } > > function Close() > { > // close the file and clean up > } >} > >wow. Ok, some remarks. The reason why I suggest the structure of the >class to be like this: this way the developer has the most control over >the conversion process. A code fragment could then look like this: ><? > $marcconv = new CSVtoMarc(); > $marcconv->SetOutputFile("mymarc.mrc"); > $marcconv->SetInputFile("mycsv.csv"); > > $marcconv->Open(); > while (!$marcconv->Eof()) > { > $curmarc = $marcconv->ProcessCurrentLine($error); > if ($curmarc) > $marcconv->WriteMarcBlob($curmarc); > else > // do some fancy error recovery here > print("an error occured: $error<br>\n"); > > $marcconv->MoveNext(); > } > $marcconv->Close(); >?> > >The Open and Close function could be written in such a way, that if no >output file name is supplied by SetOutputFile, no file is opened or >closed in the Open and Close. That would make sense if the developer >wouldn't want to export the marc blobs into a file. In that case he >wouldn't use WriteMarcBlob either, but he would do some other stuff with >the blob: e.g. save the blob to a mysql database...hmmmm....for example >phpmylibrary ;o) > >What do you think? Good, this allows the script useful not only in phpmylibrary but in general. > >To level the workload I would suggest I prepare the above class (if you >agree with its structure) as far as I can and you simply throw in the >code to actually create the marc blob. > >Oh! I forgot one thing. There has to be a mapping mechanism for mapping >the csv values to the marc fields. I guess the easiest way to do so is >creating an array like this: we take my music.csv example with the field >names 'songtitle' and 'artist'. Suppose we wanted to map it to the >(fictional) fields 234 and 321, then I would create an array like this: > > $this->csvMap = array('songtitle' ==> '234', 'artist' ==> 321); > >I don't know how modular you developed phpmylibrary, but is there a way >to write this class in such a manner, that it can be used stand-alone >without the need to install phpmylibrary? I will try to work this things out. It sounds very customized but its good. I will do the coding on this and I'll see if this kind is possible or necessary. > >This is a lot and I am almost done for now. I have only a few more >question you might be able to answer: > >-> What is the exact name of the marc format you support? Is it Marc21? It is MARC21, from www.loc.gov/marc/lite I think. common tags from here is 245 for title, 100 for author, 500 notes, etc... >-> Do you know the differences between e.g. Marc21 and UniMarc? Not yet. > >As far as I understood it, the Marc format saves it 'recordset entries' >as key/value pairs. From what I saw in phpmylibray and another tool >(called sisis) the keys don't match. Yes, because CDS/ISIS can define thier tags. And it's good. Why? because they can use it not only for books but also on other purpose like delinquents student database. etc. They only define what tag is to be searchable and what's not. It's very flexible. I'm planning to adapt their concept. But that's really a lot of work. Following that concept means not only serving library oriented software. Is that due to different formats? Not really, Its just that the librarian choses to define their own tags. But the problem is, when it comes to conversion it's not that fast because as we said, they choose their own tag, conversion will occur here. related info can also be found at iso 2709, search for it. This is their standard of importing/exporting data from one another. This is what MARC2 and CDS/ISIS used. >Or is the meaning of a key simply a convention? Could I for example go >along and define MyMarc with the key 123 being the author's name? Yes, but doing this means ignoring the standard. If you are going to transfer your file to another software, they can't read, perhaps the only software which can read it is your software itself and no one else. > >And the last question for today: I saw some recordsets in that sisis >programm with more than one author. What they did there, they appended a >sequential number to the end of the key. Suppose the author key is >'0100', then they entered: > 0100.0001 auther, one > 0100.0002 auther, two > 0100.0003 auther, three It's more like a delimmeter, it's a subfield. on MARC it works like this 100 00$aBabao, Polerio $b . . . etc. . . > >Is that supported with all marc formats and thus with our soon to be >conversion class or is that a problem? No it's not. My plan is to as you termed it is to map different fields of CSV into MARC compatible fields. > >Wow, enough for now. Feel free to answer the whole email at once of just >bit by bit. Whatever is faster. That way I can get my hands on the >keyboard and implement the new class.... > > Sash ><< csvimport.zip >> Now I'll do the coding of the CSV to MARC, I will mail you after I finished this thing and let's see if that's ok. Polerio _________________________________________________________________ Get a speedy connection with MSN Broadband. Join now! http://resourcecenter.msn.com/access/plans/freeactivation.asp |