Skip to content

Commit

Permalink
Improve implementation of getBestMatch of SHERPARoMEO authorities
Browse files Browse the repository at this point in the history
  • Loading branch information
toniprieto committed Feb 12, 2024
1 parent 4bc95a3 commit cbef294
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,37 @@ public Choices getMatches(String text, int start, int limit, String locale) {

@Override
public Choices getBestMatch(String text, String locale) {
return getMatches(text, 0, 1, locale);
// punt if there is no query text
if (text == null || text.trim().length() == 0) {
return new Choices(true);
}
int limit = 10;
SHERPAService sherpaService = new DSpace().getSingletonService(SHERPAService.class);
SHERPAResponse sherpaResponse = sherpaService.performRequest("publication", "title",
"equals", text, 0, limit);
Choices result;
if (CollectionUtils.isNotEmpty(sherpaResponse.getJournals())) {
List<Choice> list = sherpaResponse
.getJournals().stream()
.map(sherpaJournal -> new Choice(sherpaJournal.getIssns().get(0),
sherpaJournal.getTitles().get(0), sherpaJournal.getTitles().get(0)))
.collect(Collectors.toList());
int total = sherpaResponse.getJournals().size();

int confidence;
if (list.isEmpty()) {
confidence = Choices.CF_NOTFOUND;
} else if (list.size() == 1) {
confidence = Choices.CF_UNCERTAIN;
} else {
confidence = Choices.CF_AMBIGUOUS;
}
result = new Choices(list.toArray(new Choice[list.size()]), 0, total, confidence,
total > limit);
} else {
result = new Choices(false);
}
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,38 @@ public Choices getMatches(String text, int start, int limit, String locale) {

@Override
public Choices getBestMatch(String text, String locale) {
return getMatches(text, 0, 1, locale);
// punt if there is no query text
if (text == null || text.trim().length() == 0) {
return new Choices(true);
}
int limit = 10;
SHERPAService sherpaService = new DSpace().getSingletonService(SHERPAService.class);
SHERPAPublisherResponse sherpaResponse = sherpaService.performPublisherRequest("publisher", "name",
"equals", text, 0, limit);
Choices result;
if (CollectionUtils.isNotEmpty(sherpaResponse.getPublishers())) {
List<Choice> list = sherpaResponse
.getPublishers().stream()
.map(sherpaPublisher ->
new Choice(sherpaPublisher.getIdentifier(),
sherpaPublisher.getName(), sherpaPublisher.getName()))
.collect(Collectors.toList());
int total = sherpaResponse.getPublishers().size();

int confidence;
if (list.isEmpty()) {
confidence = Choices.CF_NOTFOUND;
} else if (list.size() == 1) {
confidence = Choices.CF_UNCERTAIN;
} else {
confidence = Choices.CF_AMBIGUOUS;
}
result = new Choices(list.toArray(new Choice[list.size()]), 0, total, confidence,
total > limit);
} else {
result = new Choices(false);
}
return result;
}

@Override
Expand Down

0 comments on commit cbef294

Please sign in to comment.