MCPcopy Create free account
hub / github.com/chokcoco/iCSS / calculateLabelWeights

Method calculateLabelWeights

MCP/scripts/fetch-issues.js:417–458  ·  view source on GitHub ↗
(labels, content)

Source from the content-addressed store, hash-verified

415 }
416
417 calculateLabelWeights(labels, content) {
418 const weights = {};
419
420 for (const label of labels) {
421 // 基础权重
422 let weight = this.labelWeights[label] || 1.0;
423
424 // 基于内容相关度调整权重
425 const labelRegex = new RegExp(label, 'gi');
426 const matches = content.match(labelRegex) || [];
427 weight += matches.length * 0.1;
428
429 // 基于标签位置调整权重
430 if (content.toLowerCase().includes(label.toLowerCase())) {
431 const firstIndex = content.toLowerCase().indexOf(label.toLowerCase());
432 if (firstIndex < content.length * 0.2) {
433 weight += 0.3; // 在文章开头出现的标签更重要
434 }
435 }
436
437 // 基于代码示例调整权重
438 const codeBlocks = content.match(/```[^`]+```/g) || [];
439 for (const block of codeBlocks) {
440 if (block.toLowerCase().includes(label.toLowerCase())) {
441 weight += 0.2; // 在代码示例中出现的标签更重要
442 }
443 }
444
445 // 基于标签关系调整权重
446 if (this.labelRelations[label]) {
447 const relatedLabels = this.labelRelations[label];
448 const presentRelatedLabels = relatedLabels.filter(rel =>
449 labels.includes(rel)
450 );
451 weight += presentRelatedLabels.length * 0.1; // 相关标签共现提升权重
452 }
453
454 weights[label] = weight;
455 }
456
457 return weights;
458 }
459
460 async buildLabelHierarchy() {
461 console.log('🌳 Building label hierarchy...');

Callers 1

analyzeArticleLabelsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected