Skip to content

Commit 295f3e3

Browse files
author
JW Wesson
committed
updates for SuggestProfessionsFromSkills
1 parent 4c36247 commit 295f3e3

File tree

4 files changed

+99
-54
lines changed

4 files changed

+99
-54
lines changed

src/main/java/com/sovren/SovrenClient.java

Lines changed: 83 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@
7373
import java.io.IOException;
7474
import java.time.Instant;
7575
import java.util.ArrayList;
76-
import java.util.Arrays;
7776
import java.util.Collections;
7877
import java.util.Comparator;
7978
import java.util.List;
8079
import java.util.Optional;
80+
import java.util.stream.Collectors;
8181

8282
/**
8383
* The SDK client to perform Sovren API calls.
@@ -1616,14 +1616,13 @@ public CompareProfessionsResponse compareProfessions(int profession1, int profes
16161616
* @return The API response body
16171617
* @throws SovrenException Thrown when an API error occurs
16181618
*/
1619-
public CompareSkillsToProfessionResponse compareSkillsToProfessions(int professionCodeId, String outputLanguage, SkillScore... skills) throws SovrenException {
1619+
public CompareSkillsToProfessionResponse compareSkillsToProfessions(int professionCodeId, String outputLanguage, List<SkillScore> skills) throws SovrenException {
16201620
CompareSkillsToProfessionRequest request = new CompareSkillsToProfessionRequest();
16211621
request.Skills = new ArrayList<SkillScore>();
1622-
List<SkillScore> newList = Arrays.asList(skills);
1623-
int amountOfSkills = newList.size() > 50 ? 50 : newList.size();
1622+
int amountOfSkills = skills.size() > 50 ? 50 : skills.size();
16241623

16251624
for(int i = 0; i < amountOfSkills; i++) {
1626-
request.Skills.add(newList.get(i));
1625+
request.Skills.add(skills.get(i));
16271626
};
16281627
request.ProfessionCodeId = professionCodeId;
16291628
request.OutputLanguage = outputLanguage;
@@ -1643,7 +1642,7 @@ public CompareSkillsToProfessionResponse compareSkillsToProfessions(int professi
16431642
* @param resume The resume containing the skills of the candidate
16441643
* @param professionCodeId The profession code ID from the <a href="https://sovren.com/technical-specs/latest/rest-api/data-enrichment/overview/#professions-taxonomies">Professions Taxonomy</a> to compare the skill set to.
16451644
* @param outputLanguage The language to use for the returned descriptions. If not provided, no descriptions are returned. Must be one of the supported <a href="https://sovren.com/technical-specs/latest/rest-api/data-enrichment/overview/#skills-languages">ISO code</a>
1646-
* @param weightSkillsByExperience The language to use for the returned descriptions.
1645+
* @param weightSkillsByExperience Whether or not to give a higher weight to skills that the candidate has more experience with.
16471646
* @return The API response body
16481647
* @throws SovrenException Thrown when an API error occurs
16491648
*/
@@ -1653,23 +1652,7 @@ public CompareSkillsToProfessionResponse compareSkillsToProfessions(
16531652
String outputLanguage,
16541653
boolean weightSkillsByExperience) throws SovrenException {
16551654
if(resume != null && resume.Skills != null && resume.Skills.Normalized != null && resume.Skills.Normalized.size() > 0){
1656-
SkillScore[] skills = new SkillScore[resume.Skills.Normalized.size()];
1657-
1658-
ResumeNormalizedSkill maxExperienceSkill = Collections.max(resume.Skills.Normalized, Comparator.comparing(s -> s.MonthsExperience != null ? s.MonthsExperience.Value : 0));
1659-
Integer maxExperience = Optional.ofNullable(maxExperienceSkill).map(s -> s.MonthsExperience).map(e -> e.Value).orElse(0);
1660-
1661-
for(int i = 0; i < resume.Skills.Normalized.size(); i++) {
1662-
SkillScore curSkill = new SkillScore();
1663-
ResumeNormalizedSkill curSkillOrig = resume.Skills.Normalized.get(i);
1664-
curSkill.Id = curSkillOrig.Id;
1665-
1666-
int curMonthsExperience = Optional.ofNullable(curSkillOrig.MonthsExperience).map(e -> e.Value).orElse(0);
1667-
curSkill.Score = (weightSkillsByExperience && maxExperience > 0) ? curMonthsExperience / (float)maxExperience : 1;
1668-
1669-
skills[i] = curSkill;
1670-
}
1671-
1672-
return compareSkillsToProfessions(professionCodeId, outputLanguage, skills);
1655+
return compareSkillsToProfessions(professionCodeId, outputLanguage, getNormalizedSkillsFromResume(resume, weightSkillsByExperience));
16731656
}
16741657
throw new IllegalArgumentException("The resume must be parsed with V2 skills selected, and with skills normalization enabled");
16751658
}
@@ -1769,80 +1752,132 @@ public SuggestSkillsResponse suggestSkillsFromProfessions(ParsedJob job) throws
17691752
return suggestSkillsFromProfessions(job, null);
17701753
}
17711754

1755+
private List<SkillScore> getNormalizedSkillsFromResume(ParsedResume resume, boolean weightSkillsByExperience) {
1756+
if(resume != null && resume.Skills != null && resume.Skills.Normalized != null && resume.Skills.Normalized.size() > 0){
1757+
List<SkillScore> skills = new ArrayList<SkillScore>();
1758+
1759+
ResumeNormalizedSkill maxExperienceSkill = Collections.max(resume.Skills.Normalized, Comparator.comparing(s -> s.MonthsExperience != null ? s.MonthsExperience.Value : 0));
1760+
Integer maxExperience = Optional.ofNullable(maxExperienceSkill).map(s -> s.MonthsExperience).map(e -> e.Value).orElse(0);
1761+
1762+
for(int i = 0; i < resume.Skills.Normalized.size(); i++) {
1763+
ResumeNormalizedSkill curSkill = resume.Skills.Normalized.get(i);
1764+
SkillScore newSkill = new SkillScore(curSkill.Id);
1765+
int curMonthsExperience = Optional.ofNullable(curSkill.MonthsExperience).map(e -> e.Value).orElse(0);
1766+
newSkill.Score = (weightSkillsByExperience && maxExperience > 0) ? curMonthsExperience / (float)maxExperience : 1;
1767+
1768+
skills.add(newSkill);
1769+
}
1770+
1771+
return skills;
1772+
}
1773+
throw new IllegalArgumentException("The resume must be parsed with V2 skills selected, and with skills normalization enabled.");
1774+
}
1775+
17721776
/**
17731777
* Suggest professions based on the <b>skills</b> within a given resume.
17741778
* @param resume The professions are suggested based on the <b>skills</b> within this resume.
17751779
* @param limit The maximum amount of professions returned. If not sure what value should be, provide 10 as default limit.
17761780
* @param returnMissingSkills Flag to enable returning a list of missing skills per suggested profession.
1781+
* @param outputLanguage The language to use for the returned descriptions. If not provided, no descriptions are returned. Must be one of the supported <a href="https://sovren.com/technical-specs/latest/rest-api/data-enrichment/overview/#professions-languages">ISO code</a>
1782+
* @param weightSkillsByExperience Whether or not to give a higher weight to skills that the candidate has more experience with.
17771783
* @return The API response body
17781784
* @throws SovrenException Thrown when an API error occurs
17791785
*/
1780-
public SuggestProfessionsResponse suggestProfessions(ParsedResume resume, int limit, boolean returnMissingSkills) throws SovrenException {
1786+
public SuggestProfessionsResponse suggestProfessionsFromSkills(
1787+
ParsedResume resume,
1788+
int limit,
1789+
boolean returnMissingSkills,
1790+
String outputLanguage,
1791+
boolean weightSkillsByExperience) throws SovrenException {
17811792
if(resume != null && resume.Skills != null && resume.Skills.Normalized != null && resume.Skills.Normalized.size() > 0){
1782-
List<String> ids = new ArrayList<String>();
1783-
for(ResumeNormalizedSkill skill: resume.Skills.Normalized){
1784-
ids.add(skill.Id);
1785-
}
1786-
1787-
return suggestProfessions(ids,limit,returnMissingSkills);
1793+
return suggestProfessionsFromSkills(getNormalizedSkillsFromResume(resume, weightSkillsByExperience), limit, returnMissingSkills, outputLanguage);
17881794
}
17891795
throw new IllegalArgumentException("The resume must be parsed with V2 skills selected, and with skills normalization enabled.");
17901796
}
17911797

1798+
/**
1799+
* Suggest professions based on the <b>skills</b> within a given resume.
1800+
* @param resume The professions are suggested based on the <b>skills</b> within this resume. Defaults limit returned to 10 and does not return missing skills. Use another overload to specify these parameters.
1801+
* @param outputLanguage The language to use for the returned descriptions. If not provided, no descriptions are returned. Must be one of the supported <a href="https://sovren.com/technical-specs/latest/rest-api/data-enrichment/overview/#professions-languages">ISO code</a>
1802+
* @return The API response body
1803+
* @throws SovrenException Thrown when an API error occurs
1804+
*/
1805+
public SuggestProfessionsResponse suggestProfessionsFromSkills(ParsedResume resume, String outputLanguage) throws SovrenException {
1806+
return suggestProfessionsFromSkills(resume, 10, false, outputLanguage, true);
1807+
}
1808+
17921809
/**
17931810
* Suggest professions based on the <b>skills</b> within a given resume.
17941811
* @param resume The professions are suggested based on the <b>skills</b> within this resume. Defaults limit returned to 10 and does not return missing skills. Use another overload to specify these parameters.
17951812
* @return The API response body
17961813
* @throws SovrenException Thrown when an API error occurs
17971814
*/
1798-
public SuggestProfessionsResponse suggestProfessions(ParsedResume resume) throws SovrenException {
1799-
return suggestProfessions(resume,10,false);
1815+
public SuggestProfessionsResponse suggestProfessionsFromSkills(ParsedResume resume) throws SovrenException {
1816+
return suggestProfessionsFromSkills(resume, null);
18001817
}
18011818

18021819
/**
18031820
* Suggest professions based on the <b>skills</b> within a given job.
18041821
* @param job The professions are suggested based on the <b>skills</b> within this job.
18051822
* @param limit The maximum amount of professions returned. If not sure what value should be, provide 10 as default limit.
18061823
* @param returnMissingSkills Flag to enable returning a list of missing skills per suggested profession.
1824+
* @param outputLanguage The language to use for the returned descriptions. If not provided, no descriptions are returned. Must be one of the supported <a href="https://sovren.com/technical-specs/latest/rest-api/data-enrichment/overview/#professions-languages">ISO code</a>
18071825
* @return The API response body
18081826
* @throws SovrenException Thrown when an API error occurs
18091827
*/
1810-
public SuggestProfessionsResponse suggestProfessions(ParsedJob job, int limit, boolean returnMissingSkills) throws SovrenException {
1828+
public SuggestProfessionsResponse suggestProfessionsFromSkills(ParsedJob job, int limit, boolean returnMissingSkills, String outputLanguage) throws SovrenException {
18111829
if(job != null && job.Skills != null && job.Skills.Normalized != null && job.Skills.Normalized.size() > 0){
1812-
List<String> ids = new ArrayList<String>();
1830+
List<SkillScore> skills = new ArrayList<SkillScore>();
18131831
int amountOfSkills = job.Skills.Normalized.size() > 50 ? 50 : job.Skills.Normalized.size();
18141832
for(int i = 0; i < amountOfSkills; i++) {
1815-
ids.add(job.Skills.Normalized.get(i).Id);
1833+
skills.add(new SkillScore(job.Skills.Normalized.get(i).Id));
18161834
}
18171835

1818-
return suggestProfessions(ids,limit,returnMissingSkills);
1836+
return suggestProfessionsFromSkills(skills, limit, returnMissingSkills, outputLanguage);
18191837
}
18201838
throw new IllegalArgumentException("The job must be parsed with V2 skills selected, and with skills normalization enabled");
18211839
}
18221840

18231841
/**
18241842
* Suggest professions based on the <b>skills</b> within a given job.
18251843
* @param job The professions are suggested based on the <b>skills</b> within this job. Defaults limit returned to 10 and does not return missing skills. Use another overload to specify these parameters.
1844+
* @param outputLanguage The language to use for the returned descriptions. If not provided, no descriptions are returned. Must be one of the supported <a href="https://sovren.com/technical-specs/latest/rest-api/data-enrichment/overview/#professions-languages">ISO code</a>
18261845
* @return The API response body
18271846
* @throws SovrenException Thrown when an API error occurs
18281847
*/
1829-
public SuggestProfessionsResponse suggestProfessions(ParsedJob job) throws SovrenException {
1830-
return suggestProfessions(job,10,false);
1848+
public SuggestProfessionsResponse suggestProfessionsFromSkills(ParsedJob job, String outputLanguage) throws SovrenException {
1849+
return suggestProfessionsFromSkills(job, 10, false, outputLanguage);
18311850
}
18321851

18331852
/**
1834-
* Suggest professions based on a given set of skill IDs.
1835-
* @param skillIds The skill IDs used to return the most relevant professions. The list can contain up to 50 skill IDs.
1853+
* Suggest professions based on the <b>skills</b> within a given job.
1854+
* @param job The professions are suggested based on the <b>skills</b> within this job. Defaults limit returned to 10 and does not return missing skills. Use another overload to specify these parameters.
1855+
* @return The API response body
1856+
* @throws SovrenException Thrown when an API error occurs
1857+
*/
1858+
public SuggestProfessionsResponse suggestProfessionsFromSkills(ParsedJob job) throws SovrenException {
1859+
return suggestProfessionsFromSkills(job, null);
1860+
}
1861+
1862+
/**
1863+
* Suggest professions based on a given set of skills.
1864+
* @param skillIds The skills used to return the most relevant professions. The list can contain up to 50 skills.
18361865
* @param limit The maximum amount of professions returned. If not sure what value should be, provide 10 as default limit.
18371866
* @param returnMissingSkills Flag to enable returning a list of missing skills per suggested profession.
1867+
* @param outputLanguage The language to use for the returned descriptions. If not provided, no descriptions are returned. Must be one of the supported <a href="https://sovren.com/technical-specs/latest/rest-api/data-enrichment/overview/#professions-languages">ISO code</a>
18381868
* @return The API response body
18391869
* @throws SovrenException Thrown when an API error occurs
18401870
*/
1841-
public SuggestProfessionsResponse suggestProfessions(List<String> skillIds, int limit, boolean returnMissingSkills) throws SovrenException {
1871+
public SuggestProfessionsResponse suggestProfessionsFromSkills(
1872+
List<SkillScore> skills,
1873+
int limit,
1874+
boolean returnMissingSkills,
1875+
String outputLanguage) throws SovrenException {
18421876
SuggestProfessionsRequest request = new SuggestProfessionsRequest();
1843-
request.SkillIds = skillIds;
1877+
request.Skills = skills;
18441878
request.Limit = limit;
18451879
request.ReturnMissingSkills = returnMissingSkills;
1880+
request.OutputLanguage = outputLanguage;
18461881

18471882
RequestBody body = createJsonBody(request);
18481883
Request apiRequest = new Request.Builder()
@@ -1857,10 +1892,14 @@ public SuggestProfessionsResponse suggestProfessions(List<String> skillIds, int
18571892
/**
18581893
* Suggest professions based on a given set of skill IDs.
18591894
* @param skillIds The skill IDs used to return the most relevant professions. The list can contain up to 50 skill IDs. Defaults limit returned to 10 and does not return missing skills. Use another overload to specify these parameters.
1895+
* @param outputLanguage The language to use for the returned descriptions. If not provided, no descriptions are returned. Must be one of the supported <a href="https://sovren.com/technical-specs/latest/rest-api/data-enrichment/overview/#professions-languages">ISO code</a>
18601896
* @return The API response body
18611897
* @throws SovrenException Thrown when an API error occurs
18621898
*/
1863-
public SuggestProfessionsResponse suggestProfessions(List<String> skillIds) throws SovrenException {
1864-
return suggestProfessions(skillIds,10,false);
1899+
public SuggestProfessionsResponse suggestProfessionsFromSkills(List<String> skillIds, String outputLanguage) throws SovrenException {
1900+
List<SkillScore> skills = skillIds.stream()
1901+
.map(s -> new SkillScore(s))
1902+
.collect(Collectors.toList());
1903+
return suggestProfessionsFromSkills(skills, 10, false, outputLanguage);
18651904
}
18661905
}

src/main/java/com/sovren/models/api/dataenrichment/ontology/request/SuggestProfessionsRequest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
import java.util.List;
99

10+
import com.sovren.models.api.dataenrichment.ontology.response.SkillScore;
11+
1012
/** Request body for a 'SuggestProfessions' request */
1113
public class SuggestProfessionsRequest {
12-
/** The skill IDs used to return the most relevant professions. The list can contain up to 50 skill IDs. */
13-
public List<String> SkillIds;
14+
/** The skills used to return the most relevant professions. The list can contain up to 50 skills. */
15+
public List<SkillScore> Skills;
1416
/** Flag to enable returning a list of missing skills per suggested profession. */
1517
public boolean ReturnMissingSkills = false;
1618
/** The maximum amount of professions returned. If not specified this parameter defaults to 10. */

src/main/java/com/sovren/models/api/dataenrichment/ontology/response/SkillScore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ public class SkillScore {
1313
public String Id;
1414
/** The description of the skill in the Skills Taxonomy. Will only be returned if OutputLanguage is specified in the request. This has no effect in a request body. */
1515
public String Description;
16+
17+
public SkillScore() {}
18+
public SkillScore(String id) {
19+
Id = id;
20+
}
1621
}

src/test/java/com/sovren/integration/DataEnrichmentServiceTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
1515

1616
import java.util.ArrayList;
17+
import java.util.List;
1718

1819
public class DataEnrichmentServiceTests extends TestBase {
1920
@Test
@@ -117,13 +118,11 @@ public void testCompareProfessions() {
117118
@Test
118119
public void testCompareSkillsToProfessions() {
119120
assertDoesNotThrow(() -> {
120-
SkillScore s1 = new SkillScore();
121-
SkillScore s2 = new SkillScore();
121+
List<SkillScore> skills = new ArrayList<SkillScore>();
122+
skills.add(new SkillScore("KS120076FGP5WGWYMP0F"));
123+
skills.add(new SkillScore("KS04UWLJBN9X1M3N0PZ4"));
122124

123-
s1.Id = "KS120076FGP5WGWYMP0F";
124-
s2.Id = "KS04UWLJBN9X1M3N0PZ4";
125-
126-
Client.compareSkillsToProfessions(696, "en", s1, s2);
125+
Client.compareSkillsToProfessions(696, "en", skills);
127126
});
128127
}
129128

@@ -132,7 +131,7 @@ public void testSuggestSkillsFromProfessions() {
132131
assertDoesNotThrow(() -> {
133132
ArrayList<Integer> professionCodeIds = new ArrayList<Integer>();
134133
professionCodeIds.add(696);
135-
Client.suggestSkillsFromProfessions(professionCodeIds, 10);
134+
Client.suggestSkillsFromProfessions(professionCodeIds, 10, null);
136135
});
137136
}
138137

@@ -143,7 +142,7 @@ public void testSuggestProfessions() {
143142
skillIds.add("KS120076FGP5WGWYMP0F");
144143
skillIds.add("KS125HH5XDBPZT3RFGZZ");
145144
skillIds.add("KS124PR62MV42B5C9S9F");
146-
Client.suggestProfessions((skillIds));
145+
Client.suggestProfessionsFromSkills(skillIds, null);
147146
});
148147
}
149148
}

0 commit comments

Comments
 (0)