home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 448a.lha / Citation_Base_v1.1 / REXX / AGRICOLA_IMPORT.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1990-09-13  |  6.1 KB  |  190 lines

  1. /* AGRICOLA_IMPORT.rexx  version 1.1 */
  2. /* This macro must be run from the WorkBench or a CLI (preferred). */
  3. /* The citations being imported by AGRICOLA_IMP.rexx must have been */
  4. /* generated by the AGRICOLA CD ROM and saved as a text file.  Since */
  5. /* the AGRICOLA CD ROM is not yet available for the Amiga, you will */
  6. /* have had to create the file on an AGRICOLA station or IBM PC (or */
  7. /* PC clone).  The file will have to be moved to an AmigaDOS disk */
  8. /* for this macro to have access to it.  A number of commercial or */
  9. /* public domain products are available to enable these transfers. */
  10. /* See the main Citation_Base documentation for more information. */
  11. /* The citations in the AGRICOLA file have only abbreviated journal */
  12. /* names, so this macro simply copies the abbreviated journal name */
  13. /* into the full journal name field.  You will have to replace */
  14. /* the abbreviated name with the full name by hand.  Perhaps future */
  15. /* versions of this macro will employ a 'look-up' table to do the */
  16. /* substitution for you.  Another characteristic of AGRICOLA citations */
  17. /* is that journal names contain a trailing period, which is OK when */
  18. /* the last word in the abbreviated name is truly abbreviated, but */
  19. /* some journal names are spelled out fully and should not have the */
  20. /* trailing period.  You will need to remove these periods by hand. */
  21. /*  Codes (the ampersand, &, and dollar sign, $) for toggling the */
  22. /* formatting around scientific names must also be inserted by the */
  23. /* user.  Don't be put off by the minor modifications described */
  24. /* above, the effort is minimal compared to entering the complete */
  25. /* citation. */
  26.  
  27.  
  28. /* Open the Agricola citation text file for import */
  29. /* Note:  change the disk/drive designations below to suit your setup */
  30. screentofront();
  31. in_text = getfile(,,'ram:',,'Select Agricola import file');
  32. if (in_text = '') then exit;
  33. if (open(importfile,in_text,'R') ~= 1) then;
  34.   do;
  35.     say 'I could not open the file ' || in_text || ' for importing.');
  36.     exit;
  37.   end;
  38.  
  39. /* Open file to export non-standard (bad) Agricola citations */
  40. out_text = getfile(,,'ram:',,'Filename for bad citations');
  41. if (out_text = '') then exit;
  42. if (open(exportfile,out_text,'W') ~= 1) then;
  43.   do;
  44.     say 'I could not open the file ' || out_text || ' for output.';
  45.     exit;
  46.   end;
  47.  
  48.  
  49. /* Open file to export citations in Citation_Base format. */
  50. out_cite = getfile(,,'ram:',,'Citation export filename');
  51. if (out_cite = '') then exit;
  52. if (open(exportcitefile,out_cite,'W') ~=1) then;
  53.   do;
  54.     say 'I could not open the file ' || out_cite || ' for output.';
  55.     exit;
  56.   end;
  57.  
  58.  
  59. /* Initialize variables */
  60. cite_num = 0;
  61. b = 1;
  62.  
  63.  
  64. /* Process citation and continue to end of file */
  65. do while (~EOF(importfile));
  66.  
  67.  
  68. /* Read Agricola CITN style citation */
  69.   cite_num = cite_num + 1;
  70.   skip_cite = 'no';
  71.   j = 1;
  72.   agr_string.j = readln(importfile);
  73.   do forever;
  74.     j = j + 1;
  75.     agr_string.j = readln(importfile);
  76.     agr_string.j = strip(agr_string.j,'T',d2c(13));
  77.     say agr_string.j;
  78.     if substr(agr_string.j,3,1) ~= ':' then leave;
  79.   end;
  80.   if j > 7 then;
  81.     do;
  82.       skip_cite = 'yes';
  83.       bad_cite_num.b = cite_num;
  84.       b = b + 1;
  85.     end;
  86.   else;
  87.     do;
  88.       temp = agr_string.4;
  89.       parse var temp junk ': ' junk ' ' test_year ' v. ' temp;
  90.       if right(test_year,1) = '.' then test_year = left(test_year,length(test_year)-1);
  91.       prefix_year = substr(test_year,length(test_year)-3,2);
  92.       if ((prefix year ~= '18') & (prefix_year ~= '19') & (prefix_year ~= '20')) then;
  93.         do;
  94.           skip_cite = 'yes';
  95.           bad_cite_num.b = cite_num;
  96.           b = b + 1;
  97.         end;
  98.       else NOP;
  99.     end;
  100.  
  101. /* Skip citation if in non-standard format */
  102.   if skip_cite = 'no' then;
  103.     do;
  104.  
  105. /* Extract author names and reconstruct author string */
  106.       author_string = '';
  107.       parse var agr_string.2 junk ': ' agr_string.2;
  108.       if (length(agr_string.2) >= 2) then;
  109.         do;
  110.           do forever;
  111.             parse var agr_string.2 surname ',-'  agr_string.2;
  112.             if surname == '' then leave;
  113.             parse var agr_string.2 initials '.; ' agr_string.2;
  114.             initials = compress(translate(initials,' ','.'));
  115.             author_string = (author_string || surname || ', ' || initials || ', ');
  116.           end;
  117.           author_string = left(author_string,(length(author_string)-2));
  118.         end;
  119.       else author_string = '';
  120.  
  121.  
  122. /* Extract title */
  123.       parse var agr_string.3 junk ': ' title;
  124.       title = left(title,(length(title)-1));
  125.  
  126.  
  127. /* Extract journal name */
  128.       parse var agr_string.4 junk ': ' journal ' ' agr_string.4;
  129.       do forever;
  130.         hyphen_pos = index(journal,'-');
  131.         if hyphen_pos = 0 then leave;
  132.         journal = insert('. ',journal,hyphen_pos);
  133.         journal = delstr(journal,hyphen_pos,1);
  134.       end;
  135.  
  136.  
  137. /* Extract year and volume number */
  138.       parse var agr_string.4 long_year ' v. ' volume ' ' junk 'p. ' page_numbers '.' junk;
  139.       if right(long_year,1) = '.' then long_year = left(long_year,length(long_year)-1);
  140.       year = right(long_year,4);
  141.  
  142.   
  143. /* Extract  page numbers */
  144.       hyphen_pos = index(page_numbers,'-');
  145.       if hyphen_pos = 0 then;
  146.         do;
  147.           first_page = page_numbers;
  148.           last_page = '';
  149.         end;
  150.       else;
  151.         do;
  152.           parse var page_numbers first_page "-" last_page;
  153.         end;
  154.  
  155. /* Assign string values to record (citation) values and add record */
  156.       rec.1.value = author_string;
  157.       rec.2.value = year;
  158.       rec.3.value = title;
  159.       rec.4.value = (journal || ', ' || volume || ', ' || first_page || ', ' || last_page || ', ');
  160.       rec.5.value = ('*' || journal);
  161.       do k = 1 to 5;
  162.         foo = writeln(exportcitefile,rec.k.value);
  163.       end;
  164.     end;
  165.  
  166.  
  167. /* Write non-standard (bad) citations to export file */
  168.   else;
  169.     do i = 2 to j;
  170.       foo = writeln(exportfile,agr_string.i);
  171.     end;
  172.  
  173. /* End Agricola citation import loop */      
  174. end;
  175.  
  176.  
  177. /* Report bad citations */
  178. do i = 1 to b-1;
  179.   say 'Bad citation: ' || bad_cite_num.i;
  180.   foo = writeln(exportfile,('Bad citation: ' || bad_cite_num.i));
  181. end;
  182.  
  183.  
  184. /* Exit macro gracefully */
  185. screentoback();
  186. say 'Citations imported from ' || in_text || ' now in database';
  187. exit;
  188.  
  189.  
  190.