Search in sources :

Example 1 with AuthorList

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

the class BibtexKeyPatternUtil method firstAuthorVonAndLast.

/**
     * Gets the von part and the last name of the first author/editor
     * No spaces are returned
     *
     * @param authorField
     *            a <code>String</code>
     * @return the von part and surname of an author/editor or "" if no author was found.
     *  This method is guaranteed to never return null.
     *
     * @throws NullPointerException
     *             if authorField == null
     */
public static String firstAuthorVonAndLast(String authorField) {
    AuthorList authorList = AuthorList.parse(authorField);
    if (authorList.isEmpty()) {
        return "";
    }
    StringBuilder stringBuilder = new StringBuilder();
    authorList.getAuthor(0).getVon().ifPresent(vonAuthor -> stringBuilder.append(vonAuthor.replaceAll(" ", "")));
    authorList.getAuthor(0).getLast().ifPresent(stringBuilder::append);
    return stringBuilder.toString();
}
Also used : AuthorList(org.jabref.model.entry.AuthorList)

Example 2 with AuthorList

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

the class FormatNameFunction method execute.

@Override
public void execute(BstEntry context) {
    Stack<Object> stack = vm.getStack();
    if (stack.size() < 3) {
        throw new VMException("Not enough operands on stack for operation format.name$");
    }
    Object o1 = stack.pop();
    Object o2 = stack.pop();
    Object o3 = stack.pop();
    if (!(o1 instanceof String) && !(o2 instanceof Integer) && !(o3 instanceof String)) {
        // warning("A string is needed for change.case$");
        stack.push("");
        return;
    }
    String format = (String) o1;
    Integer name = (Integer) o2;
    String names = (String) o3;
    if (names == null) {
        stack.push("");
    } else {
        AuthorList a = AuthorList.parse(names);
        if (name > a.getNumberOfAuthors()) {
            throw new VMException("Author Out of Bounds. Number " + name + " invalid for " + names);
        }
        Author author = a.getAuthor(name - 1);
        stack.push(BibtexNameFormatter.formatName(author, format, vm));
    }
}
Also used : AuthorList(org.jabref.model.entry.AuthorList) Author(org.jabref.model.entry.Author)

Example 3 with AuthorList

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

the class AuthorOrgSci method format.

@Override
public String format(String fieldText) {
    AuthorList a = AuthorList.parse(fieldText);
    if (a.isEmpty()) {
        return fieldText;
    }
    Author first = a.getAuthor(0);
    StringBuilder sb = new StringBuilder();
    sb.append(first.getLastFirst(true));
    for (int i = 1; i < a.getNumberOfAuthors(); i++) {
        sb.append(", ").append(a.getAuthor(i).getFirstLast(true));
    }
    return sb.toString();
}
Also used : AuthorList(org.jabref.model.entry.AuthorList) Author(org.jabref.model.entry.Author)

Example 4 with AuthorList

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

the class OOBibStyle method getCitationMarker.

/**
     * Format the marker for the in-text citation according to this BIB style. Uniquefier letters are added as
     * provided by the uniquefiers argument. If successive entries within the citation are uniquefied from each other,
     * this method will perform a grouping of these entries.
     *
     * @param entries       The list of JabRef BibEntry providing the data.
     * @param database      A map of BibEntry-BibDatabase pairs.
     * @param inParenthesis Signals whether a parenthesized citation or an in-text citation is wanted.
     * @param uniquefiers   Strings to add behind the year for each entry in case it's needed to separate similar
     *                      entries.
     * @param unlimAuthors  Boolean for each entry. If true, we should not use "et al" formatting regardless
     *                      of the number of authors. Can be null to indicate that no entries should have unlimited names.
     * @return The formatted citation.
     */
public String getCitationMarker(List<BibEntry> entries, Map<BibEntry, BibDatabase> database, boolean inParenthesis, String[] uniquefiers, int[] unlimAuthors) {
    // Look for groups of uniquefied entries that should be combined in the output.
    // E.g. (Olsen, 2005a, b) should be output instead of (Olsen, 2005a; Olsen, 2005b).
    int piv = -1;
    String tmpMarker = null;
    if (uniquefiers != null) {
        for (int i = 0; i < uniquefiers.length; i++) {
            if ((uniquefiers[i] == null) || uniquefiers[i].isEmpty()) {
                // Check if we just passed a group of more than one entry with uniquefier:
                if ((piv > -1) && (i > (piv + 1))) {
                    // Do the grouping:
                    group(entries, uniquefiers, piv, i - 1);
                }
                piv = -1;
            } else {
                BibEntry currentEntry = entries.get(i);
                if (piv == -1) {
                    piv = i;
                    tmpMarker = getAuthorYearParenthesisMarker(Collections.singletonList(currentEntry), database, null, unlimAuthors);
                } else {
                    // See if this entry can go into a group with the previous one:
                    String thisMarker = getAuthorYearParenthesisMarker(Collections.singletonList(currentEntry), database, null, unlimAuthors);
                    String authorField = getStringCitProperty(AUTHOR_FIELD);
                    int maxAuthors = getIntCitProperty(MAX_AUTHORS);
                    String author = getCitationMarkerField(currentEntry, database.get(currentEntry), authorField);
                    AuthorList al = AuthorList.parse(author);
                    // i always at least 1 here
                    int prevALim = unlimAuthors[i - 1];
                    if (!thisMarker.equals(tmpMarker) || ((al.getNumberOfAuthors() > maxAuthors) && (unlimAuthors[i] != prevALim))) {
                        // previous entry was part of a group:
                        if ((piv > -1) && (i > (piv + 1))) {
                            // Do the grouping:
                            group(entries, uniquefiers, piv, i - 1);
                        }
                        tmpMarker = thisMarker;
                        piv = i;
                    }
                }
            }
        }
        // Finished with the loop. See if the last entries form a group:
        if (piv >= 0) {
            // Do the grouping:
            group(entries, uniquefiers, piv, uniquefiers.length - 1);
        }
    }
    if (inParenthesis) {
        return getAuthorYearParenthesisMarker(entries, database, uniquefiers, unlimAuthors);
    } else {
        return getAuthorYearInTextMarker(entries, database, uniquefiers, unlimAuthors);
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) AuthorList(org.jabref.model.entry.AuthorList)

Example 5 with AuthorList

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

the class MSBibEntry method getSpecificAuthors.

private List<MsBibAuthor> getSpecificAuthors(String type, Element authors) {
    List<MsBibAuthor> result = null;
    NodeList nodeLst = authors.getElementsByTagNameNS("*", type);
    if (nodeLst.getLength() <= 0) {
        return result;
    }
    nodeLst = ((Element) nodeLst.item(0)).getElementsByTagNameNS("*", "NameList");
    if (nodeLst.getLength() <= 0) {
        return result;
    }
    NodeList person = ((Element) nodeLst.item(0)).getElementsByTagNameNS("*", "Person");
    if (person.getLength() <= 0) {
        return result;
    }
    result = new LinkedList<>();
    for (int i = 0; i < person.getLength(); i++) {
        NodeList firstName = ((Element) person.item(i)).getElementsByTagNameNS("*", "First");
        NodeList lastName = ((Element) person.item(i)).getElementsByTagNameNS("*", "Last");
        NodeList middleName = ((Element) person.item(i)).getElementsByTagNameNS("*", "Middle");
        StringBuilder sb = new StringBuilder();
        if (firstName.getLength() > 0) {
            sb.append(firstName.item(0).getTextContent());
            sb.append(" ");
        }
        if (middleName.getLength() > 0) {
            sb.append(middleName.item(0).getTextContent());
            sb.append(" ");
        }
        if (lastName.getLength() > 0) {
            sb.append(lastName.item(0).getTextContent());
        }
        AuthorList authorList = AuthorList.parse(sb.toString());
        for (Author author : authorList.getAuthors()) {
            result.add(new MsBibAuthor(author));
        }
    }
    return result;
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) AuthorList(org.jabref.model.entry.AuthorList) Author(org.jabref.model.entry.Author)

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