File size: 2,695 Bytes
5c0175e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Layer 7: Folder Intelligence Engine
// Detects projection / stereo / passthrough / fisheye patterns in folder paths.

import { FOLDER_PATTERNS, LayerResult, Projection, Stereo, LensType } from "../types";

export interface FolderAnalysis {
  projection: Projection | null;
  stereo: Stereo | null;
  lens: LensType | null;
  passthrough: boolean;
  matchedFolders: string[];
}

export function analyzeFolder(folderPath: string): LayerResult<FolderAnalysis> {
  const lower = folderPath.toLowerCase();
  const segments = lower.split("/").filter(Boolean);
  const matched: string[] = [];

  // Boundary-aware matcher for short tokens (ar, mr, ou, tb).
  const boundaryMatch = (text: string, token: string): boolean => {
    if (token.length <= 3) {
      const re = new RegExp(`(^|[^a-z0-9])${token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}([^a-z0-9]|$)`, "i");
      return re.test(text);
    }
    return text.includes(token);
  };

  let projection: Projection | null = null;
  let stereo: Stereo | null = null;
  let lens: LensType | null = null;
  let passthrough = false;

  for (const seg of segments) {
    if (FOLDER_PATTERNS.passthrough.some((p) => boundaryMatch(seg, p))) {
      passthrough = true;
      matched.push(`passthrough:${seg}`);
    }
    if (FOLDER_PATTERNS.vr180.some((p) => boundaryMatch(seg, p)) && !projection) {
      projection = "vr180";
      matched.push(`projection:${seg}`);
    }
    if (FOLDER_PATTERNS.vr360.some((p) => boundaryMatch(seg, p)) && !projection) {
      projection = "vr360";
      matched.push(`projection:${seg}`);
    }
    if (FOLDER_PATTERNS.sbs.some((p) => boundaryMatch(seg, p)) && !stereo) {
      stereo = "sbs";
      matched.push(`stereo:${seg}`);
    }
    if (FOLDER_PATTERNS.ou.some((p) => boundaryMatch(seg, p)) && !stereo) {
      stereo = "ou";
      matched.push(`stereo:${seg}`);
    }
    if (
      FOLDER_PATTERNS.fisheye.some((p) => boundaryMatch(seg, p)) &&
      !lens
    ) {
      // Dual fisheye if the folder explicitly says "dual"
      lens = seg.includes("dual") ? "dual_fisheye" : "fisheye";
      matched.push(`lens:${seg}`);
    }
  }

  const categoryCount = [
    projection !== null,
    stereo !== null,
    lens !== null,
    passthrough,
  ].filter(Boolean).length;
  const confidence = Math.min(0.4 + categoryCount * 0.1, 0.75);

  return {
    layer: 7,
    name: "Folder Intelligence",
    confidence,
    source: "folder",
    data: { projection, stereo, lens, passthrough, matchedFolders: matched },
    notes: matched.length > 0
      ? `Matched: ${matched.join(", ")}`
      : "No folder patterns matched",
  };
}