Skip to content

Commit

Permalink
Add month normalization to AstroPhysicsFetcher (JabRef#6022)
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Mar 6, 2020
1 parent 9c0fa85 commit d9a8088
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
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#"));
}
}

0 comments on commit d9a8088

Please sign in to comment.