Skip to content

Commit

Permalink
new functionalities added for resume analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
shliamin committed Sep 2, 2024
1 parent 0122d03 commit 12e4e31
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 20 deletions.
69 changes: 52 additions & 17 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,34 @@ import { analyzeCategories, detectLanguage } from './resumeAnalyzer.js';

let chartInstance = null;


function extractTextFromPDF(pdfData) {
const pdfjsLib = window['pdfjsLib'];
if (!pdfjsLib) {
console.error('pdfjsLib is not loaded');
return;
}

pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.10.377/pdf.worker.min.js';

const loadingTask = pdfjsLib.getDocument({data: pdfData});
return loadingTask.promise.then(pdf => {
const maxPages = pdf.numPages;
const pagePromises = [];
for (let i = 1; i <= maxPages; i++) {
pagePromises.push(pdf.getPage(i).then(page => {
return page.getTextContent().then(textContent => {
return textContent.items.map(item => item.str).join(' ');
});
}));
}
return Promise.all(pagePromises).then(pagesText => pagesText.join(' '));
});
}




// Resume upload handler
document.getElementById('resume').addEventListener('change', function(event) {
const resumeFile = event.target.files[0];
Expand All @@ -154,35 +182,42 @@ function analyzeResume(resume) {

reader.onload = function(e) {
const content = e.target.result;

fetch('english_keywords.txt')
.then(response => response.text())
.then(englishKeywords => {
fetch('german_keywords.txt')
.then(response => response.text())
.then(germanKeywords => {
const language = detectLanguage(content, englishKeywords, germanKeywords);
if (language !== 'en' && language !== 'de') {
alert('The document must be in English or German.');
return;
}

const categories = analyzeCategories(content, language === 'en' ? englishKeywords : germanKeywords);
displayChart(categories);
});
if (resume.type === 'application/pdf') {
extractTextFromPDF(content).then(text => {
analyzeTextContent(text);
});
} else {
analyzeTextContent(content);
}
};

if (resume.type === 'application/pdf') {
reader.readAsBinaryString(resume);
reader.readAsArrayBuffer(resume);
} else if (resume.type === 'text/plain') {
reader.readAsText(resume);
} else {
alert('Unsupported file type. Please upload a PDF or TXT file.');
}
}

function analyzeTextContent(content) {
fetch('english_keywords.txt')
.then(response => response.text())
.then(englishKeywords => {
fetch('german_keywords.txt')
.then(response => response.text())
.then(germanKeywords => {
const language = detectLanguage(content, englishKeywords, germanKeywords);
if (language !== 'en' && language !== 'de') {
alert('The document must be in English or German.');
return;
}

const categories = analyzeCategories(content, language === 'en' ? englishKeywords : germanKeywords);
displayChart(categories);
});
});
}



Expand Down
17 changes: 15 additions & 2 deletions resumeAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export function detectLanguage(text, englishKeywords, germanKeywords) {
}

export function analyzeCategories(content, keywords) {
// Разбиваем строку на массив ключевых слов (это используется для анализа языка)
const keywordArray = keywords.split('\n').map(keyword => keyword.trim());
console.log('Содержимое текста:', content);

const subcategoryKeywords = {
'Experience': [
'experience', 'work experience', 'professional experience', 'career history',
Expand Down Expand Up @@ -133,9 +137,15 @@ export function analyzeCategories(content, keywords) {
for (const subcategory in categoryInfo.subcategories) {
const originalValue = categoryInfo.subcategories[subcategory];

// Используем правильный массив ключевых слов для подкатегории
const keywordsForSubcategory = subcategoryKeywords[subcategory];
const found = keywordsForSubcategory.some(keyword => content.toLowerCase().includes(keyword.toLowerCase()));

const keywords = subcategoryKeywords[subcategory];
const found = keywords ? keywords.some(keyword => content.toLowerCase().includes(keyword.toLowerCase())) : false;
if (found) {
console.log(`Подкатегория '${subcategory}' найдена в тексте.`);
} else {
console.log(`Подкатегория '${subcategory}' НЕ найдена в тексте.`);
}

finalCategories[subcategory] = {
value: found ? originalValue : originalValue,
Expand All @@ -147,8 +157,11 @@ export function analyzeCategories(content, keywords) {
value: categoryInfo.value,
color: categoryInfo.color
};

console.log(`Категория '${category}' не имеет подкатегорий.`);
}
}

console.log('Финальные категории:', finalCategories);
return finalCategories;
}
2 changes: 1 addition & 1 deletion resume_analyzer.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ <h1>Compatibility Analyzer</h1>
</div>
</div>


<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.10.377/pdf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script type="module" src="main.js"></script>

Expand Down

0 comments on commit 12e4e31

Please sign in to comment.