fix : 修正文本提取工具,优化工作经验解析
This commit is contained in:
@@ -46,62 +46,90 @@ export const useAudioSpeak = (config = {}) => {
|
|||||||
|
|
||||||
// 文本提取工具函数
|
// 文本提取工具函数
|
||||||
function extractSpeechText(markdown) {
|
function extractSpeechText(markdown) {
|
||||||
if (!markdown || markdown.indexOf('job-json') === -1) {
|
if (!markdown || markdown.indexOf('job-json') === -1) {
|
||||||
return markdown;
|
return markdown;
|
||||||
}
|
}
|
||||||
const jobRegex = /``` job-json\s*({[\s\S]*?})\s*```/g;
|
const jobRegex = /``` job-json\s*({[\s\S]*?})\s*```/g;
|
||||||
const jobs = [];
|
const jobs = [];
|
||||||
let match;
|
let match;
|
||||||
let lastJobEndIndex = 0;
|
let lastJobEndIndex = 0;
|
||||||
let firstJobStartIndex = -1;
|
let firstJobStartIndex = -1;
|
||||||
|
|
||||||
while ((match = jobRegex.exec(markdown)) !== null) {
|
while ((match = jobRegex.exec(markdown)) !== null) {
|
||||||
const jobStr = match[1];
|
const jobStr = match[1];
|
||||||
try {
|
try {
|
||||||
const job = JSON.parse(jobStr);
|
const job = JSON.parse(jobStr);
|
||||||
jobs.push(job);
|
jobs.push(job);
|
||||||
if (firstJobStartIndex === -1) {
|
if (firstJobStartIndex === -1) {
|
||||||
firstJobStartIndex = match.index;
|
firstJobStartIndex = match.index;
|
||||||
}
|
|
||||||
lastJobEndIndex = jobRegex.lastIndex;
|
|
||||||
} catch (e) {
|
|
||||||
console.warn('JSON 解析失败', e);
|
|
||||||
}
|
}
|
||||||
|
lastJobEndIndex = jobRegex.lastIndex;
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('JSON 解析失败', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const guideText = firstJobStartIndex > 0 ?
|
||||||
|
markdown.slice(0, firstJobStartIndex).trim() : '';
|
||||||
|
const endingText = lastJobEndIndex < markdown.length ?
|
||||||
|
markdown.slice(lastJobEndIndex).trim() : '';
|
||||||
|
|
||||||
|
const jobTexts = jobs.map((job, index) => {
|
||||||
|
// 处理薪资格式
|
||||||
|
let salaryText = job.salary;
|
||||||
|
if (salaryText) {
|
||||||
|
// 匹配 "XXXXX-XXXXX元/月" 格式
|
||||||
|
const rangeMatch = salaryText.match(/(\d+)-(\d+)元\/月/);
|
||||||
|
if (rangeMatch) {
|
||||||
|
const minSalary = parseInt(rangeMatch[1], 10);
|
||||||
|
const maxSalary = parseInt(rangeMatch[2], 10);
|
||||||
|
|
||||||
|
// 转换为千位单位
|
||||||
|
const minK = Math.round(minSalary / 1000);
|
||||||
|
const maxK = Math.round(maxSalary / 1000);
|
||||||
|
|
||||||
|
salaryText = `${minK}千到${maxK}千每月`;
|
||||||
|
}
|
||||||
|
// 如果不是 "XXXXX-XXXXX元/月" 格式,保持原样
|
||||||
}
|
}
|
||||||
|
|
||||||
const guideText = firstJobStartIndex > 0 ?
|
// 处理经验要求格式
|
||||||
markdown.slice(0, firstJobStartIndex).trim() : '';
|
let experienceText = job.experience;
|
||||||
const endingText = lastJobEndIndex < markdown.length ?
|
if (experienceText) {
|
||||||
markdown.slice(lastJobEndIndex).trim() : '';
|
// 匹配 "X-X年" 格式,如 "1-3年"、"5-10年"
|
||||||
|
const expRangeMatch = experienceText.match(/(\d+)-(\d+)年/);
|
||||||
const jobTexts = jobs.map((job, index) => {
|
if (expRangeMatch) {
|
||||||
// 处理薪资格式
|
const minExp = parseInt(expRangeMatch[1], 10);
|
||||||
let salaryText = job.salary;
|
const maxExp = parseInt(expRangeMatch[2], 10);
|
||||||
if (salaryText) {
|
experienceText = `${minExp}到${maxExp}年`;
|
||||||
// 匹配 "XXXXX-XXXXX元/月" 格式
|
|
||||||
const rangeMatch = salaryText.match(/(\d+)-(\d+)元\/月/);
|
|
||||||
if (rangeMatch) {
|
|
||||||
const minSalary = parseInt(rangeMatch[1], 10);
|
|
||||||
const maxSalary = parseInt(rangeMatch[2], 10);
|
|
||||||
|
|
||||||
// 转换为千位单位
|
|
||||||
const minK = Math.round(minSalary / 1000);
|
|
||||||
const maxK = Math.round(maxSalary / 1000);
|
|
||||||
|
|
||||||
salaryText = `${minK}千到${maxK}千每月`;
|
|
||||||
}
|
|
||||||
// 如果不是 "XXXXX-XXXXX元/月" 格式,保持原样
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 还可以处理其他常见格式
|
||||||
|
else if (experienceText.includes('年以下')) {
|
||||||
|
// 如 "3年以下"
|
||||||
|
experienceText = experienceText.replace('年以下', '年以下');
|
||||||
|
} else if (experienceText.includes('年以上')) {
|
||||||
|
// 如 "5年以上"
|
||||||
|
experienceText = experienceText.replace('年以上', '年以上');
|
||||||
|
} else if (experienceText === '不限' || experienceText === '无经验要求') {
|
||||||
|
experienceText = '经验不限';
|
||||||
|
}
|
||||||
|
// 其他格式保持原样
|
||||||
|
}
|
||||||
|
|
||||||
return `第 ${index + 1} 个岗位,岗位名称是:${job.jobTitle},公司是:${job.companyName},薪资:${salaryText},地点:${job.location},学历要求:${job.education},经验要求:${job.experience}。`;
|
// 同样可以处理学历要求(如果需要的话)
|
||||||
});
|
let educationText = job.education;
|
||||||
|
// 这里可以添加学历格式的转换逻辑
|
||||||
|
|
||||||
const finalTextParts = [];
|
return `第 ${index + 1} 个岗位,岗位名称是:${job.jobTitle},公司是:${job.companyName},薪资:${salaryText},地点:${job.location},学历要求:${educationText},经验要求:${experienceText}。`;
|
||||||
if (guideText) finalTextParts.push(guideText);
|
});
|
||||||
finalTextParts.push(...jobTexts);
|
|
||||||
if (endingText) finalTextParts.push(endingText);
|
|
||||||
|
|
||||||
return finalTextParts.join('\n');
|
const finalTextParts = [];
|
||||||
|
if (guideText) finalTextParts.push(guideText);
|
||||||
|
finalTextParts.push(...jobTexts);
|
||||||
|
if (endingText) finalTextParts.push(endingText);
|
||||||
|
|
||||||
|
return finalTextParts.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user