From cc8dc5ca3ed674bf9ce3e00a3f45dd41839ed1bf Mon Sep 17 00:00:00 2001 From: Ognimalf <782865717@qq.com> Date: Thu, 14 Jul 2022 23:15:03 +0800 Subject: [PATCH] Support apa citation of some formats --- .../java/org/jabref/gui/EntryTypeView.java | 2 + .../model/entry/BibEntryTypesManager.java | 4 +- .../model/entry/field/StandardField.java | 4 ++ .../BiblatexAPAEntryTypeDefinitions.java | 37 +++++++++++++++++++ .../types/BibtexEntryTypeDefinitions.java | 14 +------ .../model/entry/types/StandardEntryType.java | 5 ++- .../model/entry/BibEntryTypesManagerTest.java | 2 + 7 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/jabref/model/entry/types/BiblatexAPAEntryTypeDefinitions.java diff --git a/src/main/java/org/jabref/gui/EntryTypeView.java b/src/main/java/org/jabref/gui/EntryTypeView.java index 10a95f3a5d0..0bec4381171 100644 --- a/src/main/java/org/jabref/gui/EntryTypeView.java +++ b/src/main/java/org/jabref/gui/EntryTypeView.java @@ -30,6 +30,7 @@ import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions; import org.jabref.model.entry.types.BiblatexSoftwareEntryTypeDefinitions; +import org.jabref.model.entry.types.BiblatexAPAEntryTypeDefinitions; import org.jabref.model.entry.types.BibtexEntryTypeDefinitions; import org.jabref.model.entry.types.EntryType; import org.jabref.model.entry.types.IEEETranEntryTypeDefinitions; @@ -157,6 +158,7 @@ public void initialize() { .filter(e -> !recommendedEntries.contains(e)) .collect(Collectors.toList()); otherEntries.addAll(BiblatexSoftwareEntryTypeDefinitions.ALL); + otherEntries.addAll(BiblatexAPAEntryTypeDefinitions.ALL); } else { recommendedEntries = BibtexEntryTypeDefinitions.RECOMMENDED; otherEntries = BibtexEntryTypeDefinitions.ALL diff --git a/src/main/java/org/jabref/model/entry/BibEntryTypesManager.java b/src/main/java/org/jabref/model/entry/BibEntryTypesManager.java index b737596abd6..5162ad98370 100644 --- a/src/main/java/org/jabref/model/entry/BibEntryTypesManager.java +++ b/src/main/java/org/jabref/model/entry/BibEntryTypesManager.java @@ -13,6 +13,7 @@ import org.jabref.model.entry.field.FieldFactory; import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions; import org.jabref.model.entry.types.BiblatexSoftwareEntryTypeDefinitions; +import org.jabref.model.entry.types.BiblatexAPAEntryTypeDefinitions; import org.jabref.model.entry.types.BibtexEntryTypeDefinitions; import org.jabref.model.entry.types.EntryType; import org.jabref.model.entry.types.EntryTypeFactory; @@ -21,7 +22,7 @@ public class BibEntryTypesManager { public static final String ENTRYTYPE_FLAG = "jabref-entrytype: "; private final InternalEntryTypes BIBTEX = new InternalEntryTypes(Stream.concat(BibtexEntryTypeDefinitions.ALL.stream(), IEEETranEntryTypeDefinitions.ALL.stream()).collect(Collectors.toList())); - private final InternalEntryTypes BIBLATEX = new InternalEntryTypes(Stream.concat(BiblatexEntryTypeDefinitions.ALL.stream(), BiblatexSoftwareEntryTypeDefinitions.ALL.stream()).collect(Collectors.toList())); + private final InternalEntryTypes BIBLATEX = new InternalEntryTypes(Stream.concat(BiblatexEntryTypeDefinitions.ALL.stream(), Stream.concat(BiblatexSoftwareEntryTypeDefinitions.ALL.stream(), BiblatexAPAEntryTypeDefinitions.ALL.stream())).collect(Collectors.toList())); public BibEntryTypesManager() { } @@ -99,6 +100,7 @@ public List getAllCustomTypes(BibDatabaseMode mode) { return customizedTypes.stream() .filter(entryType -> BiblatexEntryTypeDefinitions.ALL.stream().noneMatch(biblatexType -> biblatexType.getType().equals(entryType.getType()))) .filter(entryType -> BiblatexSoftwareEntryTypeDefinitions.ALL.stream().noneMatch(biblatexSoftware -> biblatexSoftware.getType().equals(entryType.getType()))) + .filter(entryType -> BiblatexAPAEntryTypeDefinitions.ALL.stream().noneMatch(biblatexAPA -> biblatexAPA.getType().equals(entryType.getType()))) .collect(Collectors.toList()); } } diff --git a/src/main/java/org/jabref/model/entry/field/StandardField.java b/src/main/java/org/jabref/model/entry/field/StandardField.java index 39c6f26d992..8199d7c7f6c 100644 --- a/src/main/java/org/jabref/model/entry/field/StandardField.java +++ b/src/main/java/org/jabref/model/entry/field/StandardField.java @@ -19,10 +19,12 @@ public enum StandardField implements Field { ADDENDUM("addendum"), ADDRESS("address"), AFTERWORD("afterword", FieldProperty.PERSON_NAMES), + AMENDMENT("amendment"), ANNOTE("annote"), ANNOTATION("annotation"), ANNOTATOR("annotator", FieldProperty.PERSON_NAMES), ARCHIVEPREFIX("archiveprefix"), + ARTICLE("article"), ASSIGNEE("assignee", FieldProperty.PERSON_NAMES), AUTHOR("author", FieldProperty.PERSON_NAMES), BOOKAUTHOR("bookauthor", FieldProperty.PERSON_NAMES), @@ -117,12 +119,14 @@ public enum StandardField implements Field { REVIEW("review"), REVISION("revision"), SCHOOL("school"), + SECTION("section", FieldProperty.NUMERIC), SERIES("series"), SHORTAUTHOR("shortauthor", FieldProperty.PERSON_NAMES), SHORTEDITOR("shorteditor", FieldProperty.PERSON_NAMES), SHORTTITLE("shorttitle"), SORTKEY("sortkey"), SORTNAME("sortname", FieldProperty.PERSON_NAMES), + SOURCE("source"), SUBTITLE("subtitle"), SWHID("swhid"), TITLE("title"), diff --git a/src/main/java/org/jabref/model/entry/types/BiblatexAPAEntryTypeDefinitions.java b/src/main/java/org/jabref/model/entry/types/BiblatexAPAEntryTypeDefinitions.java new file mode 100644 index 00000000000..f52f6edc153 --- /dev/null +++ b/src/main/java/org/jabref/model/entry/types/BiblatexAPAEntryTypeDefinitions.java @@ -0,0 +1,37 @@ +package org.jabref.model.entry.types; + +import org.jabref.model.entry.BibEntryType; +import org.jabref.model.entry.BibEntryTypeBuilder; +import org.jabref.model.entry.field.StandardField; + +import java.util.Arrays; +import java.util.List; + +public class BiblatexAPAEntryTypeDefinitions { + + private static final BibEntryType JURISDICTION = new BibEntryTypeBuilder() + .withType(StandardEntryType.JURISDICTION) + .withDetailFields(StandardField.ORGANIZATION, StandardField.CITATION_CITEORG, StandardField.CITATION_CITEDATE, StandardField.CITATION_CITEDATE, StandardField.ORIGDATE) + .withRequiredFields(StandardField.TITLE, StandardField.CITATION, StandardField.CITATION_CITEINFO, StandardField.URL, StandardField.DATE) + .build(); + + private static final BibEntryType LEGISLATION = new BibEntryTypeBuilder() + .withType(StandardEntryType.LEGISLATION) + .withImportantFields(StandardField.TITLEADDON, StandardField.ORIGDATE) + .withRequiredFields(StandardField.TITLE, StandardField.LOCATION, StandardField.URL, StandardField.DATE) + .build(); + + private static final BibEntryType LEGADMINMATERIAL = new BibEntryTypeBuilder() + .withType(StandardEntryType.LEGADMINMATERIAL) + .withImportantFields(StandardField.NUMBER, StandardField.SHORTTITLE, StandardField.NOTE, StandardField.KEYWORDS) + .withRequiredFields(StandardField.TITLE, StandardField.CITATION, StandardField.URL, StandardField.DATE) + .build(); + + private static final BibEntryType CONSTITUTION = new BibEntryTypeBuilder() + .withType(StandardEntryType.CONSTITUTION) + .withImportantFields(StandardField.ARTICLE, StandardField.AMENDMENT, StandardField.EVENTDATE, StandardField.KEYWORDS, StandardField.PART, StandardField.SECTION) + .withRequiredFields(StandardField.SOURCE, StandardField.TYPE) + .build(); + + public static final List ALL = Arrays.asList(JURISDICTION, LEGISLATION, LEGADMINMATERIAL, CONSTITUTION); +} diff --git a/src/main/java/org/jabref/model/entry/types/BibtexEntryTypeDefinitions.java b/src/main/java/org/jabref/model/entry/types/BibtexEntryTypeDefinitions.java index 08cf56625b9..8ee79a27c30 100644 --- a/src/main/java/org/jabref/model/entry/types/BibtexEntryTypeDefinitions.java +++ b/src/main/java/org/jabref/model/entry/types/BibtexEntryTypeDefinitions.java @@ -98,18 +98,6 @@ public class BibtexEntryTypeDefinitions { .withImportantFields(StandardField.EDITOR, StandardField.VOLUME, StandardField.NUMBER, StandardField.SERIES, StandardField.PAGES, StandardField.ADDRESS, StandardField.MONTH, StandardField.ORGANIZATION, StandardField.PUBLISHER, StandardField.NOTE) .build(); - /** - * A jurisdiction from court case. - *

- * Required fields: title, citation, CITATION+an:citeorg, CITATION+an:citedate, CITATION+an:citeinfo, url, date, origdate - * Optional fields: none - */ - private static final BibEntryType JURISDICTION_APA = new BibEntryTypeBuilder() - .withType(StandardEntryType.JURISDICTION_APA) - .withRequiredFields(StandardField.TITLE, StandardField.CITATION, StandardField.CITATION_CITEINFO, StandardField.URL, StandardField.DATE) - .withDetailFields(StandardField.ORGANIZATION, StandardField.CITATION_CITEORG, StandardField.CITATION_CITEDATE, StandardField.CITATION_CITEDATE, StandardField.ORIGDATE) - .build(); - /** * Technical documentation. * Required field: title. @@ -190,7 +178,7 @@ public class BibtexEntryTypeDefinitions { .build(); public static final List ALL = Arrays.asList(ARTICLE, INBOOK, BOOK, BOOKLET, INCOLLECTION, CONFERENCE, - INPROCEEDINGS, PROCEEDINGS, MANUAL, MASTERSTHESIS, PHDTHESIS, TECHREPORT, UNPUBLISHED, MISC, JURISDICTION_APA); + INPROCEEDINGS, PROCEEDINGS, MANUAL, MASTERSTHESIS, PHDTHESIS, TECHREPORT, UNPUBLISHED, MISC); public static final List RECOMMENDED = Arrays.asList(ARTICLE, BOOK, INPROCEEDINGS, TECHREPORT, MISC); diff --git a/src/main/java/org/jabref/model/entry/types/StandardEntryType.java b/src/main/java/org/jabref/model/entry/types/StandardEntryType.java index e011e2c97bf..3395a5e246f 100644 --- a/src/main/java/org/jabref/model/entry/types/StandardEntryType.java +++ b/src/main/java/org/jabref/model/entry/types/StandardEntryType.java @@ -21,8 +21,11 @@ public enum StandardEntryType implements EntryType { Unpublished("Unpublished"), // Biblatex BookInBook("BookInBook"), + CONSTITUTION("Constitution"), InReference("InReference"), - JURISDICTION_APA("Jurisdiction_apa"), + LEGISLATION("Legislation"), + LEGADMINMATERIAL("Legadminmaterial"), + JURISDICTION("Jurisdiction"), MvBook("MvBook"), MvCollection("MvCollection"), MvProceedings("MvProceedings"), diff --git a/src/test/java/org/jabref/model/entry/BibEntryTypesManagerTest.java b/src/test/java/org/jabref/model/entry/BibEntryTypesManagerTest.java index 48b47bc4f32..7ee35d67628 100644 --- a/src/test/java/org/jabref/model/entry/BibEntryTypesManagerTest.java +++ b/src/test/java/org/jabref/model/entry/BibEntryTypesManagerTest.java @@ -15,6 +15,7 @@ import org.jabref.model.entry.field.UnknownField; import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions; import org.jabref.model.entry.types.BiblatexSoftwareEntryTypeDefinitions; +import org.jabref.model.entry.types.BiblatexAPAEntryTypeDefinitions; import org.jabref.model.entry.types.BibtexEntryTypeDefinitions; import org.jabref.model.entry.types.EntryType; import org.jabref.model.entry.types.IEEETranEntryTypeDefinitions; @@ -74,6 +75,7 @@ void allTypesBibtexAreCorrect() { void allTypesBiblatexAreCorrect() { TreeSet defaultTypes = new TreeSet<>(BiblatexEntryTypeDefinitions.ALL); defaultTypes.addAll(BiblatexSoftwareEntryTypeDefinitions.ALL); + defaultTypes.addAll(BiblatexAPAEntryTypeDefinitions.ALL); assertEquals(defaultTypes, entryTypesManager.getAllTypes(BibDatabaseMode.BIBLATEX)); }