mindee
Version:
Mindee Client Library for Node.js
204 lines (203 loc) • 10.2 kB
JavaScript
import { cleanOutString, lineSeparator, } from "../../../v1/parsing/common/index.js";
import { ResumeV1SocialNetworksUrl } from "./resumeV1SocialNetworksUrl.js";
import { ResumeV1Language } from "./resumeV1Language.js";
import { ResumeV1Education } from "./resumeV1Education.js";
import { ResumeV1ProfessionalExperience } from "./resumeV1ProfessionalExperience.js";
import { ResumeV1Certificate } from "./resumeV1Certificate.js";
import { ClassificationField, StringField } from "../../../v1/parsing/standard/index.js";
/**
* Resume API version 1.2 document data.
*/
export class ResumeV1Document {
constructor(rawPrediction, pageId) {
/** The list of certificates obtained by the candidate. */
this.certificates = [];
/** The list of the candidate's educational background. */
this.education = [];
/** The candidate's first or given names. */
this.givenNames = [];
/** The list of the candidate's technical abilities and knowledge. */
this.hardSkills = [];
/** The list of languages that the candidate is proficient in. */
this.languages = [];
/** The list of the candidate's professional experiences. */
this.professionalExperiences = [];
/** The list of social network profiles of the candidate. */
this.socialNetworksUrls = [];
/** The list of the candidate's interpersonal and communication abilities. */
this.softSkills = [];
/** The candidate's last names. */
this.surnames = [];
this.address = new StringField({
prediction: rawPrediction["address"],
pageId: pageId,
});
if (rawPrediction["certificates"]) {
rawPrediction["certificates"].map((itemPrediction) => this.certificates.push(new ResumeV1Certificate({
prediction: itemPrediction,
pageId: pageId,
})));
}
this.documentLanguage = new StringField({
prediction: rawPrediction["document_language"],
pageId: pageId,
});
this.documentType = new ClassificationField({
prediction: rawPrediction["document_type"],
});
if (rawPrediction["education"]) {
rawPrediction["education"].map((itemPrediction) => this.education.push(new ResumeV1Education({
prediction: itemPrediction,
pageId: pageId,
})));
}
this.emailAddress = new StringField({
prediction: rawPrediction["email_address"],
pageId: pageId,
});
if (rawPrediction["given_names"]) {
rawPrediction["given_names"].map((itemPrediction) => this.givenNames.push(new StringField({
prediction: itemPrediction,
pageId: pageId,
})));
}
if (rawPrediction["hard_skills"]) {
rawPrediction["hard_skills"].map((itemPrediction) => this.hardSkills.push(new StringField({
prediction: itemPrediction,
pageId: pageId,
})));
}
this.jobApplied = new StringField({
prediction: rawPrediction["job_applied"],
pageId: pageId,
});
if (rawPrediction["languages"]) {
rawPrediction["languages"].map((itemPrediction) => this.languages.push(new ResumeV1Language({
prediction: itemPrediction,
pageId: pageId,
})));
}
this.nationality = new StringField({
prediction: rawPrediction["nationality"],
pageId: pageId,
});
this.phoneNumber = new StringField({
prediction: rawPrediction["phone_number"],
pageId: pageId,
});
this.profession = new StringField({
prediction: rawPrediction["profession"],
pageId: pageId,
});
if (rawPrediction["professional_experiences"]) {
rawPrediction["professional_experiences"].map((itemPrediction) => this.professionalExperiences.push(new ResumeV1ProfessionalExperience({
prediction: itemPrediction,
pageId: pageId,
})));
}
if (rawPrediction["social_networks_urls"]) {
rawPrediction["social_networks_urls"].map((itemPrediction) => this.socialNetworksUrls.push(new ResumeV1SocialNetworksUrl({
prediction: itemPrediction,
pageId: pageId,
})));
}
if (rawPrediction["soft_skills"]) {
rawPrediction["soft_skills"].map((itemPrediction) => this.softSkills.push(new StringField({
prediction: itemPrediction,
pageId: pageId,
})));
}
if (rawPrediction["surnames"]) {
rawPrediction["surnames"].map((itemPrediction) => this.surnames.push(new StringField({
prediction: itemPrediction,
pageId: pageId,
})));
}
}
/**
* Default string representation.
*/
toString() {
const givenNames = this.givenNames.join("\n ");
const surnames = this.surnames.join("\n ");
let socialNetworksUrlsSummary = "";
if (this.socialNetworksUrls && this.socialNetworksUrls.length > 0) {
const socialNetworksUrlsColSizes = [22, 52];
socialNetworksUrlsSummary += "\n" + lineSeparator(socialNetworksUrlsColSizes, "-") + "\n ";
socialNetworksUrlsSummary += "| Name ";
socialNetworksUrlsSummary += "| URL ";
socialNetworksUrlsSummary += "|\n" + lineSeparator(socialNetworksUrlsColSizes, "=");
socialNetworksUrlsSummary += this.socialNetworksUrls.map((item) => "\n " + item.toTableLine() + "\n" + lineSeparator(socialNetworksUrlsColSizes, "-")).join("");
}
let languagesSummary = "";
if (this.languages && this.languages.length > 0) {
const languagesColSizes = [10, 22];
languagesSummary += "\n" + lineSeparator(languagesColSizes, "-") + "\n ";
languagesSummary += "| Language ";
languagesSummary += "| Level ";
languagesSummary += "|\n" + lineSeparator(languagesColSizes, "=");
languagesSummary += this.languages.map((item) => "\n " + item.toTableLine() + "\n" + lineSeparator(languagesColSizes, "-")).join("");
}
const hardSkills = this.hardSkills.join("\n ");
const softSkills = this.softSkills.join("\n ");
let educationSummary = "";
if (this.education && this.education.length > 0) {
const educationColSizes = [17, 27, 11, 10, 27, 13, 12];
educationSummary += "\n" + lineSeparator(educationColSizes, "-") + "\n ";
educationSummary += "| Domain ";
educationSummary += "| Degree ";
educationSummary += "| End Month ";
educationSummary += "| End Year ";
educationSummary += "| School ";
educationSummary += "| Start Month ";
educationSummary += "| Start Year ";
educationSummary += "|\n" + lineSeparator(educationColSizes, "=");
educationSummary += this.education.map((item) => "\n " + item.toTableLine() + "\n" + lineSeparator(educationColSizes, "-")).join("");
}
let professionalExperiencesSummary = "";
if (this.professionalExperiences && this.professionalExperiences.length > 0) {
const professionalExperiencesColSizes = [17, 12, 38, 27, 11, 10, 22, 13, 12];
professionalExperiencesSummary += "\n" + lineSeparator(professionalExperiencesColSizes, "-") + "\n ";
professionalExperiencesSummary += "| Contract Type ";
professionalExperiencesSummary += "| Department ";
professionalExperiencesSummary += "| Description ";
professionalExperiencesSummary += "| Employer ";
professionalExperiencesSummary += "| End Month ";
professionalExperiencesSummary += "| End Year ";
professionalExperiencesSummary += "| Role ";
professionalExperiencesSummary += "| Start Month ";
professionalExperiencesSummary += "| Start Year ";
professionalExperiencesSummary += "|\n" + lineSeparator(professionalExperiencesColSizes, "=");
professionalExperiencesSummary += this.professionalExperiences.map((item) => "\n " + item.toTableLine() + "\n" + lineSeparator(professionalExperiencesColSizes, "-")).join("");
}
let certificatesSummary = "";
if (this.certificates && this.certificates.length > 0) {
const certificatesColSizes = [12, 32, 27, 6];
certificatesSummary += "\n" + lineSeparator(certificatesColSizes, "-") + "\n ";
certificatesSummary += "| Grade ";
certificatesSummary += "| Name ";
certificatesSummary += "| Provider ";
certificatesSummary += "| Year ";
certificatesSummary += "|\n" + lineSeparator(certificatesColSizes, "=");
certificatesSummary += this.certificates.map((item) => "\n " + item.toTableLine() + "\n" + lineSeparator(certificatesColSizes, "-")).join("");
}
const outStr = `:Document Language: ${this.documentLanguage}
:Document Type: ${this.documentType}
:Given Names: ${givenNames}
:Surnames: ${surnames}
:Nationality: ${this.nationality}
:Email Address: ${this.emailAddress}
:Phone Number: ${this.phoneNumber}
:Address: ${this.address}
:Social Networks: ${socialNetworksUrlsSummary}
:Profession: ${this.profession}
:Job Applied: ${this.jobApplied}
:Languages: ${languagesSummary}
:Hard Skills: ${hardSkills}
:Soft Skills: ${softSkills}
:Education: ${educationSummary}
:Professional Experiences: ${professionalExperiencesSummary}
:Certificates: ${certificatesSummary}`.trimEnd();
return cleanOutString(outStr);
}
}