Search in sources :

Example 1 with StringSimilarity

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();
}
Also used : FetcherException(org.jabref.logic.importer.FetcherException) StringSimilarity(org.jabref.logic.util.strings.StringSimilarity) DOI(org.jabref.model.entry.identifier.DOI)

Example 2 with StringSimilarity

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();
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) StringSimilarity(org.jabref.logic.util.strings.StringSimilarity)

Aggregations

StringSimilarity (org.jabref.logic.util.strings.StringSimilarity)2 FetcherException (org.jabref.logic.importer.FetcherException)1 BibEntry (org.jabref.model.entry.BibEntry)1 DOI (org.jabref.model.entry.identifier.DOI)1