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

Remove Guava dependency in MedlineImporter #10486

Merged
merged 2 commits into from
Oct 12, 2023
Merged
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
@@ -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;

@@ -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";
@@ -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));
}
}

@@ -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));
}
}

@@ -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);
@@ -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));
}
}

@@ -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)
@@ -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)));
}
}

@@ -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));
}
}

@@ -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);
}
@@ -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));
}
}
}
@@ -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));
}
}

@@ -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));
}
}

@@ -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 {
Original file line number Diff line number Diff line change
@@ -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 {