diff --git a/src/main/java/reciter/xml/retriever/pubmed/KnownRelationshipRetrievalStrategy.java b/src/main/java/reciter/xml/retriever/pubmed/KnownRelationshipRetrievalStrategy.java index 24907258..2dd6a015 100644 --- a/src/main/java/reciter/xml/retriever/pubmed/KnownRelationshipRetrievalStrategy.java +++ b/src/main/java/reciter/xml/retriever/pubmed/KnownRelationshipRetrievalStrategy.java @@ -58,38 +58,38 @@ protected PubMedQuery buildNameQuery(Set identitynames, Identity ide return pubMedQueryBuilder.build(); } - @Override - protected String getStrategySpecificKeyword(Identity identity) { - if (identity.getKnownRelationships() != null && !identity.getKnownRelationships().isEmpty()) { - List nameIgnoredAuthors = Arrays.asList(excludeNames.trim().split("\\s*,\\s*")); - Iterator 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 nameIgnoredAuthors = Arrays.asList(excludeNames.trim().split("\\s*,\\s*")); + Iterator 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; + } + } } diff --git a/src/main/java/reciter/xml/retriever/pubmed/PubMedQueryType.java b/src/main/java/reciter/xml/retriever/pubmed/PubMedQueryType.java index 7ea1656e..6ef0b7b2 100644 --- a/src/main/java/reciter/xml/retriever/pubmed/PubMedQueryType.java +++ b/src/main/java/reciter/xml/retriever/pubmed/PubMedQueryType.java @@ -150,43 +150,46 @@ public PubMedQuery buildPmids(List 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 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 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; // diff --git a/src/main/java/reciter/xml/retriever/pubmed/SecondInitialRetrievalStrategy.java b/src/main/java/reciter/xml/retriever/pubmed/SecondInitialRetrievalStrategy.java index 619edfea..6f7a9aff 100644 --- a/src/main/java/reciter/xml/retriever/pubmed/SecondInitialRetrievalStrategy.java +++ b/src/main/java/reciter/xml/retriever/pubmed/SecondInitialRetrievalStrategy.java @@ -52,67 +52,70 @@ protected PubMedQuery buildNameQuery(Set 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 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 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; + } + } }