√ Strange behavior of cs:choose & disambiguate="true"

In a cs:choose, should cs:else execute when any one of the preceding cs:if and cs:else-if has already triggered? With the code below that I use to troubleshoot disambiguation, I always get "disambiguate value is false" and "disambiguate value neither true or false" together. Is this right? (If it is, it really shatters my understanding of cs:choose, and I'll have to re-write a few styles.)


<choose>
<if disambiguate="true">
<text value="disambiguate value is true"/>
</if>
<else-if dismbiguate="false">
<text value="disambiguate value is false"/>
</else-if>
<else>
<text value="disambiguate value neither true or false"/>
</else>
</choose>
  • It's probably not right - it's most certainly not how this works in other contexts - but it's also non-sensical code:
    Since disambiguate is a binary condition, the "else-if" makes no sense there and is in fact the same as a regular else. I assume that's why the processor is putting out both.
  • good point. But the same result with the following code:


    <choose>
    <if disambiguate="false">
    <text value="disambiguate value is false"/>
    </if>
    <else>
    <text value="disambiguate value neither true or false"/>
    </else>
    </choose>


    Still, I get both "disambiguate value is false" and "disambiguate value neither true or false" together for all subsequent citations. As I noted in another thread (https://forums.zotero.org/discussion/34475/how-is-the-disambiguate-boolean-determined), due to this errant behavior, I can't disambiguate.
  • This has been well tested in the processor.

    Loo king at your code there, it won't actually diambiguate anything, since you are applying the same string to all entries. Try testing with real data.
  • edited January 22, 2014
    @fbennett,

    Yes, I think my style is probably off. I applied a different style (than the one I wrote) which also incorporates disambiguate="true", and it works fine. Is there an option within CSL that may be hindering the proper operation of "disambiguate"?

    Actually the snippet I posted above came from an actual macro:


    <macro name="foreign-secondary-subsequent">
    <group delimiter=", ">
    <choose>
    <if type="book">
    <text macro="foreign-author-short" />
    </if>
    <else-if type="webpage" variable="issued" match="all">
    <text macro="foreign-author-short" />
    </else-if>
    <else>
    <text macro="foreign-author-short"/>
    </else>
    </choose>
    <choose>
    <if disambiguate="true">
    <text macro="foreign-short-title" text-case="title"/>
    </if>
    ** rest is deleted **


    The disambiguate="true" in the code above doesn't work.
  • Have you validated your style?
  • yes, at fbennett.github.io/csl-validator.js. No problem.
  • If you can post the full style code to http://gist.github.com, I can take a look.
  • edited January 24, 2014
    This is really strange. I've been doing some troubleshooting by comparing two styles - one with disambiguation working and the other not. I even transplanted cs:macro name="amlaw-title" from MLZ-Amlaw style into my problematic style. Since cs:macro name="amlaw=title" is self-contained, without referring to any other macro, it should work the same as in MLZ Amlaw when called upon.

    The funny thing is that when that macro is called upon within the MLZ Amlaw style, it will disambiguate fine. But when it's called upon in my style, it won't. Below is a snippet of the cs macro name="amlaw-title" that I modified to get a cue about what is triggered and what is not. The same disambiguate="true" is triggered when this macro is called upon in MLZ Amlaw, but not when it's called upon in my style.

    I'm totally at a loss.


    <else-if>
    <conditions match="any">
    <condition type="song" variable="collection-title" match="all"/>
    <condition type="broadcast" variable="container-title" match="all"/>
    <condition type="video" variable="container-title" match="all"/>
    <condition type="post" variable="container-title" match="all"/>
    <condition type="post-weblog" variable="container-title" match="all"/>
    <condition type="webpage" variable="container-title" match="all"/>
    <condition type="paper-conference" variable="container-title" match="all"/>
    <condition type="article-magazine graphic article-journal article-newspaper chapter" match="any"/>
    <condition type="entry-encyclopedia"/>
    <condition type="entry-dictionary"/>
    </conditions>
    <text value="choice #9"/>
    <choose>
    <if>
    <conditions match="any">
    <condition position="first" context="bibliography" match="any"/>
    <condition variable="author container-author" match="none"/>
    </conditions>
    <text font-style="italic" form="short" text-case="title" variable="title"/>
    </if>
    </choose>
    <choose>
    <if disambiguate="true">
    <text value="disambiguation triggered "/>
    <text font-style="italic" form="short" text-case="title" variable="title"/>
    </if>
    </choose>
    </else-if>
  • Hang in there. It's Saturday here, and we''re past the main pressures of term. I'll take a look and we'll get to the bottom of it.
  • Thanks. As usual, I'm providing more information only to facilitate your debugging. Knowing how busy you are, I don't expect immediate solutions.
  • The CSL-m validator reports many syntax errors for the style code posted to the gist above. Here is a version with the more serious errors fixed: https://gist.github.com/fbennett/8606502

    The most glaring errors were an apostrophe character between two XML nodes, and a use of punctuation-in-quote on a cs:name node. Both of those are pretty serious, and could well adversely affect the operation of the processor. The various syntax errors are almost certainly the cause of the disambiguation failures you are seeing.

    There is a lot of new code in there -- the style is over 4,000 lines long, over a thousand lines longer than the largest MLZ styles. The size itself isn't a problem for the processor, but the more code there is, the harder it becomes to maintain the style. You might want to take a careful look and see whether there isn't potential for consolidating portions of the code to make it more compact.

    Note that the code I've posted above still doesn't validate. The code in the style makes extensive use of illegal space characters on affixes. Removing them will take some effort, but they'll need to be removed for the style to fully validate against the CSL-m schema. Trailing spaces on suffixes and leading spaces on prefixes are not permitted in CSL-m syntax outside of cs:date and cs:name nodes: ordinary spaces can only be supplied through a group delimiter. I've imposed that constraint on the syntax because elements with hard-coded spaces can easily produce broken formatting when variables are missing from the input.

    The disambiguate="true" conditionals may work correctly in the code I've posted above, but it would be a really good idea to go through the code to weed out the affixes and simplify the macros where possible.
  • Thanks for all the work and time you've put into it.

    I'm surprised that your CSL-m validator found errors in my style, as I didn't run into any when I validated it on my computer with the same validator. My style ran fine in chrome://zotero/content/tools/csledit.xul too (albeit without the desired outcome). I'll take another look.

    In any event, I had no idea spaces are not allowed in suffixes and prefixes. If that's the case, yes, there is a bit of cleaning up to do.

    Thanks, and have a wonderful weekend!
  • I had no idea spaces are not allowed in suffixes and prefixes.
    Btw. - that's only the case for csl-m. Spaces in affixes are allowed in regular CSL and I think they'll likely remain allowed.
  • @fbennett,

    Did the code you posted above work correctly for you? It still doesn't disambiguate in mine. Is there a chance that it's because I'm using the special MLZ that you provided to deal with the other issue from last week?
  • Spaces in affixes are allowed in regular CSL and I think they'll likely remain allowed.
    ♫ You say tomato and I say tomahto ... ♫

    :-)
  • Did the code you posted above work correctly for you? It still doesn't disambiguate in mine. Is there a chance that it's because I'm using the special MLZ that you provided to deal with the other issue from last week?
    I didn't build a test before posting.

    I've started building one, but on the initial run, I get this:
    CSL style error: undefined macro "ko-title"
  • edited January 24, 2014
    Oops.. Do you use a different test engine than http://fbennett.github.io/csl-validator.js/ ? Neither the CSL-m validator nor chrome://zotero/content/tools/csledit.xul reported any error with the style.
  • the validators don't check for missing macros.
  • edited January 24, 2014
    Ok, this has worked for me.


    <else-if>
    <conditions match="all">
    <condition position="subsequent"/>
    <condition position="ibid" match="none"/>
    </conditions>
    <text macro="ko-secondary-subsequent"/>
    </else-if>
    <else-if type="book" >
    <text macro="ko-book"/>
    </else-if>
    <else-if type="chapter">
    <text macro="ko-chapter"/>
    </else-if>
    <else-if type="article-journal">
    <text macro="ko-periodical"/>
    </else-if>


    (The disambiguation is done within macro="ko-secondary-subsequent".)

    Previously, the ibid/ibid-with-locator/subsequent tri-furcation was built into each of ko-book, ko-chapter and ko-periodican, and macro="ko-secondary-subsequent" would be called upon by each if the citation was a subsequent one.

    In this version, as you can see, I check position="subsequent" first. I have no idea why this routine disambiguates, whereas the previous one didn't.
  • It's hard to say without looking directly at the style code and test items that failed; but certainly evaluating the position condition early in the processing chain will make your code more compact, which is a good thing.
Sign In or Register to comment.