Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check integrity edition check implemented #1914

Merged
merged 28 commits into from
Sep 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
06c492f
Check integrity edition check
Sep 3, 2016
dcbb5c1
Merge remote-tracking branch 'upstream/master' into edition
Sep 3, 2016
41b8e3e
Conflict in Jabref_fr
Sep 3, 2016
492ca59
Changed order Biblatex/Bibtex condition
Sep 3, 2016
78bcc65
Create own object
Sep 3, 2016
36a6b3c
Rename variable
Sep 4, 2016
b7acdce
Merge remote-tracking branch 'upstream/master' into edition
Sep 5, 2016
958ca0a
Extract checker to own file
Sep 5, 2016
34d7795
Merge remote-tracking branch 'upstream/master' into edition
Sep 5, 2016
a1361b7
Improved comment
Sep 5, 2016
9c55d38
French localization: Jabref_fr: empty strings translated + removal of…
mlep Sep 2, 2016
3bcac87
Remove teamscale findings in the database package (#1577)
tschechlovdev Sep 3, 2016
a9fb9c8
Check integrity edition check
Sep 3, 2016
1674dd8
Changed order Biblatex/Bibtex condition
Sep 3, 2016
1b188ad
Create own object
Sep 3, 2016
8fa7eef
Rename variable
Sep 4, 2016
9a458f9
Mark some methods as deprecated in BibEntry and BibDatabase (#1913)
tobiasdiez Sep 4, 2016
11ecf09
Fix location field not exported correctly to office 2007 xml (#1909)
Siedlerchr Sep 4, 2016
dd6b5d9
Add possibility to remember password for shared databases. (#1846)
obraliar Sep 4, 2016
3be1ff0
Extract checker to own file
Sep 5, 2016
d0a5747
Improved comment
Sep 5, 2016
aa64626
Translation of shared (#1919)
oscargus Sep 5, 2016
a0e6d0b
Add missing entries in german localization
lenhard Sep 5, 2016
8d2ae91
Merge remote-tracking branch 'upstream/master' into edition
Sep 5, 2016
fc67a78
Merge branch 'edition' of https://github.com/grimes2/jabref into edition
Sep 5, 2016
df38c8b
Resolved conflicts
Sep 5, 2016
01d2b14
Some more conflicts de sv
Sep 5, 2016
fdbc9a2
Expressions changed
Sep 5, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- [#1813](https://github.com/JabRef/jabref/issues/1813) Import/Export preferences dialog default directory set to working directory
- [#1897](https://github.com/JabRef/jabref/issues/1897) Implemented integrity check for `year` field: Last four nonpunctuation characters should be numerals
- Address in MS-Office 2007 xml format is now imported as `location`

- [#1912](https://github.com/JabRef/jabref/issues/1912) Implemented integrity check for `edition` field: Should have the first letter capitalized (BibTeX), Should contain an integer or a literal (BibLaTeX)

### Fixed
- Fixed selecting an entry out of multiple duplicates
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/net/sf/jabref/logic/integrity/EditionChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package net.sf.jabref.logic.integrity;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Pattern;

import net.sf.jabref.BibDatabaseContext;
import net.sf.jabref.logic.integrity.IntegrityCheck.Checker;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;

public class EditionChecker implements Checker {

private static final Predicate<String> FIRST_LETTER_CAPITALIZED = Pattern.compile("^[A-Z]").asPredicate();
private static final Predicate<String> ONLY_NUMERALS_OR_LITERALS = Pattern.compile("^([0-9]+|[^0-9]+)$")
.asPredicate();

private final BibDatabaseContext bibDatabaseContextEdition;


public EditionChecker(BibDatabaseContext bibDatabaseContext) {
this.bibDatabaseContextEdition = Objects.requireNonNull(bibDatabaseContext);
}

/**
* Checks, if field contains only an integer or a literal (BibLaTeX mode)
* Checks, if the first letter is capitalized (BibTeX mode)
* BibLaTex:
* The edition of a printed publication. This must be an integer, not an ordinal.
* It is also possible to give the edition as a literal string, for example "Third, revised and expanded edition".
* Official bibtex spec:
* The edition of a book-for example, "Second".
* This should be an ordinal, and should have the first letter capitalized.
*/
@Override
public List<IntegrityMessage> check(BibEntry entry) {
Optional<String> value = entry.getField(FieldName.EDITION);
if (!value.isPresent()) {
return Collections.emptyList();
}

//BibLaTeX
if (bibDatabaseContextEdition.isBiblatexMode() && !ONLY_NUMERALS_OR_LITERALS.test(value.get().trim())) {
return Collections.singletonList(new IntegrityMessage(
Localization.lang("should contain an integer or a literal"), entry, FieldName.EDITION));
}

//BibTeX
if (!bibDatabaseContextEdition.isBiblatexMode() && !FIRST_LETTER_CAPITALIZED.test(value.get().trim())) {
return Collections.singletonList(new IntegrityMessage(
Localization.lang("should have the first letter capitalized"), entry, FieldName.EDITION));
}

return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private List<IntegrityMessage> checkBibtexEntry(BibEntry entry) {

result.addAll(new BracketChecker(FieldName.TITLE).check(entry));
result.addAll(new YearChecker().check(entry));
result.addAll(new EditionChecker(bibDatabaseContext).check(entry));
result.addAll(new UrlChecker().check(entry));
result.addAll(new FileChecker(bibDatabaseContext, fileDirectoryPreferences).check(entry));
result.addAll(new TypeChecker().check(entry));
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2490,3 +2490,6 @@ last_four_nonpunctuation_characters_should_be_numerals=Die letzten vier Nichtint
Remember_password?=Passwort_merken?

shared=geteilt

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2306,3 +2306,5 @@ Look_up_full_text_documents=Look_up_full_text_documents
You_are_about_to_look_up_full_text_documents_for_%0_entries.=You_are_about_to_look_up_full_text_documents_for_%0_entries.
last_four_nonpunctuation_characters_should_be_numerals=last_four_nonpunctuation_characters_should_be_numerals
shared=shared
should_contain_an_integer_or_a_literal=should_contain_an_integer_or_a_literal
should_have_the_first_letter_capitalized=should_have_the_first_letter_capitalized
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2456,6 +2456,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1726,3 +1726,5 @@ last_four_nonpunctuation_characters_should_be_numerals=Les_4_derniers_caractère
Remember_password?=

shared=
should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2433,6 +2433,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2465,6 +2465,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2857,6 +2857,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2434,6 +2434,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
4 changes: 4 additions & 0 deletions src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,10 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

Remember_password?=Kom_ihåg_lösenord?

shared=delad

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,9 @@ Look_up_full_text_documents=Tam_netin_belgeri_ara
You_are_about_to_look_up_full_text_documents_for_%0_entries.=%0_adet_girdi_için_tam_metin_belgeleri_aramak_üzeresiniz.

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_vi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ public void testYearChecks() {
assertWrong(createContext("year", "1986a(){},.;!?<>%&$"));
}

@Test
public void testEditionChecks() {
assertCorrect(withMode(createContext("edition", "Second"), BibDatabaseMode.BIBTEX));
assertCorrect(withMode(createContext("edition", "Third"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("edition", "second"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("edition", "2"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("edition", "2nd"), BibDatabaseMode.BIBTEX));
assertCorrect(withMode(createContext("edition", "2"), BibDatabaseMode.BIBLATEX));
assertCorrect(withMode(createContext("edition", "10"), BibDatabaseMode.BIBLATEX));
assertCorrect(
withMode(createContext("edition", "Third, revised and expanded edition"), BibDatabaseMode.BIBLATEX));
assertWrong(withMode(createContext("edition", "2nd"), BibDatabaseMode.BIBLATEX));
}

@Test
public void testBracketChecks() {
assertCorrect(createContext("title", "x"));
Expand Down