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 CCSB and DOAJ #7426

Merged
merged 26 commits into from
May 1, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.transformators.CollectionOfComputerScienceBibliographiesQueryTransformer;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldFactory;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.transformators.DefaultLuceneQueryTransformer;
import org.jabref.logic.util.OS;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
Expand Down Expand Up @@ -192,7 +192,7 @@ public Optional<HelpFile> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.transformators.DefaultLuceneQueryTransformer;
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.logic.importer.util.MediaTypes;
import org.jabref.logic.layout.format.LatexToUnicodeFormatter;
Expand Down Expand Up @@ -52,7 +52,7 @@ public Optional<HelpFile> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.transformators.JstorQueryTransformer;
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.logic.net.URLDownload;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.logic.importer.fetcher.transformators;

import java.util.Optional;
import java.util.StringJoiner;
import java.util.stream.Collectors;

import org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode;
Expand All @@ -13,7 +14,7 @@
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 {
Expand Down Expand Up @@ -142,7 +143,17 @@ private Optional<String> transform(ModifierQueryNode query) {
*
* Example: <code>2015-2021</code>
*/
protected abstract String handleYearRange(String yearRange);
protected String handleYearRange(String yearRange) {
String[] split = yearRange.split("-");
if (split.length != 2) {
return yearRange;
}
StringJoiner resultBuilder = new StringJoiner(getLogicalOrOperator());
for (int i = Integer.parseInt(split[0]); i <= Integer.parseInt(split[1]); i++) {
resultBuilder.add(handleYear(String.valueOf(i)));
}
return resultBuilder.toString();
}

/**
* Return a string representation of the un-fielded (default fielded) term
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.jabref.logic.importer.fetcher.transformators;

public class CollectionOfComputerScienceBibliographiesQueryTransformer extends AbstractQueryTransformer {

@Override
protected String getLogicalAndOperator() {
return " ";
}

@Override
protected String getLogicalOrOperator() {
return " OR ";
}

@Override
protected String getLogicalNotOperator() {
return "-";
}

@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("\"%s\"", journalTitle);
}

@Override
protected String handleYear(String year) {
return String.format("year:\"%s\"", year);
}

@Override
protected String handleUnFieldedTerm(String term) {
if (term.contains(" ")) {
return String.format("\"%s\"", term);
} else {
return term;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.jabref.logic.importer.fetcher.transformators;

/**
* 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 handleOtherField("author", author).get();
}

@Override
protected String handleTitle(String title) {
return handleOtherField("title", title).get();
}

@Override
protected String handleJournal(String journalTitle) {
return handleOtherField("journal", journalTitle).get();
}

@Override
protected String handleYear(String year) {
return handleOtherField("year", year).get();
}

@Override
protected String handleUnFieldedTerm(String term) {
return "\"" + term + "\"";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ protected String handleYear(String year) {
return year;
}

@Override
protected String handleYearRange(String yearRange) {
return yearRange;
}

@Override
protected String handleUnFieldedTerm(String term) {
return term;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ 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
Expand All @@ -43,8 +43,8 @@ protected String handleJournal(String journalTitle) {

@Override
protected String handleYear(String year) {
// ver means Veröffentlichungsangaben
return "pica.ver=" + year;
// "erj" means "Erscheinungsjahr"
return "pica.erj=" + year;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ protected String handleYear(String year) {
@Override
protected String handleYearRange(String yearRange) {
String[] split = yearRange.split("-");
if (split.length != 2) {
return yearRange;
}
return "sd:" + split[0] + getLogicalAndOperator() + "ed:" + split[1];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.jabref.logic.importer.fetcher.transformators;

import java.util.StringJoiner;

/**
* This class converts a query string written in lucene syntax into a complex query.
*
Expand Down Expand Up @@ -45,16 +43,6 @@ 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 + "\"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class ArXivQueryTransformerTest implements InfixTransformerTest {

@Override
public AbstractQueryTransformer getTransformator() {
public AbstractQueryTransformer getTransformer() {
return new ArXivQueryTransformer();
}

Expand All @@ -36,7 +36,7 @@ public String getTitlePrefix() {

@Override
public void convertYearField() throws Exception {
ArXivQueryTransformer transformer = ((ArXivQueryTransformer) getTransformator());
ArXivQueryTransformer transformer = ((ArXivQueryTransformer) getTransformer());
String queryString = "2018";
QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD);
Optional<String> query = transformer.transformLuceneQuery(luceneQuery);
Expand All @@ -48,7 +48,7 @@ public void convertYearField() throws Exception {

@Override
public void convertYearRangeField() throws Exception {
ArXivQueryTransformer transformer = ((ArXivQueryTransformer) getTransformator());
ArXivQueryTransformer transformer = ((ArXivQueryTransformer) getTransformer());

String queryString = "year-range:2018-2021";
QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.jabref.logic.importer.fetcher.transformators;

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 implements InfixTransformerTest {

@Override
public AbstractQueryTransformer 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 {
ArXivQueryTransformer transformer = ((ArXivQueryTransformer) getTransformer());
String queryString = "2018";
QueryNode luceneQuery = new StandardSyntaxParser().parse(queryString, AbstractQueryTransformer.NO_EXPLICIT_FIELD);
Optional<String> query = transformer.transformLuceneQuery(luceneQuery);
Optional<String> expected = Optional.of(queryString);
assertEquals(expected, query);
assertEquals(2018, transformer.getStartYear());
assertEquals(2018, transformer.getEndYear());
}

@Override
public void convertYearRangeField() throws Exception {
ArXivQueryTransformer transformer = ((ArXivQueryTransformer) getTransformer());

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class DBLPQueryTransformerTest implements InfixTransformerTest {

@Override
public AbstractQueryTransformer getTransformator() {
public AbstractQueryTransformer getTransformer() {
return new DBLPQueryTransformer();
}

Expand Down Expand Up @@ -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<String> searchQuery = getTransformator().transformLuceneQuery(luceneQuery);
Optional<String> searchQuery = getTransformer().transformLuceneQuery(luceneQuery);
Optional<String> expected = Optional.of("2015");
assertEquals(expected, searchQuery);
}
Expand All @@ -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<String> searchQuery = getTransformator().transformLuceneQuery(luceneQuery);
Optional<String> searchQuery = getTransformer().transformLuceneQuery(luceneQuery);
Optional<String> expected = Optional.of("2012|2013|2014|2015");
assertEquals(expected, searchQuery);
}
Expand Down
Loading