diff --git a/src/main/java/org/jabref/logic/importer/SearchBasedFetcher.java b/src/main/java/org/jabref/logic/importer/SearchBasedFetcher.java index b96dbac2ad5..3d20115bbf8 100644 --- a/src/main/java/org/jabref/logic/importer/SearchBasedFetcher.java +++ b/src/main/java/org/jabref/logic/importer/SearchBasedFetcher.java @@ -10,7 +10,7 @@ import org.apache.lucene.queryparser.flexible.core.parser.SyntaxParser; import org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser; -import static org.jabref.logic.importer.fetcher.transformators.AbstractQueryTransformer.NO_EXPLICIT_FIELD; +import static org.jabref.logic.importer.fetcher.transformers.AbstractQueryTransformer.NO_EXPLICIT_FIELD; /** * Searches web resources for bibliographic information based on a free-text query. diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ACMPortalFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/ACMPortalFetcher.java index d15e555e461..cf703faec02 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ACMPortalFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ACMPortalFetcher.java @@ -11,7 +11,7 @@ import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.SearchBasedParserFetcher; -import org.jabref.logic.importer.fetcher.transformators.DefaultQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.DefaultQueryTransformer; import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.model.util.DummyFileUpdateMonitor; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java index 0ee11216d1c..95c20775a39 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java @@ -25,7 +25,7 @@ import org.jabref.logic.importer.IdFetcher; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.PagedSearchBasedFetcher; -import org.jabref.logic.importer.fetcher.transformators.ArXivQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.ArXivQueryTransformer; import org.jabref.logic.util.io.XMLUtil; import org.jabref.logic.util.strings.StringSimilarity; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java index 6da8f0920d3..2fff3084f95 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java @@ -27,7 +27,7 @@ import org.jabref.logic.importer.PagedSearchBasedParserFetcher; import org.jabref.logic.importer.ParseException; import org.jabref.logic.importer.Parser; -import org.jabref.logic.importer.fetcher.transformators.DefaultQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.DefaultQueryTransformer; import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.logic.net.URLDownload; import org.jabref.logic.util.BuildInfo; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/CiteSeer.java b/src/main/java/org/jabref/logic/importer/fetcher/CiteSeer.java index c6e4c2b6ba5..4c72717d730 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/CiteSeer.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/CiteSeer.java @@ -20,7 +20,7 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.SearchBasedParserFetcher; -import org.jabref.logic.importer.fetcher.transformators.DefaultQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.DefaultQueryTransformer; import org.jabref.logic.importer.fileformat.CoinsParser; import org.jabref.logic.util.OS; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcher.java index b6556e0930f..71bf613c79d 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcher.java @@ -14,7 +14,7 @@ import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.SearchBasedParserFetcher; -import org.jabref.logic.importer.fetcher.transformators.DefaultQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.CollectionOfComputerScienceBibliographiesQueryTransformer; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; @@ -37,7 +37,7 @@ public CollectionOfComputerScienceBibliographiesFetcher(ImportFormatPreferences @Override public URL getURLForQuery(QueryNode luceneQuery) throws URISyntaxException, MalformedURLException, FetcherException { return new URIBuilder(BASIC_SEARCH_URL) - .addParameter("query", new DefaultQueryTransformer().transformLuceneQuery(luceneQuery).orElse("")) + .addParameter("query", new CollectionOfComputerScienceBibliographiesQueryTransformer().transformLuceneQuery(luceneQuery).orElse("")) .addParameter("sort", "score") .build() .toURL(); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/CrossRef.java b/src/main/java/org/jabref/logic/importer/fetcher/CrossRef.java index e6627f17f54..9c201e1e7c1 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/CrossRef.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/CrossRef.java @@ -19,7 +19,7 @@ import org.jabref.logic.importer.ParseException; import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.SearchBasedParserFetcher; -import org.jabref.logic.importer.fetcher.transformators.DefaultQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.DefaultQueryTransformer; import org.jabref.logic.importer.util.JsonReader; import org.jabref.logic.util.strings.StringSimilarity; import org.jabref.model.entry.Author; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DBLPFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DBLPFetcher.java index 2d12d9820f5..d961ce0b3bc 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DBLPFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DBLPFetcher.java @@ -16,7 +16,7 @@ import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.SearchBasedParserFetcher; -import org.jabref.logic.importer.fetcher.transformators.DBLPQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.DBLPQueryTransformer; import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.logic.layout.LayoutFormatterBasedFormatter; import org.jabref.logic.layout.format.RemoveLatexCommandsFormatter; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java index 5f62756cdf7..a8656936077 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java @@ -16,7 +16,7 @@ import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.SearchBasedParserFetcher; -import org.jabref.logic.importer.fetcher.transformators.DefaultQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.DefaultLuceneQueryTransformer; import org.jabref.logic.util.OS; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; @@ -192,7 +192,7 @@ public Optional getHelpPage() { @Override public URL getURLForQuery(QueryNode luceneQuery) throws URISyntaxException, MalformedURLException, FetcherException { URIBuilder uriBuilder = new URIBuilder(SEARCH_URL); - DOAJFetcher.addPath(uriBuilder, new DefaultQueryTransformer().transformLuceneQuery(luceneQuery).orElse("")); + DOAJFetcher.addPath(uriBuilder, new DefaultLuceneQueryTransformer().transformLuceneQuery(luceneQuery).orElse("")); // Number of results uriBuilder.addParameter("pageSize", "30"); // Page (not needed so far) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java index ffd4f9a55e0..fc72717086f 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java @@ -19,7 +19,7 @@ import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.PagedSearchBasedFetcher; import org.jabref.logic.importer.ParserResult; -import org.jabref.logic.importer.fetcher.transformators.ScholarQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.ScholarQueryTransformer; import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.URLDownload; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/GvkFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/GvkFetcher.java index db6afbc6606..23dd4e8080e 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/GvkFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/GvkFetcher.java @@ -11,7 +11,7 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.SearchBasedParserFetcher; -import org.jabref.logic.importer.fetcher.transformators.GVKQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.GVKQueryTransformer; import org.jabref.logic.importer.fileformat.GvkParser; import org.apache.http.client.utils.URIBuilder; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java index 9cd5341d357..18d2254e013 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java @@ -20,7 +20,7 @@ import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.PagedSearchBasedParserFetcher; import org.jabref.logic.importer.Parser; -import org.jabref.logic.importer.fetcher.transformators.IEEEQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.IEEEQueryTransformer; import org.jabref.logic.net.URLDownload; import org.jabref.logic.util.BuildInfo; import org.jabref.logic.util.OS; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/INSPIREFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/INSPIREFetcher.java index c594ebb5efc..553114e46c6 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/INSPIREFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/INSPIREFetcher.java @@ -13,7 +13,7 @@ import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.SearchBasedParserFetcher; -import org.jabref.logic.importer.fetcher.transformators.DefaultQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.DefaultLuceneQueryTransformer; import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.logic.importer.util.MediaTypes; import org.jabref.logic.layout.format.LatexToUnicodeFormatter; @@ -52,7 +52,7 @@ public Optional getHelpPage() { @Override public URL getURLForQuery(QueryNode luceneQuery) throws URISyntaxException, MalformedURLException, FetcherException { URIBuilder uriBuilder = new URIBuilder(INSPIRE_HOST); - uriBuilder.addParameter("q", new DefaultQueryTransformer().transformLuceneQuery(luceneQuery).orElse("")); // Query + uriBuilder.addParameter("q", new DefaultLuceneQueryTransformer().transformLuceneQuery(luceneQuery).orElse("")); return uriBuilder.build().toURL(); } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/JstorFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/JstorFetcher.java index 4c2f49a16d5..9e78db86377 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/JstorFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/JstorFetcher.java @@ -19,7 +19,7 @@ import org.jabref.logic.importer.ParseException; import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.SearchBasedParserFetcher; -import org.jabref.logic.importer.fetcher.transformators.DefaultQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.JstorQueryTransformer; import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.logic.net.URLDownload; import org.jabref.model.entry.BibEntry; @@ -51,7 +51,7 @@ public JstorFetcher(ImportFormatPreferences importFormatPreferences) { @Override public URL getURLForQuery(QueryNode luceneQuery) throws URISyntaxException, MalformedURLException, FetcherException { URIBuilder uriBuilder = new URIBuilder(SEARCH_HOST); - uriBuilder.addParameter("Query", new DefaultQueryTransformer().transformLuceneQuery(luceneQuery).orElse("")); + uriBuilder.addParameter("Query", new JstorQueryTransformer().transformLuceneQuery(luceneQuery).orElse("")); return uriBuilder.build().toURL(); } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java b/src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java index bfc2ca3ab8c..f8282fce74d 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java @@ -23,7 +23,7 @@ import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.SearchBasedParserFetcher; -import org.jabref.logic.importer.fetcher.transformators.DefaultQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.DefaultQueryTransformer; import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.logic.util.OS; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java index 304b76da38a..42731cc1ae5 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java @@ -28,7 +28,7 @@ import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.SearchBasedFetcher; -import org.jabref.logic.importer.fetcher.transformators.DefaultQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.DefaultQueryTransformer; import org.jabref.logic.importer.fileformat.MedlineImporter; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java index 5c3b34b6d01..efd8f4b325b 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java @@ -14,7 +14,7 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.PagedSearchBasedParserFetcher; import org.jabref.logic.importer.Parser; -import org.jabref.logic.importer.fetcher.transformators.SpringerQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.SpringerQueryTransformer; import org.jabref.logic.util.BuildInfo; import org.jabref.logic.util.OS; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ZbMATH.java b/src/main/java/org/jabref/logic/importer/fetcher/ZbMATH.java index 1794c678455..592688412ce 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ZbMATH.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ZbMATH.java @@ -16,7 +16,7 @@ import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.SearchBasedParserFetcher; -import org.jabref.logic.importer.fetcher.transformators.ZbMathQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.ZbMathQueryTransformer; import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.logic.net.URLDownload; import org.jabref.model.entry.AuthorList; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformators/ArXivQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformators/ArXivQueryTransformer.java deleted file mode 100644 index dd94eab746b..00000000000 --- a/src/main/java/org/jabref/logic/importer/fetcher/transformators/ArXivQueryTransformer.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.jabref.logic.importer.fetcher.transformators; - -import java.util.Optional; - -public class ArXivQueryTransformer extends AbstractQueryTransformer { - // These can be used for filtering in post processing - private int startYear = Integer.MAX_VALUE; - private int endYear = Integer.MIN_VALUE; - - @Override - protected String getLogicalAndOperator() { - return " AND "; - } - - @Override - protected String getLogicalOrOperator() { - return " OR "; - } - - /** - * Check whether this works as an unary operator - * @return - */ - @Override - protected String getLogicalNotOperator() { - return " ANDNOT "; - } - - @Override - protected String handleAuthor(String author) { - return String.format("au:\"%s\"", author); - } - - @Override - protected String handleTitle(String title) { - return String.format("ti:\"%s\"", title); - } - - @Override - protected String handleJournal(String journalTitle) { - return String.format("jr:\"%s\"", journalTitle); - } - - /** - * Manual testing shows that this works if added as an unfielded term, might lead to false positives - */ - @Override - protected String handleYear(String year) { - startYear = Math.min(startYear, Integer.parseInt(year)); - endYear = Math.max(endYear, Integer.parseInt(year)); - return year; - } - - /** - * Currently not supported - */ - @Override - protected String handleYearRange(String yearRange) { - String[] split = yearRange.split("-"); - startYear = Math.min(startYear, Integer.parseInt(split[0])); - endYear = Math.max(endYear, Integer.parseInt(split[1])); - return ""; - } - - @Override - protected String handleUnFieldedTerm(String term) { - return String.format("all:\"%s\"", term); - } - - public Optional getStartYear() { - return startYear == Integer.MAX_VALUE ? Optional.empty() : Optional.of(startYear); - } - - public Optional getEndYear() { - return endYear == Integer.MIN_VALUE ? Optional.empty() : Optional.of(endYear); - } -} diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformators/DBLPQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformators/DBLPQueryTransformer.java deleted file mode 100644 index df943509320..00000000000 --- a/src/main/java/org/jabref/logic/importer/fetcher/transformators/DBLPQueryTransformer.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.jabref.logic.importer.fetcher.transformators; - -import java.util.StringJoiner; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DBLPQueryTransformer extends AbstractQueryTransformer { - private static final Logger LOGGER = LoggerFactory.getLogger(DBLPQueryTransformer.class); - - @Override - protected String getLogicalAndOperator() { - return " "; - } - - @Override - protected String getLogicalOrOperator() { - return "|"; - } - - @Override - protected String getLogicalNotOperator() { - LOGGER.warn("DBLP does not support Boolean NOT operator."); - return ""; - } - - @Override - protected String handleAuthor(String author) { - // DBLP does not support explicit author field search - return String.format("\"%s\"", author); - } - - @Override - protected String handleTitle(String title) { - // DBLP does not support explicit title field search - return String.format("\"%s\"", title); - } - - @Override - protected String handleJournal(String journalTitle) { - // DBLP does not support explicit journal field search - return String.format("\"%s\"", journalTitle); - } - - @Override - protected String handleYear(String year) { - // DBLP does not support explicit year field search - return year; - } - - @Override - protected String handleYearRange(String yearRange) { - // DBLP does not support explicit year range search - String[] split = yearRange.split("-"); - StringJoiner resultBuilder = new StringJoiner(getLogicalOrOperator()); - for (int i = Integer.parseInt(split[0]); i <= Integer.parseInt(split[1]); i++) { - resultBuilder.add(String.valueOf(i)); - } - return resultBuilder.toString(); - } - - @Override - protected String handleUnFieldedTerm(String term) { - return String.format("\"%s\"", term); - } -} diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformators/ScholarQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformators/ScholarQueryTransformer.java deleted file mode 100644 index a83db9364b1..00000000000 --- a/src/main/java/org/jabref/logic/importer/fetcher/transformators/ScholarQueryTransformer.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.jabref.logic.importer.fetcher.transformators; - -public class ScholarQueryTransformer extends AbstractQueryTransformer { - // These have to be integrated into the Google Scholar query URL as these are just supported as query parameters - private int startYear = Integer.MAX_VALUE; - private int endYear = Integer.MIN_VALUE; - - @Override - protected String getLogicalAndOperator() { - return " AND "; - } - - @Override - protected String getLogicalOrOperator() { - return " OR "; - } - - @Override - protected String getLogicalNotOperator() { - return "-"; - } - - @Override - protected String handleAuthor(String author) { - return String.format("author:\"%s\"", author); - } - - @Override - protected String handleTitle(String title) { - return String.format("allintitle:\"%s\"", title); - } - - @Override - protected String handleJournal(String journalTitle) { - return String.format("source:\"%s\"", journalTitle); - } - - @Override - protected String handleYear(String year) { - startYear = Math.min(startYear, Integer.parseInt(year)); - endYear = Math.max(endYear, Integer.parseInt(year)); - return ""; - } - - @Override - protected String handleYearRange(String yearRange) { - String[] split = yearRange.split("-"); - startYear = Math.min(startYear, Integer.parseInt(split[0])); - endYear = Math.max(endYear, Integer.parseInt(split[1])); - return ""; - } - - @Override - protected String handleUnFieldedTerm(String term) { - return String.format("\"%s\"", term); - } - - public int getStartYear() { - return startYear == Integer.MAX_VALUE ? Integer.MIN_VALUE : startYear; - } - - public int getEndYear() { - return endYear == Integer.MIN_VALUE ? Integer.MAX_VALUE : endYear; - } -} diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformators/AbstractQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/AbstractQueryTransformer.java similarity index 73% rename from src/main/java/org/jabref/logic/importer/fetcher/transformators/AbstractQueryTransformer.java rename to src/main/java/org/jabref/logic/importer/fetcher/transformers/AbstractQueryTransformer.java index 32c7a6b8d18..22e8c642d80 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/transformators/AbstractQueryTransformer.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/AbstractQueryTransformer.java @@ -1,6 +1,7 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; import java.util.Optional; +import java.util.StringJoiner; import java.util.stream.Collectors; import org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode; @@ -13,13 +14,17 @@ import org.slf4j.LoggerFactory; /** - * In case the transformator contains state for a query transformation (such as the {@link IEEEQueryTransformer}), it has to be noted at the JavaDoc. + * In case the transformer contains state for a query transformation (such as the {@link IEEEQueryTransformer}), it has to be noted at the JavaDoc. * Otherwise, a single instance QueryTransformer can be used. */ public abstract class AbstractQueryTransformer { public static final String NO_EXPLICIT_FIELD = "default"; private static final Logger LOGGER = LoggerFactory.getLogger(AbstractQueryTransformer.class); + // These can be used for filtering in post processing + protected int startYear = Integer.MAX_VALUE; + protected int endYear = Integer.MIN_VALUE; + /** * Transforms a and b and c to (a AND b AND c), where * a, b, and c can be complex expressions. @@ -136,25 +141,80 @@ private Optional transform(ModifierQueryNode query) { */ protected abstract String handleYear(String year); + /** + * Parses the year range and fills startYear and endYear. + * Ensures that startYear <= endYear + */ + protected void parseYearRange(String yearRange) { + String[] split = yearRange.split("-"); + int parsedStartYear = Integer.parseInt(split[0]); + startYear = parsedStartYear; + if (split.length >= 1) { + int parsedEndYear = Integer.parseInt(split[1]); + if (parsedEndYear >= parsedStartYear) { + endYear = parsedEndYear; + } else { + startYear = parsedEndYear; + endYear = parsedStartYear; + } + } + } + /** * Return a string representation of the year-range fielded term * Should follow the structure yyyy-yyyy * * Example: 2015-2021 */ - protected abstract String handleYearRange(String yearRange); + protected String handleYearRange(String yearRange) { + parseYearRange(yearRange); + if (endYear == Integer.MAX_VALUE) { + // invalid year range + return yearRange; + } + StringJoiner resultBuilder = new StringJoiner(getLogicalOrOperator()); + for (int i = startYear; i <= endYear; i++) { + resultBuilder.add(handleYear(String.valueOf(i))); + } + return resultBuilder.toString(); + } /** * Return a string representation of the un-fielded (default fielded) term + * + * Default implementation: just return the term (in quotes if a space is contained) */ - protected abstract String handleUnFieldedTerm(String term); + protected String handleUnFieldedTerm(String term) { + return quoteStringIfSpaceIsContained(term); + } + + /** + * Encloses the given string with " if there is a space contained + * + * @return Returns a string + */ + protected String quoteStringIfSpaceIsContained(String string) { + if (string.contains(" ")) { + return "\"" + string + "\""; + } else { + return string; + } + } + + protected String createKeyValuePair(String fieldAsString, String term) { + return createKeyValuePair(fieldAsString, term, ":"); + } + + protected String createKeyValuePair(String fieldAsString, String term, String separator) { + return String.format("%s%s%s", fieldAsString, separator, quoteStringIfSpaceIsContained(term)); + } /** * Return a string representation of the provided field * If it is not supported return an empty optional. */ protected Optional handleOtherField(String fieldAsString, String term) { - return Optional.of(String.format("%s:\"%s\"", fieldAsString, term)); + return Optional.of(createKeyValuePair(fieldAsString, term)); } private Optional transform(QueryNode query) { diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformers/ArXivQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/ArXivQueryTransformer.java new file mode 100644 index 00000000000..51efafba3dd --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/ArXivQueryTransformer.java @@ -0,0 +1,49 @@ +package org.jabref.logic.importer.fetcher.transformers; + +public class ArXivQueryTransformer extends YearRangeByFilteringQueryTransformer { + @Override + protected String getLogicalAndOperator() { + return " AND "; + } + + @Override + protected String getLogicalOrOperator() { + return " OR "; + } + + @Override + protected String getLogicalNotOperator() { + return " ANDNOT "; + } + + @Override + protected String handleAuthor(String author) { + return createKeyValuePair("au", author); + } + + @Override + protected String handleTitle(String title) { + return createKeyValuePair("ti", title); + } + + @Override + protected String handleJournal(String journalTitle) { + return createKeyValuePair("jr", journalTitle); + } + + /** + * Manual testing shows that this works if added as an unfielded term, might lead to false positives + */ + @Override + protected String handleYear(String year) { + startYear = Math.min(startYear, Integer.parseInt(year)); + endYear = Math.max(endYear, Integer.parseInt(year)); + return year; + } + + @Override + protected String handleUnFieldedTerm(String term) { + return createKeyValuePair("all", term); + } + +} diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformators/DefaultQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/CollectionOfComputerScienceBibliographiesQueryTransformer.java similarity index 52% rename from src/main/java/org/jabref/logic/importer/fetcher/transformators/DefaultQueryTransformer.java rename to src/main/java/org/jabref/logic/importer/fetcher/transformers/CollectionOfComputerScienceBibliographiesQueryTransformer.java index b99e327269c..18e43a1f114 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/transformators/DefaultQueryTransformer.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/CollectionOfComputerScienceBibliographiesQueryTransformer.java @@ -1,6 +1,6 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; -public class DefaultQueryTransformer extends AbstractQueryTransformer { +public class CollectionOfComputerScienceBibliographiesQueryTransformer extends AbstractQueryTransformer { @Override protected String getLogicalAndOperator() { @@ -9,41 +9,31 @@ protected String getLogicalAndOperator() { @Override protected String getLogicalOrOperator() { - return " "; + return " OR "; } @Override protected String getLogicalNotOperator() { - return ""; + return "-"; } @Override protected String handleAuthor(String author) { - return author; + return createKeyValuePair("au", author); } @Override protected String handleTitle(String title) { - return title; + return createKeyValuePair("ti", title); } @Override protected String handleJournal(String journalTitle) { - return journalTitle; + return quoteStringIfSpaceIsContained(journalTitle); } @Override protected String handleYear(String year) { - return year; - } - - @Override - protected String handleYearRange(String yearRange) { - return yearRange; - } - - @Override - protected String handleUnFieldedTerm(String term) { - return term; + return String.format("year:%s", year); } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformers/DBLPQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/DBLPQueryTransformer.java new file mode 100644 index 00000000000..97fd186a27e --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/DBLPQueryTransformer.java @@ -0,0 +1,45 @@ +package org.jabref.logic.importer.fetcher.transformers; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * DBLP does not support explicit year field search, thus we extend YearAndYearRangeByFilteringQueryTransformer + */ +public class DBLPQueryTransformer extends YearAndYearRangeByFilteringQueryTransformer { + private static final Logger LOGGER = LoggerFactory.getLogger(DBLPQueryTransformer.class); + + @Override + protected String getLogicalAndOperator() { + return " "; + } + + @Override + protected String getLogicalOrOperator() { + return "|"; + } + + @Override + protected String getLogicalNotOperator() { + LOGGER.warn("DBLP does not support Boolean NOT operator."); + return ""; + } + + @Override + protected String handleAuthor(String author) { + // DBLP does not support explicit author field search + return quoteStringIfSpaceIsContained(author); + } + + @Override + protected String handleTitle(String title) { + // DBLP does not support explicit title field search + return quoteStringIfSpaceIsContained(title); + } + + @Override + protected String handleJournal(String journalTitle) { + // DBLP does not support explicit journal field search + return quoteStringIfSpaceIsContained(journalTitle); + } +} diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformers/DefaultLuceneQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/DefaultLuceneQueryTransformer.java new file mode 100644 index 00000000000..b13aba1b1b3 --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/DefaultLuceneQueryTransformer.java @@ -0,0 +1,42 @@ +package org.jabref.logic.importer.fetcher.transformers; + +/** + * Transforms the query to a lucene query string + */ +public class DefaultLuceneQueryTransformer extends AbstractQueryTransformer { + + @Override + protected String getLogicalAndOperator() { + return " AND "; + } + + @Override + protected String getLogicalOrOperator() { + return " OR "; + } + + @Override + protected String getLogicalNotOperator() { + return "NOT "; + } + + @Override + protected String handleAuthor(String author) { + return createKeyValuePair("author", author); + } + + @Override + protected String handleTitle(String title) { + return createKeyValuePair("title", title); + } + + @Override + protected String handleJournal(String journalTitle) { + return createKeyValuePair("journal", journalTitle); + } + + @Override + protected String handleYear(String year) { + return createKeyValuePair("year", year); + } +} diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformers/DefaultQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/DefaultQueryTransformer.java new file mode 100644 index 00000000000..f77c42b99b9 --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/DefaultQueryTransformer.java @@ -0,0 +1,37 @@ +package org.jabref.logic.importer.fetcher.transformers; + +/** + * Default query transformer without any boolean operators + */ +public class DefaultQueryTransformer extends YearAndYearRangeByFilteringQueryTransformer { + + @Override + protected String getLogicalAndOperator() { + return " "; + } + + @Override + protected String getLogicalOrOperator() { + return " "; + } + + @Override + protected String getLogicalNotOperator() { + return ""; + } + + @Override + protected String handleAuthor(String author) { + return quoteStringIfSpaceIsContained(author); + } + + @Override + protected String handleTitle(String title) { + return quoteStringIfSpaceIsContained(title); + } + + @Override + protected String handleJournal(String journalTitle) { + return quoteStringIfSpaceIsContained(journalTitle); + } +} diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformators/GVKQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/GVKQueryTransformer.java similarity index 62% rename from src/main/java/org/jabref/logic/importer/fetcher/transformators/GVKQueryTransformer.java rename to src/main/java/org/jabref/logic/importer/fetcher/transformers/GVKQueryTransformer.java index 402e68b09c0..e2da33c57ed 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/transformators/GVKQueryTransformer.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/GVKQueryTransformer.java @@ -1,11 +1,11 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; import java.util.Optional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class GVKQueryTransformer extends AbstractQueryTransformer { +public class GVKQueryTransformer extends YearRangeByFilteringQueryTransformer { private static final Logger LOGGER = LoggerFactory.getLogger(GVKQueryTransformer.class); @Override @@ -16,52 +16,46 @@ protected String getLogicalAndOperator() { @Override protected String getLogicalOrOperator() { LOGGER.warn("GVK does not support Boolean OR operator"); - return ""; + return " "; } @Override protected String getLogicalNotOperator() { LOGGER.warn("GVK does not support Boolean NOT operator"); - return ""; + return " "; } @Override protected String handleAuthor(String author) { - return String.format("pica.per=\"%s\"", author); + return createKeyValuePair("pica.per", author, "="); } @Override protected String handleTitle(String title) { - return String.format("pica.tit=\"%s\"", title); + return createKeyValuePair("pica.tit", title, "="); } @Override protected String handleJournal(String journalTitle) { // zti means "Zeitschrift", does not search for conferences (kon:) - return String.format("pica.zti=\"%s\"", journalTitle); + return createKeyValuePair("pica.zti", journalTitle, "="); } @Override protected String handleYear(String year) { - // ver means Veröffentlichungsangaben - return "pica.ver=" + year; - } - - @Override - protected String handleYearRange(String yearRange) { - // Returns empty string as otherwise leads to no results - return ""; + // "erj" means "Erscheinungsjahr" + return "pica.erj=" + year; } @Override protected String handleUnFieldedTerm(String term) { // all does not search in full-text // Other option is txt: but this does not search in meta data - return String.format("pica.all=\"%s\"", term); + return createKeyValuePair("pica.all", term, "="); } @Override protected Optional handleOtherField(String fieldAsString, String term) { - return Optional.of("pica." + fieldAsString + "=\"" + term + "\""); + return Optional.of(createKeyValuePair("pica." + fieldAsString, term, "=")); } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformators/IEEEQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/IEEEQueryTransformer.java similarity index 64% rename from src/main/java/org/jabref/logic/importer/fetcher/transformators/IEEEQueryTransformer.java rename to src/main/java/org/jabref/logic/importer/fetcher/transformers/IEEEQueryTransformer.java index a6bb4cd49c4..ad18946be53 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/transformators/IEEEQueryTransformer.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/IEEEQueryTransformer.java @@ -1,4 +1,4 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; import java.util.Objects; import java.util.Optional; @@ -6,7 +6,7 @@ /** * Needs to be instantiated for each new query */ -public class IEEEQueryTransformer extends AbstractQueryTransformer { +public class IEEEQueryTransformer extends YearRangeByFilteringQueryTransformer { // These have to be integrated into the IEEE query URL as these are just supported as query parameters // Journal is wrapped in quotes by the transformer private String journal; @@ -31,18 +31,17 @@ protected String getLogicalNotOperator() { @Override protected String handleAuthor(String author) { - return String.format("author:\"%s\"", author); + return createKeyValuePair("author", author); } @Override protected String handleTitle(String title) { - return String.format("article_title:\"%s\"", title); + return createKeyValuePair("article_title", title); } @Override protected String handleJournal(String journalTitle) { - journal = String.format("\"%s\"", journalTitle); - return ""; + return handleUnFieldedTerm(journalTitle); } @Override @@ -52,19 +51,6 @@ protected String handleYear(String year) { return ""; } - @Override - protected String handleYearRange(String yearRange) { - String[] split = yearRange.split("-"); - startYear = Math.min(startYear, Integer.parseInt(split[0])); - endYear = Math.max(endYear, Integer.parseInt(split[1])); - return ""; - } - - @Override - protected String handleUnFieldedTerm(String term) { - return String.format("\"%s\"", term); - } - @Override protected Optional handleOtherField(String fieldAsString, String term) { return switch (fieldAsString) { @@ -78,14 +64,6 @@ private Optional handleArticleNumber(String term) { return Optional.empty(); } - public Optional getStartYear() { - return startYear == Integer.MAX_VALUE ? Optional.empty() : Optional.of(startYear); - } - - public Optional getEndYear() { - return endYear == Integer.MIN_VALUE ? Optional.empty() : Optional.of(endYear); - } - public Optional getJournal() { return Objects.isNull(journal) ? Optional.empty() : Optional.of(journal); } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformators/JstorQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/JstorQueryTransformer.java similarity index 62% rename from src/main/java/org/jabref/logic/importer/fetcher/transformators/JstorQueryTransformer.java rename to src/main/java/org/jabref/logic/importer/fetcher/transformers/JstorQueryTransformer.java index 1c7be5db728..05c4b9b6ff1 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/transformators/JstorQueryTransformer.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/JstorQueryTransformer.java @@ -1,4 +1,4 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; public class JstorQueryTransformer extends AbstractQueryTransformer { @Override @@ -18,17 +18,17 @@ protected String getLogicalNotOperator() { @Override protected String handleAuthor(String author) { - return String.format("au:\"%s\"", author); + return createKeyValuePair("au", author); } @Override protected String handleTitle(String title) { - return String.format("ti:\"%s\"", title); + return createKeyValuePair("ti", title); } @Override protected String handleJournal(String journalTitle) { - return String.format("pt:\"%s\"", journalTitle); + return createKeyValuePair("pt", journalTitle); } @Override @@ -38,12 +38,10 @@ protected String handleYear(String year) { @Override protected String handleYearRange(String yearRange) { - String[] split = yearRange.split("-"); - return "sd:" + split[0] + getLogicalAndOperator() + "ed:" + split[1]; - } - - @Override - protected String handleUnFieldedTerm(String term) { - return String.format("\"%s\"", term); + parseYearRange(yearRange); + if (endYear == Integer.MAX_VALUE) { + return yearRange; + } + return "sd:" + Integer.toString(startYear) + getLogicalAndOperator() + "ed:" + Integer.toString(endYear); } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformers/ScholarQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/ScholarQueryTransformer.java new file mode 100644 index 00000000000..a1556d5cbac --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/ScholarQueryTransformer.java @@ -0,0 +1,37 @@ +package org.jabref.logic.importer.fetcher.transformers; + +public class ScholarQueryTransformer extends YearAndYearRangeByFilteringQueryTransformer { + // Start year and end year have to be integrated into the query URL itself as these are just supported as query parameters + private int startYear = Integer.MAX_VALUE; + private int endYear = Integer.MIN_VALUE; + + @Override + protected String getLogicalAndOperator() { + return " AND "; + } + + @Override + protected String getLogicalOrOperator() { + return " OR "; + } + + @Override + protected String getLogicalNotOperator() { + return "-"; + } + + @Override + protected String handleAuthor(String author) { + return createKeyValuePair("author", author); + } + + @Override + protected String handleTitle(String title) { + return createKeyValuePair("allintitle", title); + } + + @Override + protected String handleJournal(String journalTitle) { + return createKeyValuePair("source", journalTitle); + } +} diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformators/SpringerQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/SpringerQueryTransformer.java similarity index 52% rename from src/main/java/org/jabref/logic/importer/fetcher/transformators/SpringerQueryTransformer.java rename to src/main/java/org/jabref/logic/importer/fetcher/transformers/SpringerQueryTransformer.java index 3907caef708..d8aaf31f7a3 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/transformators/SpringerQueryTransformer.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/SpringerQueryTransformer.java @@ -1,6 +1,4 @@ -package org.jabref.logic.importer.fetcher.transformators; - -import java.util.StringJoiner; +package org.jabref.logic.importer.fetcher.transformers; /** * This class converts a query string written in lucene syntax into a complex query. @@ -26,17 +24,17 @@ protected String getLogicalNotOperator() { @Override protected String handleAuthor(String author) { - return String.format("name:\"%s\"", author); + return createKeyValuePair("name", author); } @Override protected String handleTitle(String title) { - return String.format("title:\"%s\"", title); + return createKeyValuePair("title", title); } @Override protected String handleJournal(String journalTitle) { - return String.format("journal:\"%s\"", journalTitle); + return createKeyValuePair("journal", journalTitle); } @@ -44,19 +42,4 @@ protected String handleJournal(String journalTitle) { protected String handleYear(String year) { return String.format("date:%s*", year); } - - @Override - protected String handleYearRange(String yearRange) { - String[] split = yearRange.split("-"); - StringJoiner resultBuilder = new StringJoiner("*" + getLogicalOrOperator() + "date:", "(date:", "*)"); - for (int i = Integer.parseInt(split[0]); i <= Integer.parseInt(split[1]); i++) { - resultBuilder.add(String.valueOf(i)); - } - return resultBuilder.toString(); - } - - @Override - protected String handleUnFieldedTerm(String term) { - return "\"" + term + "\""; - } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformers/YearAndYearRangeByFilteringQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/YearAndYearRangeByFilteringQueryTransformer.java new file mode 100644 index 00000000000..fe348bf3acd --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/YearAndYearRangeByFilteringQueryTransformer.java @@ -0,0 +1,15 @@ +package org.jabref.logic.importer.fetcher.transformers; + +/** + * This is a query transformer for a fetcher, which does not support server-side filtering by year and year-range. + * Thus, JabRef (as client) filters for years and year ranges on client-side. + */ +public abstract class YearAndYearRangeByFilteringQueryTransformer extends YearRangeByFilteringQueryTransformer { + + @Override + protected String handleYear(String year) { + startYear = Math.min(startYear, Integer.parseInt(year)); + endYear = Math.max(endYear, Integer.parseInt(year)); + return ""; + } +} diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformers/YearRangeByFilteringQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/YearRangeByFilteringQueryTransformer.java new file mode 100644 index 00000000000..40480dc4d13 --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/YearRangeByFilteringQueryTransformer.java @@ -0,0 +1,31 @@ +package org.jabref.logic.importer.fetcher.transformers; + +import java.util.Optional; + +/** + * This is a query transformer for a fetcher, which does not support server-side filtering by year-range (e.g., only publications between 1999 and 2002). + * Thus, JabRef (as client) filters for year ranges on client-side. + */ +public abstract class YearRangeByFilteringQueryTransformer extends AbstractQueryTransformer { + + public Optional getStartYear() { + return startYear == Integer.MAX_VALUE ? Optional.empty() : Optional.of(startYear); + } + + public Optional getEndYear() { + return endYear == Integer.MIN_VALUE ? Optional.empty() : Optional.of(endYear); + } + + /** + * The API does not support querying for a year range. + * Nevertheless, we store the start year and end year, + * because we filter it after fetching all results + * + * @return "", because the provider does not support server-side filtering, but our client filters + */ + @Override + protected String handleYearRange(String yearRange) { + parseYearRange(yearRange); + return ""; + } +} diff --git a/src/main/java/org/jabref/logic/importer/fetcher/transformators/ZbMathQueryTransformer.java b/src/main/java/org/jabref/logic/importer/fetcher/transformers/ZbMathQueryTransformer.java similarity index 76% rename from src/main/java/org/jabref/logic/importer/fetcher/transformators/ZbMathQueryTransformer.java rename to src/main/java/org/jabref/logic/importer/fetcher/transformers/ZbMathQueryTransformer.java index b2a466c20a1..b1e0c42d300 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/transformators/ZbMathQueryTransformer.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/transformers/ZbMathQueryTransformer.java @@ -1,4 +1,4 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; public class ZbMathQueryTransformer extends AbstractQueryTransformer { @@ -19,17 +19,17 @@ protected String getLogicalNotOperator() { @Override protected String handleAuthor(String author) { - return String.format("au:\"%s\"", author); + return createKeyValuePair("au", author); } @Override protected String handleTitle(String title) { - return String.format("ti:\"%s\"", title); + return createKeyValuePair("ti", title); } @Override protected String handleJournal(String journalTitle) { - return String.format("so:\"%s\"", journalTitle); + return createKeyValuePair("so", journalTitle); } @Override @@ -44,6 +44,6 @@ protected String handleYearRange(String yearRange) { @Override protected String handleUnFieldedTerm(String term) { - return String.format("any:\"%s\"", term); + return createKeyValuePair("any", term); } } diff --git a/src/main/java/org/jabref/logic/importer/fileformat/GvkParser.java b/src/main/java/org/jabref/logic/importer/fileformat/GvkParser.java index 9641ccdb0a0..6dc44d0ed67 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/GvkParser.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/GvkParser.java @@ -48,7 +48,7 @@ private List parseEntries(Document content) { // Namespace srwNamespace = Namespace.getNamespace("srw","http://www.loc.gov/zing/srw/"); - // Schleife ueber allen Teilergebnissen + // Schleife ueber alle Teilergebnisse // Element root = content.getDocumentElement(); Element root = (Element) content.getElementsByTagName("zs:searchRetrieveResponse").item(0); Element srwrecords = getChild("zs:records", root); @@ -62,7 +62,9 @@ private List parseEntries(Document content) { if (e != null) { e = getChild("record", e); if (e != null) { - result.add(parseEntry(e)); + BibEntry bibEntry = parseEntry(e); + // TODO: Add filtering on years (based on org.jabref.logic.importer.fetcher.transformers.YearRangeByFilteringQueryTransformer.getStartYear) + result.add(bibEntry); } } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java index 539decbf37c..6da4e04affa 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java @@ -10,7 +10,7 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; -import org.jabref.logic.importer.fetcher.transformators.AbstractQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.AbstractQueryTransformer; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UnknownField; diff --git a/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java index 88cd4b91ef0..17e8b2ded4e 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java @@ -5,7 +5,7 @@ import java.util.List; import org.jabref.logic.importer.FetcherException; -import org.jabref.logic.importer.fetcher.transformators.AbstractQueryTransformer; +import org.jabref.logic.importer.fetcher.transformers.AbstractQueryTransformer; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UnknownField; @@ -31,32 +31,30 @@ public class GvkFetcherTest { public void setUp() { fetcher = new GvkFetcher(); - bibEntryPPN591166003 = new BibEntry(); - bibEntryPPN591166003.setType(StandardEntryType.Book); - bibEntryPPN591166003.setField(StandardField.TITLE, "Effective Java"); - bibEntryPPN591166003.setField(StandardField.PUBLISHER, "Addison-Wesley"); - bibEntryPPN591166003.setField(StandardField.YEAR, "2008"); - bibEntryPPN591166003.setField(StandardField.AUTHOR, "Joshua Bloch"); - bibEntryPPN591166003.setField(StandardField.SERIES, "The @Java series"); - bibEntryPPN591166003.setField(StandardField.ADDRESS, "Upper Saddle River, NJ [u.a.]"); - bibEntryPPN591166003.setField(StandardField.EDITION, "2. ed., 5. print."); - bibEntryPPN591166003.setField(StandardField.NOTE, "Literaturverz. S. 321 - 325"); - bibEntryPPN591166003.setField(StandardField.ISBN, "9780321356680"); - bibEntryPPN591166003.setField(StandardField.PAGETOTAL, "XXI, 346"); - bibEntryPPN591166003.setField(new UnknownField("ppn_gvk"), "591166003"); - bibEntryPPN591166003.setField(StandardField.SUBTITLE, "[revised and updated for JAVA SE 6]"); - - bibEntryPPN66391437X = new BibEntry(); - bibEntryPPN66391437X.setType(StandardEntryType.Book); - bibEntryPPN66391437X.setField(StandardField.TITLE, "Effective unit testing"); - bibEntryPPN66391437X.setField(StandardField.PUBLISHER, "Manning"); - bibEntryPPN66391437X.setField(StandardField.YEAR, "2013"); - bibEntryPPN66391437X.setField(StandardField.AUTHOR, "Lasse Koskela"); - bibEntryPPN66391437X.setField(StandardField.ADDRESS, "Shelter Island, NY"); - bibEntryPPN66391437X.setField(StandardField.ISBN, "9781935182573"); - bibEntryPPN66391437X.setField(StandardField.PAGETOTAL, "XXIV, 223"); - bibEntryPPN66391437X.setField(new UnknownField("ppn_gvk"), "66391437X"); - bibEntryPPN66391437X.setField(StandardField.SUBTITLE, "A guide for Java developers"); + bibEntryPPN591166003 = new BibEntry(StandardEntryType.Book) + .withField(StandardField.TITLE, "Effective Java") + .withField(StandardField.PUBLISHER, "Addison-Wesley") + .withField(StandardField.YEAR, "2008") + .withField(StandardField.AUTHOR, "Joshua Bloch") + .withField(StandardField.SERIES, "The @Java series") + .withField(StandardField.ADDRESS, "Upper Saddle River, NJ [u.a.]") + .withField(StandardField.EDITION, "2. ed., 5. print.") + .withField(StandardField.NOTE, "Literaturverz. S. 321 - 325") + .withField(StandardField.ISBN, "9780321356680") + .withField(StandardField.PAGETOTAL, "XXI, 346") + .withField(new UnknownField("ppn_gvk"), "591166003") + .withField(StandardField.SUBTITLE, "[revised and updated for JAVA SE 6]"); + + bibEntryPPN66391437X = new BibEntry(StandardEntryType.Book) + .withField(StandardField.TITLE, "Effective unit testing") + .withField(StandardField.PUBLISHER, "Manning") + .withField(StandardField.YEAR, "2013") + .withField(StandardField.AUTHOR, "Lasse Koskela") + .withField(StandardField.ADDRESS, "Shelter Island, NY") + .withField(StandardField.ISBN, "9781935182573") + .withField(StandardField.PAGETOTAL, "XXIV, 223") + .withField(new UnknownField("ppn_gvk"), "66391437X") + .withField(StandardField.SUBTITLE, "A guide for Java developers"); } @Test @@ -69,7 +67,7 @@ public void simpleSearchQueryURLCorrect() throws Exception { String query = "java jdk"; QueryNode luceneQuery = new StandardSyntaxParser().parse(query, AbstractQueryTransformer.NO_EXPLICIT_FIELD); URL url = fetcher.getURLForQuery(luceneQuery); - assertEquals("http://sru.gbv.de/gvk?version=1.1&operation=searchRetrieve&query=pica.all%3D%22java%22+and+pica.all%3D%22jdk%22&maximumRecords=50&recordSchema=picaxml&sortKeys=Year%2C%2C1", url.toString()); + assertEquals("http://sru.gbv.de/gvk?version=1.1&operation=searchRetrieve&query=pica.all%3Djava+and+pica.all%3Djdk&maximumRecords=50&recordSchema=picaxml&sortKeys=Year%2C%2C1", url.toString()); } @Test @@ -77,7 +75,7 @@ public void complexSearchQueryURLCorrect() throws Exception { String query = "kon:java tit:jdk"; QueryNode luceneQuery = new StandardSyntaxParser().parse(query, AbstractQueryTransformer.NO_EXPLICIT_FIELD); URL url = fetcher.getURLForQuery(luceneQuery); - assertEquals("http://sru.gbv.de/gvk?version=1.1&operation=searchRetrieve&query=pica.kon%3D%22java%22+and+pica.tit%3D%22jdk%22&maximumRecords=50&recordSchema=picaxml&sortKeys=Year%2C%2C1", url.toString()); + assertEquals("http://sru.gbv.de/gvk?version=1.1&operation=searchRetrieve&query=pica.kon%3Djava+and+pica.tit%3Djdk&maximumRecords=50&recordSchema=picaxml&sortKeys=Year%2C%2C1", url.toString()); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformators/JstorQueryTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformators/JstorQueryTransformerTest.java deleted file mode 100644 index e8a5a6014b9..00000000000 --- a/src/test/java/org/jabref/logic/importer/fetcher/transformators/JstorQueryTransformerTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.jabref.logic.importer.fetcher.transformators; - -class JstorQueryTransformerTest implements InfixTransformerTest { - - @Override - public AbstractQueryTransformer getTransformator() { - return new JstorQueryTransformer(); - } - - @Override - public String getAuthorPrefix() { - return "au:"; - } - - @Override - public String getUnFieldedPrefix() { - return ""; - } - - @Override - public String getJournalPrefix() { - return "pt:"; - } - - @Override - public String getTitlePrefix() { - return "ti:"; - } - - @Override - public void convertYearField() throws Exception { - - } - - @Override - public void convertYearRangeField() throws Exception { - - } -} diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformators/ArXivQueryTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformers/ArXivQueryTransformerTest.java similarity index 54% rename from src/test/java/org/jabref/logic/importer/fetcher/transformators/ArXivQueryTransformerTest.java rename to src/test/java/org/jabref/logic/importer/fetcher/transformers/ArXivQueryTransformerTest.java index ac5933ae7bb..0eba3b200aa 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/transformators/ArXivQueryTransformerTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/transformers/ArXivQueryTransformerTest.java @@ -1,4 +1,4 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; import java.util.Optional; @@ -7,10 +7,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -class ArXivQueryTransformerTest implements InfixTransformerTest { +class ArXivQueryTransformerTest extends YearRangeByFilteringQueryTransformerTest { @Override - public AbstractQueryTransformer getTransformator() { + public ArXivQueryTransformer getTransformer() { return new ArXivQueryTransformer(); } @@ -36,25 +36,13 @@ public String getTitlePrefix() { @Override public void convertYearField() throws Exception { - ArXivQueryTransformer transformer = ((ArXivQueryTransformer) getTransformator()); + ArXivQueryTransformer transformer = getTransformer(); String queryString = "2018"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); Optional query = transformer.transformLuceneQuery(luceneQuery); - Optional expected = Optional.of(queryString); - assertEquals(expected, query); + assertEquals(Optional.of("2018"), query); assertEquals(2018, transformer.getStartYear()); assertEquals(2018, transformer.getEndYear()); } - @Override - public void convertYearRangeField() throws Exception { - ArXivQueryTransformer transformer = ((ArXivQueryTransformer) getTransformator()); - - String queryString = "year-range:2018-2021"; - QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - transformer.transformLuceneQuery(luceneQuery); - - assertEquals(2018, transformer.getStartYear()); - assertEquals(2021, transformer.getEndYear()); - } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformers/CollectionOfComputerScienceBibliographiesQueryTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformers/CollectionOfComputerScienceBibliographiesQueryTransformerTest.java new file mode 100644 index 00000000000..305421a3db1 --- /dev/null +++ b/src/test/java/org/jabref/logic/importer/fetcher/transformers/CollectionOfComputerScienceBibliographiesQueryTransformerTest.java @@ -0,0 +1,53 @@ +package org.jabref.logic.importer.fetcher.transformers; + +import java.util.Optional; + +import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; +import org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class CollectionOfComputerScienceBibliographiesQueryTransformerTest extends InfixTransformerTest { + + @Override + public CollectionOfComputerScienceBibliographiesQueryTransformer getTransformer() { + return new CollectionOfComputerScienceBibliographiesQueryTransformer(); + } + + @Override + public String getAuthorPrefix() { + return "au:"; + } + + @Override + public String getUnFieldedPrefix() { + return ""; + } + + @Override + public String getJournalPrefix() { + return ""; + } + + @Override + public String getTitlePrefix() { + return "ti:"; + } + + @Override + public void convertYearField() throws Exception { + String queryString = "2018"; + QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); + Optional query = getTransformer().transformLuceneQuery(luceneQuery); + assertEquals(Optional.of("year:2018"), query); + } + + @Override + public void convertYearRangeField() throws Exception { + String queryString = "year-range:2018-2021"; + QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); + Optional query = getTransformer().transformLuceneQuery(luceneQuery); + assertEquals(Optional.of("year:2018 OR year:2019 OR year:2020 OR year:2021"), query); + } + +} diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformators/DBLPQueryTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformers/DBLPQueryTransformerTest.java similarity index 78% rename from src/test/java/org/jabref/logic/importer/fetcher/transformators/DBLPQueryTransformerTest.java rename to src/test/java/org/jabref/logic/importer/fetcher/transformers/DBLPQueryTransformerTest.java index d531f19da9d..1801576f0b2 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/transformators/DBLPQueryTransformerTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/transformers/DBLPQueryTransformerTest.java @@ -1,4 +1,4 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; import java.util.Optional; @@ -7,10 +7,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -class DBLPQueryTransformerTest implements InfixTransformerTest { +class DBLPQueryTransformerTest extends InfixTransformerTest { @Override - public AbstractQueryTransformer getTransformator() { + public DBLPQueryTransformer getTransformer() { return new DBLPQueryTransformer(); } @@ -38,7 +38,7 @@ public String getTitlePrefix() { public void convertYearField() throws Exception { String queryString = "year:2015"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional searchQuery = getTransformator().transformLuceneQuery(luceneQuery); + Optional searchQuery = getTransformer().transformLuceneQuery(luceneQuery); Optional expected = Optional.of("2015"); assertEquals(expected, searchQuery); } @@ -47,7 +47,7 @@ public void convertYearField() throws Exception { public void convertYearRangeField() throws Exception { String queryString = "year-range:2012-2015"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional searchQuery = getTransformator().transformLuceneQuery(luceneQuery); + Optional searchQuery = getTransformer().transformLuceneQuery(luceneQuery); Optional expected = Optional.of("2012|2013|2014|2015"); assertEquals(expected, searchQuery); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformers/DefaultQueryTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformers/DefaultQueryTransformerTest.java new file mode 100644 index 00000000000..70b4e4a5bfb --- /dev/null +++ b/src/test/java/org/jabref/logic/importer/fetcher/transformers/DefaultQueryTransformerTest.java @@ -0,0 +1,29 @@ +package org.jabref.logic.importer.fetcher.transformers; + +class DefaultQueryTransformerTest extends YearAndYearRangeByFilteringQueryTransformerTest { + + @Override + protected DefaultQueryTransformer getTransformer() { + return new DefaultQueryTransformer(); + } + + @Override + public String getAuthorPrefix() { + return ""; + } + + @Override + public String getUnFieldedPrefix() { + return ""; + } + + @Override + public String getJournalPrefix() { + return ""; + } + + @Override + public String getTitlePrefix() { + return ""; + } +} diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformators/GVKQueryTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformers/GVKQueryTransformerTest.java similarity index 80% rename from src/test/java/org/jabref/logic/importer/fetcher/transformators/GVKQueryTransformerTest.java rename to src/test/java/org/jabref/logic/importer/fetcher/transformers/GVKQueryTransformerTest.java index 9dab863dc10..0f366ece141 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/transformators/GVKQueryTransformerTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/transformers/GVKQueryTransformerTest.java @@ -1,4 +1,4 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; import java.util.Optional; @@ -8,10 +8,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -class GVKQueryTransformerTest implements InfixTransformerTest { +class GVKQueryTransformerTest extends InfixTransformerTest { @Override - public AbstractQueryTransformer getTransformator() { + public GVKQueryTransformer getTransformer() { return new GVKQueryTransformer(); } @@ -37,10 +37,9 @@ public String getTitlePrefix() { @Override public void convertYearField() throws Exception { - String queryString = "year:2018"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional query = getTransformator().transformLuceneQuery(luceneQuery); + Optional query = getTransformer().transformLuceneQuery(luceneQuery); Optional expected = Optional.of("ver:2018"); assertEquals(expected, query); @@ -49,6 +48,5 @@ public void convertYearField() throws Exception { @Disabled("Not supported by GVK") @Override public void convertYearRangeField() throws Exception { - } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformators/IEEEQueryTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformers/IEEEQueryTransformerTest.java similarity index 81% rename from src/test/java/org/jabref/logic/importer/fetcher/transformators/IEEEQueryTransformerTest.java rename to src/test/java/org/jabref/logic/importer/fetcher/transformers/IEEEQueryTransformerTest.java index 7d2042a34e3..e1b252e1f12 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/transformators/IEEEQueryTransformerTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/transformers/IEEEQueryTransformerTest.java @@ -1,14 +1,16 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; + +import java.util.Optional; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; import org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser; import static org.junit.jupiter.api.Assertions.assertEquals; -class IEEEQueryTransformerTest implements InfixTransformerTest { +class IEEEQueryTransformerTest extends InfixTransformerTest { @Override - public AbstractQueryTransformer getTransformator() { + public IEEEQueryTransformer getTransformer() { return new IEEEQueryTransformer(); } @@ -34,7 +36,7 @@ public String getTitlePrefix() { @Override public void convertJournalField() throws Exception { - IEEEQueryTransformer transformer = ((IEEEQueryTransformer) getTransformator()); + IEEEQueryTransformer transformer = ((IEEEQueryTransformer) getTransformer()); String queryString = "journal:Nature"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); @@ -45,11 +47,14 @@ public void convertJournalField() throws Exception { @Override public void convertYearField() throws Exception { - IEEEQueryTransformer transformer = ((IEEEQueryTransformer) getTransformator()); + // IEEE does not support year range + // Thus, a generic test does not work + + IEEEQueryTransformer transformer = ((IEEEQueryTransformer) getTransformer()); String queryString = "year:2021"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - transformer.transformLuceneQuery(luceneQuery); + Optional result = transformer.transformLuceneQuery(luceneQuery); assertEquals(2021, transformer.getStartYear()); assertEquals(2021, transformer.getEndYear()); @@ -57,8 +62,7 @@ public void convertYearField() throws Exception { @Override public void convertYearRangeField() throws Exception { - - IEEEQueryTransformer transformer = ((IEEEQueryTransformer) getTransformator()); + IEEEQueryTransformer transformer = ((IEEEQueryTransformer) getTransformer()); String queryString = "year-range:2018-2021"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformators/InfixTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformers/InfixTransformerTest.java similarity index 56% rename from src/test/java/org/jabref/logic/importer/fetcher/transformators/InfixTransformerTest.java rename to src/test/java/org/jabref/logic/importer/fetcher/transformers/InfixTransformerTest.java index f986a04c7e0..70088f66604 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/transformators/InfixTransformerTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/transformers/InfixTransformerTest.java @@ -1,4 +1,4 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; import java.util.Optional; @@ -11,87 +11,88 @@ /** * Test Interface for all transformers that use infix notation for their logical binary operators */ -public interface InfixTransformerTest { +public abstract class InfixTransformerTest { - AbstractQueryTransformer getTransformator(); + protected abstract T getTransformer(); /* All prefixes have to include the used separator * Example in the case of ':': "author:" */ - String getAuthorPrefix(); - String getUnFieldedPrefix(); + protected abstract String getAuthorPrefix(); - String getJournalPrefix(); + protected abstract String getUnFieldedPrefix(); - String getTitlePrefix(); + protected abstract String getJournalPrefix(); + + protected abstract String getTitlePrefix(); @Test - default void convertAuthorField() throws Exception { + public void convertAuthorField() throws Exception { String queryString = "author:\"Igor Steinmacher\""; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional searchQuery = getTransformator().transformLuceneQuery(luceneQuery); + Optional searchQuery = getTransformer().transformLuceneQuery(luceneQuery); Optional expected = Optional.of(getAuthorPrefix() + "\"Igor Steinmacher\""); assertEquals(expected, searchQuery); } @Test - default void convertUnFieldedTerm() throws Exception { + public void convertUnFieldedTerm() throws Exception { String queryString = "\"default value\""; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional searchQuery = getTransformator().transformLuceneQuery(luceneQuery); + Optional searchQuery = getTransformer().transformLuceneQuery(luceneQuery); Optional expected = Optional.of(getUnFieldedPrefix() + queryString); assertEquals(expected, searchQuery); } @Test - default void convertExplicitUnFieldedTerm() throws Exception { + public void convertExplicitUnFieldedTerm() throws Exception { String queryString = "default:\"default value\""; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional searchQuery = getTransformator().transformLuceneQuery(luceneQuery); + Optional searchQuery = getTransformer().transformLuceneQuery(luceneQuery); Optional expected = Optional.of(getUnFieldedPrefix() + "\"default value\""); assertEquals(expected, searchQuery); } @Test - default void convertJournalField() throws Exception { + public void convertJournalField() throws Exception { String queryString = "journal:Nature"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional searchQuery = getTransformator().transformLuceneQuery(luceneQuery); - Optional expected = Optional.of(getJournalPrefix() + "\"Nature\""); + Optional searchQuery = getTransformer().transformLuceneQuery(luceneQuery); + Optional expected = Optional.of(getJournalPrefix() + "Nature"); assertEquals(expected, searchQuery); } @Test - void convertYearField() throws Exception; + public abstract void convertYearField() throws Exception; @Test - void convertYearRangeField() throws Exception; + public abstract void convertYearRangeField() throws Exception; @Test - default void convertMultipleValuesWithTheSameField() throws Exception { + public void convertMultipleValuesWithTheSameField() throws Exception { String queryString = "author:\"Igor Steinmacher\" author:\"Christoph Treude\""; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional searchQuery = getTransformator().transformLuceneQuery(luceneQuery); - Optional expected = Optional.of(getAuthorPrefix() + "\"Igor Steinmacher\"" + getTransformator().getLogicalAndOperator() + getAuthorPrefix() + "\"Christoph Treude\""); + Optional searchQuery = getTransformer().transformLuceneQuery(luceneQuery); + Optional expected = Optional.of(getAuthorPrefix() + "\"Igor Steinmacher\"" + getTransformer().getLogicalAndOperator() + getAuthorPrefix() + "\"Christoph Treude\""); assertEquals(expected, searchQuery); } @Test - default void groupedOperations() throws Exception { + public void groupedOperations() throws Exception { String queryString = "(author:\"Igor Steinmacher\" OR author:\"Christoph Treude\" AND author:\"Christoph Freunde\") AND title:test"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional searchQuery = getTransformator().transformLuceneQuery(luceneQuery); - Optional expected = Optional.of("(" + getAuthorPrefix() + "\"Igor Steinmacher\"" + getTransformator().getLogicalOrOperator() + "(" + getAuthorPrefix() + "\"Christoph Treude\"" + getTransformator().getLogicalAndOperator() + getAuthorPrefix() + "\"Christoph Freunde\"))" + getTransformator().getLogicalAndOperator() + getTitlePrefix() + "\"test\""); + Optional searchQuery = getTransformer().transformLuceneQuery(luceneQuery); + Optional expected = Optional.of("(" + getAuthorPrefix() + "\"Igor Steinmacher\"" + getTransformer().getLogicalOrOperator() + "(" + getAuthorPrefix() + "\"Christoph Treude\"" + getTransformer().getLogicalAndOperator() + getAuthorPrefix() + "\"Christoph Freunde\"))" + getTransformer().getLogicalAndOperator() + getTitlePrefix() + "test"); assertEquals(expected, searchQuery); } @Test - default void notOperator() throws Exception { + public void notOperator() throws Exception { String queryString = "!(author:\"Igor Steinmacher\" OR author:\"Christoph Treude\")"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional searchQuery = getTransformator().transformLuceneQuery(luceneQuery); - Optional expected = Optional.of(getTransformator().getLogicalNotOperator() + "(" + getAuthorPrefix() + "\"Igor Steinmacher\"" + getTransformator().getLogicalOrOperator() + getAuthorPrefix() + "\"Christoph Treude\")"); + Optional searchQuery = getTransformer().transformLuceneQuery(luceneQuery); + Optional expected = Optional.of(getTransformer().getLogicalNotOperator() + "(" + getAuthorPrefix() + "\"Igor Steinmacher\"" + getTransformer().getLogicalOrOperator() + getAuthorPrefix() + "\"Christoph Treude\")"); assertEquals(expected, searchQuery); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformators/ScholarQueryTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformers/JstorQueryTransformerTest.java similarity index 52% rename from src/test/java/org/jabref/logic/importer/fetcher/transformators/ScholarQueryTransformerTest.java rename to src/test/java/org/jabref/logic/importer/fetcher/transformers/JstorQueryTransformerTest.java index e83329b893a..85a1db5c454 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/transformators/ScholarQueryTransformerTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/transformers/JstorQueryTransformerTest.java @@ -1,20 +1,22 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; + +import java.util.Optional; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; import org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser; import static org.junit.jupiter.api.Assertions.assertEquals; -class ScholarQueryTransformerTest implements InfixTransformerTest { +class JstorQueryTransformerTest extends InfixTransformerTest { @Override - public AbstractQueryTransformer getTransformator() { - return new ScholarQueryTransformer(); + public JstorQueryTransformer getTransformer() { + return new JstorQueryTransformer(); } @Override public String getAuthorPrefix() { - return "author:"; + return "au:"; } @Override @@ -24,36 +26,27 @@ public String getUnFieldedPrefix() { @Override public String getJournalPrefix() { - return "source:"; + return "pt:"; } @Override public String getTitlePrefix() { - return "allintitle:"; + return "ti:"; } @Override public void convertYearField() throws Exception { - ScholarQueryTransformer transformer = ((ScholarQueryTransformer) getTransformator()); - - String queryString = "year:2021"; + String queryString = "year:2018"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - transformer.transformLuceneQuery(luceneQuery); - - assertEquals(2021, transformer.getStartYear()); - assertEquals(2021, transformer.getEndYear()); + Optional query = getTransformer().transformLuceneQuery(luceneQuery); + assertEquals(Optional.of("sd:2018 AND ed:2018"), query); } @Override public void convertYearRangeField() throws Exception { - - ScholarQueryTransformer transformer = ((ScholarQueryTransformer) getTransformator()); - String queryString = "year-range:2018-2021"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - transformer.transformLuceneQuery(luceneQuery); - - assertEquals(2018, transformer.getStartYear()); - assertEquals(2021, transformer.getEndYear()); + Optional query = getTransformer().transformLuceneQuery(luceneQuery); + assertEquals(Optional.of("sd:2018 AND ed:2021"), query); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformers/ScholarQueryTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformers/ScholarQueryTransformerTest.java new file mode 100644 index 00000000000..f2264ca0735 --- /dev/null +++ b/src/test/java/org/jabref/logic/importer/fetcher/transformers/ScholarQueryTransformerTest.java @@ -0,0 +1,30 @@ +package org.jabref.logic.importer.fetcher.transformers; + +class ScholarQueryTransformerTest extends YearAndYearRangeByFilteringQueryTransformerTest { + + @Override + public ScholarQueryTransformer getTransformer() { + return new ScholarQueryTransformer(); + } + + @Override + public String getAuthorPrefix() { + return "author:"; + } + + @Override + public String getUnFieldedPrefix() { + return ""; + } + + @Override + public String getJournalPrefix() { + return "source:"; + } + + @Override + public String getTitlePrefix() { + return "allintitle:"; + } + +} diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformators/SpringerQueryTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformers/SpringerQueryTransformerTest.java similarity index 78% rename from src/test/java/org/jabref/logic/importer/fetcher/transformators/SpringerQueryTransformerTest.java rename to src/test/java/org/jabref/logic/importer/fetcher/transformers/SpringerQueryTransformerTest.java index c0fbd484251..fb53f80ba37 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/transformators/SpringerQueryTransformerTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/transformers/SpringerQueryTransformerTest.java @@ -1,4 +1,4 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; import java.util.Optional; @@ -7,7 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -class SpringerQueryTransformerTest implements InfixTransformerTest { +class SpringerQueryTransformerTest extends InfixTransformerTest { @Override public String getAuthorPrefix() { @@ -15,7 +15,7 @@ public String getAuthorPrefix() { } @Override - public AbstractQueryTransformer getTransformator() { + public SpringerQueryTransformer getTransformer() { return new SpringerQueryTransformer(); } @@ -38,7 +38,7 @@ public String getTitlePrefix() { public void convertYearField() throws Exception { String queryString = "year:2015"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional searchQuery = getTransformator().transformLuceneQuery(luceneQuery); + Optional searchQuery = getTransformer().transformLuceneQuery(luceneQuery); Optional expected = Optional.of("date:2015*"); assertEquals(expected, searchQuery); @@ -48,7 +48,7 @@ public void convertYearField() throws Exception { public void convertYearRangeField() throws Exception { String queryString = "year-range:2012-2015"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional searchQuery = getTransformator().transformLuceneQuery(luceneQuery); + Optional searchQuery = getTransformer().transformLuceneQuery(luceneQuery); Optional expected = Optional.of("date:2012* OR date:2013* OR date:2014* OR date:2015*"); assertEquals(expected, searchQuery); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformers/YearAndYearRangeByFilteringQueryTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformers/YearAndYearRangeByFilteringQueryTransformerTest.java new file mode 100644 index 00000000000..54bd9c12247 --- /dev/null +++ b/src/test/java/org/jabref/logic/importer/fetcher/transformers/YearAndYearRangeByFilteringQueryTransformerTest.java @@ -0,0 +1,21 @@ +package org.jabref.logic.importer.fetcher.transformers; + +import java.util.Optional; + +import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; +import org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public abstract class YearAndYearRangeByFilteringQueryTransformerTest extends YearRangeByFilteringQueryTransformerTest { + @Override + public void convertYearField() throws Exception { + YearAndYearRangeByFilteringQueryTransformer transformer = getTransformer(); + String queryString = "year:2021"; + QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); + Optional query = transformer.transformLuceneQuery(luceneQuery); + assertEquals(Optional.of(""), query); + assertEquals(2021, transformer.getStartYear()); + assertEquals(2021, transformer.getEndYear()); + } +} diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformers/YearRangeByFilteringQueryTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformers/YearRangeByFilteringQueryTransformerTest.java new file mode 100644 index 00000000000..244f2ed8e4a --- /dev/null +++ b/src/test/java/org/jabref/logic/importer/fetcher/transformers/YearRangeByFilteringQueryTransformerTest.java @@ -0,0 +1,31 @@ +package org.jabref.logic.importer.fetcher.transformers; + +import java.util.Optional; + +import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; +import org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public abstract class YearRangeByFilteringQueryTransformerTest extends InfixTransformerTest { + + @Override + public void convertYearRangeField() throws Exception { + YearRangeByFilteringQueryTransformer transformer = getTransformer(); + + String queryString = "year-range:2018-2021"; + QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); + Optional result = transformer.transformLuceneQuery(luceneQuery); + + // The API does not support querying for a year range + // The implementation of the fetcher filters the results manually + + // The implementations returns an empty query + assertEquals(Optional.of(""), result); + + // The implementation sets the start year and end year values according to the query + assertEquals(2018, transformer.getStartYear()); + assertEquals(2021, transformer.getEndYear()); + } + +} diff --git a/src/test/java/org/jabref/logic/importer/fetcher/transformators/ZbMathQueryTransformerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/transformers/ZbMathQueryTransformerTest.java similarity index 78% rename from src/test/java/org/jabref/logic/importer/fetcher/transformators/ZbMathQueryTransformerTest.java rename to src/test/java/org/jabref/logic/importer/fetcher/transformers/ZbMathQueryTransformerTest.java index 73737455534..0b9cd9a88d1 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/transformators/ZbMathQueryTransformerTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/transformers/ZbMathQueryTransformerTest.java @@ -1,4 +1,4 @@ -package org.jabref.logic.importer.fetcher.transformators; +package org.jabref.logic.importer.fetcher.transformers; import java.util.Optional; @@ -7,10 +7,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -class ZbMathQueryTransformerTest implements InfixTransformerTest { +class ZbMathQueryTransformerTest extends InfixTransformerTest { @Override - public AbstractQueryTransformer getTransformator() { + public ZbMathQueryTransformer getTransformer() { return new ZbMathQueryTransformer(); } @@ -38,7 +38,7 @@ public String getTitlePrefix() { public void convertYearField() throws Exception { String queryString = "year:2015"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional searchQuery = getTransformator().transformLuceneQuery(luceneQuery); + Optional searchQuery = getTransformer().transformLuceneQuery(luceneQuery); Optional expected = Optional.of("py:2015"); assertEquals(expected, searchQuery); } @@ -47,7 +47,7 @@ public void convertYearField() throws Exception { public void convertYearRangeField() throws Exception { String queryString = "year-range:2012-2015"; QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD); - Optional searchQuery = getTransformator().transformLuceneQuery(luceneQuery); + Optional searchQuery = getTransformer().transformLuceneQuery(luceneQuery); Optional expected = Optional.of("py:2012-2015"); assertEquals(expected, searchQuery); }