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

Added extra stats to be sent with MrDLib recommendations #4452

Merged
merged 9 commits into from
Dec 28, 2018
Merged
24 changes: 21 additions & 3 deletions src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.ScrollPane;
Expand Down Expand Up @@ -125,10 +126,12 @@ private ScrollPane getPrivacyDialog(BibEntry entry) {

Button button = new Button(Localization.lang("I Agree"));
button.setDefaultButton(true);
Text line1 = new Text(Localization.lang("Mr. DLib is an external service which provides article recommendations based on the currently selected entry. Data about the selected entry must be sent to Mr. DLib in order to provide these recommendations. Do you agree that this data may be sent?"));

Text line1 = new Text(Localization.lang("JabRef requests recommendations from Mr. DLib, which is an external service. To enable Mr. DLib to calculate recommendations, some of your data must be shared with Mr. DLib. Generally, the more data is shared the better recommendations can be calculated. However, we understand that some of your data in JabRef is sensitive, and you may not want to share it. Therefore, Mr. DLib offers a choice of which data you would like to share."));
line1.setWrappingWidth(1300.0);
Text line2 = new Text(Localization.lang("This setting may be changed in preferences at any time."));
Text line2 = new Text(Localization.lang("Whatever option you choose, Mr. DLib may share its data with research partners to further improve recommendation quality as part of a 'living lab'. Mr. DLib may also release public datasets that may contain anonymized information about you and the recommendations (sensitive information such as metadata of your articles will be anonymised through e.g. hashing). Research partners are obliged to adhere to the same strict data protection policy as Mr. DLib."));
line2.setWrappingWidth(1300.0);
Text line3 = new Text(Localization.lang("This setting may be changed in preferences at any time."));
Hyperlink mdlLink = new Hyperlink(Localization.lang("Further information about Mr DLib. for JabRef users."));
mdlLink.setOnAction(event -> {
try {
Expand All @@ -138,15 +141,30 @@ private ScrollPane getPrivacyDialog(BibEntry entry) {
dialogService.showErrorDialogAndWait(e);
}
});
VBox vb = new VBox();
CheckBox cbTitle = new CheckBox(Localization.lang("Entry Title (Required to deliver recommendations.)"));
cbTitle.setSelected(true);
cbTitle.setDisable(true);
CheckBox cbVersion = new CheckBox(Localization.lang("JabRef Version (Required to ensure backwards compatibility with Mr. DLib's Web Service)"));
cbVersion.setSelected(true);
cbVersion.setDisable(true);
CheckBox cbLanguage = new CheckBox(Localization.lang("JabRef Language (Provides for better recommendations by giving an indication of user's preferred language.)"));
CheckBox cbOS = new CheckBox(Localization.lang("Operating System (Provides for better recommendations by giving an indication of user's system set-up.)"));
CheckBox cbTimezone = new CheckBox(Localization.lang("Timezone (Provides for better recommendations by indicating the time of day the request is being made.)"));
vb.getChildren().addAll(cbTitle, cbVersion, cbLanguage, cbOS, cbTimezone);
vb.setSpacing(10);

button.setOnAction(event -> {
JabRefPreferences prefs = JabRefPreferences.getInstance();
prefs.putBoolean(JabRefPreferences.ACCEPT_RECOMMENDATIONS, true);
prefs.putBoolean(JabRefPreferences.SEND_LANGUAGE_DATA, cbLanguage.isSelected());
prefs.putBoolean(JabRefPreferences.SEND_OS_DATA, cbOS.isSelected());
prefs.putBoolean(JabRefPreferences.SEND_TIMEZONE_DATA, cbTimezone.isSelected());
dialogService.showWarningDialogAndWait(Localization.lang("Restart"), Localization.lang("Please restart JabRef for preferences to take effect."));
setContent(getRelatedArticlesPane(entry));
});

vbox.getChildren().addAll(line1, mdlLink, line2, button);
vbox.getChildren().addAll(line1, line2, mdlLink, line3, vb, button);
root.setContent(vbox);

return root;
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Optional;

Expand All @@ -16,6 +17,7 @@
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.FieldName;
import org.jabref.preferences.JabRefPreferences;

import org.apache.http.client.utils.URIBuilder;
import org.slf4j.Logger;
Expand All @@ -27,6 +29,7 @@
public class MrDLibFetcher implements EntryBasedFetcher {
private static final Logger LOGGER = LoggerFactory.getLogger(MrDLibFetcher.class);
private static final String NAME = "MDL_FETCHER";
private static final String MDL_JABREF_PARTNER_ID = "1";
private final String LANGUAGE;
private final Version VERSION;

Expand Down Expand Up @@ -104,11 +107,22 @@ private String constructQuery(String queryWithTitle) {
URIBuilder builder = new URIBuilder();
builder.setScheme("http");
builder.setHost(getMdlUrl());
builder.setPath("/v2/items/" + queryWithTitle + "/related_items");
builder.addParameter("partner_id", "jabref");
builder.setPath("/v2/documents/" + queryWithTitle + "/related_documents");
builder.addParameter("partner_id", MDL_JABREF_PARTNER_ID);
builder.addParameter("app_id", "jabref_desktop");
builder.addParameter("app_version", VERSION.getFullVersion());
builder.addParameter("app_lang", LANGUAGE);

JabRefPreferences prefs = JabRefPreferences.getInstance();
if (prefs.getBoolean(JabRefPreferences.SEND_LANGUAGE_DATA)) {
builder.addParameter("app_lang", LANGUAGE);
}
if (prefs.getBoolean(JabRefPreferences.SEND_OS_DATA)) {
builder.addParameter("os", System.getProperty("os.name"));
}
if (prefs.getBoolean(JabRefPreferences.SEND_TIMEZONE_DATA)) {
builder.addParameter("timezone", Calendar.getInstance().getTimeZone().getID());
}

try {
URI uri = builder.build();
LOGGER.trace("Request: " + uri.toString());
Expand All @@ -120,6 +134,6 @@ private String constructQuery(String queryWithTitle) {
}

private String getMdlUrl() {
return VERSION.isDevelopmentVersion() ? "api-dev.darwingoliath.com" : "api.darwingoliath.com";
return VERSION.isDevelopmentVersion() ? "api-dev.darwingoliath.com" : "api.mr-dlib.org";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ private RankedBibEntry populateBibEntry(JSONObject recommendation) {
// parse each of the relevant fields into variables
String authors = isRecommendationFieldPresent(recommendation, "authors") ? getAuthorsString(recommendation) : "";
String title = isRecommendationFieldPresent(recommendation, "title") ? recommendation.getString("title") : "";
String year = isRecommendationFieldPresent(recommendation, "year_published") ? Integer.toString(recommendation.getInt("year_published")) : "";
String year = isRecommendationFieldPresent(recommendation, "published_year") ? Integer.toString(recommendation.getInt("published_year")) : "";
String journal = isRecommendationFieldPresent(recommendation, "published_in") ? recommendation.getString("published_in") : "";
String url = isRecommendationFieldPresent(recommendation, "url") ? recommendation.getString("url") : "";
Integer rank = isRecommendationFieldPresent(recommendation, "url") ? recommendation.getInt("recommendation_id") : 100;
Integer rank = isRecommendationFieldPresent(recommendation, "recommendation_id") ? recommendation.getInt("recommendation_id") : 100;

// Populate bib entry with relevant data
current.setField(FieldName.AUTHOR, authors);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ public class JabRefPreferences implements PreferencesService {
public static final String PUSH_TO_APPLICATION = "pushToApplication";
public static final String SHOW_RECOMMENDATIONS = "showRecommendations";
public static final String ACCEPT_RECOMMENDATIONS = "acceptRecommendations";
public static final String SEND_LANGUAGE_DATA = "sendLanguageData";
public static final String SEND_OS_DATA = "sendOSData";
public static final String SEND_TIMEZONE_DATA = "sendTimezoneData";
public static final String VALIDATE_IN_ENTRY_EDITOR = "validateInEntryEditor";
// Dropped file handler
public static final String DROPPEDFILEHANDLER_RENAME = "DroppedFileHandler_RenameFile";
Expand Down Expand Up @@ -571,6 +574,9 @@ private JabRefPreferences() {

defaults.put(SHOW_RECOMMENDATIONS, Boolean.TRUE);
defaults.put(ACCEPT_RECOMMENDATIONS, Boolean.FALSE);
defaults.put(SEND_LANGUAGE_DATA, Boolean.FALSE);
defaults.put(SEND_OS_DATA, Boolean.FALSE);
defaults.put(SEND_TIMEZONE_DATA, Boolean.FALSE);
defaults.put(VALIDATE_IN_ENTRY_EDITOR, Boolean.TRUE);
defaults.put(EDITOR_EMACS_KEYBINDINGS, Boolean.FALSE);
defaults.put(EDITOR_EMACS_KEYBINDINGS_REBIND_CA, Boolean.TRUE);
Expand Down
17 changes: 14 additions & 3 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ Entry\ table=Entry table

Entry\ table\ columns=Entry table columns

Entry\ Title\ (Required\ to\ deliver\ recommendations.)=Entry Title (Required to deliver recommendations.)

Entry\ type=Entry type

Entry\ type\ names\ are\ not\ allowed\ to\ contain\ white\ space\ or\ the\ following\ characters=Entry type names are not allowed to contain white space or the following characters
Expand Down Expand Up @@ -580,8 +582,14 @@ Invalid\ URL=Invalid URL

Online\ help=Online help

JabRef\ Language\ (Provides\ for\ better\ recommendations\ by\ giving\ an\ indication\ of\ user's\ preferred\ language.)=JabRef Language (Provides for better recommendations by giving an indication of user's preferred language.)

JabRef\ preferences=JabRef preferences

JabRef\ requests\ recommendations\ from\ Mr.\ DLib,\ which\ is\ an\ external\ service.\ To\ enable\ Mr.\ DLib\ to\ calculate\ recommendations,\ some\ of\ your\ data\ must\ be\ shared\ with\ Mr.\ DLib.\ Generally,\ the\ more\ data\ is\ shared\ the\ better\ recommendations\ can\ be\ calculated.\ However,\ we\ understand\ that\ some\ of\ your\ data\ in\ JabRef\ is\ sensitive,\ and\ you\ may\ not\ want\ to\ share\ it.\ Therefore,\ Mr.\ DLib\ offers\ a\ choice\ of\ which\ data\ you\ would\ like\ to\ share.=JabRef requests recommendations from Mr. DLib, which is an external service. To enable Mr. DLib to calculate recommendations, some of your data must be shared with Mr. DLib. Generally, the more data is shared the better recommendations can be calculated. However, we understand that some of your data in JabRef is sensitive, and you may not want to share it. Therefore, Mr. DLib offers a choice of which data you would like to share.

JabRef\ Version\ (Required\ to\ ensure\ backwards\ compatibility\ with\ Mr.\ DLib's\ Web\ Service)=JabRef Version (Required to ensure backwards compatibility with Mr. DLib's Web Service)

Join=Join

Joins\ selected\ keywords\ and\ deletes\ selected\ keywords.=Joins selected keywords and deletes selected keywords.
Expand Down Expand Up @@ -662,9 +670,6 @@ Move\ up=Move up

Moved\ group\ "%0".=Moved group "%0".

Mr.\ DLib\ is\ an\ external\ service\ which\ provides\ article\ recommendations\ based\ on\ the\ currently\ selected\ entry.\ Data\ about\ the\ selected\ entry\ must\ be\ sent\ to\ Mr.\ DLib\ in\ order\ to\ provide\ these\ recommendations.\ Do\ you\ agree\ that\ this\ data\ may\ be\ sent?=Mr. DLib is an external service which provides article recommendations based on the currently selected entry. Data about the selected entry must be sent to Mr. DLib in order to provide these recommendations. Do you agree that this data may be sent?


Name=Name
Name\ formatter=Name formatter

Expand Down Expand Up @@ -744,6 +749,8 @@ Opening=Opening

Operation\ canceled.=Operation canceled.

Operating\ System\ (Provides\ for\ better\ recommendations\ by\ giving\ an\ indication\ of\ user's\ system\ set-up.)=Operating System (Provides for better recommendations by giving an indication of user's system set-up.)

Optional\ fields=Optional fields

Options=Options
Expand Down Expand Up @@ -1079,6 +1086,8 @@ This\ operation\ requires\ one\ or\ more\ entries\ to\ be\ selected.=This operat

This\ setting\ may\ be\ changed\ in\ preferences\ at\ any\ time.=This setting may be changed in preferences at any time.

Timezone\ (Provides\ for\ better\ recommendations\ by\ indicating\ the\ time\ of\ day\ the\ request\ is\ being\ made.)=Timezone (Provides for better recommendations by indicating the time of day the request is being made.)

Toggle\ entry\ preview=Toggle entry preview
Toggle\ groups\ interface=Toggle groups interface

Expand Down Expand Up @@ -1144,6 +1153,8 @@ web\ link=web link

What\ do\ you\ want\ to\ do?=What do you want to do?

Whatever\ option\ you\ choose,\ Mr.\ DLib\ may\ share\ its\ data\ with\ research\ partners\ to\ further\ improve\ recommendation\ quality\ as\ part\ of\ a\ 'living\ lab'.\ Mr.\ DLib\ may\ also\ release\ public\ datasets\ that\ may\ contain\ anonymized\ information\ about\ you\ and\ the\ recommendations\ (sensitive\ information\ such\ as\ metadata\ of\ your\ articles\ will\ be\ anonymised\ through\ e.g.\ hashing).\ Research\ partners\ are\ obliged\ to\ adhere\ to\ the\ same\ strict\ data\ protection\ policy\ as\ Mr.\ DLib.=Whatever option you choose, Mr. DLib may share its data with research partners to further improve recommendation quality as part of a 'living lab'. Mr. DLib may also release public datasets that may contain anonymized information about you and the recommendations (sensitive information such as metadata of your articles will be anonymised through e.g. hashing). Research partners are obliged to adhere to the same strict data protection policy as Mr. DLib.

When\ adding/removing\ keywords,\ separate\ them\ by=When adding/removing keywords, separate them by
Will\ write\ XMP-metadata\ to\ the\ PDFs\ linked\ from\ selected\ entries.=Will write XMP-metadata to the PDFs linked from selected entries.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class MrDLibImporterTest {
@BeforeEach
public void setUp() {
importer = new MrDLibImporter();
String testInput = "{ \"label\": { \"label-language\": \"en\", \"label-text\": \"Related Items\" }, \"recommendation-set-id\": \"1\", \"recommendations\": { \"74021358\": { \"abstract\": \"abstract\", \"authors\": [ \"Sajovic, Marija\" ], \"year_published\": \"2006\", \"item_id_original\": \"12088644\", \"keywords\": [ \"visoko\\u0161olski program Geodezija - smer Prostorska informatika\" ], \"language_provided\": \"sl\", \"recommendation_id\": \"1\", \"title\": \"The protection of rural lands with the spatial development strategy on the case of Hrastnik commune\", \"url\": \"http://drugg.fgg.uni-lj.si/701/1/GEV_0199_Sajovic.pdf\" }, \"82005804\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"30145702\", \"language_provided\": null, \"recommendation_id\": \"2\", \"title\": \"Engagement of the volunteers in the solution to the accidents in the South-Moravia region\" }, \"82149599\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"97690763\", \"language_provided\": null, \"recommendation_id\": \"3\", \"title\": \"\\\"The only Father's word\\\". The relationship of the Father and the Son in the documents of saint John of the Cross\", \"url\": \"http://www.nusl.cz/ntk/nusl-285711\" }, \"84863921\": { \"abstract\": \"abstract\", \"authors\": [ \"Kaffa, Elena\" ], \"year_published\": null, \"item_id_original\": \"19397104\", \"keywords\": [ \"BX\", \"D111\" ], \"language_provided\": \"en\", \"recommendation_id\": \"4\", \"title\": \"Greek Church of Cyprus, the Morea and Constantinople during the Frankish Era (1196-1303)\" }, \"88950992\": { \"abstract\": \"abstract\", \"authors\": [ \"Yasui, Kono\" ], \"year_published\": null, \"item_id_original\": \"38763657\", \"language_provided\": null, \"recommendation_id\": \"5\", \"title\": \"A Phylogenetic Consideration on the Vascular Plants, Cotyledonary Node Including Hypocotyl Being Taken as the Ancestral Form : A Preliminary Note\" } }}";
String testInput = "{ \"label\": { \"label-language\": \"en\", \"label-text\": \"Related Items\" }, \"recommendation-set-id\": \"1\", \"recommendations\": { \"74021358\": { \"abstract\": \"abstract\", \"authors\": [ \"Sajovic, Marija\" ], \"published_year\": \"2006\", \"item_id_original\": \"12088644\", \"keywords\": [ \"visoko\\u0161olski program Geodezija - smer Prostorska informatika\" ], \"language_provided\": \"sl\", \"recommendation_id\": \"1\", \"title\": \"The protection of rural lands with the spatial development strategy on the case of Hrastnik commune\", \"url\": \"http://drugg.fgg.uni-lj.si/701/1/GEV_0199_Sajovic.pdf\" }, \"82005804\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"30145702\", \"language_provided\": null, \"recommendation_id\": \"2\", \"title\": \"Engagement of the volunteers in the solution to the accidents in the South-Moravia region\" }, \"82149599\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"97690763\", \"language_provided\": null, \"recommendation_id\": \"3\", \"title\": \"\\\"The only Father's word\\\". The relationship of the Father and the Son in the documents of saint John of the Cross\", \"url\": \"http://www.nusl.cz/ntk/nusl-285711\" }, \"84863921\": { \"abstract\": \"abstract\", \"authors\": [ \"Kaffa, Elena\" ], \"year_published\": null, \"item_id_original\": \"19397104\", \"keywords\": [ \"BX\", \"D111\" ], \"language_provided\": \"en\", \"recommendation_id\": \"4\", \"title\": \"Greek Church of Cyprus, the Morea and Constantinople during the Frankish Era (1196-1303)\" }, \"88950992\": { \"abstract\": \"abstract\", \"authors\": [ \"Yasui, Kono\" ], \"year_published\": null, \"item_id_original\": \"38763657\", \"language_provided\": null, \"recommendation_id\": \"5\", \"title\": \"A Phylogenetic Consideration on the Vascular Plants, Cotyledonary Node Including Hypocotyl Being Taken as the Ancestral Form : A Preliminary Note\" } }}";
input = new BufferedReader(new StringReader(testInput));
}

Expand Down