()
| 458 | } |
| 459 | |
| 460 | async buildLabelHierarchy() { |
| 461 | console.log('🌳 Building label hierarchy...'); |
| 462 | |
| 463 | // 基于预定义的分类构建层级关系 |
| 464 | for (const [category, labels] of Object.entries(this.labelCategories)) { |
| 465 | // 将分类作为父节点 |
| 466 | for (const label of labels) { |
| 467 | await new Promise((resolve, reject) => { |
| 468 | this.db.run( |
| 469 | `INSERT OR REPLACE INTO label_hierarchy (parent_label, child_label, relation_type) |
| 470 | VALUES (?, ?, ?)`, |
| 471 | [category, label, 'category'], |
| 472 | (err) => { |
| 473 | if (err) reject(err); |
| 474 | else resolve(); |
| 475 | } |
| 476 | ); |
| 477 | }); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | // 基于标签共现关系构建关联 |
| 482 | const relatedLabelsSQL = ` |
| 483 | SELECT label1, label2, correlation_score |
| 484 | FROM label_relations |
| 485 | WHERE correlation_score > 0.5 |
| 486 | ORDER BY correlation_score DESC |
| 487 | `; |
| 488 | |
| 489 | this.db.all(relatedLabelsSQL, [], async (err, rows) => { |
| 490 | if (err) { |
| 491 | console.error('Error building label hierarchy:', err); |
| 492 | return; |
| 493 | } |
| 494 | |
| 495 | for (const row of rows) { |
| 496 | await new Promise((resolve, reject) => { |
| 497 | this.db.run( |
| 498 | `INSERT OR REPLACE INTO label_hierarchy (parent_label, child_label, relation_type) |
| 499 | VALUES (?, ?, ?)`, |
| 500 | [row.label1, row.label2, 'related'], |
| 501 | (err) => { |
| 502 | if (err) reject(err); |
| 503 | else resolve(); |
| 504 | } |
| 505 | ); |
| 506 | }); |
| 507 | } |
| 508 | }); |
| 509 | } |
| 510 | |
| 511 | async saveAnalysisToDatabase(issueNumber, analysis) { |
| 512 | const insertSQL = ` |
no test coverage detected