14
$\begingroup$

I would like to switch over the citation helper from the current kludged together back-end based on MathSciNet data, to an officially supported back-end (very kindly!) provided by Zentralblatt.

We'll need to rewrite a small amount of javascript for this to happen. If someone (ideally who knows javascript, and ideally who knows how to hack the existing javascript served on a page, so the new code can be tested before deployment) would like to help, please let me know.

The problem is simple to describe:

We need to modify the code currently served via http://cdn.sstatic.net/js/third-party/citation-helper.js?v=2, so that instead of retrieving results from, https://ec2.mathoverflow.org/cite?q=, it retrieves results from https://zbmath.org/citationmatching/mathoverflow?q=, and appropriately parses the JSON.

It's mostly just a matter of working out how the JSON structure has changed, and emitting appropriate HTML based on that. The HTML should be basically the same as what we already produce, but we should also include the Zbl identifier, linked directly to the corresponding Zbl page. The title of the article itself should be a hyperlink to the first "link" result.

$\endgroup$
5
  • $\begingroup$ So it's really just modifying getCitationHtmlto match the JSON data from ZBL? $\endgroup$
    – Asaf Karagila Mod
    Commented Dec 13, 2016 at 6:31
  • $\begingroup$ Yes, I think so. It should be quite straightforward. $\endgroup$
    – Kim Morrison Mod
    Commented Dec 13, 2016 at 21:54
  • $\begingroup$ I gave it my mediocre shot. $\endgroup$
    – Asaf Karagila Mod
    Commented Dec 13, 2016 at 22:26
  • 2
    $\begingroup$ I've marked this as "status-planned", as the modified code is now off to Stack Exchange for review, and hopefully deployment not far down the track. $\endgroup$
    – Kim Morrison Mod
    Commented Jan 13, 2017 at 0:03
  • $\begingroup$ I think now it's as good a time as any to put status-completed on this post. $\endgroup$
    – Asaf Karagila Mod
    Commented Mar 10, 2017 at 17:47

3 Answers 3

7
$\begingroup$

As an example, the first result here contains the JSON

{
  "results": [
    {
      "pagination": "266-278", 
      "links": [
        "http://dx.doi.org/10.1017/jsl.2013.12"
      ], 
      "title": "On $\\omega_1$-strongly compact cardinals", 
      "year": "2014", 
      "source": "J. Symb. Log. 79, No. 1, 266-278 (2014).", 
      "score": 3.316698, 
      "zbl_id": "1337.03076", 
      "authors": "Bagaria, Joan; Magidor, Menachem"
    },
    ...
}

which should render as something like

Bagaria, Joan; Magidor, Menachem, On $\omega_1$-strongly compact cardinals, J. Symb. Log. 79, No. 1, 266-278 (2014). Zbl 1337.03076

$\endgroup$
9
  • $\begingroup$ Is there any chance to get the "source" field break down to journal/volume/number/pages/year? You know, like a proper .bib citation? $\endgroup$
    – Asaf Karagila Mod
    Commented Dec 15, 2016 at 7:29
  • $\begingroup$ I'll ask, but my contact at Zentralblatt is now on holidays. $\endgroup$
    – Kim Morrison Mod
    Commented Dec 15, 2016 at 22:09
  • $\begingroup$ Scott, being unfamiliar with the Christian world's holidays. When do these holidays end usually? Do we have to wait until next year? That's insane, it's an entire year! :-) $\endgroup$
    – Asaf Karagila Mod
    Commented Dec 26, 2016 at 10:05
  • $\begingroup$ He said he'll back be mid-January. $\endgroup$
    – Kim Morrison Mod
    Commented Dec 26, 2016 at 21:13
  • $\begingroup$ Is next week "mid-January"? $\endgroup$
    – Asaf Karagila Mod
    Commented Jan 7, 2017 at 8:35
  • $\begingroup$ Ok, "mid-January" is now. :-) Could you explain why it would be better to break the source field down into components? Fabian at Zentralblatt says it might be possible, but I'm hesitant to ask him to do this work without good motivation. $\endgroup$
    – Kim Morrison Mod
    Commented Jan 11, 2017 at 22:16
  • $\begingroup$ Well, it's nicer to have a better control over the formatting of the output. I figured it must be a few lines of code (instead of collecting journal/volume/number/pages/year into one field, just return them separately). If it's a lot of work, I guess we can work with what we have. $\endgroup$
    – Asaf Karagila Mod
    Commented Jan 12, 2017 at 6:07
  • $\begingroup$ We've decided it's too much work. $\endgroup$
    – Kim Morrison Mod
    Commented Jan 12, 2017 at 22:31
  • $\begingroup$ Oh well. Thanks anyway. $\endgroup$
    – Asaf Karagila Mod
    Commented Jan 13, 2017 at 4:45
4
$\begingroup$
function getCitationHtml(json) {
    var cite = $('<cite>').attr('authors', json.authors)
              .append('_' + json.authors + '_, ')
              .append('[**' + json.title + '**](' + encodeURI(json.links.length > 0 ? json.links[0] : '') + '), ')
              .append(json.source + ' [Zbl' + json.zbl_id + '](https://zbmath.org/?q=an:' + json.zbl_id + ')')
              .append('.');

    var citeContainer = $('<span></span>').append(cite).html();

    return citeContainer;
    }
$\endgroup$
10
  • $\begingroup$ I have never worked with Jason, so I have no idea if this is even valid. Do let me know, though. $\endgroup$
    – Asaf Karagila Mod
    Commented Dec 13, 2016 at 22:25
  • $\begingroup$ First --- we're going to have to work out how to test this. Can someone who knows how to do this show us how to modify in place the javascript coming from SE? $\endgroup$
    – Kim Morrison Mod
    Commented Dec 15, 2016 at 1:10
  • $\begingroup$ Second, I see some problems. 1) json.links is an array, possibly empty. If it is non-empty, we want to use the first entry as the URL. If it is empty we don't want to hyperlink the title. 2) There is no longer a json.citation_markdown field. $\endgroup$
    – Kim Morrison Mod
    Commented Dec 15, 2016 at 1:12
  • $\begingroup$ (Thanks, of course, for making a start!) $\endgroup$
    – Kim Morrison Mod
    Commented Dec 15, 2016 at 1:13
  • 1
    $\begingroup$ I guess we can change this using Developer Tools to change an instance of the running code and check. I'll give it a shot in a little bit. $\endgroup$
    – Asaf Karagila Mod
    Commented Dec 15, 2016 at 7:06
  • $\begingroup$ Also, I think that in answers if you use an empty link, it just produces a text. $\endgroup$
    – Asaf Karagila Mod
    Commented Dec 15, 2016 at 7:07
  • $\begingroup$ I added a test for json.links being empty; I think the previous code would have linked to "undefined". $\endgroup$
    – Kim Morrison Mod
    Commented Dec 15, 2016 at 22:35
  • 3
    $\begingroup$ We are now waiting on Zentralblatt adding an Allow-Access-Control-Origin header, so that we can test this code. No update expected until mid-January. $\endgroup$
    – Kim Morrison Mod
    Commented Dec 15, 2016 at 23:09
  • $\begingroup$ Any news on the header issue? $\endgroup$
    – Asaf Karagila Mod
    Commented Jan 13, 2017 at 4:57
  • $\begingroup$ The headers are all fixed. For now it allows all cross domain requests. $\endgroup$
    – Kim Morrison Mod
    Commented Jan 13, 2017 at 21:41
3
$\begingroup$

We will also need to modify the fetchCallback function from http://cdn.sstatic.net/js/third-party/citation-helper.js?v=2.

This is the current content of that function, which we can "edit in place" to update.

// Callback to run when search completes.
function fetchCallback(response) {
  // Here's an example of what the 'response' argument might contain.
  // response = {
  //  "results": [
  //    {
  //      "pagination": "2586-2620", 
  //      "links": [
  //        "http://dx.doi.org/10.1016/j.jfa.2014.12.018", 
  //        "http://www.arxiv.org/abs/1406.4766"
  //      ], 
  //      "title": "Free transport for finite depth subfactor planar algebras", 
  //      "year": "2015", 
  //      "source": "", 
  //      "score": 2.15747, 
  //      "zbl_id": "06435710", 
  //      "authors": "Nelson, Brent"
  //    }, 
  //    {
  //      "pagination": "183-214", 
  //      "links": [
  //        "http://dx.doi.org/10.1023/A:1021296230310"
  //      ], 
  //      "title": "Exchange relation planar algebras", 
  //      "year": "2002", 
  //      "source": "Geom. Dedicata 95, 183-214 (2002).", 
  //      "score": 2.15747,   
  //      "zbl_id": "1022.46039", 
  //      "authors": "Landau, Zeph A."
  //    }
  //  ]
  // }        
        var html = $('<div class="list">');
        for (var i = 0; i < response.results.length; i++) {
            var result = response.results[i];
            var zbl = 'https://zbmath.org/?q=an:' + result.zbl_id;

            var link = result.links.length > 0 ? result.links[0] : '';
            var arxiv = '';
            for (var j = 0; j < result.links.length; j++) {
                     arxiv = result.links[j].includes("arxiv") ? result.links[j] : arxiv;
                }
            var authors = sanitizeForDisplay(result.authors);
            var title = sanitizeForDisplay(result.title);
            var citationHtml = sanitizeForDisplay(result.source);

            var result = $('<div class="item" style="float:none;padding:5px">')
                .html($('<div class = "summary post-link" style="float:none;width:auto;font-weight:bold;">')
                    .text(title))
                .append('<br/>')
                .append($('<span class="body-summary" style="float:none"></span>')
                    .append(authors + '<br/>' + citationHtml + '<br/> Preview (opens in new tab): ')
                    .append(renderOptionalLink(link, 'article'))
                    .append(renderOptionalLink(zbl, 'zbmath'))
                    .append(renderOptionalLink(arxiv, 'arxiv'))
                )
                .click(loadResultCallback(link, result))
                .hover(function () { $(this).css('background-color', '#e6e6e6') }, function () { $(this).css('background-color', '#fff') });

            html.append(result);
            result.find('a').on('click', function(e) { e.stopPropagation(); });
        }
        $('#results').html('').append(html);
        MathJax.Hub.Queue(['Typeset', MathJax.Hub, 'results']);
        $('#popup-cite .search-spinner').removeSpinner();
}
$\endgroup$
6
  • $\begingroup$ I've tried to do some editing. Of course we don't know how badly it will fail before we can test it properly. But I do think that having separate fields for the citation parts is crucial for getting properly formatted output. I'm not entirely sure about the free and pdf fields, though. $\endgroup$
    – Asaf Karagila Mod
    Commented Dec 17, 2016 at 9:23
  • $\begingroup$ I probably messed it up, but I tried to add a code that checks if there is a link with arxiv substring, and in that case it adds it to the optional links. $\endgroup$
    – Asaf Karagila Mod
    Commented Dec 18, 2016 at 7:54
  • $\begingroup$ Ah, good idea. Fixed two problems. $\endgroup$
    – Kim Morrison Mod
    Commented Dec 18, 2016 at 21:08
  • $\begingroup$ Wow, only one minor typo and one syntactic problem? Impressive. $\endgroup$
    – Asaf Karagila Mod
    Commented Dec 19, 2016 at 5:17
  • $\begingroup$ You might want to test it before you push it, I have created a Stack Snippet here. I'm not sure what is in the pending edit but you need to remove .citation from this line var result = response.results[i].citation; otherwise it won't work. If you find Stack Snippets to cumbersome, consider a jsfiddle. $\endgroup$
    – rene
    Commented Dec 23, 2016 at 20:48
  • $\begingroup$ @rene: Of course there will be testing before we push the new code. But we need to wait for ZBL to fix some stuff, and maybe return "better json" (as you can find in the comments to the other answers on this page). $\endgroup$
    – Asaf Karagila Mod
    Commented Dec 26, 2016 at 9:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .