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

Fix IEEE test #7852

Merged
merged 11 commits into from
Jun 29, 2021
28 changes: 24 additions & 4 deletions src/main/java/org/jabref/logic/importer/fetcher/IEEE.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ public class IEEE implements FulltextFetcher, PagedSearchBasedParserFetcher {

private final ImportFormatPreferences preferences;

private IEEEQueryTransformer transformer;

public IEEE(ImportFormatPreferences preferences) {
this.preferences = Objects.requireNonNull(preferences);
}

/**
* @implNote <a href="https://developer.ieee.org/docs/read/Metadata_API_responses">documentation</a>
*/
private static BibEntry parseJsonRespone(JSONObject jsonEntry, Character keywordSeparator) {
private static BibEntry parseJsonResponse(JSONObject jsonEntry, Character keywordSeparator) {
BibEntry entry = new BibEntry();

switch (jsonEntry.optString("content_type")) {
Expand Down Expand Up @@ -205,8 +207,24 @@ public Parser getParser() {
JSONArray results = jsonObject.getJSONArray("articles");
for (int i = 0; i < results.length(); i++) {
JSONObject jsonEntry = results.getJSONObject(i);
BibEntry entry = parseJsonRespone(jsonEntry, preferences.getKeywordSeparator());
entries.add(entry);
BibEntry entry = parseJsonResponse(jsonEntry, preferences.getKeywordSeparator());
boolean addEntry;
// In case entry has no year, add it
// In case an entry has a year, check if its in the year range
// The implementation uses some Java 8 Optional magic to implement that
if (entry.hasField(StandardField.YEAR)) {
koppor marked this conversation as resolved.
Show resolved Hide resolved
addEntry = entry.getField(StandardField.YEAR).filter(year -> {
Integer yearAsInteger = Integer.valueOf(year);
return
transformer.getStartYear().map(startYear -> yearAsInteger >= startYear).orElse(true) &&
transformer.getEndYear().map(endYear -> yearAsInteger <= endYear).orElse(true);
}).map(x -> true).orElse(false);
} else {
addEntry = true;
}
if (addEntry) {
entries.add(entry);
}
}
}

Expand All @@ -226,7 +244,9 @@ public Optional<HelpFile> getHelpPage() {

@Override
public URL getURLForQuery(QueryNode luceneQuery, int pageNumber) throws URISyntaxException, MalformedURLException, FetcherException {
IEEEQueryTransformer transformer = new IEEEQueryTransformer();
// transformer is stored globally, because we need to filter out the bib entries by the year manually
// the transformer stores the min and max year
transformer = new IEEEQueryTransformer();
String transformedQuery = transformer.transformLuceneQuery(luceneQuery).orElse("");
URIBuilder uriBuilder = new URIBuilder("https://ieeexploreapi.ieee.org/api/v1/search/articles");
uriBuilder.addParameter("apikey", API_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public class IEEEQueryTransformer extends YearRangeByFilteringQueryTransformer {
// Journal is wrapped in quotes by the transformer
private String journal;
private String articleNumber;
private int startYear = Integer.MAX_VALUE;
private int endYear = Integer.MIN_VALUE;

@Override
protected String getLogicalAndOperator() {
Expand Down Expand Up @@ -40,8 +38,9 @@ protected String handleTitle(String title) {
}

@Override
protected String handleJournal(String journalTitle) {
return handleUnFieldedTerm(journalTitle);
protected String handleJournal(String journal) {
this.journal = journal;
return handleUnFieldedTerm(journal);
}

@Override
Expand Down
13 changes: 8 additions & 5 deletions src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ void searchByQueryFindsEntry() throws Exception {
.withField(StandardField.DATE, "14-22 May 2016")
.withField(StandardField.YEAR, "2016")
.withField(StandardField.EVENTDATE, "14-22 May 2016")
.withField(StandardField.EVENTTITLEADDON, "Austin, TX")
.withField(StandardField.LOCATION, "Austin, TX")
.withField(StandardField.EVENTTITLEADDON, "Austin, TX, USA")
.withField(StandardField.LOCATION, "Austin, TX, USA")
.withField(StandardField.DOI, "10.1145/2884781.2884806")
.withField(StandardField.JOURNALTITLE, "2016 IEEE/ACM 38th International Conference on Software Engineering (ICSE)")
.withField(StandardField.PAGES, "273--284")
Expand All @@ -121,9 +121,12 @@ void searchByQueryFindsEntry() throws Exception {
.withField(StandardField.PUBLISHER, "IEEE")
.withField(StandardField.KEYWORDS, "Portals, Documentation, Computer bugs, Joining processes, Industries, Open source software, Newcomers, Newbies, Novices, Beginners, Open Source Software, Barriers, Obstacles, Onboarding, Joining Process")
.withField(StandardField.TITLE, "Overcoming Open Source Project Entry Barriers with a Portal for Newcomers")
.withField(StandardField.FILE, ":https\\://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=7886910:PDF")
.withField(StandardField.ABSTRACT, "Community-based Open Source Software (OSS) projects are usually self-organized and dynamic, receiving contributions from distributed volunteers. Newcomer are important to the survival, long-term success, and continuity of these communities. However, newcomers face many barriers when making their first contribution to an OSS project, leading in many cases to dropouts. Therefore, a major challenge for OSS projects is to provide ways to support newcomers during their first contribution. In this paper, we propose and evaluate FLOSScoach, a portal created to support newcomers to OSS projects. FLOSScoach was designed based on a conceptual model of barriers created in our previous work. To evaluate the portal, we conducted a study with 65 students, relying on qualitative data from diaries, self-efficacy questionnaires, and the Technology Acceptance Model. The results indicate that FLOSScoach played an important role in guiding newcomers and in lowering barriers related to the orientation and contribution process, whereas it was not effective in lowering technical barriers. We also found that FLOSScoach is useful, easy to use, and increased newcomers' confidence to contribute. Our results can help project maintainers on deciding the points that need more attention in order to help OSS project newcomers overcome entry barriers.");
List<BibEntry> fetchedEntries = fetcher.performSearch("Overcoming Open Source Project Entry Barriers with a Portal for Newcomers");
.withField(StandardField.FILE, ":https\\://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=7886910:PDF");
// The quotes are important to get the paper found. Without quotes, the fetcher constructs a query making IEEE returning no entry at all.
// It seems that IEEE cannot handle more than 6 AND conditions in a query as of 2021-06
List<BibEntry> fetchedEntries = fetcher.performSearch("\"Overcoming Open Source Project Entry Barriers with a Portal for Newcomers\"");
koppor marked this conversation as resolved.
Show resolved Hide resolved
// Abstract should not be included in JabRef tests
fetchedEntries.get(0).clearField(StandardField.ABSTRACT);
assertEquals(Collections.singletonList(expected), fetchedEntries);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ default void supportsJournalSearch() throws Exception {

assertFalse(result.isEmpty());
result.forEach(bibEntry -> {
assertTrue(bibEntry.hasField(StandardField.JOURNAL));
String journal = bibEntry.getField(StandardField.JOURNAL).orElse("");
assertTrue(journal.contains(getTestJournal().replace("\"", "")));
});
Expand Down