Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implimented arXivId Parsing for PDF with arXivId #12335

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.identifier.ArXivIdentifier;
import org.jabref.model.entry.identifier.DOI;
import org.jabref.model.entry.types.EntryType;
import org.jabref.model.entry.types.StandardEntryType;
Expand Down Expand Up @@ -51,6 +52,8 @@ public class PdfContentImporter extends PdfImporter {

private static final Pattern YEAR_EXTRACT_PATTERN = Pattern.compile("\\d{4}");

private static final int ARXIV_PREFIX_LENGTH = "arxiv:".length();

// input lines into several lines
private String[] lines;

Expand Down Expand Up @@ -364,12 +367,14 @@ Optional<BibEntry> getEntryFromPDFContent(String firstpageContents, String lineS
String volume = null;
String number = null;
String pages = null;
String arXivId = null;
// year is a class variable as the method extractYear() uses it;
String publisher = null;

EntryType type = StandardEntryType.InProceedings;
if (curString.length() > 4) {
// special case: possibly conference as first line on the page
arXivId = getArXivId(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an example why comments are to be avoided as much as possible, this line compiles fine, runs fine but the comment above it is misguiding. Please move comment to its correct location.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

extractYear();
doi = getDoi(null);
if (curString.contains("Conference")) {
Expand All @@ -387,7 +392,8 @@ Optional<BibEntry> getEntryFromPDFContent(String firstpageContents, String lineS
}
}
}

// sometimes ArXiv ID is read before title
arXivId = getArXivId(arXivId);
// start: title
fillCurStringWithNonEmptyLines();
title = streamlineTitle(curString);
Expand Down Expand Up @@ -507,6 +513,7 @@ Optional<BibEntry> getEntryFromPDFContent(String firstpageContents, String lineS
}
} else {
doi = getDoi(doi);
arXivId = getArXivId(arXivId);

if ((publisher == null) && curString.contains("IEEE")) {
// IEEE has the conference things at the end
Expand All @@ -531,6 +538,10 @@ Optional<BibEntry> getEntryFromPDFContent(String firstpageContents, String lineS
}
}

if (arXivId != null && arXivId.contains(year)) {
year = null;
}

BibEntry entry = new BibEntry();
entry.setType(type);

Expand All @@ -557,20 +568,26 @@ Optional<BibEntry> getEntryFromPDFContent(String firstpageContents, String lineS
if (doi != null) {
entry.setField(StandardField.DOI, doi);
}
if (arXivId != null) {
entry.setField(StandardField.EPRINT, arXivId);
}
if (series != null) {
entry.setField(StandardField.SERIES, series);
}
if (volume != null) {
entry.setField(StandardField.VOLUME, volume);
}
if (number != null) {
if (number != null && number.chars().allMatch(Character::isDigit)) {
entry.setField(StandardField.NUMBER, number);
}
if (pages != null) {
entry.setField(StandardField.PAGES, pages);
}
if (year != null) {
entry.setField(StandardField.YEAR, year);
} else if (arXivId != null) {
year = "20" + arXivId.substring(0, 2);
entry.setField(StandardField.YEAR, year);
}
if (publisher != null) {
entry.setField(StandardField.PUBLISHER, publisher);
Expand All @@ -592,6 +609,26 @@ private String getDoi(String doi) {
return doi;
}

private String getArXivId(String arXivId) {
if (arXivId != null) {
return arXivId;
}

String arXiv = curString.split(" ")[0];
arXivId = ArXivIdentifier.parse(arXiv).map(ArXivIdentifier::asString).orElse(null);

if (arXivId == null || curString.length() < arXivId.length() + ARXIV_PREFIX_LENGTH) {
return arXivId;
}
// The arxiv string also contains the year
curString = curString.substring(arXivId.length() + ARXIV_PREFIX_LENGTH);
extractYear();
curString = "";
proceedToNextNonEmptyLine();

return arXivId;
}

private String getFirstPageContents(PDDocument document) throws IOException {
PDFTextStripper stripper = new PDFTextStripper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,42 @@ British Journal of Nutrition (2008), 99, 1–11 doi: 10.1017/S0007114507795296
assertEquals(Optional.of(entry), importer.getEntryFromPDFContent(firstPageContent, "\n", Optional.empty()));
}

@Test
void extractArXivFromPage1() {
BibEntry entry = new BibEntry(StandardEntryType.TechReport)
.withField(StandardField.AUTHOR, "Filippo Riccaa and Alessandro Marchettob and Andrea Stoccoc")
.withField(StandardField.TITLE, "A Multi-Year Grey Literature Review on AI-assisted Test Automation")
.withField(StandardField.YEAR, "2024")
.withField(StandardField.EPRINT, "2408.06224v1")
.withField((StandardField.KEYWORDS), "Test Automation Artificial Intelligence AI-assisted Test Automation Grey Literature Automated Test Generation Self-Healing Test Scripts");

String firstPageContent = """
arXiv:2408.06224v1 [cs.SE] 12 Aug 2024
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it guaranteed that the arXiv id will be on the first line? If not we need to add at least two more tests.

  • ArXiv id in a middle line (the line begins with the id)
  • ArXiv ID in a middle line (the ID is somewhere in the middle of that line)

You can use JUnit 5 Parameterized Tests to reduce verbosity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello houssem, I checked multiple arXiv papers(10) and all of them had their arxiv string at the last line, here you can see it at the top(sorry for the oversight, will fix that) but moving it at the last also passes the test, and since all these papers have the same format i think the arxiv string would mostly be at the end

A Multi-Year Grey Literature Review on AI-assisted Test Automation

Filippo Riccaa, Alessandro Marchettob and Andrea Stoccoc

aUniversity of Genoa, Via Balbi 5, Genova, 16126, Italy
bUniversity of Trento, Via Sommarive 9, Trento, 38123, Italy
cTechnical University of Munich, Boltzmannstraße 3, Munich, 85748, Germany
dfortiss GmbH, Guerickestraße 25, Munich, 80805, Germany

Keywords:
Test Automation
Artificial Intelligence
AI-assisted Test Automation
Grey Literature
Automated Test Generation
Self-Healing Test Scripts

*Corresponding author
[email protected] (F. Ricca)
https://person.dibris.unige.it/ricca-filippo/ (F. Ricca)
ORCID(s): 0000-0002-3928-5408 (F. Ricca); 0000-0002-6833-896X (A. Marchetto); 0000-0001-8956-3894 (A. Stocco)""";

assertEquals(Optional.of(entry), importer.getEntryFromPDFContent(firstPageContent, "\n", Optional.empty()));
}

@ParameterizedTest
@MethodSource("providePdfData")
void pdfTitleExtraction(String expectedTitle, String filePath) throws Exception {
Expand Down