Skip to content

Commit

Permalink
整理学科领域
Browse files Browse the repository at this point in the history
  • Loading branch information
zepinglee committed Jul 16, 2024
1 parent 78e536d commit 5fdbc70
Show file tree
Hide file tree
Showing 92 changed files with 307 additions and 211 deletions.
105 changes: 99 additions & 6 deletions lib/check_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,105 @@
]


VALID_FIELDS = [
"anthropology",
"astronomy",
"biology",
"botany",
"chemistry",
"communications",
"engineering",
"generic-base",
"geography",
"geology",
"history",
"humanities",
"law",
"linguistics",
"literature",
"math",
"medicine",
"philosophy",
"physics",
"political_science",
"psychology",
"science",
"social_science",
"sociology",
"theology",
"zoology",
]


def info(s):
print(f"Info: {s}", file=sys.stderr)


def warning(s):
print(f"Warning: {s}", file=sys.stderr)

def check_fields(file, csl_content, root):
for field_el in root.xpath(".//cs:category[@field]", namespaces=ns):
field = field_el.attrib["field"]
if field not in VALID_FIELDS:
msg = f'File "{file}", line {field_el.sourceline}: Invalid field'
warning(msg)


def check_field(file, csl_content, root):
field = ""
fields = []
field_el = None
for field_el in root.xpath(".//cs:category[@field]", namespaces=ns):
if not field:
field = field_el.attrib["field"]
fields.append(field_el.attrib["field"])

title = root.xpath(".//cs:title", namespaces=ns)[0].text
style_id = root.xpath(".//cs:id", namespaces=ns)[0].text
summary = ""
if summary_els := root.xpath(".//cs:summary", namespaces=ns):
summary = summary_els[0].text

if "export" in style_id:
return

if not field:
msg = f'File "{file}": Empty field'
warning(msg)

if "GB/T 7714" in title:
assert field == "generic-base"
return

# fields_str = " ".join(fields)
# # if fields_str != "generic-base":
# if len(fields) > 1:
# print(title, fields_str, sep="\t")

if field == "generic-base":

def warn_field(file, field_el):
if field_el is not None:
msg = f'File "{file}", line {field_el.sourceline}: Inappropriate field'
else:
msg = f'File "{file}": Inappropriate field'
warning(msg)

if (
"journal" in title.lower()
or "学报" in title
or "journal" in style_id
or root.xpath(".//cs:issn", namespaces=ns)
):
if "编排规范" in title:
return
warn_field(file, field_el)
# elif "学位论文" not in summary and "出版社" not in title:
# warn_field(file, field_el)
elif "大学" not in title and "研究院" not in title and "科学院" not in title and "出版社" not in title:
warn_field(file, field_el)


def check_affixes(path, root):
for element in root.xpath(".//*[@prefix='']"):
Expand Down Expand Up @@ -323,10 +415,6 @@ def reorder_info_items(root):
tag += "[@citation-format]"
if (tag == "category") & (infoNode.get("field") is not None):
tag += "[@field]"
try:
counter.append((INFO_ITEM_ORDER.index(tag), infoNode.get("field")))
except:
print("Unknown element: " + tag)
# check if node is a comment
elif etree.tostring(
infoNode, encoding="utf-8", xml_declaration=False
Expand Down Expand Up @@ -415,6 +503,10 @@ def check_style(file):

# info(f'Running test of "{style_name}.csl"')

check_fields(file, csl_content, style)

check_field(file, csl_content, style)

check_affixes(file, root)

check_conditions(file, csl_content, style)
Expand Down Expand Up @@ -448,15 +540,16 @@ def write_style(style, path):
# style_str = style_str.replace("–", "–") # en dash
style_str = style_str.replace("–", "–") # en dash
style_str = style_str.replace("—", "—") # em dash
style_str = style_str.replace("GB/T 7714—", "GB/T 7714—") # em dash
style_str = re.sub(r"(\S)[ \t]+<!--", r"\1 <!--", style_str)
style_str = re.sub(r"<!--\s*(\S)", r"<!-- \1", style_str)
style_str = re.sub(r"(\S)[ \t]*-->", r"\1 -->", style_str)

if style_str != original_content:
now = datetime.datetime.now().astimezone().isoformat(timespec="seconds")
style_str = re.sub(r"<updated>[^<]*</updated>", f"<updated>{now}</updated>", style_str)
with open(path, "w") as f:
f.write(style_str)
with open(path, "w") as f:
f.write(style_str)


def main():
Expand Down
4 changes: 2 additions & 2 deletions src/accounting-research/accounting-research.csl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<email>[email protected]</email>
</author>
<category citation-format="author-date"/>
<category field="generic-base"/>
<updated>2024-06-06T13:18:48+08:00</updated>
<category field="social_science"/>
<updated>2024-07-16T16:16:21+08:00</updated>
<rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
</info>
<locale xml:lang="zh">
Expand Down
4 changes: 2 additions & 2 deletions src/accounting-research/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
],
"contributor": [],
"citation_format": "author-date",
"field": "generic-base",
"updated": "2024-06-06T13:18:48+08:00",
"field": "social_science",
"updated": "2024-07-16T16:16:21+08:00",
"citations": "(库恩, 2012)<br>\n(Fourney, c1971)<br>\n(贾东琴和柯平, 2011)<br>\n(Fan &#38; Sommers, 2013)<br>\n(武丽丽等, 2008)<br>\n(Myburg et al., 2014)<br>\n(中国互联网络信息中心, 2012; Bawden, 2008)<br>\n",
"bibliography": "<div class=\"csl-bib-body maxoffset-0 second-field-align-false hangingindent-true\">\n <div class=\"csl-entry\">贾东琴, 柯平. 2011. 面向数字素养的高校图书馆数字服务体系研究. 中国图书馆学会, 编//中国图书馆学会年会论文集. 北京: 国家图书馆出版社: 45~52.</div>\n <div class=\"csl-entry\">库恩. 2012. 科学革命的结构: 第 4 版. 金吾伦, 胡新和, 译. 2 版. 北京: 北京大学出版社.</div>\n <div class=\"csl-entry\">武丽丽, 华一新, 张亚军, 刘英敏. 2008. “北斗一号”监控管理网设计与实现. 测绘科学, 5: 8~9[2009–10–25].</div>\n <div class=\"csl-entry\">中国互联网络信息中心. 2012. 第 29 次中国互联网络发展现状统计报告. [2013–03–26].</div>\n <div class=\"csl-entry\">Bawden, D. 2008. Origins and Concepts of Digital Literacy(2008–05–04)[2013–03–08].</div>\n <div class=\"csl-entry\">Fan, X., C. H. Sommers. 2013. Food Irradiation Research and Technology. 2 edition. Ames, Iowa: Blackwell Publishing: 25~26[2014–06–26].</div>\n <div class=\"csl-entry\">Fourney, M. E. c1971. Advances in Holographic Photoelasticity//Symposium on Applications of Holography in Mechanics. New York: ASME: 17~38.</div>\n <div class=\"csl-entry\">Myburg, A. A., D. Grattapaglia, G. A. Tuskan, U. Hellsten, R. D. Hayes, J. Grimwood, J. Jenkins, E. Lindquist, H. Tice, D. Bauer, D. M. Goodstein, I. Dubchak, A. Poliakov, E. Mizrachi, A. R. K. Kullan, S. G. Hussey, D. Pinard, K. van der Merwe, P. Singh, I. van Jaarsveld, O. B. Silva-Junior, R. C. Togawa, M. R. Pappas, D. A. Faria, C. P. Sansaloni, C. D. Petroli, X. Yang, P. Ranjan, T. J. Tschaplinski, C.-Y. Ye, T. Li, L. Sterck, K. Vanneste, F. Murat, M. Soler, H. S. Clemente, N. Saidi, H. Cassan-Wang, C. Dunand, C. A. Hefer, E. Bornberg-Bauer, A. R. Kersting, K. Vining, V. Amarasinghe, M. Ranik, S. Naithani, J. Elser, A. E. Boyd, A. Liston, J. W. Spatafora, P. Dharmwardhana, R. Raja, C. Sullivan, E. Romanel, M. Alves-Ferreira, C. Külheim, W. Foley, V. Carocha, J. Paiva, D. Kudrna, S. H. Brommonschenkel, G. Pasquali, M. Byrne, P. Rigault, J. Tibbits, A. Spokevicius, R. C. Jones, D. A. Steane, R. E. Vaillancourt, B. M. Potts, F. Joubert, K. Barry, G. J. Pappas, S. H. Strauss, P. Jaiswal, J. Grima-Pettenati, J. Salse, Y. Van de Peer, D. S. Rokhsar, J. Schmutz. 2014. The Genome of Eucalyptus Grandis. Nature, 510: 356~362[2014–06–25].</div>\n</div>",
"tags": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
<email>[email protected]</email>
</author>
<category citation-format="numeric"/>
<category field="generic-base"/>
<category field="science"/>
<issn>1000-7091</issn>
<summary>添加平行语言支持,即在中文文献后添加其英文的翻译。作者为首字母大写。文章的题目大小写与 `Zotero` 中的 `Title` 字段一致,不显示 `URL`。</summary>
<updated>2024-06-18T15:39:15+08:00</updated>
<updated>2024-07-16T16:09:56+08:00</updated>
<rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
</info>
<locale xml:lang="zh">
Expand Down
4 changes: 2 additions & 2 deletions src/acta-agriculurae-boreali-sinica/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
],
"contributor": [],
"citation_format": "numeric",
"field": "generic-base",
"field": "science",
"summary": "添加平行语言支持,即在中文文献后添加其英文的翻译。作者为首字母大写。文章的题目大小写与 `Zotero` 中的 `Title` 字段一致,不显示 `URL`。",
"updated": "2024-06-18T15:39:15+08:00",
"updated": "2024-07-16T16:09:56+08:00",
"citations": "<sup>[1–8]</sup>",
"bibliography": "<div class=\"csl-bib-body maxoffset-8 second-field-align-false hangingindent-false\">\n <div class=\"csl-entry\">[1] 库恩. 科学革命的结构: 第 4 版[M]. 金吾伦, 胡新和, 译. 2 版. 北京: 北京大学出版社, 2012.\n <div class=\"csl-block\">科学革命的结构.</div>\n </div>\n <div class=\"csl-entry\">[2] Fan X, Sommers C H. Food irradiation research and technology[M]. 2 edition. Ames, Iowa: Blackwell Publishing, 2013: 25-26.</div>\n <div class=\"csl-entry\">[3] 贾东琴, 柯平. 面向数字素养的高校图书馆数字服务体系研究[C]. 中国图书馆学会, 编//中国图书馆学会年会论文集. 北京: 国家图书馆出版社, 2011: 45-52.</div>\n <div class=\"csl-entry\">[4] Fourney M E. Advances in holographic photoelasticity[C]//Symposium on Applications of Holography in Mechanics. New York: ASME, c1971: 17-38.</div>\n <div class=\"csl-entry\">[5] 武丽丽, 华一新, 张亚军, 刘英敏. “北斗一号”监控管理网设计与实现[J]. 测绘科学, 2008, 33(5): 8-9. doi: <a href=\"https://doi.org/10.3771/j.issn.1009-2307.2008.05.002\">10.3771/j.issn.1009-2307.2008.05.002</a>.</div>\n <div class=\"csl-entry\">[6] Myburg A A, Grattapaglia D, Tuskan G A, Hellsten U, Hayes R D, Grimwood J, Jenkins J, Lindquist E, Tice H, Bauer D, Goodstein D M, Dubchak I, Poliakov A, Mizrachi E, Kullan A R K, Hussey S G, Pinard D, van der Merwe K, Singh P, van Jaarsveld I, Silva-Junior O B, Togawa R C, Pappas M R, Faria D A, Sansaloni C P, Petroli C D, Yang X, Ranjan P, Tschaplinski T J, Ye C-Y, Li T, Sterck L, Vanneste K, Murat F, Soler M, Clemente H S, Saidi N, Cassan-Wang H, Dunand C, Hefer C A, Bornberg-Bauer E, Kersting A R, Vining K, Amarasinghe V, Ranik M, Naithani S, Elser J, Boyd A E, Liston A, Spatafora J W, Dharmwardhana P, Raja R, Sullivan C, Romanel E, Alves-Ferreira M, Külheim C, Foley W, Carocha V, Paiva J, Kudrna D, Brommonschenkel S H, Pasquali G, Byrne M, Rigault P, Tibbits J, Spokevicius A, Jones R C, Steane D A, Vaillancourt R E, Potts B M, Joubert F, Barry K, Pappas G J, Strauss S H, Jaiswal P, Grima-Pettenati J, Salse J, Van de Peer Y, Rokhsar D S, Schmutz J. The genome of eucalyptus grandis[J]. Nature, 2014, 510: 356-362. doi: <a href=\"https://doi.org/10.1038/nature13308\">10.1038/nature13308</a>.</div>\n <div class=\"csl-entry\">[7] 中国互联网络信息中心. 第 29 次中国互联网络发展现状统计报告[R].(2012-01-16). [2013-03-26]. <a href=\"http://www.cnnic.net.cn/hlwfzyj/hlwxzbg/201201/P020120709345264469680\">http://www.cnnic.net.cn/hlwfzyj/hlwxzbg/201201/P020120709345264469680</a>.</div>\n <div class=\"csl-entry\">[8] Bawden D. Origins and concepts of digital literacy[EB](2008-05-04).</div>\n</div>",
"tags": [
Expand Down
3 changes: 2 additions & 1 deletion src/acta-geologica-sinica/acta-geologica-sinica.csl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
<email>[email protected]</email>
</author>
<category citation-format="author-date"/>
<category field="geology"/>
<summary>1. 按照语言显示“等”或“et al.”;2. 姓名取消全大写;3. 仅纯电子资源显示引用日期和 URL;4. 无 DOI;5. 正文的引用使用全角括号。</summary>
<updated>2024-06-18T23:21:28+08:00</updated>
<updated>2024-07-16T16:16:48+08:00</updated>
<rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
</info>
<locale xml:lang="zh">
Expand Down
3 changes: 2 additions & 1 deletion src/acta-geologica-sinica/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
],
"contributor": [],
"citation_format": "author-date",
"field": "geology",
"summary": "1. 按照语言显示“等”或“et al.”;2. 姓名取消全大写;3. 仅纯电子资源显示引用日期和 URL;4. 无 DOI;5. 正文的引用使用全角括号。",
"updated": "2024-06-18T23:21:28+08:00",
"updated": "2024-07-16T16:16:48+08:00",
"citations": "(库恩, 2012)<br>\n(Fourney, c1971)<br>\n(贾东琴等, 2011)<br>\n(Fan et al., 2013)<br>\n(武丽丽等, 2008)<br>\n(Myburg et al., 2014)<br>\n(中国互联网络信息中心, 2012; Bawden, 2008)<br>\n",
"bibliography": "<div class=\"csl-bib-body maxoffset-0 second-field-align-false hangingindent-true\">\n <div class=\"csl-entry\">贾东琴, 柯平, 2011. 面向数字素养的高校图书馆数字服务体系研究[C]//中国图书馆学会. 中国图书馆学会年会论文集: 2011 年卷. 北京: 国家图书馆出版社: 45-52.</div>\n <div class=\"csl-entry\">库恩, 2012. 科学革命的结构: 第 4 版[M]. 金吾伦, 胡新和, 译. 2 版. 北京: 北京大学出版社.</div>\n <div class=\"csl-entry\">武丽丽, 华一新, 张亚军, 等, 2008. “北斗一号”监控管理网设计与实现[J]. 测绘科学, 33(5): 8-9.</div>\n <div class=\"csl-entry\">中国互联网络信息中心, 2012. 第 29 次中国互联网络发展现状统计报告[R].</div>\n <div class=\"csl-entry\">Bawden D, 2008. Origins and concepts of digital literacy[EB/OL]. (2008-05-04)[2013-03-08]. <a href=\"http://www.soi.city.ac.uk/~dbawden/digital%20literacy%20chapter.pdf\">http://www.soi.city.ac.uk/~dbawden/digital%20literacy%20chapter.pdf</a>.</div>\n <div class=\"csl-entry\">Fan X, Sommers C H, 2013. Food irradiation research and technology[M]. 2nd ed. Ames, Iowa: Blackwell Publishing: 25-26.</div>\n <div class=\"csl-entry\">Fourney M E, c1971. Advances in holographic photoelasticity[C]//Symposium on Applications of Holography in Mechanics, August 23–25, 1971, University of Southern California, Los Angeles, California. New York: ASME: 17-38.</div>\n <div class=\"csl-entry\">Myburg A A, Grattapaglia D, Tuskan G A, et al., 2014. The genome of eucalyptus grandis[J]. Nature, 510: 356-362.</div>\n</div>",
"tags": [
Expand Down
4 changes: 2 additions & 2 deletions src/acta-microbiologica-sinica/acta-microbiologica-sinica.csl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<email>[email protected]</email>
</author>
<category citation-format="numeric"/>
<category field="generic-base"/>
<category field="biology"/>
<summary>文章的题目大小写与 `Zotero` 中的 `Title` 字段一致,不显示 `URL` 和 `DOI`。</summary>
<updated>2024-06-06T13:18:48+08:00</updated>
<updated>2024-07-16T16:17:07+08:00</updated>
<rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
</info>
<locale xml:lang="zh">
Expand Down
4 changes: 2 additions & 2 deletions src/acta-microbiologica-sinica/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
],
"contributor": [],
"citation_format": "numeric",
"field": "generic-base",
"field": "biology",
"summary": "文章的题目大小写与 `Zotero` 中的 `Title` 字段一致,不显示 `URL` 和 `DOI`。",
"updated": "2024-06-06T13:18:48+08:00",
"updated": "2024-07-16T16:17:07+08:00",
"citations": "<sup>[1–8]</sup>",
"bibliography": "<div class=\"csl-bib-body maxoffset-0 second-field-align-false hangingindent-false\">\n <div class=\"csl-entry\">[1] 库恩. 科学革命的结构: 第 4 版[M]. 金吾伦, 胡新和, 译. 2 版. 北京: 北京大学出版社, 2012.</div>\n <div class=\"csl-entry\">[2] Fan X, Sommers C H. Food irradiation research and technology[M/OL]. 2 edition. Ames, Iowa: Blackwell Publishing, 2013: 25-26[2014-06-26].</div>\n <div class=\"csl-entry\">[3] 贾东琴, 柯平. 面向数字素养的高校图书馆数字服务体系研究[C]. 中国图书馆学会, 编//中国图书馆学会年会论文集. 北京: 国家图书馆出版社, 2011: 45-52.</div>\n <div class=\"csl-entry\">[4] Fourney M E. Advances in holographic photoelasticity[C]//Symposium on Applications of Holography in Mechanics. New York: ASME, c1971: 17-38.</div>\n <div class=\"csl-entry\">[5] 武丽丽, 华一新, 张亚军, 刘英敏. “北斗一号”监控管理网设计与实现[J/OL]. 测绘科学, 2008, 33(5): 8-9[2009-10-25].</div>\n <div class=\"csl-entry\">[6] Myburg A A, Grattapaglia D, Tuskan G A, Hellsten U, Hayes R D, Grimwood J, Jenkins J, Lindquist E, Tice H, Bauer D, Goodstein D M, Dubchak I, Poliakov A, Mizrachi E, Kullan A R K, Hussey S G, Pinard D, van der Merwe K, Singh P, van Jaarsveld I, Silva-Junior O B, Togawa R C, Pappas M R, Faria D A, Sansaloni C P, Petroli C D, Yang X, Ranjan P, Tschaplinski T J, Ye C-Y, Li T, Sterck L, Vanneste K, Murat F, Soler M, Clemente H S, Saidi N, Cassan-Wang H, Dunand C, Hefer C A, Bornberg-Bauer E, Kersting A R, Vining K, Amarasinghe V, Ranik M, Naithani S, Elser J, Boyd A E, Liston A, Spatafora J W, Dharmwardhana P, Raja R, Sullivan C, Romanel E, Alves-Ferreira M, Külheim C, Foley W, Carocha V, Paiva J, Kudrna D, Brommonschenkel S H, Pasquali G, Byrne M, Rigault P, Tibbits J, Spokevicius A, Jones R C, Steane D A, Vaillancourt R E, Potts B M, Joubert F, Barry K, Pappas G J, Strauss S H, Jaiswal P, Grima-Pettenati J, Salse J, Van de Peer Y, Rokhsar D S, Schmutz J. The genome of eucalyptus grandis[J/OL]. Nature, 2014, 510: 356-362[2014-06-25].</div>\n <div class=\"csl-entry\">[7] 中国互联网络信息中心. 第 29 次中国互联网络发展现状统计报告[R/OL].(2012-01-16). [2013-03-26]. <a href=\"http://www.cnnic.net.cn/hlwfzyj/hlwxzbg/201201/P020120709345264469680\">http://www.cnnic.net.cn/hlwfzyj/hlwxzbg/201201/P020120709345264469680</a>[2013-03-26].</div>\n <div class=\"csl-entry\">[8] Bawden D. Origins and concepts of digital literacy[EB/OL](2008-05-04)[2013-03-08].</div>\n</div>",
"tags": [
Expand Down
7 changes: 4 additions & 3 deletions src/advances-in-water-science/advances-in-water-science.csl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<email>[email protected]</email>
</author>
<category citation-format="numeric"/>
<category field="generic-base"/>
<category field="science"/>
<issn>l001-6791</issn>
<summary>1. 按照语言显示“等”或“et al.”;2. 仅纯电子资源显示引用日期和 URL;3. 无 DOI;4. 中文文献的英译(中文文献需要将作者姓名、标题、期刊、出版地、出版社的英文翻译分别填写在 `extra` 中的 `original-author`, `original-title`, `original-container-title`, `original-publisher-place`, `original-publisher` 字段。)。</summary>
<updated>2024-06-06T22:19:17+08:00</updated>
<updated>2024-07-16T16:10:04+08:00</updated>
<rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
</info>
<locale xml:lang="zh">
Expand Down Expand Up @@ -488,7 +488,8 @@
<text macro="title"/>
<text macro="secondary-contributors"/>
</group>
<text macro="container-booklike"/></group>
<text macro="container-booklike"/>
</group>
<text macro="edition"/>
<text macro="publisher"/>
</else-if>
Expand Down
Loading

0 comments on commit 5fdbc70

Please sign in to comment.