use of org.jabref.logic.util.strings.StringSimilarity in project jabref by JabRef.
the class ArXiv method searchForEntries.
private List<ArXivEntry> searchForEntries(BibEntry entry) throws FetcherException {
// 1. Eprint
Optional<String> identifier = entry.getField(FieldName.EPRINT);
if (StringUtil.isNotBlank(identifier)) {
try {
// Get pdf of entry with the specified id
return OptionalUtil.toList(searchForEntryById(identifier.get()));
} catch (FetcherException e) {
LOGGER.warn("arXiv eprint API request failed", e);
}
}
// 2. DOI and other fields
String query;
Optional<String> doi = entry.getField(FieldName.DOI).flatMap(DOI::parse).map(DOI::getNormalized);
if (doi.isPresent()) {
// Search for an entry in the ArXiv which is linked to the doi
query = "doi:" + doi.get();
} else {
Optional<String> authorQuery = entry.getField(FieldName.AUTHOR).map(author -> "au:" + author);
Optional<String> titleQuery = entry.getField(FieldName.TITLE).map(title -> "ti:" + title);
query = OptionalUtil.toList(authorQuery, titleQuery).stream().collect(Collectors.joining("+AND+"));
}
Optional<ArXivEntry> arxivEntry = searchForEntry(query);
if (arxivEntry.isPresent()) {
// Check if entry is a match
StringSimilarity match = new StringSimilarity();
String arxivTitle = arxivEntry.get().title.orElse("");
String entryTitle = entry.getField(FieldName.TITLE).orElse("");
if (match.isSimilar(arxivTitle, entryTitle)) {
return OptionalUtil.toList(arxivEntry);
}
}
return Collections.emptyList();
}
use of org.jabref.logic.util.strings.StringSimilarity in project jabref by JabRef.
the class CrossRef method extractIdentifier.
@Override
public Optional<DOI> extractIdentifier(BibEntry inputEntry, List<BibEntry> fetchedEntries) throws FetcherException {
final String entryTitle = REMOVE_BRACES_FORMATTER.format(inputEntry.getLatexFreeField(FieldName.TITLE).orElse(""));
final StringSimilarity stringSimilarity = new StringSimilarity();
for (BibEntry fetchedEntry : fetchedEntries) {
// currently only title-based comparison
// title
Optional<String> dataTitle = fetchedEntry.getField(FieldName.TITLE);
if (OptionalUtil.isPresentAnd(dataTitle, title -> stringSimilarity.isSimilar(entryTitle, title))) {
return fetchedEntry.getDOI();
}
// subtitle
// additional check, as sometimes subtitle is needed but sometimes only duplicates the title
Optional<String> dataSubtitle = fetchedEntry.getField(FieldName.SUBTITLE);
Optional<String> dataWithSubTitle = OptionalUtil.combine(dataTitle, dataSubtitle, (title, subtitle) -> title + " " + subtitle);
if (OptionalUtil.isPresentAnd(dataWithSubTitle, titleWithSubtitle -> stringSimilarity.isSimilar(entryTitle, titleWithSubtitle))) {
return fetchedEntry.getDOI();
}
}
return Optional.empty();
}
Aggregations