Coder Social home page Coder Social logo

citeproc-java's Introduction



citeproc-java


citeproc-java is a Citation Style Language (CSL) processor for Java.
It interprets CSL styles and generates citations and bibliographies.

Apache License, Version 2.0 Actions Status


Quick start

CSLItemData item = new CSLItemDataBuilder()
    .type(CSLType.ARTICLE_JOURNAL)
    .title("Protein measurement with the Folin phenol reagent")
    .author(
        new CSLNameBuilder().given("Oliver H.").family("Lowry").build(),
        new CSLNameBuilder().given("Nira J.").family("Rosebrough").build(),
        new CSLNameBuilder().given("A. Lewis").family("Farr").build(),
        new CSLNameBuilder().given("Rose J.").family("Randall").build()
    )
    .issued(1951)
    .containerTitle("The Journal of biological chemistry")
    .volume(193)
    .issue(1)
    .page(265, 275)
    .build();

String bibl = CSL.makeAdhocBibliography("apa", item).makeString();

Output:

<div class="csl-bib-body">
  <div class="csl-entry">Lowry, O. H., Rosebrough, N. J., Farr, A. L., &amp; Randall, R. J. (1951). Protein measurement with the Folin phenol reagent. <span style="font-style: italic">The Journal of Biological Chemistry</span>, <span style="font-style: italic">193</span>(1), 265&ndash;275.</div>
</div>

Rendered:


Lowry, O. H., Rosebrough, N. J., Farr, A. L., & Randall, R. J. (1951). Protein measurement with the Folin phenol reagent. The Journal of Biological Chemistry, 193(1), 265–275.

Features

  • Generates citations and bibliographies
  • Supports 10000+ citation styles and various locales
  • Different output formats such as html, text, asciidoc, and fo
  • Importers for BibTeX, EndNote, and RIS
  • Command-line tool to execute the library without setting up a development environment

Dependencies

To use citeproc-java, you need three things: the library itself, the CSL styles, and the CSL locales. The styles and locales are distributed separately, because they are updated more frequently than citeproc-java.

Here's the configuration for Gradle:

dependencies {
    implementation 'de.undercouch:citeproc-java:3.1.0'
    implementation 'org.citationstyles:styles:24.3'
    implementation 'org.citationstyles:locales:24.3'
}

And here's the configuration for Maven:

<dependencies>
  <dependency>
    <groupId>de.undercouch</groupId>
    <artifactId>citeproc-java</artifactId>
    <version>3.1.0</version>
  </dependency>
  <dependency>
    <groupId>org.citationstyles</groupId>
    <artifactId>styles</artifactId>
    <version>24.3</version>
  </dependency>
  <dependency>
    <groupId>org.citationstyles</groupId>
    <artifactId>locales</artifactId>
    <version>24.3</version>
  </dependency>
</dependencies>

Usage

In the quick start example above, you have seen how to create bibliographies with CSL.makeAdhocBibliography(). This method provides a simple interface that covers many use cases. The following usage instructions give you with much more control.

First, create an ItemDataProvider that provides citation item data to the CSL processor. You can either implement this interface yourself or use one of the default implementations such as the ListItemDataProvider:

ListItemDataProvider lidp = new ListItemDataProvider(
    new CSLItemDataBuilder()
      	.id("Smith2013")
      	.type(CSLType.ARTICLE_JOURNAL)
      	.title("Some journal article")
      	.author("John", "Smith")
      	.issued(2013)
      	.containerTitle("Some journal")
      	.build(),
    new CSLItemDataBuilder()
        .id("Johnson2024")
        .type(CSLType.BOOK)
        .title("My turbulent life")
        .author("Peter", "Johnson")
        .issued(2024)
        .build()
);

Note how the item data is created through a builder DSL. In citeproc-java you can use builders for all model objects.

If you like, you can also load the citation item data from a file. For example, the BibTeXItemDataProvider can import BibTeX databases. See the section on importers below.

After having created an ItemDataProvider, you can instantiate the CSL processor:

CSL citeproc = new CSL(lidp, "apa");
citeproc.setOutputFormat("text");

You have to provide the item data provider and a CSL style (select one of the 10,000+ styles bundled in the org.citationstyles:styles dependency). The processor tries to load the style from the classpath, but you may also pass your own style as a serialized CSL string to the constructor.

To create a bibliography that contains a set of citation items, call the registerCitationItems(String...) method and introduce the item IDs to the processor:

citeproc.registerCitationItems("Smith2013", "Johnson2024");

The processor will request the corresponding citation item data from the provided ItemDataProvider.

Alternatively, you can call makeCitation(String) to generate citation strings that you can insert into your document.

List<Citation> s1 = citeproc.makeCitation("Smith2013");
System.out.println(s1.get(0).getText());
//=> (Smith, 2013) (for the "apa" style configured above)

List<Citation> s2 = citeproc.makeCitation("Johnson2024");
System.out.println(s2.get(0).getText());
//=> (Johnson, 2024)

The processor saves each ID, so you can generate a bibliography that contains all citations you used in your document.

Bibliography bibl = citeproc.makeBibliography();
for (String entry : bibl.getEntries()) {
    System.out.println(entry);
}

//=> Johnson, P. (2024). My turbulent life.
//   Smith, J. (2013). Some journal article. Some Journal.

Importers

citeproc-java supports several input file formats. This allows you to create citations and bibliographies from your existing citation databases.

For example, you can load a BibTeX file as follows:

BibTeXDatabase db = new BibTeXConverter().loadDatabase(
    Files.newInputStream(Paths.get("mydb.bib")));

After that, you can create an ItemDataProvider and pass it to the CSL processor.

BibTeXItemDataProvider provider = new BibTeXItemDataProvider();
    provider.addDatabase(db);

CSL citeproc = new CSL(provider, "apa");

Now, you can use the CSL processor as described above.

Besides BibTeXItemDataProvider, there is EndNoteItemDataProvider and RISItemDataProvider, which allow you to read EndNote and RIS files respectively.

For convenience, you can use BibliographyFileReader, which automatically detects the file format and returns a corresponding ItemDataProvider:

BibliographyFileReader bfr = new BibliographyFileReader();
ItemDataProvider idp = bfr.readBibliographyFile(new File("mydb.bib"));
CSL citeproc = new CSL(idp, "apa");

Output formats

citeproc-java supports several output formats. The most common ones are html and text, but you can also use asciidoc and fo.

Call the CSL processor’s setOutputFormat(String) method to set the desired format.

citeproc.setOutputFormat("html");

Command-line tool

citeproc-java binaries are available from the GitHub releases page. On macOS, you can install the command line tool with Homebrew.

brew tap michel-kraemer/citeproc-java
brew install citeproc-java

With the command-line tool, can use citeproc-java without setting up a full development environment. The tool allows you to easily create citations and bibliographies. In particular, it comes in handy if ...

  • you are an author using CSL and you want a quick way to preview your citations or bibliographies, or if
  • you are a CSL style author and want to test your style files.

The tool can render bibliographies and citations, convert a database (e.g. BibTeX, EndNote, or RIS file) to a CSL json document, or list citation IDs from a database. There even is an interactive shell.

To get the tool's help, call the following command:

citeproc-java --help

Building

If you want to hack on citeproc-java (which would be much appreciated, by the way), clone the repository and execute the following command to compile the library and to run the unit tests:

./gradlew test

The script automatically downloads the correct Gradle version, so you won’t have to do anything else. If everything runs successfully, you can create a .jar library:

./gradlew jar

The library will be located under the citeproc-java/build/libs directory.

To install the library in your local Maven repository execute the following command:

./gradlew publishToMavenLocal

If you want to build the command line tool run the following command:

./gradlew installDist

The command line tool will be installed to citeproc-java-tool/build/install/citeproc-java-tool.

Notes on used components

citeproc-js

The library uses citeproc-js for testing (i.e. in unit tests to compare its own output to what citeproc-js renders). citeproc-js has been created by Frank G. Bennett and is licensed under the Common Public Attribution License Version 1.0.

Name Parser

The BibTeX name parser's grammar is based on the one found in the bibtex-ruby. The original grammar is licensed under GPL v3. It has been converted to ANTLR and is released here under the Apache License 2.0 by permission of the original author Sylvester Keil.

BibTeX Converter

The BibTeX to CSL converter is based on the mapping used in Docear as presented by Joeran Beel.

Docear is released under the GPLv2 but its code may also be reused in projects licensed under Apache License 2.0. The mapping is released here under the Apache License 2.0 by permission of Joeran Beel, Docear.

Smart Quotes

The algorithm that produces typographically correct quotation marks and apostrophes is based on smartquotes.js written by Kelly Martin and released under the MIT license. The code has been translated to Java and improved to support more edge cases as well as multiple languages.

Alphanum Algorithm

citeproc-java is able to sort citations in a natural, language-sensitive way. The implementation of this behaviour is loosely based on the Alphanum algorithm by Dave Koelle and the Java implementation released under the MIT license. However, it has been extended to use a java.text.Collator for locale-sensitive comparison, and it is also able to compare arbitrarily large numbers.

Title case algorithm

The implementation of the algorithm that converts strings to title case is based on the JavaScript library to-title-case by David Gouch released under the MIT license. The code has been translated to Java and was slightly modified to produce strings that adhere to the CSL specification.

License

citeproc-java is licensed under the Apache License, Version 2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

citeproc-java's People

Contributors

dependabot[bot] avatar gallardo avatar michel-kraemer avatar siedlerchr avatar stefanhagel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

citeproc-java's Issues

Encoding of CSL definition (CSL definitions are read as non-Unicode)

Thank you for the great tool.
There is a problem with the encoding of the CSL definitions. When working with bibliographical input files in UTF-8 citeproc-java seems to still load CSL definitions in ANSI, and then uses these non-Unicode values in the output. Thus when processing a UTF-8-encoded json file with the command line
citeproc-java bibliography -i "sds.json" -s chicago-author-date -f html >1.htm
the program outputs a html file, which has all the unicode characters of the input file preserved, but instead of the en-dash (U+2013) it uses the character 0x96, which corresponds to the ANSI code of the en-dash, but does not display correctly when the rest of the file is encoded in UTF-8.
The same goes for CSL definitions containing signs in non-Western languages (example: gost-r-7-0-5-2008): they are read in their respective non-Unicode codepage.

Lexical error when encountering UTF-8 in .bib file

Hey there,

love your project! Automate all the things!

I got the following exception when calling citeproc-java on a .bib file containing a unicode character (namely “):

Exception in thread "main" org.jbibtex.TokenMgrError: Lexical error at line 1, column 248.  Encountered: "\u201c" (8220), after : ""
	at org.jbibtex.LaTeXParserTokenManager.getNextToken(LaTeXParserTokenManager.java:303)
	at org.jbibtex.LaTeXParser.jj_scan_token(LaTeXParser.java:408)
	at org.jbibtex.LaTeXParser.jj_3R_6(LaTeXParser.java:270)
	at org.jbibtex.LaTeXParser.jj_3_3(LaTeXParser.java:253)
	at org.jbibtex.LaTeXParser.jj_2_3(LaTeXParser.java:242)
	at org.jbibtex.LaTeXParser.String(LaTeXParser.java:190)
	at org.jbibtex.LaTeXParser.Object(LaTeXParser.java:66)
	at org.jbibtex.LaTeXParser.ObjectList(LaTeXParser.java:46)
	at org.jbibtex.LaTeXParser.LaTeX(LaTeXParser.java:21)
	at org.jbibtex.LaTeXParser.parse(LaTeXParser.java:16)
	at de.undercouch.citeproc.bibtex.BibTeXConverter.toItemData(BibTeXConverter.java:161)
	at de.undercouch.citeproc.bibtex.BibTeXConverter.toItemData(BibTeXConverter.java:143)
	at de.undercouch.citeproc.bibtex.BibTeXItemDataProvider.addDatabase(BibTeXItemDataProvider.java:32)
	at de.undercouch.citeproc.CSLTool.readBibliographyFile(CSLTool.java:325)
	at de.undercouch.citeproc.CSLTool.run(CSLTool.java:255)
	at de.undercouch.citeproc.CSLTool.main(CSLTool.java:139)

This is the .bib file in question: ref.txt

examples at http://michel-kraemer.github.io/citeproc-java/ does not compile

I am trying to execute the code example at http://michel-kraemer.github.io/citeproc-java/

CSLItemData item = new CSLItemDataBuilder("citeproc-java", CSLType.WEBPAGE)
.title("citeproc-java: A Citation Style Language (CSL) processor for Java")
.author("Michel", "Krämer")
.issued(2014, 2, 27)
.URL("http://michel-kraemer.github.io/citeproc-java/")
.accessed(2014, 10, 25)
.build();

String bibl = CSL.makeAdhocBibliography("ieee", item).makeString();

The code example doesn't work. There is no constructor CSLItemDataBuilder(String, CSLType)

ThreadLocal issue

Hi,
I'm using citeproc-java in a Tomcat web app and it works fine until I shutdown my Tomcat. At that time, I get the following error message in the logs:

15-Nov-2018 13:42:04.296 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [MyApp] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@164ff66]) and a value of type [de.undercouch.citeproc.script.JREScriptRunner] (value [de.undercouch.citeproc.script.JREScriptRunner@13558c8]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

Any idea?

Thanks,
Benoit

MemLeak in V8

I'm experiencing an OOME when using v8. Inspecting the code I'm missing the code to dispose the callback methods from the functionRegistry in V8. Maybe I'm missing something? (I'm using the example code from https://michel-kraemer.github.io/citeproc-java/.) Is it possible to deregister the items?

Environment:

  • linux 4.4.120-45-default x86_64
  • java 8u161-oracle
  • com.eclipsesource.j2v8:j2v8_linux_x86_64:4.8.0

Example code (run with -Xmx64m renders 1869 entries before terminating with OOME):

import de.undercouch.citeproc.CSL;
import de.undercouch.citeproc.csl.CSLItemData;
import de.undercouch.citeproc.csl.CSLItemDataBuilder;
import de.undercouch.citeproc.csl.CSLType;

import java.io.IOException;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        CSLItemData item;
        item = new CSLItemDataBuilder()
                .type(CSLType.WEBPAGE)
                .title("citeproc-java: A Citation Style Language (CSL) processor for Java")
                .author("Michel", "Krämer")
                .issued(2016, 11, 20)
                .URL("http://michel-kraemer.github.io/citeproc-java/")
                .accessed(2018, 4, 12)
                .build();

        try {
            System.out.println("Press enter to begin");
            scanner.nextLine();
            for (int i=1; i <= 3000; i++) {
                System.out.println("entry " + i + ":" + CSL.makeAdhocBibliography("ieee", item).makeString());
            }
            System.out.println("Press enter to end");
            scanner.nextLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Line break in BibTeX title causes incorrect rendering of special characters

While the official 0.6 release is not able to deal with a line break in the BibTeX title the current sources are. However the line break causes some rendering issues of special characters and escaped characters. I don't know whether line breaks in the title should be rated as valid and whether this is an issue of citeproc-java but I wanted to record it here anyhow.

Thank you,

Andreas

Artificial example:

@Article{Issue09,
author = "Jo{"e}l Biran{\c c}on and Philippe Maisonobe and Michel Merle",
title = "Localisation de syst`emes
diff'erentiels, stratifications de {W}hitney et condition de {T}hom",
journal = "Invent. Math.",
volume = 66,
year = 1990,
pages = "12--16"}

results in the following text output:

J. Birancon, P. Maisonobe, and M. Merle, “Localisation de syst`emes diff’erentiels, stratifications de {W}hitney et condition de {T}hom,” Invent. Math., vol. 66, pp. 12–16, 1990.

while

@Article{Issue09,
author = "Jo{"e}l Biran{\c c}on and Philippe Maisonobe and Michel Merle",
title = "Localisation de syst`emes diff'erentiels, stratifications de {W}hitney et condition de {T}hom",
journal = "Invent. Math.",
volume = 66,
year = 1990,
pages = "12--16"}

results in the correct output:

J. Birancon, P. Maisonobe, and M. Merle, “Localisation de systèmes différentiels, stratifications de Whitney et condition de Thom,” Invent. Math., vol. 66, pp. 12–16, 1990.

[Question] Additional Formaters

I like the additional formaters in this project compared to the citeproc-js project. In particular I am finding the FO transformation very useful. Additionally, I'd imagine others might find ASCIIDoc of interest. In 2013 I saw Sanders Kleinfeld from O'Riely give a talk about how they were planning to author all their books in AsciiDoc.

Is there a good reason for the exclusion? I am interested in submitting these as a pull request to https://github.com/Juris-M/citeproc-js. Do you think this would be a good idea? Have you attempted it in the past?

BibTeXConverter may fail with java.lang.Error

Current JavaCC-generated parser classes BibTeXParser and LaTeXParser throw an instance of org.jbibtex.TokenMgrError if there is a problem with the tokenization of the input stream (e.g. the LaTeX string contains unicode characters). Unfortunately, class TokenMgrError extends java.lang.Error (not java.lang.Exception as one might expect), which means that they silently pass through regular try-catch protection, possibly terminating the whole JVM process.

Therefore, BibTeXConverter should wrap calls to BibTeXParser#parse(Reader) and LaTeXParser#parse(String) with a try-catch statement that has an explict catch-clause for org.jbibtex.TokenMgrError.

Example stack trace can be seen here:
https://code.google.com/p/java-bibtex/issues/detail?id=20#c12

Also, citeproc-java could update its JBibTeX dependency to the latest 1.0.10 version (makes both parser classes more tolerable towards "extravagant characters" in the input stream, but does not address the TokenMgrError issue).

BibTeXItemDataProviderTest broken: two instead one citations

Upgrading citeproc-js to https://github.com/Juris-M/citeproc-js/releases/tag/1.1.215 breaks de.undercouch.citeproc.bibtex.BibTeXItemDataProviderTest.numericAlphabetical in

List<Citation> cs = citeproc.makeCitation(k.getValue());
assertEquals(1, cs.size());
when citing entry Anonymous:1990:DMR: the second invokation produces two citations instead of one.

The problem could be have been introduced upstream.

(N.B.: The test would be more valuable if it wouldn't pick random entries. Randomness hinders tests reproducibility.)

editortranslator role is not supported

The editortranslator role is included in the CSL 1.0.1 specification, but support for this role has not been implemented (e.g., the CSLItemDataBuilder does not contain an editorTranslator(CSLName... editorTranslator) method).

./gradlew install fails

Trying to build and install on Mac OS X 10.9, with Java 1.8.0_20, I get this:

$ ./gradlew install
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
:buildSrc:compileJava UP-TO-DATE
:buildSrc:compileGroovy UP-TO-DATE
:buildSrc:processResources UP-TO-DATE
:buildSrc:classes UP-TO-DATE
:buildSrc:jar UP-TO-DATE
:buildSrc:assemble UP-TO-DATE
:buildSrc:compileTestJava UP-TO-DATE
:buildSrc:compileTestGroovy UP-TO-DATE
:buildSrc:processTestResources UP-TO-DATE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test UP-TO-DATE
:buildSrc:check UP-TO-DATE
:buildSrc:build UP-TO-DATE
:citeproc-java:downloadCiteprocJs UP-TO-DATE
:citeproc-java:downloadXmldomJs UP-TO-DATE
:citeproc-java:downloadXmle4xJs UP-TO-DATE
:citeproc-java:generateSources UP-TO-DATE
:citeproc-java:compileJava UP-TO-DATE
:citeproc-java:processResources UP-TO-DATE
:citeproc-java:classes UP-TO-DATE
:citeproc-java:jar UP-TO-DATE
:citeproc-java:javadoc
/Users/maloneyc/git/michel-kraemer/citeproc-java/citeproc-java/src/main/java/de/undercouch/citeproc/CSL.java:92: error: unmappable character for encoding ASCII
 *     .author("Michel", "Kr?mer")
                            ^
1 error
:citeproc-java:javadoc FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':citeproc-java:javadoc'.
> Javadoc generation failed.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 5.812 secs

Importing items from Mendeley fails

While importing using the Zotero remote connector works (except for the unicode issue reported in #43, importing from Mendelay fails both from citeproc-java.bat and when using a JVM.
After authorizing, when executing

citeproc-java mendeley list

I get:

Retrieving items ...Exception in thread "main" java.lang.NullPointerException
at de.undercouch.citeproc.mendeley.MendeleyConnector.getItemIDs(Mendeley
Connector.java:164)
at de.undercouch.citeproc.remote.RemoteConnectorAdapter.getItemIDs(Remot
eConnectorAdapter.java:69)
at de.undercouch.citeproc.remote.RemoteConnectorAdapter.getItemIDs(Remot
eConnectorAdapter.java:69)
at de.undercouch.citeproc.helper.tool.CachingRemoteConnector.getItemIDs(
CachingRemoteConnector.java:107)
at de.undercouch.citeproc.tool.AbstractRemoteCommand.connect(AbstractRem
oteCommand.java:139)
at de.undercouch.citeproc.tool.AbstractRemoteCommand.doRun(AbstractRemot
eCommand.java:79)
at de.undercouch.citeproc.tool.AbstractCSLToolCommand.run(AbstractCSLToo
lCommand.java:113)
at de.undercouch.citeproc.CSLTool.doRun(CSLTool.java:170)
at de.undercouch.citeproc.tool.AbstractCSLToolCommand.run(AbstractCSLToo
lCommand.java:113)
at de.undercouch.citeproc.CSLTool.main(CSLTool.java:132)

This seems to indicate that response.getHeaders(LINK); returns NULL in some circumstances? In that case, should one test against NULL here?

Returning meaningful errors

I am getting following error while catching exception. Is it possible for you to return meaningful parse error?

ib Parse error [Ljava.lang.StackTraceElement;@8814e9
Exception Found ;org.openoffice.testaddon.TestAddOn.dispatch(TestAddOn.java:196)
Bib Parse error [Ljava.lang.StackTraceElement;@1256ea2
Exception Found ;org.openoffice.testaddon.TestAddOn.dispatch(TestAddOn.java:196)

And line 196 is:

Bibliography bibl = citeproc.makeBibliography();

getAuthor()[0].getFamily() and cid.getAuthor()[0].getGiven() returns null on various entries

While using mentioned methods, it returns null on various entries despite of Authors re present. My code given below:

CSLItemData cid;
            Iterator<Map.Entry<Key, BibTeXEntry >> entries = db.getEntries().entrySet().iterator();
            while (entries.hasNext())
            {
                Map.Entry<Key, BibTeXEntry> entry = entries.next();
                Key key = entry.getKey();
                BibTeXEntry e = db.resolveEntry(key);
                cid = bibC.toItemData(e);
                System.out.println(cid.getAuthor()[0].getFamily()+","+cid.getAuthor()[0].getGiven());
            }

Null Exception while reading JabRef based file

HI again
Come across a weird exception null while parsing a file. The file in question can be downloaded here:

https://dl.dropboxusercontent.com/u/35231160/docear.bib

It has 1642 bib entries and it breaks on entry# 1626 having Title: {{M}etainformation und {D}atenintegration in betrieblichen {U}mweltinformationssystemen({BUIS})}
Id is rautenstrauch3

Stack trace also not being helpful to identify exact cause. Code given below:

ArrayList<String> records = new ArrayList<String>();
                short i = 0;
                CSLItemData cid;
                String rec = "";
                //For Time Stamp related to JabRef
                Key timestampKey = new Key("timestamp");
                CSLDateParser dateParser = new CSLDateParser();
                Iterator<Map.Entry<Key, BibTeXEntry >> entries = db.getEntries().entrySet().iterator();
                String Title = "";
                String timestamp = "";
                String author = "";
                String pages = "";
                System.out.println("Total = "+db.getEntries().size());
                int f = 0;
                while (entries.hasNext())
                 {
                    f++;
                     System.out.println("Printing Values in Loop...index# "+f);
                    Map.Entry<Key, BibTeXEntry> entry = entries.next();
                    Key key = entry.getKey();
                    BibTeXEntry e = db.resolveEntry(key);
                    Value ts = e.getField(timestampKey);
                    if(ts == null)
                    {
                        timestamp = "-";
                    }
                    else
                    {
                        CSLDate date = dateParser.parse(ts.toUserString());
                        timestamp = date.getDateParts()[0][0]+"";
                        if (date.getDateParts()[0].length > 1)
                        {
                            timestamp+="-"+date.getDateParts()[0][1]+"";
                        }
                        if (date.getDateParts()[0].length > 2)
                        {
                            timestamp+="-"+date.getDateParts()[0][2]+"";
                        }
                    }

                    cid = bibC.toItemData(e);
                    /**
                     * Author
                     */
                    if(cid.getAuthor()[0].getGiven() == null && cid.getAuthor()[0].getFamily() == null)
                    {
                       // author = cid.getAuthor()[0].getLiteral().toString();
                    }
                    else
                    {
                      //  author = cid.getAuthor()[0].getGiven()+","+cid.getAuthor()[0].getFamily();
                    }
                    pages = cid.getNumberOfPages();

                    if(pages == null)
                    {
                        pages = "-";
                    }
                    Title = cid.getTitle();
                    System.out.println("Title = "+Title+"\n================================\n");
                    if(Title == null)
                    {
                        Title = "-";
                    }
                   //////// rec= pages+"%"+cid.getId()+"%"+Title+"%"+author+"%"+timestamp;
                    //System.out.println(rec);
                    //LOGGER.info(rec);
                   // records.add(rec);
                 }

Cannot generate citations for report or thesis using APA csl

I'm using citeproc-java to generate citations with the APA 6th edition stylesheet. (https://github.com/citation-style-language/styles/blob/master/apa.csl) It fails when I attempt to create a display citation for report or thesis. I'm using version 1.0.1 of citeproc-java.

It's not clear to me if the error is with citeproc-java or with the CSL; the MLA CSL (https://github.com/citation-style-language/styles/blob/master/modern-language-association.csl) works just fine, but then again, the APA CSL works for other ref types.

When I attempt to build the display citation via

CSL.makeAdhocBibliography(APA_6THED, cslItemData).makeString()

I get an error message that begins with:

2017-05-18 09:08:37.649:WARN:oejs.ServletHandler:qtp261518457-17:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Could not make bibliography

The key parts seems to be:

Caused by:
de.undercouch.citeproc.script.ScriptRunnerException: Could not call method
at de.undercouch.citeproc.script.JREScriptRunner.callMethod(JREScriptRunner.java:108)

Caused by:
javax.script.ScriptException: TypeError: Cannot read property "slice" from undefined in at line number 808
at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)

Caused by:
:808 TypeError: Cannot read property "slice" from undefined
at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)

I can paste the full stacktrace if it would help.

In trying to resolve the bug, I went through the APA CSL to see if there was a mandatory element that I needed in order to get it to work. I added edition, version, collection title, number, container title, url, and doi, beyond the core elements: author, title, publisher, publisher place, issued. That didn't fix the issue.

I then tried a more minimalist approach and tried removing everything I could, but that produced the same error.

CSLItemDataBuilder builder = new CSLItemDataBuilder();
builder.title("Sample report title");
builder.type(CSLType.REPORT);
builder.publisher("ICPSR");
builder.publisherPlace("Ann Arbor, MI");
CSLName name = new CSLName("Richardson", "Matthew", null, null, null, null, null, null, null, null, null, null);
CSLName[] authors = new CSLName[1];
authors[0] = name;
builder.author(authors);
int[] dateParts = new int[]{2017,5,1};
int[][] datePartsArray = new int[1][3];
datePartsArray[0] = dateParts;
CSLDate date = new CSLDate(datePartsArray, null, null, null, null);
builder.issued(date);
CSLItemData cslItemData = builder.build();
return CSL.makeAdhocBibliography(APA_6THED, cslItemData).makeString();

Any assistance you can provide is greatly appreciated.

Editors get listed twice

Im creating References in APA style. I just recognized that if there is one editor, it will be added twice, but the Ed. shortcut is correct.
Example:
Costantino, C. (2004). Three Essays on Vertical Product Differentiation: Exclusivity, Non-exclusivity and Advertising. (R. R. Betancourt, R. R. Betancourt, Ed.).

Not sure, if I'm doing something wrong, or if it is an error.
Tank you!

NPE on call to CSL.makeAdhocBibliography

I'm calling CSL.makeAdhocBibliography with style "apa" and format "text", with one CSLItemData. Getting this NPE:

NullPointerException   org.mozilla.javascript.ScriptRuntime.newObjectLiteral (ScriptRuntime.java:3599)

Here's the full stack trace, though it isn't particularly enlightening:

java.lang.NullPointerException: null
 at org.mozilla.javascript.ScriptRuntime.newObjectLiteral (ScriptRuntime.java:3599)
    de.undercouch.citeproc.xmle4x._c_script_0 (:91)
    de.undercouch.citeproc.xmle4x.call (:-1)
    org.mozilla.javascript.ContextFactory.doTopCall (ContextFactory.java:426)
    org.mozilla.javascript.ScriptRuntime.doTopCall (ScriptRuntime.java:3178)
    de.undercouch.citeproc.xmle4x.call (:-1)
    de.undercouch.citeproc.xmle4x.exec (:-1)
    de.undercouch.citeproc.script.RhinoScriptRunner.loadScript (RhinoScriptRunner.java:97)
    de.undercouch.citeproc.CSL.<init> (CSL.java:162)
    de.undercouch.citeproc.CSL.<init> (CSL.java:130)
    de.undercouch.citeproc.CSL.<init> (CSL.java:94)
    de.undercouch.citeproc.CSL.<init> (CSL.java:63)
    de.undercouch.citeproc.CSL.makeAdhocBibliography (CSL.java:615)
    cayenne.formats.citation$__GT_citation.doInvoke (citation.clj:55)
    clojure.lang.RestFn.invoke (RestFn.java:410)
    user$eval13644.invoke (form-init5047851267256796025.clj:1)
    clojure.lang.Compiler.eval
 (Compiler.java:6619)
    clojure.lang.Compiler.eval (Compiler.java:6582)
    clojure.core$eval.invoke (core.clj:2852)
    clojure.main$repl$read_eval_print__6588$fn__6591.invoke (main.clj:259)
    clojure.main$repl$read_eval_print__6588.invoke (main.clj:259)
    clojure.main$repl$fn__6597.invoke (main.clj:277)
    clojure.main$repl.doInvoke (main.clj:277)
    clojure.lang.RestFn.invoke (RestFn.java:1096)
    clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__13043.invoke (interruptible_eval.clj:56)
    clojure.lang.AFn.applyToHelper (AFn.java:159)
    clojure.lang.AFn.applyTo (AFn.java:151)
    clojure.core$apply.invoke (core.clj:617)
    clojure.core$with_bindings_STAR_.doInvoke (core.clj:1788)
    clojure.lang.RestFn.invoke (RestFn.java:425)
    clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke (interruptible_eval.clj:41)
    clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__13084$fn__13087.invoke (interruptible_eval.clj:171)
    clojure.core$comp$fn__4154.invoke
 (core.clj:2330)
    clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__13077.invoke (interruptible_eval.clj:138)
    clojure.lang.AFn.run (AFn.java:24)
    java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:615)
    java.lang.Thread.run (Thread.java:744)

Running OpenJDK7:

java version "1.7.0_45"
OpenJDK Runtime Environment (IcedTea 2.4.3) (ArchLinux build 7.u45_2.4.3-1-x86_64)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)

Any ideas?

Karl

Unknown RIS Labels

When importing from a RIS file exported from Zotero, an exception is thrown for unknown labels such as "L2". It might make sense rather to ignore such cases, in order to be forward compatible.

Cannot process BibEntry with \r

When one of the BibTeX fields contains a \r an exception is thrown.
Maybe this gets fixed when updating jBibTeX?

important part of the exception

org.jbibtex.TokenMgrError: Lexical error at line 2, column 0.  Encountered: <EOF> after : ""
    at org.jbibtex.LaTeXParserTokenManager.getNextToken(LaTeXParserTokenManager.java:303) ~[jbibtex-1.0.8.jar:?]
    at org.jbibtex.LaTeXParser.jj_ntk(LaTeXParser.java:447) ~[jbibtex-1.0.8.jar:?]
    at org.jbibtex.LaTeXParser.ObjectList(LaTeXParser.java:33) ~[jbibtex-1.0.8.jar:?]
    at org.jbibtex.LaTeXParser.LaTeX(LaTeXParser.java:21) ~[jbibtex-1.0.8.jar:?]
    at org.jbibtex.LaTeXParser.parse(LaTeXParser.java:16) ~[jbibtex-1.0.8.jar:?]
    at de.undercouch.citeproc.bibtex.BibTeXConverter.toItemData(BibTeXConverter.java:161) ~[citeproc-java-0.6.jar:?]
    ...

Help wanted: Improving performance when repeatedly creating a one-entry bibliography

In JabRef, we use

CSL.makeAdhocBibliography(style, outputFormat.getFormat(), cslItemData);

to create the HTML-preview for the currently selected item in the BibTeX database. Every time the user scrolls through the main list, we update the preview and call this code again. I have carefully profiled what happens, but everything points to this call being the source of our memory and performance problems. I know that makeAdhocBibliography has a clear warning sign in its comments that it will be expensive.

Can you recommend the best possible way to handle our situation so that it is as resource-friendly as possible? We have the following constants and variables:

  • the style is set in the preferences and stays constant most of the time
  • the output format is fixed as well
  • we provide the cslItemData every time the preview needs to be updated

I'm asking this question because at the moment I see no sensible way with one of the built-in ItemDataProviders to achieve this. Therefore, one of my first questions would be: Is it OK to make an ItemDataProvider that changes its content? I would then initialize a CSL instance with an empty provider and change its underlying ItemData list every time we need to render an item.

Question: how to serialize a JSON map?

I am parsing JSON from a file with this code:

Map<String, Object> jm = new JsonParser(
    new JsonLexer(
        new InputStreamReader(
            new URL("foo.json").openStream()
        )
    )
).parseObject();

Now, I want to serialize it back out to an OutputStream, but am having trouble figuring out how to do it.

BTW, we are planning to use this library in a citation exporting service at PMC: https://github.com/Klortho/citation-exporter

Journal titles lost when importing from BibTeX files

I have exported data for journal articles from Zotero Standalone to "BibLaTeX" format, then used the citeproc-java BibTeXConverter to import these.
The "journaltitle" fields were not imported to either "containerTitle" or "collectionTitle" as expected; these were however filled with data from "series".
Indeed BibTeXConverter.java tries to import a field (73)
private static final String FIELD_JOURNAL = "journal";
while the database file would require (73)
private static final String FIELD_JOURNALTITLE = "journaltitle";
and (235-237)

		if (entries.containsKey(FIELD_JOURNALTITLE)) {
			builder.containerTitle(entries.get(FIELD_JOURNALTITLE));
			builder.collectionTitle(entries.get(FIELD_JOURNALTITLE));

Or, of course, query both options if there are versions with a field "journal"

java.lang.NoSuchMethodError: org.mozilla.javascript.ScriptRuntime.getObjectProp

I'm trying to compile the Getting Started example; I am running into a NoSuchMethodError that I can't seem to overcome. My code compiles fine through maven with dependencies below. At runtime, it appears that citeproc-java/src-gen/main/resources/de/undercouch/citeproc/xmle4x.js is getting compiled on-the-fly, but it won't run due to mismatch on the method signature with the rhino engine. AFAIK, this should be loaded in java7 and not present a problem. Have tried adding in rhino dependencies org.mozilla:rhino:1.7R4 and rhino:js:1.7R2 without success. That's frustrating as the mozilla rhino does seem to have the right method signature. Any ideas?

Stacktrace

java.lang.NoSuchMethodError: org.mozilla.javascript.ScriptRuntime.getObjectProp(Ljava/lang/Object;Ljava/lang/String;Lorg/mozilla/javascript/Context;Lorg/mozilla/javascript/Scriptable;)Ljava/lang/Object;
    at de.undercouch.citeproc.xmle4x._c_script_0(Unknown Source)
    at de.undercouch.citeproc.xmle4x.call(Unknown Source)
    at org.mozilla.javascript.ContextFactory.doTopCall(Unknown Source)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(Unknown Source)
    at de.undercouch.citeproc.xmle4x.call(Unknown Source)
    at de.undercouch.citeproc.xmle4x.exec(Unknown Source)
    at de.undercouch.citeproc.script.RhinoScriptRunner.loadScript(RhinoScriptRunner.java:97)
    at de.undercouch.citeproc.CSL.<init>(CSL.java:162)
    at de.undercouch.citeproc.CSL.<init>(CSL.java:130)
    at de.undercouch.citeproc.CSL.<init>(CSL.java:94)
    at de.undercouch.citeproc.CSL.<init>(CSL.java:63)

Example Code

        CSL citeproc = new CSL(new DummyProvider(), "ieee");
        citeproc.setOutputFormat("html");

        citeproc.registerCitationItems("ID-1", "ID-2", "ID-3");

        List<Citation> s1 = citeproc.makeCitation("ID-1");
        System.out.println(s1.get(0).getText());
        //=> [1] (for the "ieee" style)

        List<Citation> s2 = citeproc.makeCitation("ID-2");
        System.out.println(s2.get(0).getText());
        //=> [2]

        Bibliography bibl = citeproc.makeBibliography();
        for (String entry : bibl.getEntries()) {
            System.out.println(entry);
        }

Maven Dependencies

        <repository>
            <id>oss-snapshots-repo</id>
            <name>Sonatype OSS Maven Repository</name>
            <url>https://oss.sonatype.org/content/groups/public</url>
            <snapshots
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>

        <dependency>
            <groupId>de.undercouch</groupId>
            <artifactId>citeproc-java</artifactId>
            <version>0.6</version>
        </dependency>
        <dependency>
            <groupId>org.citationstyles</groupId>
            <artifactId>styles</artifactId>
            <version>1.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.citationstyles</groupId>
            <artifactId>locales</artifactId>
            <version>1.0.1-SNAPSHOT</version>
        </dependency>
$ env | grep JAVA
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/

$ java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

$ mvn -v
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T10:37:52-07:00)
Maven home: /usr/local/Cellar/maven/3.2.1/libexec
Java version: 1.7.0_60, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac"

$ javap -cp  ~/.m2/repository/org/mozilla/rhino/1.7R4/rhino-1.7R4.jar org.mozilla.javascript.ScriptRuntime | grep getObjectProp
  public static java.lang.Object getObjectProp(java.lang.Object, java.lang.String, org.mozilla.javascript.Context);
  public static java.lang.Object getObjectProp(java.lang.Object, java.lang.String, org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable);
  public static java.lang.Object getObjectProp(org.mozilla.javascript.Scriptable, java.lang.String, org.mozilla.javascript.Context);
  public static java.lang.Object getObjectPropNoWarn(java.lang.Object, java.lang.String, org.mozilla.javascript.Context);

cannot parse unicode character

org.jbibtex.TokenMgrError: Lexical error at line 1, column 35. Encountered: "\u00e7" (231), after : "" at org.jbibtex.LaTeXParserTokenManager.getNextToken(LaTeXParserTokenManager.java:303) at org.jbibtex.LaTeXParser.jj_scan_token(LaTeXParser.java:408) at org.jbibtex.LaTeXParser.jj_3R_6(LaTeXParser.java:270) at org.jbibtex.LaTeXParser.jj_3_3(LaTeXParser.java:253) at org.jbibtex.LaTeXParser.jj_2_3(LaTeXParser.java:242) at org.jbibtex.LaTeXParser.String(LaTeXParser.java:190) at org.jbibtex.LaTeXParser.Object(LaTeXParser.java:66) at org.jbibtex.LaTeXParser.ObjectList(LaTeXParser.java:46) at org.jbibtex.LaTeXParser.LaTeX(LaTeXParser.java:21) at org.jbibtex.LaTeXParser.parse(LaTeXParser.java:16) at de.undercouch.citeproc.bibtex.BibTeXConverter.toItemData(BibTeXConverter.java:161) at de.undercouch.citeproc.bibtex.BibTeXConverter.toItemData(BibTeXConverter.java:143) at de.undercouch.citeproc.bibtex.BibTeXItemDataProvider.addDatabase(BibTeXItemDataProvider.java:32) at

The author name has unicode "\u00e7" which is causing this exception. Here is the citation being parsed
"@Article{Bloem_2014,doi = {10.4204/eptcs.157.7},url = {http://dx.doi.org/10.4204/eptcs.157.7},year = 2014,month = {jul},publisher = {Open Publishing Association},volume = {157},pages = {34--50},author = {Roderick Bloem and Rüdiger Ehlers and Swen Jacobs and Robert Könighofer},title = {How to Handle Assumptions in Synthesis},journal = {Electronic Proceedings in Theoretical Computer Science}}"

Issues with code in Java 10

Hello Michael,

The provided sample code generates a string of kind null312. , when running with Java 10.

Few details:

  • The issue is not reproducible on Java 8;
  • The issue appears only on the first run of CSL.makeBibliography() method, all subsequent calls work fine;
  • Specific version: Java 10.0.2+13, OS: Mac OS.

Although I am pretty sure that the problem is connected with Java 10 changes, will highly appreciate your help. Thanks in advance!


import de.undercouch.citeproc.CSL;
import de.undercouch.citeproc.ItemDataProvider;
import de.undercouch.citeproc.csl.CSLItemData;
import de.undercouch.citeproc.csl.CSLItemDataBuilder;
import de.undercouch.citeproc.csl.CSLType;

public class BibliographyFailure {
    public static final String ID = "0";

    public static void main(String[] args) throws IOException {
        CSL formatter = getCSL();

        String bibliography = formatter.makeBibliography().makeString();

        System.out.println(bibliography);
    }

    private static CSL getCSL() throws IOException {
        SingleItemDataProvider provider = new SingleItemDataProvider();
        CSLItemDataBuilder itemBuilder = new CSLItemDataBuilder()
                .id(ID)
                .type(CSLType.ARTICLE_MAGAZINE)
                .abstrct("Some abstract")
                .title("Some title")
                .publisher("Some Cool Publisher Limited")
                .ISSN("12345678")
                .containerTitle("Cont Title")
                .journalAbbreviation("MYCM")
                .source("Magazines")
                .page("312")
                .pageFirst("312");
        provider.setItem(itemBuilder.build());

        CSL formatter = new CSL(provider, "mla");
        formatter.setOutputFormat("text");
        formatter.registerCitationItems(ID);
        return formatter;
    }

    private static class SingleItemDataProvider implements ItemDataProvider {
        private CSLItemData item;

        public void setItem(CSLItemData item) {
            this.item = item;
        }

        @Override
        public CSLItemData retrieveItem(String id) {
            return item;
        }

        @Override
        public String[] getIds() {
            return new String[]{item.getId()};
        }
    }
}

Cannot make citations for dependent styles

I am using this code to make the citations and it works fine.
String bibl = CSL.makeAdhocBibliography("chicago-author-date", item).makeString();

But, how to make a citations that is dependent?
String bibl = CSL.makeAdhocBibliography("dependent/water", item).makeString();

It gives an error: java.lang.Boolean cannot be cast to java.util.List. Is there different a way to make citation for the dependent ones?

Issue in parse error while having empty author field

I am loading a BibTex file, this time having author field empty but I m not sure whether it's the real case. I get following error

Bib Parse error [Ljava.lang.StackTraceElement;@8814e9
Bib Parse error [Ljava.lang.StackTraceElement;@228a02
Exception Found ;org.openoffice.testaddon.TestAddOn.dispatch(TestAddOn.java:216)

I am printing Excepton as

System.out.println("Exception Found ;"+ex.getStackTrace()[0].toString());

Message like Bib Parse error [Ljava.lang.StackTraceElement;@8814e9 is not being helpfult to figure out

Line 216 actually is Iterator<Map.Entry<Key, BibTeXEntry >> entries = db.getEntries().entrySet().iterator()

Code is give here:

http://pastebin.com/EeERzFWg

Example bib File here: https://drive.google.com/file/d/0B2hk8b9pF-ZZeGQ4UGtXMFhpN2c/edit?usp=sharing

Different Citation Formats

Reference to your code here, the code snippet you gave:

List<Citation> s1 = citeproc.makeCitation("ID-1");
System.out.println(s1.get(0).getText());
//=> [1] (for the "ieee" style)

results [1]

Now there are some Citation types for instance Ecology who add citations in fomat like: (Normal et al. 2000, p. 12) instead of [1]

How can I get relevant citation format if I already select CSL type?
Beside difference in format, one of the unique thing about these formats as they also show Page Numbers in reference, for insantance p. 12 in above example.

Unicode in Zotero-imported strings is doubly-encoded utf-8

I am returning to an issue I have raised earlier and could not find a solution for.
It concerns Unicode in items that are retrieved from Zotero. Characters above #127 are not encoded correctly as utf-8, but as an utf-8 encoding of the individual byte components of the correct utf-8 characters. In this way, a character that would normally be encoded with 2 bits has 4 bits (see example below).

In most but not all cases, this can be reverted by converting the strings from utf-8, taking the result as consisting of 8-bit characters once more forming utf-8. However, even this is bound to fail in certain cases, making the regular Zotero import basically unusable for working with literature other than English (and Latin).

The issue is easily reproduced using citeproc-java.bat to generate a bibliography from Zotero, e.g.:
.\citeproc-java.bat --output "bib.txt" zotero bibliography
Any accented vowel or German Umlaut is concerned, as are entries containing Greek, Arabic etc.

For instance, one of my entries reads in notpad++, which correctly interprets the file as utf-8:

[19]E. Pöhlmann, Denkmäler altgriechischer Musik: Sammlung, Übertragung und Erläuterung aller Fragmente und Fälschungen. Nürnberg: Carl, 1970.

while it should read:

[19]E. Pöhlmann, Denkmäler altgriechischer Musik: Sammlung, Übertragung und Erläuterung aller Fragmente und Fälschungen. Nürnberg: Carl, 1970.

On closer inspection (e.g. changing the display mode from utf-8 to Ansi, or using a hex editor), the entry actually reads like this:

[19]E. Pöhlmann, Denkmäler altgriechischer Musik: Sammlung, Übertragung und Erläuterung aller Fragmente und Fälschungen. Nürnberg: Carl, 1970.

So far I have no idea where this double-encoding may happen...

All best,
Stefan

PS: I should add that this does not concern Unicode characters that are part of the csl style - only text imported from Zotero.

Reading CSLformat from File

Hi
Refer to this constructor:

public CSL(ItemDataProvider itemDataProvider,
   AbbreviationProvider abbreviationProvider,
   String style)
    throws IOException

is style here content of XML file of a .csl file that needs to be used for citation?

JAVA 8

Seems like not working with JAVA 8. Is this true?

citeproc-java requires Java 8 or higher

Hi Michel,
First, I would like to appreciate your hard word for creating this great library.

I would like to include your library into my Android project. However, I am using Java 1.7. I have been reading and trying several solutions to upgrade my project to Java 1.8. Some of them recommend using Jack. However, I am also using Realm as a database for my app. As it is explained here and here Realm is not working with Jack.

Is there any possibility to compile citeproc-java with Java 1.7? Any other idea or workaround on how to solve this? I am novel with Java, only a few months, and I am not very agile yet.

Thanks

Source code : Build failed

Hi,

I try to build a new jar from the source code. The aim is to change the dependency version for jBibText.

But when I try to build the project without any change in it, I get an exception :

FAILURE: Build failed with an exception.

  • Where:
    Build file '/Users/xxxx/Downloads/citeproc-java-0.6 2/build.gradle' line: 70

  • What went wrong:
    Execution failed for task ':generateSources'.

    Index: 0, Size: 0

I don't usually used Gradle so I don't known how to solve the problem.
Thanks for your help.

Citeproc-java complains about script related exceptions

Hello, Michel. Very glad to find the useful tool (and the docs) you wrote!

I want to use citeproc-java and CSL to convert some bib files to plain text. I followed the instructions in the documentation on my macbook, but some errors occurred:

Exception in thread "main" java.lang.IllegalArgumentException: Could not update items
at de.undercouch.citeproc.CSL.registerCitationItems(CSL.java:508)
at de.undercouch.citeproc.bibtex.BibTeXItemDataProvider.registerCitationItems(BibTeXItemDataProvider.java:42)
at Main.main(Main.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: de.undercouch.citeproc.script.ScriptRunnerException: Could not call method
at de.undercouch.citeproc.script.JREScriptRunner.callMethod(JREScriptRunner.java:121)
at de.undercouch.citeproc.CSL.registerCitationItems(CSL.java:506)
... 7 more
Caused by: javax.script.ScriptException: ReferenceError: "dump" is not defined in at line number 830
at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:470)
at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:392)
at jdk.nashorn.api.scripting.NashornScriptEngine.invokeMethod(NashornScriptEngine.java:199)
at de.undercouch.citeproc.script.JREScriptRunner.callMethod(JREScriptRunner.java:117)
... 8 more
Caused by: :830 ReferenceError: "dump" is not defined
at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319)
at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291)
at jdk.nashorn.internal.objects.Global.noSuchProperty(Global.java:1441)
at jdk.nashorn.internal.scripts.Script$Recompilation$288$30224A$^eval_.error(:830)
at jdk.nashorn.internal.scripts.Script$Recompilation$203$523263A$^eval_.dateParseArray(:12730)
at jdk.nashorn.internal.scripts.Script$Recompilation$199$100473A$^eval_.retrieveItem(:2870)
at jdk.nashorn.internal.scripts.Script$Recompilation$198$617052A$^eval_.doinserts(:15103)
at jdk.nashorn.internal.scripts.Script$Recompilation$195$235101AAAA$^eval_.updateItems(:6064)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:665)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199)
at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:386)
... 10 more

This is the code I wrote:

        BibTeXDatabase db = new BibTeXConverter().loadDatabase(
                new FileInputStream("mybibs.bib"));
        BibTeXItemDataProvider provider = new BibTeXItemDataProvider();
        provider.addDatabase(db);

        CSL citeproc = new CSL(provider, "ieee");
        citeproc.setOutputFormat("text");
        provider.registerCitationItems(citeproc);

        Bibliography bibl = citeproc.makeBibliography();
        for (String entry : bibl.getEntries()) {
            System.out.println(entry);
        }

I tried updating the JDK, but nothing changed at all.
I also tried setting it up on a Windows 10 PC, and the errors are almost the same.

Besides, running the citeproc-java interactive shell, produced the same errors:

> bibliography
Exception in thread "main" java.lang.IllegalArgumentException: Could not update items
at de.undercouch.citeproc.CSL.registerCitationItems(CSL.java:508)
at de.undercouch.citeproc.tool.BibliographyCommand.generateCSL(BibliographyCommand.java:175)
at de.undercouch.citeproc.tool.BibliographyCommand.doRun(BibliographyCommand.java:137)
at de.undercouch.citeproc.tool.InputFileCommand.doRun(InputFileCommand.java:121)
at de.undercouch.citeproc.tool.AbstractCSLToolCommand.run(AbstractCSLToolCommand.java:113)
at de.undercouch.citeproc.tool.ShellCommand.mainLoop(ShellCommand.java:189)
at de.undercouch.citeproc.tool.ShellCommand.doRun(ShellCommand.java:110)
at de.undercouch.citeproc.tool.AbstractCSLToolCommand.run(AbstractCSLToolCommand.java:113)
at de.undercouch.citeproc.CSLTool.doRun(CSLTool.java:170)
at de.undercouch.citeproc.tool.AbstractCSLToolCommand.run(AbstractCSLToolCommand.java:113)
at de.undercouch.citeproc.CSLTool.main(CSLTool.java:132)
Caused by: de.undercouch.citeproc.script.ScriptRunnerException: Could not call method
at de.undercouch.citeproc.script.V8ScriptRunner.callMethod(V8ScriptRunner.java:146)
at de.undercouch.citeproc.CSL.registerCitationItems(CSL.java:506)
... 10 more
Caused by: undefined:830: ReferenceError: dump is not defined
dump("CSL error: " + str + "\n");
^
ReferenceError: dump is not defined
at Object.CSL.error (:830:9)
at CSL.Engine.dateParseArray (:12730:25)
at CSL.Engine.retrieveItem (:2870:48)
at CSL.Registry.doinserts (:15103:31)
at CSL.Engine.updateItems (:6064:19)
com.eclipsesource.v8.V8ScriptExecutionException
at com.eclipsesource.v8.V8._executeVoidFunction(Native Method)
at com.eclipsesource.v8.V8.executeVoidFunction(V8.java:1004)
at com.eclipsesource.v8.V8Object.executeVoidFunction(V8Object.java:418)
at de.undercouch.citeproc.script.V8ScriptRunner.callMethod(V8ScriptRunner.java:144)
... 11 more

Since I'm not familiar with javascript or the related libraries used in citeproc-java, I'd appreciate if you could help.

EcmaError TypeError when the bibliography is making

I've tried a lot of different ways to compute a bibliography as I observed in the unit test file : CSLTest.java, but the same exception is always raised.

This is an example :

        CSLItemData item =new CSLItemDataBuilder()
            .id("Lycklama:1978:UTSb")
            .type(CSLType.ARTICLE_JOURNAL)
            .title("UNIX Time-Sharing System: UNIX on a Microprocessor")
            .author("H.", "Lycklama")
            .volume(57)
            .issue(6)
            .page("2087-2101")
            .issued(new CSLDateBuilder().dateParts(new int[]{1978, 7}, new int[]{1978, 8}).build())
            .containerTitle("The Bell System Technical Journal")
            .ISSN("0005-8580")
            .URL("http://bstj.bell-labs.com/BSTJ/images/Vol57/bstj57-6-2087.pdf")
            .build();

        try {
            CSL citeproc = new CSL(new ListItemDataProvider(item), "/config/citeproc/ieee.csl");
            List<Citation> a = citeproc.makeCitation(item.getId());
            citeproc.setOutputFormat("text");
            Bibliography b = citeproc.makeBibliography();
            return b.getEntries()[0];
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }

And each time I get these exceptions :

java.lang.IllegalArgumentException: Could not make bibliography
    at de.undercouch.citeproc.CSL.makeBibliography(CSL.java:444)
    at de.undercouch.citeproc.CSL.makeBibliography(CSL.java:412)
    at de.undercouch.citeproc.CSL.makeBibliography(CSL.java:398)
...
Caused by: de.undercouch.citeproc.script.ScriptRunnerException: Could not execute code
    at de.undercouch.citeproc.script.RhinoScriptRunner.eval(RhinoScriptRunner.java:119)
    at de.undercouch.citeproc.CSL.makeBibliography(CSL.java:432)
    ... 140 more
Caused by: org.mozilla.javascript.EcmaError: TypeError: Impossible de lire la propriété "strings" de undefined (<code>#1)
    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3951)
    at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3929)
    at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3962)
    at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3981)
...

(translation of the last one : Impossible to read the "strings" property of undefined)

I've noted the the CSL file is well read.
Also I've declared in my pom.xml, the followed versions :

  • Rhino : 1.7.7
  • Citeproc-java : 0.6

Could you help me please ??

Cheers,
Adrien

BibTeXItemDataProviderTest broken: rendered wrong abbreviation ('ed' instead of 'Ed')

(This seems to be provoked by an update in the APA csl.)

I have tried updating the expected text with the output from Zotero, but the test still outputs 'ed.' instead of 'Ed.'. According to https://owl.purdue.edu/owl/research_and_citation/apa_style/apa_formatting_and_style_guide/apa_abbreviations.html, ed. means 'edition' while Ed. means Editor.

Expected

Hu, X. (2007). Essays on the Role of Specific Human Capital (J. Hellerstein, Ed.).

Actual

Hu, X. (2007). Essays on the Role of Specific Human Capital (J. Hellerstein, ed.).

Additional Output formats

You already have "html", "text", "asciidoc", "fo", and "rtf". Just wondering if we can add another one "xml" to this list.

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 to get additional tagged output format like above. The elements could be any and standard.

Code style preferences artifact

Could you include an artifact of the code style preferences you have? The Eclipse XML format for code style exports would work best. This will help contributors like me keep things organized the way that you like.

Process fails on certain PDF files?

Hi,

Trying to run siteproc against a specific PDF file, causes a crash to my machine.
Can you please verify this file works for you? I notice it is a power point file converted to PDF
23847801770001241.pdf

The problematic process is the pdftoxml, when running against this file, the memory consumption rises until 100%, causing the machine to crash.

et al formatting in group citation

I reported this as issue #3723 for jabref and they suggested to post the problem here.

I am working on a journal-stylefile for which I need author-year citations with the et al in italics - like this:

(Nader et al, 1983; Rueffer et al, 2001; Di Bisceglie et al, 2013)

What I do get is:
(Nader et al, 1983; Rueffer et al, 2001; Di Bisceglie et al, 2013)

The first et al is in italics, the rest not. If the citations are added separately, they are put separately and the et al string is in italics in both:

(Yang et al, 2011) (Campo et al, 2011)

In the stylefile, the citation arguments are defined like this:
CITATION
AuthorField=author/editor
YearField="year"
MaxAuthors=2
AuthorSeparator=", "
AuthorLastSeparator=" & "
EtAlString=" et al"
ItalicEtAl="true"
CitationSeparator="; "
MultiCiteChronological=true
BracketBefore="("
BracketAfter=")"
CitationCharacterFormat="Default Style"
FormatCitations="true"
UniquefierSeparator=", "
InTextYearSeparator=" "
YearSeparator=", "

So according to documentaion, the et al should be in italics. Why then, in a group, is only the first et al formatted and not the rest?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.