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

Add month normalization to AstroPhysicsFetcher #6022

Merged
merged 4 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.jabref.logic.cleanup.MoveFieldCleanup;
import org.jabref.logic.formatter.bibtexfields.ClearFormatter;
import org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter;
import org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter;
import org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter;
import org.jabref.logic.formatter.bibtexfields.RemoveNewlinesFormatter;
Expand Down Expand Up @@ -143,6 +144,7 @@ public void doPostCleanup(BibEntry entry) {
new FieldFormatterCleanup(StandardField.ABSTRACT, new RemoveNewlinesFormatter()).cleanup(entry);
new FieldFormatterCleanup(StandardField.TITLE, new RemoveBracesFormatter()).cleanup(entry);
new FieldFormatterCleanup(StandardField.AUTHOR, new NormalizeNamesFormatter()).cleanup(entry);
new FieldFormatterCleanup(StandardField.MONTH, new NormalizeMonthFormatter()).cleanup(entry);

// Remove ADS note
new FieldFormatterCleanup(new UnknownField("adsnote"), new ClearFormatter()).cleanup(entry);
Expand Down Expand Up @@ -249,7 +251,6 @@ public Optional<BibEntry> performSearchById(String identifier) throws FetcherExc
* bibcodes
*/
private List<BibEntry> performSearchByIds(Collection<String> identifiers) throws FetcherException {

List<String> ids = identifiers.stream().filter(identifier -> !StringUtil.isBlank(identifier)).collect(Collectors.toList());
if (ids.isEmpty()) {
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public List<FieldChange> cleanup(BibEntry entry) {
private List<FieldChange> cleanupSingleField(Field fieldKey, BibEntry entry) {
if (!entry.hasField(fieldKey)) {
// Not set -> nothing to do
return new ArrayList<>();
return Collections.emptyList();
}
String oldValue = entry.getField(fieldKey).orElse(null);

// Run formatter
String newValue = formatter.format(oldValue);

if (oldValue.equals(newValue)) {
return new ArrayList<>();
return Collections.emptyList();
} else {
if (newValue.isEmpty()) {
entry.clearField(fieldKey);
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/org/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public void setField(Map<Field, String> fields) {
/**
* Set a field, and notify listeners about the change.
*
* @param field The field to set
* @param field The field to set
* @param value The value to set
* @param eventSource Source the event is sent from
*/
Expand Down Expand Up @@ -543,16 +543,15 @@ public Optional<FieldChange> setField(Field field, String value, EntriesEventSou
/**
* Set a field, and notify listeners about the change.
*
* @param field The field to set.
* @param field The field to set.
* @param value The value to set.
*/
public Optional<FieldChange> setField(Field field, String value) {
return setField(field, value, EntriesEventSource.LOCAL);
}

/**
* Remove the mapping for the field name, and notify listeners about
* the change.
* Remove the mapping for the field name, and notify listeners about the change.
*
* @param field The field to clear.
*/
Expand Down Expand Up @@ -588,9 +587,9 @@ public Optional<FieldChange> clearField(Field field, EntriesEventSource eventSou
* database argument is given, this method will try to look up missing fields in
* entries linked by the "crossref" field, if any.
*
* @param fields An array of field names to be checked.
* @param database The database in which to look up crossref'd entries, if any. This
* argument can be null, meaning that no attempt will be made to follow crossrefs.
* @param fields An array of field names to be checked.
* @param database The database in which to look up crossref'd entries, if any. This argument can be null, meaning
* that no attempt will be made to follow crossrefs.
* @return true if all fields are set or could be resolved, false otherwise.
*/
public boolean allFieldsPresent(Collection<OrFields> fields, BibDatabase database) {
Expand All @@ -610,9 +609,11 @@ public Object clone() {

/**
* This returns a canonical BibTeX serialization. Special characters such as "{" or "&" are NOT escaped, but written
* as is
* as is. In case the JabRef "hack" for distinguishing "field = value" and "field = {value}" (in .bib files) is
* used, it is output as "field = {#value#}", which may cause headaches in debugging. We nevertheless do it this way
* to a) enable debugging the internal representation and b) save time at this method.
* <p>
* Serializes all fields, even the JabRef internal ones. Does NOT serialize "KEY_FIELD" as field, but as key
* Serializes all fields, even the JabRef internal ones. Does NOT serialize "KEY_FIELD" as field, but as key.
*/
@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public void setUp() {
public void formatExample() {
assertEquals("#dec#", formatter.format(formatter.getExampleInput()));
}

@Test
public void plainAprilShouldBeApril() {
assertEquals("#apr#", formatter.format("#apr#"));
}
}