forked from hushidong/biblatex-gb7714-2015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gb7714texttobib.pl
1670 lines (1492 loc) · 53.4 KB
/
gb7714texttobib.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
##%
##% ---------------------------------------------------------------
##% gb7714texttobib--- A transformation tool for GB/T 7714-2015 style
##% bibliography text to bib source file
##%
##% Maintained by huzhenzhen
##% Homepage: <https://github.com/hushidong/biblatex-gb7714-2015>
##% history:
##% 2017/02/26 v1.0g
##% E-mail:
##% Released under the LaTeX Project Public License v1.3c or later
##% usage:
##% perl gb7714texttobib.pl in=textfilename out=bibfilename
##% options(need to do):
##% style=ay or default
##% key=ay or default
##%
##% ---------------------------------------------------------------
#%Target:: 将pdf文档中拷出的参考文献文本转换成bib文件,文本文件中的一条参考文献为一行
#%Method:: 利用perl进行文本处理,处理和判断的两个重要方面是:
# 分析分割后的文本的位置和内容,使用的是正则表达式匹配,主要两种方式
# 1.根据标点和本文特征一部分一部分的解析,比如book条目处理
# 2.直接列出所有可能的正则表达式一个个匹配,比如article条目处理
#%Date :: 2017-02-22
#%Note :: 1.网址之类如果解析出错,应确认其前导词http://之前没有空格
# 2.有些以.连接有从属关系的机构作者,可以把.后的空格去掉便于正确解析
# 3.有些尽管解析到的域不是真实的域,但不影响著录格式(显示效果),相应条目的域
# 可以在bib文件中完善,尽管从实用角度并不需要这么做。
#
##% ---------------------------------------------------------------
##% todo: 1. pdf 的比较?
##% obsolete intro:
##% 1.源文件文档如果个别地方不符合规范,可以修改一下
##% (a):inbook/standard类中,当出现//后面第二项是booktitle且其中存在:时,先把父标题的冒号改成colon,比如
##% [M]//李承森. 宋史: 第 1 册. 北京: 中华书局. 应把宋史后的冒号改掉
##% [S]//全国文献工作标准化技术委员会. 文献工作国家标准汇编: 3. 北京: 中国标准出版社, 1988: 59–92.
##% ---------------------------------------------------------------
foreach $file(@ARGV){
print 'file:',$file,"\n";
if($file=~m/in=/){
($infile)=($file=~m/in=(.*)/)
}
if($file=~m/out=/){
($outfile)=($file=~m/out=(.*)/)
}
}
open (FHR,"<$infile");
open (FHW,">$outfile");
print FHW '% Encoding: UTF-8',"\n";
@references=<FHR>;#将所有的文献存为@references数组,各文献以<行>为单位进行区分
$ns=1;
$ne=@references;
$nline=0;
foreach $reference(@references){
$nline=$nline+1;
if($nline<$ns){next;} #先跳过几行进行,配合后面的last进行当行测试
while($reference=~m/–/){
$reference=~s/–/-/;#直接利用正则表达式更正页码/日期/网址中的连字符
}
print "$reference ";#打印各文献的内容
undef $entrytype;
undef $author;
undef $title;
undef $journal;
undef $translator;
undef $bookauthor;
undef $booktitle;
undef $version;
undef $address;
undef $publisher;
undef $institution;
undef $year;
undef $type;
undef $date;
undef $volume;
undef $number;
undef $pages;
undef $eventdate;
undef $urldate;
undef $url;
undef $doi;
undef $note;
undef $eventyvn;
undef $endeventyvn;
undef $eventdate;
undef $eventvol;
undef $eventnum;
undef $endeventdate;
undef $endeventvol;
undef $endeventnum;
#---------------------------------------------------------------
#条目类型:期刊和期刊中析出的文献/periodical、article
#---------------------------------------------------------------
if(1){
if($reference=~m/\[J\]/){
if($reference=~m/:\s/ and $reference=~m/:\s\D/){#根据存在出版社前的冒号加空格区分
print 'this entry is periodical',"\n";
$entrytype='periodical';
}else{
print 'this entry is article',"\n";
$entrytype='article';
}
}
if($entrytype eq 'periodical'){#字符串比较用eq而数字比较用==,如果用==那么两边都是1,则是真
$regexformach='\[J\]\.';
&bfidentifier;
($preadderess, $pospublisher)=($reference=~m/\[J\]\.(.*):\s(.*)/);
print 'preadderess =',$preadderess,"\n";
print 'pospublisher=',$pospublisher,"\n";
($eventyear, $address)=($preadderess=~m/(.*)\.\s(.*)/);
print 'eventyear =',$eventyear,"\n";
print 'address =',$address,"\n";
($eventyvn, $endeventyvn)=($eventyear=~m/(.*)\-(.*)/);#yvn表示year,volume,number
print 'eventyvn =',$eventyvn,"\n";
print 'endeventyvn =',$endeventyvn,"\n";
if($eventyvn=~m/.*,.*/){#存在逗号表明有卷信息
($eventdate, $eventvol, $eventnum)=($eventyvn=~m/\s*(.*),\s(.*)\((.*)\)/);#yvn表示year,volume,number
print 'eventdate =',$eventdate,"\n";
print 'eventvol =',$eventvol,"\n";
print 'eventnum =',$eventnum,"\n";
if($endeventyvn){
($endeventdate, $endeventvol, $endeventnum)=($endeventyvn=~m/\s*(.*),\s(.*)\((.*)\)/);#yvn表示year,volume,number
print 'endeventdate =',$endeventdate,"\n";
print 'endeventvol =',$endeventvol,"\n";
print 'endeventnum =',$endeventnum,"\n";
}
}else{
($eventdate, $eventnum)=($eventyvn=~m/\s*(.*)\((.*)\)/);#yvn表示year,volume,number
print 'eventdate =',$eventdate,"\n";
print 'eventvol =',$eventvol,"\n";
print 'eventnum =',$eventnum,"\n";
if($endeventyvn){
($endeventdate, $endeventnum)=($endeventyvn=~m/\s*(.*)\((.*)\)/);#yvn表示year,volume,number
print 'endeventdate =',$endeventdate,"\n";
print 'endeventvol =',$endeventvol,"\n";
print 'endeventnum =',$endeventnum,"\n";
}
}
if($endeventdate){
$date=$eventdate.'-'.$endeventdate;
}else{
$date=$eventdate
}
if($endeventvol){
$volume=$eventvol.'-'.$endeventvol;
}else{
$volume=$eventvol
}
if($endeventnum){
$number=$eventnum.'-'.$endeventnum;
}else{
$number=$eventnum
}
print 'date =',$date,"\n";
print 'volume =',$volume,"\n";
print 'number =',$number,"\n";
($publisher)=($pospublisher=~m/(.*),/);
print 'publisher =',$publisher,"\n";
}
if($entrytype eq 'article'){
$regexformach='\[J\]\.';
&bfidentifier;
$flagmatched=0;
$regexbfjournal='\]\.\s(.*),\s(.*),\s(.*)\((.*)\):\s(.*)\.';#包括全部信息
if($reference=~m/$regexbfjournal/){
($journal,$date,$volume,$number,$pages)=($reference=~m/$regexbfjournal/);
$flagmatched=1;
print '包括全部信息',"\n";
}
$regexbfjournal='\]\.\s(.*),\s(.*),\s(.*)\((.*)\)\.';#没有页码
if($reference=~m/$regexbfjournal/ and $flagmatched==0){
($journal,$date,$volume,$number)=($reference=~m/$regexbfjournal/);
$flagmatched=1;
print '没有页码',"\n";
}
$regexbfjournal='\]\.\s(.*),\s(.*),\s(.*):\s(.*)\.';#没有期
if($reference=~m/$regexbfjournal/ and $flagmatched==0){
($journal,$date,$volume,$pages)=($reference=~m/$regexbfjournal/);
$flagmatched=1;
print '没有期',"\n";
}
$regexbfjournal='\]\.\s(.*),\s(.*)\((.*)\):\s(.*)\.';#没有卷/年
if($reference=~m/$regexbfjournal/ and $flagmatched==0){
($journal,$date,$number,$pages)=($reference=~m/$regexbfjournal/);
$flagmatched=1;
if($date!~m/\d{4}/){
$volume=$date;
$date='';
}
print '没有卷/年',"\n";
}
$regexbfjournal='\]\.\s(.*),\s(.*),\s(.*)\.';#没有页码,期
if($reference=~m/$regexbfjournal/ and $flagmatched==0){
($journal,$date,$volume)=($reference=~m/$regexbfjournal/);
$flagmatched=1;
print '没有页码,期',"\n";
}
$regexbfjournal='\]\.\s(.*),\s(.*)\((.*)\)\.';#没有页码,卷/年
if($reference=~m/$regexbfjournal/ and $flagmatched==0){
($journal,$date,$number)=($reference=~m/$regexbfjournal/);
$flagmatched=1;
if($date!~m/\d{4}/){
$volume=$date;
$date='';
}
print '没有页码,卷/年',"\n";
}
$regexbfjournal='\]\.\s(.*),\s(.*):\s(.*)\.';#没有卷/年,期
if($reference=~m/$regexbfjournal/ and $flagmatched==0){
($journal,$date,$pages)=($reference=~m/$regexbfjournal/);
$flagmatched=1;
if($date!~m/\d{4}/){
$volume=$date;
$date='';
}
print '没有卷/年,期',"\n";
}
if($flagmatched==0){
print 'the text after title was not matched, please add a regex for the current entry in the perl source code!',"\n";
print '当前条目标题之后的内容没有匹配的正则表达式,请在perl代码中增加适合该条目正则表达式!',"\n";
}
print 'journal =',$journal,"\n";
print 'date =',$date,"\n";
print 'volume =',$volume,"\n";
print 'number =',$number,"\n";
print 'pages =',$pages,"\n";
}
#判断期刊中析出的文献,带url
if($reference=~m/\[J\/OL\]/){
print 'this entry is article with url',"\n";
$entrytype='article';
$regexformach='\[J\/OL\]\.';
&bfidentifier;
($postitle)=($reference=~m/\[J\/OL\]\.\s(.*)/);
if($postitle=~m/\[.*\]/){#存在urldate
($preurldate,$urldate,$posurl)=($postitle=~m/(.*)\[(.*)\]\.\s(.*)/);
}else{#不存在urldate
($preurldate,$posurl)=($postitle=~m/(.*)(http:.*)/);
}
unless($preurldate=~m/\.$/){$preurldate=$preurldate.'.';}#加个点统一上面两种方式
#处理url和doi
$regexposurl='(.*)doi:\s(.*)';#处理url和doi
if($posurl=~m/$regexposurl/i){
($url,$doi)=($posurl=~m/$regexposurl/i);
}else{
$url=$posurl;
}
#处理urldate前的内容,基本article不带url的情况相同
$flagmatched=0;
$regexbfjournal='(.*),\s(.*),\s(.*)\((.*)\):\s(.*)\.';#包括全部信息
if($preurldate=~m/$regexbfjournal/ and $flagmatched==0){
($journal,$date,$volume,$number,$pages)=($preurldate=~m/$regexbfjournal/);
$flagmatched=1;
}
$regexbfjournal='(.*),\s(.*),\s(.*)\((.*)\)\.';#没有页码
if($preurldate=~m/$regexbfjournal/ and $flagmatched==0){
($journal,$date,$volume,$number)=($preurldate=~m/$regexbfjournal/);
$flagmatched=1;
}
$regexbfjournal='(.*),\s(.*),\s(.*):\s(.*)\.';#没有期
if($preurldate=~m/$regexbfjournal/ and $flagmatched==0){
($journal,$date,$volume,$pages)=($preurldate=~m/$regexbfjournal/);
$flagmatched=1;
}
$regexbfjournal='(.*),\s(.*)\((.*)\):\s(.*)\.';#没有卷/年
if($preurldate=~m/$regexbfjournal/ and $flagmatched==0){
($journal,$date,$number,$pages)=($preurldate=~m/$regexbfjournal/);
$flagmatched=1;
if($date!~m/\d{4}/){
$volume=$date;
$date='';
}
}
$regexbfjournal='(.*),\s(.*),\s(.*)\.';#没有页码,期
if($preurldate=~m/$regexbfjournal/ and $flagmatched==0){
($journal,$date,$volume)=($preurldate=~m/$regexbfjournal/);
$flagmatched=1;
}
$regexbfjournal='(.*),\s(.*)\((.*)\)\.';#没有页码,卷/年
if($preurldate=~m/$regexbfjournal/ and $flagmatched==0){
($journal,$date,$number)=($preurldate=~m/$regexbfjournal/);
$flagmatched=1;
if($date!~m/\d{4}/){
$volume=$date;
$date='';
}
}
$regexbfjournal='(.*),\s(.*):\s(.*)\.';#没有卷/年,期
if($preurldate=~m/$regexbfjournal/ and $flagmatched==0){
($journal,$date,$pages)=($preurldate=~m/$regexbfjournal/);
$flagmatched=1;
if($date!~m/\d{4}/){
$volume=$date;
$date='';
}
}
if($flagmatched==0){
print 'the text after title was not matched, please add a regex for the current entry in the perl source code!',"\n";
print '当前条目标题之后的内容没有匹配的正则表达式,请在perl代码中增加适合该条目正则表达式!',"\n";
}
print 'journal =',$journal,"\n";
print 'date =',$date,"\n";
print 'volume =',$volume,"\n";
print 'number =',$number,"\n";
print 'pages =',$pages,"\n";
print 'urldate =',$urldate,"\n";
print 'url =',$url,"\n";
print 'doi =',$doi,"\n";
}
}
#---------------------------------------------------------------
#条目类型:判断报纸中析出的文献/newspaper
#---------------------------------------------------------------
if(1){
if($reference=~m/\[N\]/){
print 'this entry is newspaper',"\n";
$entrytype='newspaper';
$note='news';
$regexnewsflag='\[N\]';
$onlineflag=0;
}
if($reference=~m/\[N\/OL\]/){
print 'this entry is newspaper with url',"\n";
$entrytype='newspaper';
$note='news';
$regexnewsflag='\[N\/OL\]';
$onlineflag=1;
}
if($entrytype eq 'newspaper'){
if($onlineflag==1){
$regexformach='\[N\/OL\]';
&bfidentifier;
print 'has url',"\n";
$flagmatched=0;
$regexnewspostitle='\.\s(.*),\s(.*)\((.*)\)\s*\[(.*)\]\.\s(.*)';
if($reference=~m/$regexnewsflag$regexnewspostitle/ and $flagmatched==0){
$flagmatched=1;
($journal,$date,$number,$urldate,$posurl)=($reference=~m/$regexnewsflag$regexnewspostitle/);}
$regexnewspostitle='\.\s(.*),\s(.*)\s*\[(.*)\]\.\s(.*)';
if($reference=~m/$regexnewsflag$regexnewspostitle/ and $flagmatched==0){
$flagmatched=1;
($journal,$date,$urldate,$posurl)=($reference=~m/$regexnewsflag$regexnewspostitle/);}
if($flagmatched==0){
print 'the text after title was not matched, please add a regex for the current entry in the perl source code!',"\n";
print '当前条目标题之后的内容没有匹配的正则表达式,请在perl代码中增加适合该条目正则表达式!',"\n";
}
}else{
$regexformach='\[N\]';
&bfidentifier;
print 'no url',"\n";
$regexnewspostitle='\.\s(.*),\s(.*)\((.*)\)';
($journal,$date,$number)=($reference=~m/$regexnewsflag$regexnewspostitle/);
}
#处理url和doi
$regexposurl='(.*)doi:\s(.*)';#处理url和doi
if($posurl=~m/$regexposurl/i){
($url,$doi)=($posurl=~m/$regexposurl/i);
}else{
$url=$posurl;
}
# print 'journal =',$journal,"\n";
# print 'date =',$date,"\n";
# print 'volume =',$volume,"\n";
# print 'number =',$number,"\n";
# print 'pages =',$pages,"\n";
# print 'urldate =',$urldate,"\n";
# print 'url =',$url,"\n";
# print 'doi =',$doi,"\n";
}
}
#---------------------------------------------------------------
#条目类型:论文集中析出的文献/inproceedings
#---------------------------------------------------------------
if(1){#\/\/
if ($reference=~m/\[C\/OL\]\/\//){
$entrytype='inproceedings';
print "this entry's type is: $entrytype with url\n";
$regexformach='\[C\/OL\]\/\/';
&bfidentifier;
$regexformach='C\/OL\]\/\/';
&bfaddressinbook;
&afpublisherbookurl;
}elsif($reference=~m/\[C\]\/\//){
$entrytype='inproceedings';
print "this entry's type is: $entrytype \n";
$regexformach='\[C\]\/\/';
&bfidentifier;
$regexformach='C\]\/\/';
&bfaddressinbook;
&afpublisherbook;
}
if ($entrytype eq 'inproceedings'){
if ($address=~m/\[S\.l\.\]/ or $address=~m/出版地不详/) {#当存在英文的[s.n.]
$address="";
}
if ($publisher=~m/\[s\.n\.\]/ or $publisher=~m/出版者不详/) {#当存在英文的[s.n.]
$publisher="";
}
$date=$year;
}
}
#---------------------------------------------------------------
#条目类型:论文集/proceedings
#---------------------------------------------------------------
if(1){
if ($reference=~m/\[C\/OL\]\./){
$entrytype='proceedings';
print "this entry's type is: $entrytype with url\n";
$regexformach='\[C\/OL\]\.';
&bfidentifier;
$regexformach='C\/OL\]\.';
&bfaddressbook;
&afpublisherbookurl;
}elsif($reference=~m/\[C\]\./){
$entrytype='proceedings';
print "this entry's type is: $entrytype \n";
$regexformach='\[C\]\.';
&bfidentifier;
$regexformach='C\]\.';
&bfaddressbook;
&afpublisherbook;
}
if ($entrytype eq 'proceedings'){
if ($address=~m/\[S\.l\.\]/ or $address=~m/出版地不详/) {#当存在英文的[s.n.]
$address="";
}
if ($publisher=~m/\[s\.n\.\]/ or $publisher=~m/出版者不详/) {#当存在英文的[s.n.]
$publisher="";
}
$date=$year;
print 'date=',"$date";
}
}
#---------------------------------------------------------------
#条目类型:未出版物/unpublished
#---------------------------------------------------------------
if(1){
if ($reference=~m/\[Z\/OL\]\./){
$entrytype='unpublished';
print "this entry's type is: $entrytype with url\n";
$regexformach='\[Z\/OL\]\.';
&bfidentifier;
$regexformach='Z\/OL\]\.';
&bfaddressbook;
&afpublisherbookurlb;
}elsif($reference=~m/\[Z\]\./){
$entrytype='unpublished';
print "this entry's type is: $entrytype \n";
$regexformach='\[Z\]\.';
&bfidentifier;
$regexformach='Z\]\.';
&bfaddressbook;
&afpublisherbookb;
}
if ($entrytype eq 'unpublished'){
$date=$year;
print 'date=',"$date";
}
}
#---------------------------------------------------------------
#条目类型:手册、档案/manual
#---------------------------------------------------------------
if(1){
if ($reference=~m/\[A\/OL\]\./){
$entrytype='manual';
print "this entry's type is: $entrytype with url\n";
$regexformach='\[A\/OL\]\.';
&bfidentifier;
$regexformach='A\/OL\]\.';
&bfaddressbook;
&afpublisherbookurlb;
}elsif($reference=~m/\[A\]\./){
$entrytype='manual';
print "this entry's type is: $entrytype \n";
$regexformach='\[A\]\.';
&bfidentifier;
$regexformach='A\]\.';
&bfaddressbook;
&afpublisherbookb;
}
if ($entrytype eq 'manual'){
$date=$year;
print 'date=',"$date";
}
}
#---------------------------------------------------------------
#条目类型:报告/report
#---------------------------------------------------------------
if(1){
if ($reference=~m/\[R\/OL\]\./){
$entrytype='report';
print "this entry's type is: $entrytype with url\n";
$regexformach='\[R\/OL\]\.';
&bfidentifier;
$regexformach='R\/OL\]\.';
&bfaddressbook;
&afpublisherbookurlb;
}elsif($reference=~m/\[R\]\./){
$entrytype='report';
print "this entry's type is: $entrytype \n";
$regexformach='\[R\]\.';
&bfidentifier;
$regexformach='R\]\.';
&bfaddressbook;
&afpublisherbookb;
}
if ($entrytype eq 'report'){
$date=$year;
print 'date=',"$date";
}
}
#---------------------------------------------------------------
#条目类型:标准/standard
#---------------------------------------------------------------
if(1){
if ($reference=~m/\[S\/OL\]\./){
$entrytype='standard';
print "this entry's type is: $entrytype with url\n";
$regexformach='\[S\/OL\]\.';
&bfidentifier;
$regexformach='S\/OL\]\.';
&bfaddressbook;
&afpublisherbookurl;
}elsif($reference=~m/\[S\]\./){
$entrytype='standard';
print "this entry's type is: $entrytype \n";
$regexformach='\[S\]\.';
&bfidentifier;
$regexformach='S\]\.';
&bfaddressbook;
&afpublisherbook;
}elsif ($reference=~m/\[S\/OL\]\/\//){
$entrytype='standard';
print "this entry's type is: $entrytype with url\n";
$regexformach='\[S\/OL\]\/\/';
&bfidentifier;
$regexformach='S\/OL\]\/\/';
&bfaddressinbook;
&afpublisherbookurl;
}elsif($reference=~m/\[S\]\/\//){
$entrytype='standard';
print "this entry's type is: $entrytype \n";
$regexformach='\[S\]\/\/';
&bfidentifier;
$regexformach='S\]\/\/';
&bfaddressinbook;
&afpublisherbook;
}
if ($entrytype eq 'standard'){
if ($address=~m/\[S\.l\.\]/ or $address=~m/出版地不详/) {#当存在英文的[s.n.]
$address="";
}
if ($publisher=~m/\[s\.n\.\]/ or $publisher=~m/出版者不详/) {#当存在英文的[s.n.]
$publisher="";
}
$date=$year;
$note='standard';
print 'date=',"$date";
print 'note=',"$note";
}
}
#---------------------------------------------------------------
#条目类型:学位论文/thesis
#---------------------------------------------------------------
if(1){
if ($reference=~m/\[D\/OL\]\./){
$entrytype='thesis';
print "this entry's type is: $entrytype with url\n";
$regexformach='\[D\/OL\]\.';
&bfidentifier;
$regexformach='D\/OL\]\.';
&bfaddressbook;
&afpublisherbookurl;
}elsif($reference=~m/\[D\]\./){
$entrytype='thesis';
print "this entry's type is: $entrytype \n";
$regexformach='\[D\]\.';
&bfidentifier;
$regexformach='D\]\.';
&bfaddressbook;
&afpublisherbook;
}
if ($entrytype eq 'thesis'){
if ($address=~m/\[S\.l\.\]/ or $address=~m/出版地不详/) {#当存在英文的[s.n.]
$address="";
}
if ($publisher=~m/\[s\.n\.\]/ or $publisher=~m/出版者不详/) {#当存在英文的[s.n.]
$publisher="";
}
$date=$year;
print 'date=',"$date";
}
}
#---------------------------------------------------------------
#条目类型:汇编中析出的文献/incollection
#---------------------------------------------------------------
if(1){#\/\/
if ($reference=~m/\[G\/OL\]\/\//){
$entrytype='incollection';
print "this entry's type is: $entrytype with url\n";
$regexformach='\[G\/OL\]\/\/';
&bfidentifier;
$regexformach='G\/OL\]\/\/';
&bfaddressinbook;
&afpublisherbookurl;
}elsif($reference=~m/\[G\]\/\//){
$entrytype='incollection';
print "this entry's type is: $entrytype \n";
$regexformach='\[G\]\/\/';
&bfidentifier;
$regexformach='G\]\/\/';
&bfaddressinbook;
&afpublisherbook;
}
if ($entrytype eq 'incollection'){
if ($address=~m/\[S\.l\.\]/ or $address=~m/出版地不详/) {#当存在英文的[s.n.]
$address="";
}
if ($publisher=~m/\[s\.n\.\]/ or $publisher=~m/出版者不详/) {#当存在英文的[s.n.]
$publisher="";
}
$date=$year;
}
}
#---------------------------------------------------------------
#条目类型:汇编/collection
#---------------------------------------------------------------
if(1){
if ($reference=~m/\[G\/OL\]\./){
$entrytype='collection';
print "this entry's type is: $entrytype with url\n";
$regexformach='\[G\/OL\]\.';
&bfidentifier;
$regexformach='G\/OL\]\.';
&bfaddressbook;
&afpublisherbookurl;
}elsif($reference=~m/\[G\]\./){
$entrytype='collection';
print "this entry's type is: $entrytype \n";
$regexformach='\[G\]\.';
&bfidentifier;
$regexformach='G\]\.';
&bfaddressbook;
&afpublisherbook;
}
if ($entrytype eq 'collection'){
if ($address=~m/\[S\.l\.\]/ or $address=~m/出版地不详/) {#当存在英文的[s.n.]
$address="";
}
if ($publisher=~m/\[s\.n\.\]/ or $publisher=~m/出版者不详/) {#当存在英文的[s.n.]
$publisher="";
}
$date=$year;
print 'date=',"$date";
}
}
#---------------------------------------------------------------
#条目类型:专利/patent
#---------------------------------------------------------------
if(1){
if ($reference=~m/\[P\/OL\]\./){
$entrytype='patent';
print "this entry's type is: $entrytype with url\n";
$regexformach='\[P\/OL\]\.';
&bfidentifier;
}elsif($reference=~m/\[P\]\./){
$entrytype='patent';
print "this entry's type is: $entrytype \n";
$regexformach='\[P\]\.';
&bfidentifier;
}
if($entrytype eq 'patent'){
($postitle)=($reference=~m/$regexformach\s*(.*)/);
print 'postitle=',$postitle,"\n";
$titlenumber=$title;
if($titlenumber=~m/:\s*\d.*/){
($title,$number)=($titlenumber=~m/(.*):\s*(\d.*)/);
print 'title =',$title,"\n";
print 'number =',$number,"\n";
}
if($postitle=~m/\[.*\]/ and $reference=~m/\[P\/OL\]\./){
($date,$urldate,$posurl)=($postitle=~/(.*)\s*\[(.*)\]\.\s*(.*)/);
print 'date=',$date,"\n";
print 'urldate =',$urldate,"\n";
print 'posurl =',$posurl,"\n";
if($posurl=~m/DOI/i){#匹配存在doi的话
($url,$doi)=($posurl=~m/(.*)DOI:(.*)\./i);
print 'url=',"$url \n";
print 'doi=',"$doi \n";
}else{
$url=$posurl;
print 'url =',"$url \n";
}
}else{
$posurl=$postitle;
if($posurl=~m/DOI/i){#匹配存在doi的话
($date,$doi)=($posurl=~m/(.*)DOI:(.*)\./i);
print 'date=',"$date \n";
print 'doi =',"$doi \n";
}else{
$date=$posurl;
print 'date =',"$date \n";
}
}
}
}
#---------------------------------------------------------------
#条目类型:电子资源/online
#---------------------------------------------------------------
if(1){
if ($reference=~m/\[EB\/OL\]\./){#匹配[EB/OL]判断为online类型
$entrytype='online';
print "this entry's type is: $entrytype \n";
$regexformach='\[EB\/OL\]\.';
&bfidentifier;
($postitle)=($reference=~m/$regexformach\s*(.*)/);
print 'postitle=',$postitle,"\n";
if($postitle=~m/\(.*\)/ and $postitle=~m/\[.*\]/){#存在更新日期和引用日期
($eventdate,$urldate,$posurl)=($postitle=~/\s*\((.*)\)\s*\[(.*)\]\.\s*(.*)/);
}elsif($postitle=~m/\(.*\)/ and $postitle!~m/\[.*\]/){#存在更新日期但无引用日期
($eventdate,$posurl)=($postitle=~/\s*\((.*)\)\.\s*(.*)/);
}elsif($postitle!~m/\(.*\)/ and $postitle=~m/\[.*\]/){#存在引用日期但无更新日期
($urldate,$posurl)=($postitle=~/\s*\[(.*)\]\.\s*(.*)/);
}else{
($posurl)=($postitle=~/\s*(.*)/);
}
print 'eventdate=',$eventdate,"\n";
print 'urldate =',$urldate,"\n";
print 'posurl =',$posurl,"\n";
if($posurl=~m/DOI/i){#匹配存在doi的话
($url,$doi)=($posurl=~m/(.*)DOI:(.*)\./i);
print 'url=',"$url \n";
print 'doi=',"$doi \n";
}else{
$url=$posurl;
print 'url =',"$url \n";
}
}
}
#---------------------------------------------------------------
#条目类型:专著/book
#---------------------------------------------------------------
if(1){
if ($reference=~m/\[M\]\./){#匹配[M]判断为book类型
print "this entry's type is: book \n";
$entrytype='book';
$regexformach='\[M\]\.';
&bfidentifier;
$regexformach='M\]\.';
&bfaddressbook;
&afpublisherbook;
if ($address=~m/\[S\.l\.\]/ or $address=~m/出版地不详/) {#当存在英文的[s.n.]
$address="";
}
if ($publisher=~m/\[s\.n\.\]/ or $publisher=~m/出版者不详/) {#当存在英文的[s.n.]
$publisher="";
}
$date=$year;
}
}
#---------------------------------------------------------------
#条目类型:专著但存在网址/book with url
#---------------------------------------------------------------
if(1){
if ($reference=~m/\[M\/OL\]\./){
print "this entry's type is: book with url\n";
$entrytype='book';
$regexformach='\[M\/OL\]\.';
&bfidentifier;
$regexformach='M\/OL\]\.';
&bfaddressbook;
&afpublisherbookurl;
if ($address=~m/\[S\.l\.\]/ or $address=~m/出版地不详/) {#当存在英文的[s.n.]
$address="";
}
if ($publisher=~m/\[s\.n\.\]/ or $publisher=~m/出版者不详/) {#当存在英文的[s.n.]
$publisher="";
}
$date=$year;
}
}
#---------------------------------------------------------------
#条目类型:专著中析出文献/inbook
#---------------------------------------------------------------
if(1){
if ($reference=~m/\[M\]\/\//){#匹配[M]//判断为inbook类型
print "this entry's type is: inbook \n";
$entrytype='inbook';
$regexformach='\[M\]\/\/';
&bfidentifier;
$regexformach='M\]\/\/';
&bfaddressinbook;
&afpublisherbook;#出版社及之后的信息inbook/book一样的
if ($address=~m/\[S\.l\.\]/ or $address=~m/出版地不详/) {#当存在英文的[s.n.]
$address="";
}
if ($publisher=~m/\[s\.n\.\]/ or $publisher=~m/出版者不详/) {#当存在英文的[s.n.]
$publisher="";
}
$date=$year;
}
}
#---------------------------------------------------------------
#条目类型:专著中析出文献但存在网址/inbook with url
#---------------------------------------------------------------
if(1){
if ($reference=~m/\[M\/OL\]\/\//){#匹配[M]//判断为inbook类型
print "this entry's type is: inbook \n";
$entrytype='inbook';
$regexformach='\[M\/OL\]\/\/';
&bfidentifier;
$regexformach='M\/OL\]\/\/';
&bfaddressinbook;
&afpublisherbookurl;#出版社及之后的信息inbook/book一样的
if ($address=~m/\[S\.l\.\]/ or $address=~m/出版地不详/) {#当存在英文的[s.n.]
$address="";
}
if ($publisher=~m/\[s\.n\.\]/ or $publisher=~m/出版者不详/) {#当存在英文的[s.n.]
$publisher="";
}
$date=$year;
}
}
#---------------------------------------------------------------
#输出到bib文件中
#---------------------------------------------------------------
if(1){
if($date=~m/-\d{4}/){#存在enddate的情况下,将中间的连字符转化成斜杠
print 'date=',$date,"\n";
($datetempa,$datetempb)=($date=~m/(.*)-(\d{4}.*)/);
$date=$datetempa.'/'.$datetempb;
print 'date=',$date,"\n";
}
if($url=~m/.*\.$/){
$urlplusdot=$url;
($url)=($urlplusdot=~m/(.*)\.$/);#去掉处于条目末尾的url地址后的点
}
#最后输出
print "\n";
print '@',"$entrytype",'{',"ref-$nline-$sn",',',"\n";
$author&& print 'author = {',$author,'},',"\n";
$title&& print 'title = {',$title,'},',"\n";
$journal&& print 'journal = {',$journal,'},',"\n";
$translator&& print 'translator= {',$translator,'},',"\n";
$bookauthor&& print 'bookauthor= {',$bookauthor,'},',"\n";
$booktitle&& print 'booktitle = {',$booktitle,'},',"\n";
$version&& print 'version = {',$version,'},',"\n";
$address&& print 'address = {',$address,'},',"\n";
$publisher&& print 'publisher = {',$publisher,'},',"\n";
$type&& print 'type = {',$type,'},',"\n";
$date&& print 'date = {',$date,'},',"\n";
$volume&& print 'volume = {',$volume,'},',"\n";
$number&& print 'number = {',$number,'},',"\n";
$pages&& print 'pages = {',$pages,'},',"\n";
$eventdate&& print 'eventdate = {',$eventdate,'},',"\n";
$urldate&& print 'urldate = {',$urldate,'},',"\n";
$url&& print 'url = {',$url,'},',"\n";
$doi&& print 'doi = {',$doi,'},',"\n";
$note&& print 'note = {',$note,'},',"\n";
print '}',"\n";