Skip to content

Commit

Permalink
Remove Guava dependency in MedlineImporter (JabRef#10486)
Browse files Browse the repository at this point in the history
* Remove Guava dependency in MedlineImporter

* Use proper HTML in JavaDoc in MedlineImporterTest
  • Loading branch information
koppor authored Oct 12, 2023
1 parent 7031842 commit d906509
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.model.strings.StringUtil;

import com.google.common.base.Joiner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -57,10 +56,6 @@ public class MedlineImporter extends Importer implements Parser {

private static final Locale ENGLISH = Locale.ENGLISH;

private static String join(List<String> list, String string) {
return Joiner.on(string).join(list);
}

@Override
public String getName() {
return "Medline/PubMed";
Expand Down Expand Up @@ -228,14 +223,14 @@ private void parseBookDocument(XMLStreamReader reader, Map<Field, String> fields

// populate multiple occurrence fields
if (!sectionTitleList.isEmpty()) {
fields.put(new UnknownField("sections"), join(sectionTitleList, "; "));
fields.put(new UnknownField("sections"), String.join("; ", sectionTitleList));
}
addKeywords(fields, keywordList);
if (!publicationTypeList.isEmpty()) {
fields.put(new UnknownField("pubtype"), join(publicationTypeList, ", "));
fields.put(new UnknownField("pubtype"), String.join(", ", publicationTypeList));
}
if (!articleTitleList.isEmpty()) {
fields.put(new UnknownField("article"), join(articleTitleList, ", "));
fields.put(new UnknownField("article"), String.join(", ", articleTitleList));
}
}

Expand Down Expand Up @@ -316,11 +311,11 @@ private void parseBookInformation(XMLStreamReader reader, Map<Field, String> fie
}

if (!isbnList.isEmpty()) {
fields.put(StandardField.ISBN, join(isbnList, ", "));
fields.put(StandardField.ISBN, String.join(", ", isbnList));
}

if (!titleList.isEmpty()) {
putIfValueNotNull(fields, StandardField.TITLE, join(titleList, " "));
putIfValueNotNull(fields, StandardField.TITLE, String.join(" ", titleList));
}
}

Expand Down Expand Up @@ -538,14 +533,14 @@ private void parseMedlineCitation(XMLStreamReader reader, Map<Field, String> fie

// populate multiple occurrence fields
if (!citationSubsets.isEmpty()) {
fields.put(new UnknownField("citation-subset"), join(citationSubsets, ", "));
fields.put(new UnknownField("citation-subset"), String.join(", ", citationSubsets));
}
addMeshHeading(fields, meshHeadingList);
addPersonalNames(fields, personalNameSubjectList);
addOtherId(fields, otherIdList);
addKeywords(fields, keywordList);
if (!spaceFlightMissionList.isEmpty()) {
fields.put(new UnknownField("space-flight-mission"), join(spaceFlightMissionList, ", "));
fields.put(new UnknownField("space-flight-mission"), String.join(", ", spaceFlightMissionList));
}
addInvestigators(fields, investigatorList);
addNotes(fields, generalNoteList);
Expand Down Expand Up @@ -679,7 +674,7 @@ private void parseGeneSymbolList(XMLStreamReader reader, Map<Field, String> fiel
}

if (!geneSymbols.isEmpty()) {
fields.put(new UnknownField("gene-symbols"), join(geneSymbols, ", "));
fields.put(new UnknownField("gene-symbols"), String.join(", ", geneSymbols));
}
}

Expand All @@ -704,7 +699,7 @@ private void parseChemicalList(XMLStreamReader reader, Map<Field, String> fields
}
}

fields.put(new UnknownField("chemicals"), join(chemicalNames, ", "));
fields.put(new UnknownField("chemicals"), String.join(", ", chemicalNames));
}

private void parseMedlineJournalInfo(XMLStreamReader reader, Map<Field, String> fields, String startElement)
Expand Down Expand Up @@ -789,7 +784,7 @@ private void parseArticleInformation(XMLStreamReader reader, Map<Field, String>
}

if (!titleList.isEmpty()) {
fields.put(StandardField.TITLE, StringUtil.stripBrackets(join(titleList, " ")));
fields.put(StandardField.TITLE, StringUtil.stripBrackets(String.join(" ", titleList)));
}
}

Expand Down Expand Up @@ -908,7 +903,7 @@ private void addNotes(Map<Field, String> fields, List<String> generalNoteList) {
}

if (!notes.isEmpty()) {
fields.put(StandardField.NOTE, join(notes, ", "));
fields.put(StandardField.NOTE, String.join(", ", notes));
}
}

Expand All @@ -932,21 +927,21 @@ private void addInvestigators(Map<Field, String> fields, List<Investigator> inve
}

if (!affiliationInfos.isEmpty()) {
fields.put(new UnknownField("affiliation"), join(affiliationInfos, ", "));
fields.put(new UnknownField("affiliation"), String.join(", ", affiliationInfos));
}

fields.put(new UnknownField("investigator"), join(investigatorNames, " and "));
fields.put(new UnknownField("investigator"), String.join(" and ", investigatorNames));
}
}

private void addKeywords(Map<Field, String> fields, List<String> keywordList) {
// Check whether MeshHeadingList exists or not
if (fields.get(StandardField.KEYWORDS) == null) {
fields.put(StandardField.KEYWORDS, join(keywordList, KEYWORD_SEPARATOR));
fields.put(StandardField.KEYWORDS, String.join(KEYWORD_SEPARATOR, keywordList));
} else {
if (!keywordList.isEmpty()) {
// if it exists, combine the MeshHeading with the keywords
String result = join(keywordList, "; ");
String result = String.join("; ", keywordList);
result = fields.get(StandardField.KEYWORDS) + KEYWORD_SEPARATOR + result;
fields.put(StandardField.KEYWORDS, result);
}
Expand Down Expand Up @@ -975,7 +970,7 @@ private void addPersonalNames(Map<Field, String> fields, List<PersonalNameSubjec
personalNames.add(result.toString());
}

fields.put(StandardField.AUTHOR, join(personalNames, " and "));
fields.put(StandardField.AUTHOR, String.join(" and ", personalNames));
}
}
}
Expand All @@ -994,7 +989,7 @@ private void addMeshHeading(Map<Field, String> fields, List<MeshHeading> meshHea
keywords.add(result.toString());
}

fields.put(StandardField.KEYWORDS, join(keywords, KEYWORD_SEPARATOR));
fields.put(StandardField.KEYWORDS, String.join(KEYWORD_SEPARATOR, keywords));
}
}

Expand Down Expand Up @@ -1065,7 +1060,7 @@ private void addAbstract(XMLStreamReader reader, Map<Field, String> fields, Stri
}

if (!abstractTextList.isEmpty()) {
fields.put(StandardField.ABSTRACT, join(abstractTextList, " "));
fields.put(StandardField.ABSTRACT, String.join(" ", abstractTextList));
}
}

Expand Down Expand Up @@ -1170,7 +1165,7 @@ private void handleAuthorList(XMLStreamReader reader, Map<Field, String> fields,
}
}

fields.put(StandardField.AUTHOR, join(authorNames, " and "));
fields.put(StandardField.AUTHOR, String.join(" and ", authorNames));
}

private void parseAuthor(XMLStreamReader reader, List<String> authorNames) throws XMLStreamException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Articles in the medline format can be downloaded from http://www.ncbi.nlm.nih.gov/pubmed/. 1. Search for a term and
* make sure you have selected the PubMed database 2. Select the results you want to export by checking their checkboxes
* 3. Press on the 'Send to' drop down menu on top of the search results 4. Select 'File' as Destination and 'XML' as
* Format 5. Press 'Create File' to download your search results in a medline xml file
* Articles in the medline format can be downloaded from http://www.ncbi.nlm.nih.gov/pubmed/.
* <ol>
* <li>Search for a term and make sure you have selected the <strong>PubMed</strong> database.</li>
* <li>Select the results you want to export by checking their checkboxes.</li>
* <li>Press on the <strong>'Send to'</strong> drop down menu on top of the search results.</li>
* <li>Select <strong>'File'</strong> as Destination and <strong>'XML'</strong> as Format.</li>
* <li>Press <strong>'Create File'</strong> to download your search results in a medline xml file.</li>
* </ol>
*/
public class MedlineImporterTest {

Expand Down

0 comments on commit d906509

Please sign in to comment.