Search in sources :

Example 16 with AuthorList

use of org.jabref.model.entry.AuthorList in project jabref by JabRef.

the class NameFormatter method format.

public String format(String toFormat, String inParameters) {
    AuthorList al = AuthorList.parse(toFormat);
    String parameters;
    if ((inParameters == null) || inParameters.isEmpty()) {
        parameters = "*:*:\"{ff}{vv}{ll}{,jj} \"";
    } else {
        parameters = inParameters;
    }
    String[] cases = parameters.split("@@");
    for (String aCase : cases) {
        String[] formatString = aCase.split("@");
        if (formatString.length < 3) {
            // Error
            return toFormat;
        }
        if ("*".equals(formatString[0])) {
            return format(toFormat, al, formatString);
        } else {
            if (al.getNumberOfAuthors() <= Integer.parseInt(formatString[0])) {
                return format(toFormat, al, formatString);
            }
        }
    }
    return toFormat;
}
Also used : AuthorList(org.jabref.model.entry.AuthorList)

Example 17 with AuthorList

use of org.jabref.model.entry.AuthorList in project jabref by JabRef.

the class OOBibStyle method createAuthorList.

private String createAuthorList(String author, int maxAuthors, String andString, String yearSep) {
    Objects.requireNonNull(author);
    //  The String to represent authors that are not mentioned, e.g. " et al."
    String etAlString = getStringCitProperty(ET_AL_STRING);
    // The String to add between author names except the last two, e.g. ", ".
    String authorSep = getStringCitProperty(AUTHOR_SEPARATOR);
    // The String to put after the second to last author in case of three or more authors
    String oxfordComma = getStringCitProperty(OXFORD_COMMA);
    StringBuilder sb = new StringBuilder();
    AuthorList al = AuthorList.parse(author);
    if (!al.isEmpty()) {
        sb.append(getAuthorLastName(al, 0));
    }
    if ((al.getNumberOfAuthors() > 1) && ((al.getNumberOfAuthors() <= maxAuthors) || (maxAuthors < 0))) {
        int j = 1;
        while (j < (al.getNumberOfAuthors() - 1)) {
            sb.append(authorSep);
            sb.append(getAuthorLastName(al, j));
            j++;
        }
        if (al.getNumberOfAuthors() > 2) {
            sb.append(oxfordComma);
        }
        sb.append(andString);
        sb.append(getAuthorLastName(al, al.getNumberOfAuthors() - 1));
    } else if (al.getNumberOfAuthors() > maxAuthors) {
        sb.append(etAlString);
    }
    sb.append(yearSep);
    return sb.toString();
}
Also used : AuthorList(org.jabref.model.entry.AuthorList)

Example 18 with AuthorList

use of org.jabref.model.entry.AuthorList in project jabref by JabRef.

the class OOBibStyle method getAuthorLastName.

/**
     * Look up the nth author and return the proper last name for citation markers.
     *
     * @param al     The author list.
     * @param number The number of the author to return.
     * @return The author name, or an empty String if inapplicable.
     */
private String getAuthorLastName(AuthorList al, int number) {
    StringBuilder sb = new StringBuilder();
    if (al.getNumberOfAuthors() > number) {
        Author a = al.getAuthor(number);
        a.getVon().filter(von -> !von.isEmpty()).ifPresent(von -> sb.append(von).append(' '));
        sb.append(a.getLast().orElse(""));
    }
    return sb.toString();
}
Also used : SortedSet(java.util.SortedSet) FieldName(org.jabref.model.entry.FieldName) StringUtil(org.jabref.model.strings.StringUtil) BibDatabase(org.jabref.model.database.BibDatabase) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset) Layout(org.jabref.logic.layout.Layout) Author(org.jabref.model.entry.Author) Locale(java.util.Locale) LayoutFormatter(org.jabref.logic.layout.LayoutFormatter) Map(java.util.Map) BibEntry(org.jabref.model.entry.BibEntry) Set(java.util.Set) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Reader(java.io.Reader) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) InputStreamReader(java.io.InputStreamReader) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) AuthorList(org.jabref.model.entry.AuthorList) List(java.util.List) StringReader(java.io.StringReader) LayoutHelper(org.jabref.logic.layout.LayoutHelper) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) Pattern(java.util.regex.Pattern) LogFactory(org.apache.commons.logging.LogFactory) Collections(java.util.Collections) InputStream(java.io.InputStream) Author(org.jabref.model.entry.Author)

Example 19 with AuthorList

use of org.jabref.model.entry.AuthorList in project jabref by JabRef.

the class BibtexNameFormatterTest method testFormatName.

@Test
public void testFormatName() {
    {
        AuthorList al = AuthorList.parse("Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
        Assert.assertEquals("de~laVall{\\'e}e~PoussinCharles Louis Xavier~Joseph", BibtexNameFormatter.formatName(al.getAuthor(0), "{vv}{ll}{jj}{ff}", Assert::fail));
    }
    {
        AuthorList al = AuthorList.parse("Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
        Assert.assertEquals("de~la Vall{\\'e}e~Poussin, C.~L. X.~J.", BibtexNameFormatter.formatName(al.getAuthor(0), "{vv~}{ll}{, jj}{, f.}", Assert::fail));
    }
    {
        AuthorList al = AuthorList.parse("Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
        Assert.assertEquals("de~la Vall{\\'e}e~Poussin, C.~L. X.~J?", BibtexNameFormatter.formatName(al.getAuthor(0), "{vv~}{ll}{, jj}{, f}?", Assert::fail));
    }
    AuthorList al = AuthorList.parse("Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
    Assert.assertEquals("dlVP", BibtexNameFormatter.formatName(al.getAuthor(0), "{v{}}{l{}}", Assert::fail));
    assertNameFormatA("Meyer, J?", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
    assertNameFormatB("J.~Meyer", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
    assertNameFormatC("Jonathan Meyer", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
    assertNameFormatA("Masterly, {\\'{E}}?", "{\\'{E}}douard Masterly");
    assertNameFormatB("{\\'{E}}.~Masterly", "{\\'{E}}douard Masterly");
    assertNameFormatC("{\\'{E}}douard Masterly", "{\\'{E}}douard Masterly");
    assertNameFormatA("{\\\"{U}}nderwood, U?", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot");
    assertNameFormatB("U.~{\\\"{U}}nderwood", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot");
    assertNameFormatC("Ulrich {\\\"{U}}nderwood", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot");
    assertNameFormatA("Victor, P.~{\\'E}?", "Paul {\\'E}mile Victor and and de la Cierva y Codorn{\\’\\i}u, Juan");
    assertNameFormatB("P.~{\\'E}. Victor", "Paul {\\'E}mile Victor and and de la Cierva y Codorn{\\’\\i}u, Juan");
    assertNameFormatC("Paul~{\\'E}mile Victor", "Paul {\\'E}mile Victor and and de la Cierva y Codorn{\\’\\i}u, Juan");
}
Also used : Assert(org.junit.Assert) AuthorList(org.jabref.model.entry.AuthorList) Test(org.junit.Test)

Aggregations

AuthorList (org.jabref.model.entry.AuthorList)19 Author (org.jabref.model.entry.Author)8 BibEntry (org.jabref.model.entry.BibEntry)4 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 LayoutFormatter (org.jabref.logic.layout.LayoutFormatter)2 FieldName (org.jabref.model.entry.FieldName)2 Test (org.junit.Test)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Charset (java.nio.charset.Charset)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1