Understanding Choose by variable

classic Classic list List threaded Threaded
5 messages Options
jda
Reply | Threaded
Open this post in threaded view
|

Understanding Choose by variable

jda

I'm toying with writing a CSL parser and have found this to be rather difficult. I've been able to deal with relatively simple styles, like JBC, but find the more complex ones baffling. For example, the Chicago styles. Here's one macro from the Chicago Author-Date style:

  <macro name="secondary-contributors">
    <choose>
      <if type="chapter paper-conference" match="none">
        <group delimiter=". ">
          <choose>
            <if variable="author">
              <names variable="editor">
                <label form="verb" text-case="capitalize-first" suffix=" " plural="never"/>
                <name and="text" delimiter=", "/>
              </names>
            </if>
          </choose>
          <choose>
            <if variable="author editor" match="any">
              <names variable="translator">
                <label form="verb" text-case="capitalize-first" suffix=" " plural="never"/>
                <name and="text" delimiter=", "/>
              </names>
            </if>
          </choose>
        </group>
      </if>
    </choose>
  </macro>

Could someone translate the logic of this macro into English for me?

The <if type= node is self-explanatory. However, what does <if variable="author"> mean? To me it would seem to mean

if type is a chapter or paper-conference

  if an author is to be output

     substitute the editor


but that makes no sense. Also, what does <if variable="author editor" match="any"> mean?

I appreciate any explanation someone on the list can give.

Thanks,

Jon
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
xbiblio-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/xbiblio-devel
Reply | Threaded
Open this post in threaded view
|

Re: Understanding Choose by variable

Sylvester Keil
Have you read the specification? It's fairly straightforward:

http://rst.projectfondue.com/api/v1/rst2html/?rst_url=https://raw.github.com/citation-style-language/documentation/master/specification.txt&css_url=http://citation-style-language.github.com/styles/css/screen.css&output_type=html&callback=&document_output=whole&highlight_style=manni#choose

The variable condition 'tests whether the default (long) forms of the given variables contain non-empty values'.

Basically, in a choose node you can have a number of conditional blocks (i.e., if, else-if, else nodes); each if/else-if node can define a number of conditions; each condition has a value (multiple values are possible too). When you parse the node, you can create a list of condition-types and values. For example:

<if variable="author"> yields the list: ['variable', 'author']

<if variable="author" is-numeric="edition"> yields the list: [['variable', 'author'], ['is-numeric', 'edition']]
<if variable="author editor" is-numeric="edition"> yields the list: [['variable', 'author'], ['variable', 'editor'], ['is-numeric', 'edition']]

Additionally, each node can have a 'match' attribute which tells you how to combine the list of conditions (provided there is more than one condition).

So, to answer your question:

> <if variable="author editor" match="any">


This block evaluates to true if the your citation item contains either an author or an editor.

Here you can see how this is implemented in citeproc-ruby:

https://github.com/inukshuk/citeproc-ruby/blob/master/lib/citeproc/ruby/renderer/choose.rb#L38

On line 46, node.conditions returns the list of conditions for the node as a list of [type, value] arrays as I explained above; each item in the list is evaluated according to its type and the whole list is reduced using either all?, any?, or none? as specified by the node's match attribute.

Hope that helps!

Sylvester


On Jan 22, 2013, at 3:35 PM, jda wrote:

>
> I'm toying with writing a CSL parser and have found this to be rather difficult. I've been able to deal with relatively simple styles, like JBC, but find the more complex ones baffling. For example, the Chicago styles. Here's one macro from the Chicago Author-Date style:
>
>  <macro name="secondary-contributors">
>    <choose>
>      <if type="chapter paper-conference" match="none">
>        <group delimiter=". ">
>          <choose>
>            <if variable="author">
>              <names variable="editor">
>                <label form="verb" text-case="capitalize-first" suffix=" " plural="never"/>
>                <name and="text" delimiter=", "/>
>              </names>
>            </if>
>          </choose>
>          <choose>
>            <if variable="author editor" match="any">
>              <names variable="translator">
>                <label form="verb" text-case="capitalize-first" suffix=" " plural="never"/>
>                <name and="text" delimiter=", "/>
>              </names>
>            </if>
>          </choose>
>        </group>
>      </if>
>    </choose>
>  </macro>
>
> Could someone translate the logic of this macro into English for me?
>
> The <if type= node is self-explanatory. However, what does <if variable="author"> mean? To me it would seem to mean
>
> if type is a chapter or paper-conference
>
>  if an author is to be output
>
>     substitute the editor
>
>
> but that makes no sense. Also, what does <if variable="author editor" match="any"> mean?
>
> I appreciate any explanation someone on the list can give.
>
> Thanks,
>
> Jon
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. ON SALE this month only -- learn more at:
> http://p.sf.net/sfu/learnnow-d2d
> _______________________________________________
> xbiblio-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/xbiblio-devel


------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
xbiblio-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/xbiblio-devel
Reply | Threaded
Open this post in threaded view
|

Re: Understanding Choose by variable

Simon Hewitt
In reply to this post by jda
I'm no expert but here is my reading:

It's not a substitution as such but how to build the
"secondary-contributors" macro - the author is not touched.

The "<if variable="author">" means if currently dealing with an author (from
where the macro is called) then add the editor to the list (of
secondary-contributors)

The "<if variable="author editor" match="any">" means if currently dealing
with an author OR editor (from where the macro is called) then add the
translator to the list (of secondary-contributors).

So when "secondary-contributors" is used with an author, it will then have
his editor and translator (where present and in that order) to output.
When "secondary-contributors" is used with an editor, it will have his
translator (where present) to output.

Cheers
Simon

-----Original Message-----
From: jda [mailto:[hidden email]]
Sent: 22 January 2013 14:36
To: [hidden email]
Subject: [xbiblio-devel] Understanding Choose by variable


I'm toying with writing a CSL parser and have found this to be rather
difficult. I've been able to deal with relatively simple styles, like JBC,
but find the more complex ones baffling. For example, the Chicago styles.
Here's one macro from the Chicago Author-Date style:

  <macro name="secondary-contributors">
    <choose>
      <if type="chapter paper-conference" match="none">
        <group delimiter=". ">
          <choose>
            <if variable="author">
              <names variable="editor">
                <label form="verb" text-case="capitalize-first" suffix=" "
plural="never"/>
                <name and="text" delimiter=", "/>
              </names>
            </if>
          </choose>
          <choose>
            <if variable="author editor" match="any">
              <names variable="translator">
                <label form="verb" text-case="capitalize-first" suffix=" "
plural="never"/>
                <name and="text" delimiter=", "/>
              </names>
            </if>
          </choose>
        </group>
      </if>
    </choose>
  </macro>

Could someone translate the logic of this macro into English for me?

The <if type= node is self-explanatory. However, what does <if
variable="author"> mean? To me it would seem to mean

if type is a chapter or paper-conference

  if an author is to be output

     substitute the editor


but that makes no sense. Also, what does <if variable="author editor"
match="any"> mean?

I appreciate any explanation someone on the list can give.

Thanks,

Jon
----------------------------------------------------------------------------
--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, MVC,
Windows 8 Apps, JavaScript and much more. Keep your skills current with
LearnDevNow - 3,200 step-by-step video tutorials by Microsoft MVPs and
experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
xbiblio-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/xbiblio-devel



------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
xbiblio-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/xbiblio-devel
Reply | Threaded
Open this post in threaded view
|

Re: Understanding Choose by variable

Sebastian Karcher
In reply to this post by jda
if <variable> tests for the presence of a variable.
http://citationstyles.org/downloads/specification.html#choose

So the above means:
If an item is a chapter or a conference paper:
     if the item has an author
         print the editor here
     if the item has either and editor or an author (match="any")
        print the translator here

The purpose of this is that you don't want the editor printed here if it has been used at the start of the citation.
This could almost certainly be simplified/improved using substitute -
http://citationstyles.org/downloads/specification.html#substitute
last time I looked at the style I didn't have the time to check and fix that (and the functionality would be the same, it's just cleaner with substitute) -  so
it might not be the best example. For a more typical use, see e.g. this, which prints the type of material - Web vs. Print - for MLA style:
<choose>
  <if variable="URL DOI" match="any">
    <text variable="archive" prefix=" " suffix=". "/>
    <text value="Web" prefix=" "/>
    <text prefix=". " suffix="." macro="access"/>
  </if>
  <else>
    <text value="Print" prefix=" "/>
  </else>
</choose>

In other words, if an item has either the variable DOI, or the variable URL, it's considered a web source and the style puts "Web." at the end of the citation, otherwise it's considered print and the style puts "Print" at the end of the citation. (if you look at the style it tests for a range of other materials - film, audio recording, etc. - first. This is just to illustrate the idea.

Hope that helps.


On Tue, Jan 22, 2013 at 7:35 AM, jda <[hidden email]> wrote:

I'm toying with writing a CSL parser and have found this to be rather difficult. I've been able to deal with relatively simple styles, like JBC, but find the more complex ones baffling. For example, the Chicago styles. Here's one macro from the Chicago Author-Date style:

  <macro name="secondary-contributors">
    <choose>
      <if type="chapter paper-conference" match="none">
        <group delimiter=". ">
          <choose>
            <if variable="author">
              <names variable="editor">
                <label form="verb" text-case="capitalize-first" suffix=" " plural="never"/>
                <name and="text" delimiter=", "/>
              </names>
            </if>
          </choose>
          <choose>
            <if variable="author editor" match="any">
              <names variable="translator">
                <label form="verb" text-case="capitalize-first" suffix=" " plural="never"/>
                <name and="text" delimiter=", "/>
              </names>
            </if>
          </choose>
        </group>
      </if>
    </choose>
  </macro>

Could someone translate the logic of this macro into English for me?

The <if type= node is self-explanatory. However, what does <if variable="author"> mean? To me it would seem to mean

if type is a chapter or paper-conference

  if an author is to be output

     substitute the editor


but that makes no sense. Also, what does <if variable="author editor" match="any"> mean?

I appreciate any explanation someone on the list can give.

Thanks,

Jon
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
xbiblio-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/xbiblio-devel



--
Sebastian Karcher
Ph.D. Candidate
Department of Political Science
Northwestern University

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
xbiblio-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/xbiblio-devel
jda
Reply | Threaded
Open this post in threaded view
|

Re: Understanding Choose by variable

jda
In reply to this post by Sylvester Keil
Thanks to all who answered my questions, it was very helpful indeed. What I didn't understand (but do now) is that <if variable=...> refers to the presence of information in  that field in the reference metadata. So for example when outputting the title (or whatever) one might have to see if the reference metadata contains an editor.

And i think I see that what I was trying to is not possible. That was to convert the .csl instruction set into another, proprietary, style set (not .csl). But since the capabilities are not entirely congruent, I think that's not going to be possible. Rather, the .csl itself would have to be used directly to render the styled reference. I'll have to put some more thought into this...

Thanks again,

Jon



------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
xbiblio-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/xbiblio-devel