Compare commits
3 Commits
1bd892afbf
...
733d2bcc7b
| Author | SHA1 | Date | |
|---|---|---|---|
| 733d2bcc7b | |||
| 977e63f372 | |||
| be2ac762bd |
@@ -159,6 +159,7 @@ func (h *IACEHandler) InitializeProject(c *gin.Context) {
|
|||||||
|
|
||||||
created := 0
|
created := 0
|
||||||
seenCatZone := make(map[string]bool)
|
seenCatZone := make(map[string]bool)
|
||||||
|
catCount := make(map[string]int)
|
||||||
for _, mp := range matchOutput.MatchedPatterns {
|
for _, mp := range matchOutput.MatchedPatterns {
|
||||||
// Narrative relevance filter: skip patterns whose zone/scenario
|
// Narrative relevance filter: skip patterns whose zone/scenario
|
||||||
// mentions machine-specific terms that don't appear in our components
|
// mentions machine-specific terms that don't appear in our components
|
||||||
@@ -167,6 +168,12 @@ func (h *IACEHandler) InitializeProject(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, cat := range mp.HazardCats {
|
for _, cat := range mp.HazardCats {
|
||||||
|
// Per-category cap: limit hazards per category based on relevance
|
||||||
|
maxForCat := categoryHazardCap(cat, len(comps))
|
||||||
|
if catCount[cat] >= maxForCat {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Dedup by category + normalized zone
|
// Dedup by category + normalized zone
|
||||||
zoneKey := normalizeZoneKey(mp.ZoneDE)
|
zoneKey := normalizeZoneKey(mp.ZoneDE)
|
||||||
if zoneKey == "" {
|
if zoneKey == "" {
|
||||||
@@ -212,6 +219,7 @@ func (h *IACEHandler) InitializeProject(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
if cerr == nil {
|
if cerr == nil {
|
||||||
created++
|
created++
|
||||||
|
catCount[cat]++
|
||||||
hazardIDsByCategory[cat] = hz.ID
|
hazardIDsByCategory[cat] = hz.ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,53 +199,126 @@ func containsSubstring(haystack, needle string) bool {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// machineSpecificTerms are words in a pattern's zone/scenario that indicate
|
// genericSafetyTerms are words that appear in almost all risk assessments
|
||||||
// the pattern is specific to a particular machine type. If a pattern contains
|
// and should NOT be used to determine machine-specificity.
|
||||||
// such a term but the machine narrative does NOT, the pattern is irrelevant.
|
var genericSafetyTerms = map[string]bool{
|
||||||
var machineSpecificTerms = []string{
|
"maschine": true, "anlage": true, "bereich": true, "gesamte": true,
|
||||||
"extruder", "spinnmaschine", "spielplatz", "aufzug", "elevator",
|
"arbeitsplatz": true, "gefahrbereich": true, "gefahrstelle": true,
|
||||||
"kran", "crane", "bagger", "excavator", "traktor", "tractor",
|
"gefahrenstelle": true, "person": true, "werker": true, "bediener": true,
|
||||||
"harvester", "druckmaschine", "printing", "webstuhl", "weaving",
|
"steuerung": true, "schutzeinrichtung": true, "sicherheit": true,
|
||||||
"ofen", "furnace", "kessel", "boiler", "walzwerk", "rolling",
|
"betrieb": true, "wartung": true, "instandhaltung": true, "reinigung": true,
|
||||||
"zentrifuge", "centrifuge", "autoklav", "autoclave", "saege",
|
"bewegung": true, "beweglich": true, "feststehend": true, "teil": true,
|
||||||
"kreissaege", "circular_saw", "hobel", "fraese", "drehmaschine",
|
"teile": true, "oeffnung": true, "zugang": true, "gefahr": true,
|
||||||
"lathe", "schleifmaschine", "grinder", "stanze", "stanzpresse",
|
"verletzung": true, "quetsch": true, "scher": true, "schneid": true,
|
||||||
"infusion", "beatmung", "ventilator", "patient",
|
"stoss": true, "schlag": true, "einzug": true, "brand": true,
|
||||||
"lebensmittel", "food", "pharma", "verpackung", "packaging",
|
"motor": true, "antrieb": true, "achse": true, "achsen": true,
|
||||||
"seilnetz", "kletterseil", "schaukel", "rutsche",
|
"kabel": true, "leitung": true, "schaltschrank": true, "spannung": true,
|
||||||
"gabelstapler", "forklift", "flurfoerder",
|
"schutz": true, "gehaeuse": true, "oberflaeche": true, "boden": true,
|
||||||
|
"leitfaehig": true, "elektrisch": true, "mechanisch": true,
|
||||||
|
"bedienfeld": true, "display": true, "anzeige": true,
|
||||||
|
"energie": true, "druck": true, "temperatur": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// isPatternRelevant checks whether a pattern match is relevant to the actual
|
// isPatternRelevant checks whether a pattern match is relevant to the actual
|
||||||
// machine described in the narrative. A pattern is considered irrelevant if its
|
// machine described in the narrative. Uses narrative vocabulary overlap:
|
||||||
// zone or scenario contains machine-specific terms that don't appear in the
|
// if the pattern's zone/scenario contains machine-specific words (not generic
|
||||||
// narrative or component list.
|
// safety terms) and NONE of them appear in the narrative → irrelevant.
|
||||||
func isPatternRelevant(mp iace.PatternMatch, narrative string, compNames []string) bool {
|
func isPatternRelevant(mp iace.PatternMatch, narrative string, compNames []string) bool {
|
||||||
patternText := iace.NormalizeDEPublic(mp.ZoneDE + " " + mp.ScenarioDE + " " + mp.PatternName)
|
patternText := iace.NormalizeDEPublic(mp.ZoneDE + " " + mp.ScenarioDE)
|
||||||
narrativeNorm := iace.NormalizeDEPublic(narrative)
|
narrativeNorm := iace.NormalizeDEPublic(narrative)
|
||||||
|
|
||||||
// Check if pattern mentions machine-specific terms absent from narrative
|
// Extract machine-specific words from pattern (not generic safety terms)
|
||||||
for _, term := range machineSpecificTerms {
|
patternWords := strings.Fields(patternText)
|
||||||
if !strings.Contains(patternText, term) {
|
var specificWords []string
|
||||||
|
for _, w := range patternWords {
|
||||||
|
// Clean punctuation
|
||||||
|
w = strings.Trim(w, ".,;:!?()/-")
|
||||||
|
if len(w) < 5 || genericSafetyTerms[w] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Pattern mentions this machine-specific term — check if machine has it
|
specificWords = append(specificWords, w)
|
||||||
if strings.Contains(narrativeNorm, term) {
|
}
|
||||||
continue // Machine has this term, pattern is relevant
|
|
||||||
|
// If pattern has no specific words, it's generic → always relevant
|
||||||
|
if len(specificWords) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if at least one specific word appears in the narrative or components
|
||||||
|
for _, sw := range specificWords {
|
||||||
|
if strings.Contains(narrativeNorm, sw) {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
// Also check component names
|
|
||||||
found := false
|
|
||||||
for _, cn := range compNames {
|
for _, cn := range compNames {
|
||||||
if strings.Contains(cn, term) {
|
if strings.Contains(cn, sw) {
|
||||||
found = true
|
return true
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
|
||||||
return false // Pattern mentions a machine type we don't have
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
|
// No specific word found in narrative → pattern is for a different machine
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// categoryHazardCap returns the maximum number of hazards to generate per category.
|
||||||
|
// Caps are based on typical ISO 12100 risk assessment proportions:
|
||||||
|
// - Core physical categories (mechanical, electrical): scale with component count
|
||||||
|
// - Secondary categories (thermal, noise, material): smaller fixed caps
|
||||||
|
// - Software/IT/organizational categories: minimal (these are usually covered by
|
||||||
|
// other standards like IEC 62443, not ISO 12100 machinery risk assessment)
|
||||||
|
func categoryHazardCap(cat string, componentCount int) int {
|
||||||
|
// Core machinery hazard categories — scale with complexity
|
||||||
|
switch cat {
|
||||||
|
case "mechanical_hazard":
|
||||||
|
// Typically 1-3 hazards per component (quetschen, scheren, stoss...)
|
||||||
|
cap := componentCount * 3
|
||||||
|
if cap < 15 {
|
||||||
|
cap = 15
|
||||||
|
}
|
||||||
|
if cap > 60 {
|
||||||
|
cap = 60
|
||||||
|
}
|
||||||
|
return cap
|
||||||
|
case "electrical_hazard":
|
||||||
|
// Typically 8-15 for a standard machine
|
||||||
|
cap := componentCount
|
||||||
|
if cap < 8 {
|
||||||
|
cap = 8
|
||||||
|
}
|
||||||
|
if cap > 20 {
|
||||||
|
cap = 20
|
||||||
|
}
|
||||||
|
return cap
|
||||||
|
case "pneumatic_hydraulic":
|
||||||
|
return 8
|
||||||
|
case "thermal_hazard":
|
||||||
|
return 6
|
||||||
|
case "noise_vibration":
|
||||||
|
return 4
|
||||||
|
case "material_environmental":
|
||||||
|
return 6
|
||||||
|
case "ergonomic", "ergonomic_hazard":
|
||||||
|
return 4
|
||||||
|
case "fire_explosion":
|
||||||
|
return 4
|
||||||
|
case "radiation_hazard", "emc_hazard":
|
||||||
|
return 3
|
||||||
|
// Software/IT/organizational — minimal for machinery assessment
|
||||||
|
case "safety_function_failure":
|
||||||
|
return 5
|
||||||
|
case "software_fault":
|
||||||
|
return 3
|
||||||
|
case "configuration_error":
|
||||||
|
return 3
|
||||||
|
case "hmi_error":
|
||||||
|
return 3
|
||||||
|
case "maintenance_hazard":
|
||||||
|
return 4
|
||||||
|
case "mode_confusion":
|
||||||
|
return 2
|
||||||
|
default:
|
||||||
|
return 3
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalizeZoneKey reduces a zone string to its core components for better dedup.
|
// normalizeZoneKey reduces a zone string to its core components for better dedup.
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ var synonymSets = [][]string{
|
|||||||
{"schneid", "cut", "schnitt"},
|
{"schneid", "cut", "schnitt"},
|
||||||
{"stoss", "schlag", "impact", "treff", "aufprall"},
|
{"stoss", "schlag", "impact", "treff", "aufprall"},
|
||||||
{"einzug", "fang", "erfass", "entangle", "wickel"},
|
{"einzug", "fang", "erfass", "entangle", "wickel"},
|
||||||
{"elektrisch", "stromschlag", "electric", "beruehr", "spannungsfuehr"},
|
{"elektrisch", "stromschlag", "electric", "beruehr", "spannungsfuehr", "koerperdurchstroemung"},
|
||||||
{"brand", "feuer", "fire", "kabelbrand", "kurzschluss"},
|
{"brand", "feuer", "fire", "kabelbrand", "kurzschluss", "ueberlast", "ueberstrom"},
|
||||||
{"verbrenn", "burn", "heiss", "thermisch"},
|
{"verbrenn", "burn", "heiss", "thermisch", "lichtbogen"},
|
||||||
{"laerm", "noise", "gehoer", "schall"},
|
{"laerm", "noise", "gehoer", "schall", "dezibel"},
|
||||||
{"vibration", "schwing"},
|
{"vibration", "schwing"},
|
||||||
{"ergonom", "haltung", "handhabung", "bedien"},
|
{"ergonom", "haltung", "handhabung", "bedien", "bewegungsapparat"},
|
||||||
{"kuehlschmierstoff", "kss", "aerosol", "coolant"},
|
{"kuehlschmierstoff", "kss", "aerosol", "coolant"},
|
||||||
{"pneumat", "druckluft", "compressed"},
|
{"pneumat", "druckluft", "compressed"},
|
||||||
{"hydraul", "druck", "pressure"},
|
{"hydraul", "druck", "pressure"},
|
||||||
@@ -48,6 +48,9 @@ var synonymSets = [][]string{
|
|||||||
{"stolper", "rutsch", "slip", "trip"},
|
{"stolper", "rutsch", "slip", "trip"},
|
||||||
{"leckage", "austreten", "leak"},
|
{"leckage", "austreten", "leak"},
|
||||||
{"einstich", "puncture", "spritz"},
|
{"einstich", "puncture", "spritz"},
|
||||||
|
{"isolat", "kriechstrom", "schutzleiter", "erdung", "indirekt"},
|
||||||
|
{"luft", "kriechstreck", "beruehrer", "oberflaeche", "leitfaehig"},
|
||||||
|
{"emv", "strahlung", "radiation", "elektromagnet", "stoereinfluss"},
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompareBenchmark runs the full comparison between Ground Truth and engine output.
|
// CompareBenchmark runs the full comparison between Ground Truth and engine output.
|
||||||
|
|||||||
Reference in New Issue
Block a user