Verified Owner
Top Description Inners Fields Constructors Methods
org.jabref.logic.importer.fileformat.pdf

public Class RuleBasedBibliographyPdfImporter

extends BibliographyFromPdfImporter
implements PlainCitationParser
Class Inheritance
All Implemented Interfaces
org.jabref.logic.importer.plaincitation.PlainCitationParser
Annotations
@AllowedToUseApacheCommonsLang3:Fastest method to count spaces in a string
Imports
java.io.IOException, java.nio.file.Path, java.util.ArrayList, .List, .Optional, java.util.regex.Matcher, .Pattern, org.jabref.architecture.AllowedToUseApacheCommonsLang3, org.jabref.logic.citationkeypattern.CitationKeyGenerator, .CitationKeyPatternPreferences, org.jabref.logic.cleanup.URLCleanup, org.jabref.logic.formatter.bibtexfields.NormalizeUnicodeFormatter, org.jabref.logic.importer.AuthorListParser, .ParserResult, org.jabref.logic.importer.plaincitation.PlainCitationParser, .ReferencesBlockFromPdfFinder, org.jabref.logic.l10n.Localization, org.jabref.model.entry.AuthorList, .BibEntry, .Date, org.jabref.model.entry.field.Field, .StandardField, org.jabref.model.entry.types.StandardEntryType, com.google.common.annotations.VisibleForTesting, org.apache.commons.lang3.StringUtils, org.apache.pdfbox.pdmodel.PDDocument, org.jspecify.annotations.NonNull, .Nullable, org.slf4j.Logger, .LoggerFactory

Parses the references from the "References" section from a PDF.

Currently, IEEE two column format is supported.

To extract a BibEntry matching the PDF, see PdfContentImporter.

Todo

This class is similar to org.jabref.logic.importer.plaincitation.RuleBasedPlainCitationParser, we need to unify them.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
pack-priv static record

Field Summary

Modifier and TypeField and Description
private static final Pattern
private final @Nullable CitationKeyPatternPreferences
private static final Logger
private static final Pattern
private static final Pattern
private static final Pattern
private final NormalizeUnicodeFormatter
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public String
getDescription()

Implements abstract org.jabref.logic.importer.Importer.getDescription.

Returns the description of the import format.

public List<BibEntry>
getEntriesFromPDFContent(String contents)

In: [1] ...\n...\n...[2]...\n...\n...\n[3]...

public String
getId()

Implements abstract org.jabref.logic.importer.Importer.getId.

Returns a slug, which identifies this importer.

pack-priv static List<RuleBasedBibliographyPdfImporter.IntermediateData>
public String
getName()

Implements abstract org.jabref.logic.importer.Importer.getName.

Returns the name of this import format.

public ParserResult
public Optional<BibEntry>
pack-priv BibEntry
parsePlainCitation(String number, String reference)

Example: J.

private static RuleBasedBibliographyPdfImporter.EntryUpdateResult
updateEntryAndReferenceIfMatches(String reference, Pattern
A pattern matching two groups: The first one to take, the second one to leave at the end of the string
pattern
,
BibEntry result, Field field)

Field Detail

AUTHORS_AND_TITLE_AT_BEGINNINGback to summary
private static final Pattern AUTHORS_AND_TITLE_AT_BEGINNING
citationKeyPatternPreferencesback to summary
private final @Nullable CitationKeyPatternPreferences citationKeyPatternPreferences
LOGGERback to summary
private static final Logger LOGGER

Hides org.jabref.logic.importer.Importer.LOGGER.

MONTH_AND_YEARback to summary
private static final Pattern MONTH_AND_YEAR
MONTH_RANGE_AND_YEARback to summary
private static final Pattern MONTH_RANGE_AND_YEAR
NOback to summary
private static final Pattern NO
normalizeUnicodeFormatterback to summary
private final NormalizeUnicodeFormatter normalizeUnicodeFormatter
PAGEback to summary
private static final Pattern PAGE
PAGESback to summary
private static final Pattern PAGES
PROCEEDINGS_INDICATIONback to summary
private static final Pattern PROCEEDINGS_INDICATION
REFERENCE_PATTERNback to summary
private static final Pattern REFERENCE_PATTERN
SERIESback to summary
private static final Pattern SERIES
TITLEback to summary
private static final Pattern TITLE
VOLUMEback to summary
private static final Pattern VOLUME
WORKSHOPback to summary
private static final Pattern WORKSHOP
YEARback to summary
private static final Pattern YEAR
YEAR_AT_ENDback to summary
private static final Pattern YEAR_AT_END

Constructor Detail

RuleBasedBibliographyPdfImporterback to summary
public RuleBasedBibliographyPdfImporter()
RuleBasedBibliographyPdfImporterback to summary
public RuleBasedBibliographyPdfImporter(@NonNull CitationKeyPatternPreferences citationKeyPatternPreferences)

Method Detail

getDescriptionback to summary
public String getDescription()

Implements abstract org.jabref.logic.importer.Importer.getDescription.

Doc from org.jabref.logic.importer.Importer.getDescription.

Returns the description of the import format.

The description should specify
what kind of entries from what sources and based on what specification it is able to import

by what criteria it isRecognizedFormat(BufferedReader) recognizes an import format

Annotations
@Override
getEntriesFromPDFContentback to summary
public List<BibEntry> getEntriesFromPDFContent(String contents)

In: [1] ...\n...\n...[2]...\n...\n...\n[3]...

getIdback to summary
public String getId()

Implements abstract org.jabref.logic.importer.Importer.getId.

Doc from org.jabref.logic.importer.Importer.getId.

Returns a slug, which identifies this importer. Used, for example, to identify the importer in CLI.

Typically, this name should be short, in English, and should not contain special characters like #, %, etc.

Annotations
@Override
getIntermediateDataback to summary
pack-priv static List<RuleBasedBibliographyPdfImporter.IntermediateData> getIntermediateData(String contents)
Annotations
@VisibleForTesting
getNameback to summary
public String getName()

Implements abstract org.jabref.logic.importer.Importer.getName.

Doc from org.jabref.logic.importer.Importer.getName.

Returns the name of this import format. Typically, this is a string that denotes file type or format. It can also be localized, like "XMP-annotated PDF".

Annotations
@Override
importDatabaseback to summary
public ParserResult importDatabase(Path filePath, PDDocument document) throws IOException

Implements abstract org.jabref.logic.importer.fileformat.pdf.PdfImporter.importDatabase.

Online Grobid implementation: org.jabref.logic.importer.util.GrobidService#processReferences(java.nio.file.Path, org.jabref.logic.importer.ImportFormatPreferences)

Annotations
@Override
parsePlainCitationback to summary
public Optional<BibEntry> parsePlainCitation(String reference)

Implements org.jabref.logic.importer.plaincitation.PlainCitationParser.parsePlainCitation.

Annotations
@Override
parsePlainCitationback to summary
pack-priv BibEntry parsePlainCitation(String number, String reference)

Example: J. Knaster et al., “Overview of the IFMIF/EVEDA project”, Nucl. Fusion, vol. 57, p. 102016, 2017. doi:10.1088/ 1741-4326/aa6a6a

Annotations
@VisibleForTesting
updateEntryAndReferenceIfMatchesback to summary
private static RuleBasedBibliographyPdfImporter.EntryUpdateResult updateEntryAndReferenceIfMatches(String reference, Pattern pattern, BibEntry result, Field field)
Parameters
pattern:Pattern

A pattern matching two groups: The first one to take, the second one to leave at the end of the string

org.jabref.logic.importer.fileformat.pdf back to summary

private final Record RuleBasedBibliographyPdfImporter.EntryUpdateResult

extends Record
Class Inheritance
Record Components
modified:boolean 
newReference:String 

Field Summary

Modifier and TypeField and Description
private final boolean
modified

Record Component accessed by modified().

private final String
newReference

Record Component accessed by newReference().

Constructor Summary

AccessConstructor and Description
private
EntryUpdateResult(boolean modified, String newReference)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public boolean
modified()

Record Component getter of modified.

public String
newReference()

Record Component getter of newReference.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

modifiedback to summary
private final boolean modified

Record Component accessed by modified().

newReferenceback to summary
private final String newReference

Record Component accessed by newReference().

Constructor Detail

EntryUpdateResultback to summary
private EntryUpdateResult(boolean modified, String newReference)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

modifiedback to summary
public boolean modified()

Record Component getter of modified.

newReferenceback to summary
public String newReference()

Record Component getter of newReference.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

org.jabref.logic.importer.fileformat.pdf back to summary

pack-priv final Record RuleBasedBibliographyPdfImporter.IntermediateData

extends Record
Class Inheritance
Annotations
@VisibleForTesting
Record Components
number:String 
reference:String 

Field Summary

Modifier and TypeField and Description
private final String
number

Record Component accessed by number().

private final String
reference

Record Component accessed by reference().

Constructor Summary

AccessConstructor and Description
pack-priv
IntermediateData(String number, String reference)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public String
number()

Record Component getter of number.

public String
reference()

Record Component getter of reference.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

numberback to summary
private final String number

Record Component accessed by number().

referenceback to summary
private final String reference

Record Component accessed by reference().

Constructor Detail

IntermediateDataback to summary
pack-priv IntermediateData(String number, String reference)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

numberback to summary
public String number()

Record Component getter of number.

referenceback to summary
public String reference()

Record Component getter of reference.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.