From 3a09fa2e7ca8236670b45c5c4508a05ddae111fc Mon Sep 17 00:00:00 2001 From: conorfos <40298107+conorfos@users.noreply.github.com> Date: Fri, 28 Dec 2018 18:47:17 +0000 Subject: [PATCH] Added extra stats to be sent with MrDLib recommendations (#4452) --- .../gui/entryeditor/RelatedArticlesTab.java | 24 ++++++++++++++++--- .../logic/importer/fetcher/MrDLibFetcher.java | 22 +++++++++++++---- .../importer/fileformat/MrDLibImporter.java | 4 ++-- .../jabref/preferences/JabRefPreferences.java | 6 +++++ src/main/resources/l10n/JabRef_en.properties | 17 ++++++++++--- .../fileformat/MrDLibImporterTest.java | 2 +- 6 files changed, 62 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index dbbe9ff096a..4bd30b7c614 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -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; @@ -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 { @@ -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; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java index 2ae7db36e35..0e3e30898bd 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java @@ -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; @@ -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; @@ -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; @@ -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()); @@ -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"; } } diff --git a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java index 6320b8d7483..5bc8af04b8c 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java @@ -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); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 692df3eec82..5d3d38d061e 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -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"; @@ -574,6 +577,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); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 1af3cc0c045..b22353562b3 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -364,6 +364,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 @@ -573,8 +575,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. @@ -653,9 +661,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 @@ -735,6 +740,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 @@ -1070,6 +1077,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 @@ -1135,6 +1144,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. diff --git a/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java index 5af07b4dfa3..723afd1b6fc 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java @@ -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)); }