zotero / translation-server

A Node.js-based server to run Zotero translators
Other
117 stars 48 forks source link

ISBN search returns extra note object causing CSL export to fail #67

Closed dhimmel closed 5 years ago

dhimmel commented 5 years ago

The following search query is for an ISBN:

curl \
  --header "Content-Type: text/plain" \
  --data 'isbn:9780262517638' \
  'https://translate.manubot.org/search'

The output is:

[
    {
        "key": "ZGT6YNIL",
        "version": 0,
        "itemType": "book",
        "creators": [
            {
                "firstName": "Peter",
                "lastName": "Suber",
                "creatorType": "author"
            }
        ],
        "tags": [
            {
                "tag": "Open access publishing",
                "type": 1
            }
        ],
        "ISBN": "9780262517638",
        "title": "Open access",
        "place": "Cambridge, Mass",
        "publisher": "MIT Press",
        "date": "2012",
        "numPages": "242",
        "series": "MIT Press essential knowledge series",
        "callNumber": "Z286.O63 S83 2012",
        "extra": "OCLC: ocn754518563",
        "libraryCatalog": "Library of Congress ISBN"
    },
    {
        "itemType": "note",
        "note": "What is open access? -- Motivation -- Varieties -- Policies -- Scope -- Copyright -- Economics -- Casualties -- Future -- Self-help"
    }
]

Notice that the output array contains two objects. The second one is bizarre:

    {
        "itemType": "note",
        "note": "What is open access? -- Motivation -- Varieties -- Policies -- Scope -- Copyright -- Economics -- Casualties -- Future -- Self-help"
    }

If we pass the full JSON output to /format with the following command:

curl \
 --header "Content-Type: application/json" \
 --data @zotero-data.json \
 'https://translate.manubot.org/export?format=csljson'

We get notified that "An error occurred during translation." The translation-server stdout log contains:

(4)(+0000000): Translate: Parsing code for CSL JSON (bc03b4fe-436d-4a1f-ba59-de4d2d7a63f7, 2017-07-05 19:32:38)

(3)(+0000001): Translate: Beginning translation with CSL JSON

(3)(+0000000): TypeError: Cannot read property 'noteToTitle' of undefined

    TypeError: Cannot read property 'noteToTitle' of undefined
        at Zotero.Utilities.Translate.itemToCSLJSON (/home/translate/translation-server/modules/zotero/chrome/content/zotero/xpcom/utilities.js:1706:33)
        at Function.itemToCSLJSON (/home/translate/translation-server/src/translation/sandboxManager.js:94:17)
        at doExport (eval at <anonymous> (/home/translate/translation-server/src/translation/sandboxManager.js:68:4), <anonymous>:111:43)
        at Zotero.Translate.Export.rest (/home/translate/translation-server/modules/zotero/chrome/content/zotero/xpcom/translation/translate.js:1406:49)
        at loadPromise.then (/home/translate/translation-server/modules/zotero/chrome/content/zotero/xpcom/translation/translate.js:1396:39)
        at <anonymous>
        at process._tickDomainCallback (internal/process/next_tick.js:228:7)

What's the best solution? Should the ISBN search omit the second note object? Should the CSL exporter ignore this note?

Are there other cases where the /search endpoint returns multiple results? Should we always take the first one on our end, before passing to /export?

dstillman commented 5 years ago

Should we always take the first one on our end, before passing to /export?

If you don't need child notes, yes. The first one is the parent item.

I've also fixed child notes to include the parent item key, which was missing, and fixed translation-server's CSL-JSON note export, but there's really no reason to export notes as CSL-JSON.

dhimmel commented 5 years ago

If you don't need child notes, yes. The first one is the parent item.

Got it. Are there other things besides notes that can be added as additional objects in the top-level array? Let's assume we're specifying ?single=1 such that only singular translators will be used.

dstillman commented 5 years ago

Got it. Are there other things besides notes that can be added as additional objects in the top-level array?

No, currently only notes.