Closed dominic01 closed 5 years ago
Yes, this is possible. You have to create your own style as follows.
First of all, you have to find a style that is closest to what you want to achieve. In your case, it seems to be APA. Download the original style file from https://github.com/citation-style-language/styles/blob/9296c8c/apa.csl and amend it with the tags you need. For example, from line 78 to 96 you'll find the macro for the author. Use the prefix
and suffix
attributes to add your <au>
and </au>
tags respectively. Do the same for the other macros and tags.
After that, pass the style as a string to the CSL.Engine
constructor:
var citeproc = new CSL.Engine(citeprocSys, yourNewStyleAsText);
Appreciate your response and this is exactly what I did in my test environment. This is working and thank you. However, I am looking for a more generic way of getting the tags. That is using the JSON element names as tags like
I was trying to play around with the src/formatters.js and somehow it didnt work. Any pointers would be of great help.
Hello Michel, Hello Dominic, I'm working on the same project to create a dataset for GROBID so I will need annotated outputs (see here http://grobid.readthedocs.io/en/latest/training/Bibliographical-references/) @dominic01 Have you modified the code already? Would you like to share it? Changing the JSON elements will work for the title however not for date and other abbreviated names.
@michel-kraemer I've considered your idea to change the CSL files, however changing all 1700 files will prove rather difficult, is there any other possibility? If not, (certainly not ideal) I will have to change the code. Could you point me to the necessary lines?
This can be done with hooks in the processor. It has been a very long time since anyone asked about it, and I will need to dig into the code to figure out the incantations. But definitely possible.
Thanks for the quick reply, let me know when you find it...
Dear @fbennett , have you found the part in the script "citeproc_commonjs.js" where I can add the annotated tags?
@dominic01 Have you modified the code already? Would you like to share it? Changing the JSON elements will work for the title however not for date and other abbreviated names.
I tried few sample tags and it worked. But didn't progress further because of too many files need to be changes. I was expecting a simple solution that will put the JSON field names as tags in the output file. apa-tag.txt
Hey @dominic01
I put your idea into practice so I wrote a script to change all .csl files, feel free to use it.
Using nodejs/javascript
styleString = styleString.replace(/<text variable="(.*?)"( prefix="([^"]*)")?( suffix="([^"]*)")?/g, '<text variable="$1" prefix="$3<$1>" suffix="</$1>$5"');
styleString = styleString.replace(/<date variable="(.*?)"( prefix="([^"]*)")?( suffix="([^"]*)")?/g, '<date variable="$1" prefix="$3<$1>" suffix="</$1>$5"');
styleString = styleString.replace(/<names variable="(.*?)"( prefix="([^"]*)")?( suffix="([^"]*)")?/g, '<names variable="$1" prefix="$3<$1>" suffix="</$1>$5"');
To disable sorting please use:
styleString = styleString.replace(/<sort>([\s\S]*?)<\/sort>/g,'');
I'm very late with a response here, but in case the question comes up again ...
Enabling variable wrapper hooks in the processor is one way to do this, but it's not been documented, and would require study and testing. For simple tags to the source variables begin the output, though, you can just set the csl_reverse_lookup_support
flag on the processor. It doesn't work dynamically, you need to modify the setting in the source before instantiating with a style. The line to change is here:
https://github.com/Juris-M/citeproc-js/blob/master/src/state.js#L152
That setting is what is used in the CSL Style Editor to show where each piece of output comes from in the style and vice-versa. The source line in the editor where the change is applied is here:
Frank
Is it possible to get a tagged output in addition to the styles. input:
Output Bibliography: APA
Friedl, J. E. F. (2006). Mastering Regular Expressions (3rd ed.). O’Reilly Media.
I am expecting a tagged output like:
<aus><au>Friedl, J. E. F.</au></aus>. (<dt>2006</dt>). <ti>Mastering Regular Expressions</ti> (<et>3rd ed.</et>). <pu>O’Reilly Media</pu>.
Is it possible?