99 lines
3.1 KiB
Go
99 lines
3.1 KiB
Go
package service
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"materialanalyzer/internal/model"
|
|
)
|
|
|
|
func BuildMaterialSpecific(p model.Product, visual model.VisualFeatures, texture model.TextureFeatures, semantic model.SemanticFeatures) map[string]interface{} {
|
|
family := MaterialFamily(p.Category, p.Material)
|
|
out := map[string]interface{}{
|
|
"family": family,
|
|
"source_category": p.Category,
|
|
"source_material": p.Material,
|
|
"size_label": p.SizeLabel,
|
|
"width_in": p.WidthIn,
|
|
"length_in": p.LengthIn,
|
|
"dominant_color_name": semantic.ColorFamily,
|
|
"confidence": map[string]float64{
|
|
"family": 0.86,
|
|
"dominant_color_name": 0.88,
|
|
"surface_finish": semantic.FieldConfidence["surface_finish"],
|
|
"visual_style": semantic.FieldConfidence["visual_style"],
|
|
},
|
|
}
|
|
|
|
switch family {
|
|
case "wood":
|
|
out["species"] = inferSpecies(p)
|
|
out["grain_direction"] = orientationLabel(texture.PrimaryOrientationDeg)
|
|
out["knot_density"] = densityLabel(texture.EdgeDensity, 0.08, 0.17)
|
|
out["cathedral_density"] = densityLabel(texture.OrientationVariance, 0.48, 0.72)
|
|
case "tile", "stone_tile":
|
|
out["surface_look"] = tileSurfaceLook(p, semantic)
|
|
out["stone_type"] = inferStoneType(p)
|
|
out["vein_density"] = densityLabel(texture.EdgeDensity, 0.06, 0.14)
|
|
out["vein_orientation"] = orientationLabel(texture.PrimaryOrientationDeg)
|
|
out["grout_color"] = "unknown"
|
|
out["tile_visual_variation"] = semantic.Variation
|
|
case "vinyl":
|
|
out["printed_pattern"] = semantic.VisualStyle
|
|
out["emboss_depth"] = densityLabel(texture.TextureFrequency, 0.12, 0.24)
|
|
out["surface_finish"] = semantic.SurfaceFinish
|
|
out["wood_or_stone_look"] = vinylLook(p, semantic)
|
|
default:
|
|
out["texture_density"] = densityLabel(texture.TextureFrequency, 0.12, 0.24)
|
|
out["surface_finish"] = semantic.SurfaceFinish
|
|
}
|
|
|
|
_ = visual
|
|
return out
|
|
}
|
|
|
|
func densityLabel(v, medium, high float64) string {
|
|
switch {
|
|
case v >= high:
|
|
return "High"
|
|
case v >= medium:
|
|
return "Medium"
|
|
default:
|
|
return "Low"
|
|
}
|
|
}
|
|
|
|
func inferStoneType(p model.Product) string {
|
|
text := strings.ToLower(p.Material + " " + p.StyleName)
|
|
for _, s := range []string{"marble", "travertine", "slate", "limestone", "granite", "terrazzo", "concrete", "cement"} {
|
|
if strings.Contains(text, s) {
|
|
return strings.Title(s)
|
|
}
|
|
}
|
|
if strings.Contains(text, "stone") {
|
|
return "Stone"
|
|
}
|
|
return "Unknown"
|
|
}
|
|
|
|
func tileSurfaceLook(p model.Product, semantic model.SemanticFeatures) string {
|
|
text := strings.ToLower(p.Material + " " + p.StyleName + " " + semantic.VisualStyle)
|
|
if containsAnyText(text, "oak", "maple", "hickory", "walnut", "pine", "wood") {
|
|
return "wood_look"
|
|
}
|
|
if containsAnyText(text, "marble", "stone", "slate", "travertine", "limestone", "granite") {
|
|
return "stone_look"
|
|
}
|
|
return "tile"
|
|
}
|
|
|
|
func vinylLook(p model.Product, semantic model.SemanticFeatures) string {
|
|
text := strings.ToLower(p.Material + " " + p.StyleName + " " + semantic.VisualStyle)
|
|
if containsAnyText(text, "marble", "stone", "slate", "travertine", "tile") {
|
|
return "stone_look"
|
|
}
|
|
if containsAnyText(text, "oak", "maple", "hickory", "walnut", "pine", "wood") {
|
|
return "wood_look"
|
|
}
|
|
return "unknown"
|
|
}
|