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

Collaborator lookup #525

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -58,38 +58,38 @@ protected PubMedQuery buildNameQuery(Set<AuthorName> identitynames, Identity ide
return pubMedQueryBuilder.build();
}

@Override
protected String getStrategySpecificKeyword(Identity identity) {
if (identity.getKnownRelationships() != null && !identity.getKnownRelationships().isEmpty()) {
List<String> nameIgnoredAuthors = Arrays.asList(excludeNames.trim().split("\\s*,\\s*"));
Iterator<KnownRelationship> iter = identity.getKnownRelationships().iterator();
final KnownRelationship firstRelationship = iter.next();
String first = null;
if(!nameIgnoredAuthors.contains(firstRelationship.getName().getLastName() + " " + firstRelationship.getName().getFirstInitial())) {
first = firstRelationship.getName().getLastName() + " " + firstRelationship.getName().getFirstInitial() + "[au]";
}
if (!iter.hasNext()) {
return first;
}
//for more than 1 institutions
final StringBuilder buf = new StringBuilder();
if(first != null) {
buf.append("(" + first);
}
while(iter.hasNext()) {
KnownRelationship knownRelationship = iter.next();
if(!nameIgnoredAuthors.contains(knownRelationship.getName().getLastName() + " " + knownRelationship.getName().getFirstInitial())) {
buf.append(" OR ");
buf.append(knownRelationship.getName().getLastName() + " " + firstRelationship.getName().getFirstInitial() + "[au]");
}
}
buf.append(")");
return buf.toString();
} else {
return null;
}
}

@Override
protected String getStrategySpecificKeyword(Identity identity) {
if (identity.getKnownRelationships() != null && !identity.getKnownRelationships().isEmpty()) {
List<String> nameIgnoredAuthors = Arrays.asList(excludeNames.trim().split("\\s*,\\s*"));
Iterator<KnownRelationship> iter = identity.getKnownRelationships().iterator();
final KnownRelationship firstRelationship = iter.next();
String first = null;
if(!nameIgnoredAuthors.contains(firstRelationship.getName().getLastName() + " " + firstRelationship.getName().getFirstInitial())) {
first = firstRelationship.getName().getLastName() + " " + firstRelationship.getName().getFirstInitial() + "[au] OR "
+ firstRelationship.getName().getLastName() + " " + firstRelationship.getName().getFirstInitial() + "[ir]";
}
if (!iter.hasNext()) {
return first;
}
final StringBuilder buf = new StringBuilder();
if(first != null) {
buf.append("(" + first);
}
while(iter.hasNext()) {
KnownRelationship knownRelationship = iter.next();
if(!nameIgnoredAuthors.contains(knownRelationship.getName().getLastName() + " " + knownRelationship.getName().getFirstInitial())) {
buf.append(" OR ");
buf.append(knownRelationship.getName().getLastName() + " " + knownRelationship.getName().getFirstInitial() + "[au] OR "
+ knownRelationship.getName().getLastName() + " " + knownRelationship.getName().getFirstInitial() + "[ir]");
}
}
buf.append(")");
return buf.toString();
} else {
return null;
}
}
}
77 changes: 40 additions & 37 deletions src/main/java/reciter/xml/retriever/pubmed/PubMedQueryType.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,43 +150,46 @@ public PubMedQuery buildPmids(List<Long> pmids) {
return p;
}

public String contsructAuthorQuery() {
if (this.identityAuthorNames != null && this.identityAuthorNames.size() > 0) {

// Below is code from Apache's StringUtils class, modified to remove null checks.
Iterator<AuthorName> iterator = this.identityAuthorNames.iterator();

final AuthorName first = iterator.next();
String firstName = first.getLastName() + " " + first.getFirstInitial() + "[au]";
if(this.isAuthorFullNameRequired) {
firstName = first.getLastName() + " " + first.getFirstName() + "[au]";
}
if (!iterator.hasNext()) {
return firstName;
}

// two or more elements
final StringBuilder buf = new StringBuilder();
if (first != null) {
buf.append("(" + firstName);
}

while (iterator.hasNext()) {
buf.append(" OR ");
final AuthorName obj = iterator.next();
if(this.isAuthorFullNameRequired) { //For FullName Strict retrieval strategy
buf.append(obj.getLastName() + " " + obj.getFirstName() + "[au]");
} else {
buf.append(obj.getLastName() + " " + obj.getFirstInitial() + "[au]");
}

}
buf.append(")");
return buf.toString();
} else {
return null;
}
}
public String constructAuthorQuery() {
if (this.identityAuthorNames != null && this.identityAuthorNames.size() > 0) {

Iterator<AuthorName> iterator = this.identityAuthorNames.iterator();
final AuthorName first = iterator.next();
String firstName = first.getLastName() + " " + first.getFirstInitial() + "[au] OR "
+ first.getLastName() + " " + first.getFirstInitial() + "[ir]";
if(this.isAuthorFullNameRequired) {
firstName = first.getLastName() + " " + first.getFirstName() + "[au] OR "
+ first.getLastName() + " " + first.getFirstName() + "[ir]";
}
if (!iterator.hasNext()) {
return firstName;
}

final StringBuilder buf = new StringBuilder();
if (first != null) {
buf.append("(" + firstName);
}

while (iterator.hasNext()) {
buf.append(" OR ");
final AuthorName obj = iterator.next();
if(this.isAuthorFullNameRequired) {
buf.append(obj.getLastName() + " " + obj.getFirstName() + "[au] OR "
+ obj.getLastName() + " " + obj.getFirstName() + "[ir]");
} else {
buf.append(obj.getLastName() + " " + obj.getFirstInitial() + "[au] OR "
+ obj.getLastName() + " " + obj.getFirstInitial() + "[ir]");
}
}
buf.append(")");
return buf.toString();
} else {
return null;
}
}




// private static final int THRESHOLD = 25;
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,67 +52,70 @@ protected PubMedQuery buildNameQuery(Set<AuthorName> identitynames, Identity ide
return pubMedQueryBuilder.build();
}

@Override
protected String getStrategySpecificKeyword(Identity identity) {
if (identity.getPrimaryName() != null || (identity.getAlternateNames() != null && !identity.getAlternateNames().isEmpty())) {
String middleName = null;
if(identity.getPrimaryName().getMiddleName() != null) {
middleName = identity.getPrimaryName().getMiddleName();
} else {
middleName = "";
}
String combinedFirstMiddleName = identity.getPrimaryName().getFirstName() + middleName;
String capitalizeFirstMiddle = ReCiterStringUtil.deAccent(combinedFirstMiddleName.chars().filter(Character::isUpperCase)
.mapToObj(c -> Character.toString((char)c))
.collect(Collectors.joining()));
String first = null;
if(capitalizeFirstMiddle.length() >= 2) {
first = identity.getPrimaryName().getLastName() + " " + capitalizeFirstMiddle.substring(0, 2) + "[au]";
}

if(first != null && identity.getAlternateNames() != null && !identity.getAlternateNames().isEmpty()) {
return first;
}

Iterator<AuthorName> iter = identity.getAlternateNames().iterator();

final StringBuilder buf = new StringBuilder();
if(first != null) {
buf.append("(" + first);
} else {
buf.append("(");
}
while(iter.hasNext()) {
AuthorName alternateName = iter.next();
String alternateNameWithInitial = null;
if(alternateName.getMiddleName() != null) {
middleName = alternateName.getMiddleName();
} else {
middleName = "";
}
combinedFirstMiddleName = alternateName.getFirstName() + middleName;
capitalizeFirstMiddle = ReCiterStringUtil.deAccent(combinedFirstMiddleName.chars().filter(Character::isUpperCase)
.mapToObj(c -> Character.toString((char)c))
.collect(Collectors.joining()));
if(capitalizeFirstMiddle.length() >= 2) {
alternateNameWithInitial = alternateName.getLastName() + " " + capitalizeFirstMiddle.substring(0, 2) + "[au]";
}
if(alternateNameWithInitial != null) {
buf.append(alternateNameWithInitial);
buf.append(" OR ");
}
}
buf.append(")");
if(buf.toString().endsWith(" OR )")) {
return buf.toString().substring(0, buf.toString().length() - 5) + ")";
}
else {
return buf.toString();
}
} else {
return null;
}
}

@Override
protected String getStrategySpecificKeyword(Identity identity) {
if (identity.getPrimaryName() != null || (identity.getAlternateNames() != null && !identity.getAlternateNames().isEmpty())) {
String middleName = null;
if(identity.getPrimaryName().getMiddleName() != null) {
middleName = identity.getPrimaryName().getMiddleName();
} else {
middleName = "";
}
String combinedFirstMiddleName = identity.getPrimaryName().getFirstName() + middleName;
String capitalizeFirstMiddle = ReCiterStringUtil.deAccent(combinedFirstMiddleName.chars().filter(Character::isUpperCase)
.mapToObj(c -> Character.toString((char)c))
.collect(Collectors.joining()));
String first = null;
if(capitalizeFirstMiddle.length() >= 2) {
first = identity.getPrimaryName().getLastName() + " " + capitalizeFirstMiddle.substring(0, 2) + "[au] OR "
+ identity.getPrimaryName().getLastName() + " " + capitalizeFirstMiddle.substring(0, 2) + "[ir]";
}

if(first != null && identity.getAlternateNames() != null && !identity.getAlternateNames().isEmpty()) {
return first;
}

Iterator<AuthorName> iter = identity.getAlternateNames().iterator();

final StringBuilder buf = new StringBuilder();
if(first != null) {
buf.append("(" + first);
} else {
buf.append("(");
}
while(iter.hasNext()) {
AuthorName alternateName = iter.next();
String alternateNameWithInitial = null;
if(alternateName.getMiddleName() != null) {
middleName = alternateName.getMiddleName();
} else {
middleName = "";
}
combinedFirstMiddleName = alternateName.getFirstName() + middleName;
capitalizeFirstMiddle = ReCiterStringUtil.deAccent(combinedFirstMiddleName.chars().filter(Character::isUpperCase)
.mapToObj(c -> Character.toString((char)c))
.collect(Collectors.joining()));
if(capitalizeFirstMiddle.length() >= 2) {
alternateNameWithInitial = alternateName.getLastName() + " " + capitalizeFirstMiddle.substring(0, 2) + "[au] OR "
+ alternateName.getLastName() + " " + capitalizeFirstMiddle.substring(0, 2) + "[ir]";
}
if(alternateNameWithInitial != null) {
buf.append(alternateNameWithInitial);
if (iter.hasNext()) {
buf.append(" OR ");
}
}
}
buf.append(")");
if(buf.toString().endsWith(" OR )")) {
return buf.toString().substring(0, buf.toString().length() - 5) + ")";
}
else {
return buf.toString();
}
} else {
return null;
}
}

}