relateby-pattern 0.4.2

Core pattern data structures
Documentation
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
"""
Type stubs for pattern_core Python bindings.

This module provides Python-friendly bindings for pattern-core, enabling
Python developers to programmatically construct and operate on Pattern and Subject instances.
"""

from typing import Any, Callable, Dict, Generic, List, Optional, Set, Tuple, TypeVar, Union, overload

# Type variables for generic pattern operations
T = TypeVar('T')
V = TypeVar('V')
R = TypeVar('R')  # For para return type

class Value:
    """
    Value represents property value types that can be stored in Subject properties.

    Supports standard types (string, int, decimal, boolean, symbol) and extended types
    (array, map, range, measurement).
    """

    @staticmethod
    def string(s: str) -> 'Value':
        """
        Create a string value.

        Args:
            s: String value

        Returns:
            String value instance
        """
        ...

    @staticmethod
    def int(i: int) -> 'Value':
        """
        Create an integer value.

        Args:
            i: Integer value

        Returns:
            Integer value instance
        """
        ...

    @staticmethod
    def decimal(f: float) -> 'Value':
        """
        Create a decimal value.

        Args:
            f: Decimal/float value

        Returns:
            Decimal value instance
        """
        ...

    @staticmethod
    def boolean(b: bool) -> 'Value':
        """
        Create a boolean value.

        Args:
            b: Boolean value

        Returns:
            Boolean value instance
        """
        ...

    @staticmethod
    def symbol(s: str) -> 'Value':
        """
        Create a symbol value.

        Args:
            s: Symbol identifier string

        Returns:
            Symbol value instance
        """
        ...

    @staticmethod
    def array(items: List[Any]) -> 'Value':
        """
        Create an array value.

        Args:
            items: List of Value instances

        Returns:
            Array value instance
        """
        ...

    @staticmethod
    def map(items: Dict[str, Any]) -> 'Value':
        """
        Create a map value.

        Args:
            items: Dictionary mapping strings to Value instances

        Returns:
            Map value instance
        """
        ...

    @staticmethod
    def range(lower: Optional[float] = None, upper: Optional[float] = None) -> 'Value':
        """
        Create a range value.

        Args:
            lower: Lower bound (inclusive), None for unbounded
            upper: Upper bound (inclusive), None for unbounded

        Returns:
            Range value instance
        """
        ...

    @staticmethod
    def measurement(value: float, unit: str) -> 'Value':
        """
        Create a measurement value.

        Args:
            value: Numeric measurement value
            unit: Unit string (e.g., "meters", "kg")

        Returns:
            Measurement value instance
        """
        ...

    def as_string(self) -> str:
        """Extract string value. Raises TypeError if not a string."""
        ...

    def as_int(self) -> int:
        """Extract integer value. Raises TypeError if not an integer."""
        ...

    def as_decimal(self) -> float:
        """Extract decimal value. Raises TypeError if not a decimal."""
        ...

    def as_boolean(self) -> bool:
        """Extract boolean value. Raises TypeError if not a boolean."""
        ...

    def as_array(self) -> List[Any]:
        """Extract array value. Raises TypeError if not an array."""
        ...

    def as_map(self) -> Dict[str, Any]:
        """Extract map value. Raises TypeError if not a map."""
        ...

class Subject:
    """
    Self-descriptive value type with identity, labels, and properties.

    Subjects can represent nodes in a graph or any entity with properties and labels.
    """

    def __init__(
        self,
        identity: str,
        labels: Optional[Set[str]] = None,
        properties: Optional[Dict[str, Value]] = None
    ) -> None:
        """
        Create a new Subject.

        Args:
            identity: Symbol identifier (string)
            labels: Set of label strings (optional)
            properties: Map of property names to Value instances (optional)
        """
        ...

    @property
    def identity(self) -> str:
        """Get the subject's identity symbol."""
        ...

    def get_labels(self) -> Set[str]:
        """Get all labels as a Python set."""
        ...

    def get_properties(self) -> Dict[str, Any]:
        """Get all properties as a Python dictionary."""
        ...

    def add_label(self, label: str) -> None:
        """
        Add a label to the subject.

        Args:
            label: Label string to add
        """
        ...

    def remove_label(self, label: str) -> None:
        """
        Remove a label from the subject.

        Args:
            label: Label string to remove
        """
        ...

    def has_label(self, label: str) -> bool:
        """
        Check if subject has a specific label.

        Args:
            label: Label string to check

        Returns:
            True if label exists, False otherwise
        """
        ...

    def get_property(self, name: str) -> Optional[Value]:
        """
        Get property value by name.

        Args:
            name: Property name

        Returns:
            Value instance if property exists, None otherwise
        """
        ...

    def set_property(self, name: str, value: Union[Value, str, int, float, bool, list, dict]) -> None:
        """
        Set property value.

        Args:
            name: Property name
            value: Property value (Value instance or Python native type)
        """
        ...

    def remove_property(self, name: str) -> None:
        """
        Remove a property.

        Args:
            name: Property name to remove
        """
        ...

    @staticmethod
    def from_id(identity: str) -> 'Subject':
        """
        Create an identity-only Subject with no labels or properties.

        Use as a lightweight reference for add_relationship source/target args
        when you only have an identity string.

        Example::

            g.add_relationship(rel, Subject.from_id("alice"), Subject.from_id("bob"))
        """
        ...

    @staticmethod
    def build(identity: str) -> 'SubjectBuilder':
        """
        Create a SubjectBuilder for fluent subject construction.

        Args:
            identity: The identity string for the subject

        Returns:
            SubjectBuilder for chaining

        Example:
            >>> subject = Subject.build("alice").label("Person").property("name", "Alice").done()
        """
        ...

class Pattern(Generic[V]):
    """
    Recursive, nested structure (s-expression-like) that can hold any value type.

    Pattern[V] is fully generic - V can be primitives, objects, or even other Patterns,
    enabling nesting types like Pattern[Pattern[T]].

    A pattern consists of a valu and zero or more elements (patterns).
    The value decorates or says something about the pattern represented by the elements.
    Atomic patterns have no elements.
    """

    @staticmethod
    def point(value: Any) -> 'Pattern':
        """
        Create an atomic pattern (no elements).

        Args:
            value: The value for this pattern (any Python type)

        Returns:
            Atomic Pattern instance
        """
        ...

    @staticmethod
    def pattern(value: Any, elements: List['Pattern']) -> 'Pattern':
        """
        Create a pattern with value decoration and elements.

        The value decorates or describes the pattern represented by the elements.

        Args:
            value: The value decoration for this pattern
            elements: List of Pattern instances that form the pattern

        Returns:
            Pattern instance with value and elements
        """
        ...

    @staticmethod
    def of(value: Any) -> 'Pattern':
        """
        Alias for point(). Lift a value into a Pattern.

        This follows the functional programming convention where
        'of' is used to lift a value into a functor/applicative.

        Args:
            value: The value for this pattern (any Python type)

        Returns:
            Atomic Pattern instance
        """
        ...

    @staticmethod
    def from_values(values: List[Any]) -> List['Pattern']:
        """
        Convert a list of values into a list of patterns.

        Applies Pattern.of() (which is Pattern.point()) uniformly to every value,
        lifting each into a Pattern. Works on any type including Patterns.

        Args:
            values: List of values to convert (any type)

        Returns:
            List of Pattern instances

        Example:
            >>> # From primitives
            >>> patterns = Pattern.from_values([1, 2, 3])
            >>> len(patterns)
            3
            >>> # From patterns (creates Pattern<Pattern<T>>)
            >>> p1 = Pattern.point("a")
            >>> patterns = Pattern.from_values([p1])
            >>> patterns[0].value  # This is a Pattern!
            Pattern(value="a", elements=0)
        """
        ...

    @property
    def value(self) -> Any:
        """Get the pattern's value (can be any Python type including Pattern)."""
        ...

    @property
    def elements(self) -> List['Pattern']:
        """Get the pattern's elements (the patterns that make up this pattern)."""
        ...

    def is_atomic(self) -> bool:
        """
        Check if pattern is atomic (has no elements).

        Returns:
            True if pattern has no elements, False otherwise
        """
        ...

    def length(self) -> int:
        """
        Get the number of direct elements in this pattern.

        Returns:
            Number of elements
        """
        ...

    def size(self) -> int:
        """
        Get the total number of nodes in the pattern tree.

        Returns:
            Total node count (including this node)
        """
        ...

    def depth(self) -> int:
        """
        Get the maximum nesting depth of the pattern.

        Returns:
            Maximum depth (0 for atomic patterns)
        """
        ...

    def values(self) -> List[Any]:
        """
        Get all values as a flat list (pre-order traversal).

        Returns:
            List of all values (any type) in traversal order
        """
        ...

    def any_value(self, predicate: Callable[[Any], bool]) -> bool:
        """
        Check if any value satisfies the predicate.

        Args:
            predicate: Function that takes a value and returns bool

        Returns:
            True if any value satisfies predicate, False otherwise
        """
        ...

    def all_values(self, predicate: Callable[[Any], bool]) -> bool:
        """
        Check if all values satisfy the predicate.

        Args:
            predicate: Function that takes a value and returns bool

        Returns:
            True if all values satisfy predicate, False otherwise
        """
        ...

    def filter(self, predicate: Callable[['Pattern'], bool]) -> List['Pattern']:
        """
        Filter patterns by predicate.

        Args:
            predicate: Function that takes a Pattern and returns bool

        Returns:
            List of patterns that satisfy predicate
        """
        ...

    def find_first(self, predicate: Callable[['Pattern'], bool]) -> Optional['Pattern']:
        """
        Find first pattern matching predicate.

        Args:
            predicate: Function that takes a Pattern and returns bool

        Returns:
            First matching pattern, or None if not found
        """
        ...

    def matches(self, other: 'Pattern') -> bool:
        """
        Check if patterns have identical structure.

        Args:
            other: Pattern to compare with

        Returns:
            True if patterns match structurally
        """
        ...

    def contains(self, other: 'Pattern') -> bool:
        """
        Check if this pattern contains other as a subpattern.

        Args:
            other: Pattern to search for

        Returns:
            True if other is a subpattern
        """
        ...

    def map(self, func: Callable[[Any], Any]) -> 'Pattern':
        """
        Transform values while preserving structure.

        Args:
            func: Function that takes a value and returns a new value

        Returns:
            New Pattern with transformed values
        """
        ...

    def fold(self, init: Any, func: Callable[[Any, Any], Any]) -> Any:
        """
        Fold over all values with an accumulator.

        Args:
            init: Initial accumulator value
            func: Function that takes (accumulator, value) and returns new accumulator

        Returns:
            Final accumulator value
        """
        ...

    def para(self, func: Callable[['Pattern[V]', List[R]], R]) -> R:
        """
        Paramorphism: structure-aware fold with access to pattern structure.

        At each node, applies func to (current_pattern, element_results) where
        element_results is a list of results from recursively processing elements.
        Evaluation is bottom-up (elements before parents) and left-to-right.

        Atomic patterns receive an empty list for element_results.

        This enables structure-dependent computations like depth-weighted sums,
        computing multiple statistics in one pass (sum, count, depth), and
        structure-preserving transformations.

        Args:
            func: Function taking (Pattern[V], List[R]) -> R
                  - First arg is the pattern at current position (including value and elements)
                  - Second arg is list of results from recursive para on elements
                  - Returns result of type R

        Returns:
            Result of applying func across the entire pattern structure

        Example:
            >>> # Depth-weighted sum: value + sum of element results
            >>> pattern = Pattern.pattern(1, [
            ...     Pattern.point(2),
            ...     Pattern.pattern(3, [Pattern.point(4)])
            ... ])
            >>> result = pattern.para(lambda p, rs: p.value + sum(rs))
            >>> # Result: 1 + (2 + 0) + (3 + (4 + 0)) = 1 + 2 + 7 = 10

            >>> # Atomic pattern receives empty list
            >>> atomic = Pattern.point(5)
            >>> result = atomic.para(lambda p, rs: p.value + sum(rs))
            >>> # Result: 5 + 0 = 5

            >>> # Equivalent to fold for simple value aggregation
            >>> result = pattern.para(lambda p, rs: p.value + sum(rs))
            >>> fold_result = pattern.fold(0, lambda acc, v: acc + v)
            >>> # Both produce same sum of values
        """
        ...

    def combine(self, other: 'Pattern') -> 'Pattern':
        """
        Combine two patterns associatively.

        Args:
            other: Pattern to combine with

        Returns:
            Combined Pattern
        """
        ...

    @staticmethod
    def zip3(
        left: List['Pattern'],
        right: List['Pattern'],
        values: List[Any]
    ) -> List['Pattern']:
        """
        Create patterns by combining three lists pointwise (zipWith3).

        Takes three lists and combines them element-wise to create relationship patterns.
        Each resulting pattern has value from values list and elements [left, right].

        This is useful for creating relationships from separate lists of source nodes,
        target nodes, and relationship values.

        Args:
            left: First list of patterns (e.g., source nodes)
            right: Second list of patterns (e.g., target nodes)
            values: List of values for the new patterns (e.g., relationship types)

        Returns:
            List of patterns where each has value from values and elements [left[i], right[i]]

        Example:
            >>> sources = [Pattern.point("Alice"), Pattern.point("Bob")]
            >>> targets = [Pattern.point("Company"), Pattern.point("Project")]
            >>> rel_types = ["WORKS_FOR", "MANAGES"]
            >>> relationships = Pattern.zip3(sources, targets, rel_types)
        """
        ...

    @staticmethod
    def zip_with(
        left: List['Pattern'],
        right: List['Pattern'],
        value_fn: Callable[['Pattern', 'Pattern'], Any]
    ) -> List['Pattern']:
        """
        Create patterns by applying a function to pairs from two lists (zipWith2).

        Takes two lists of patterns and applies a function to each pair to compute
        the value for the resulting pattern. Useful when relationship values are
        derived from the patterns being connected.

        Args:
            left: First list of patterns (e.g., source nodes)
            right: Second list of patterns (e.g., target nodes)
            value_fn: Function that computes value from each pair of patterns

        Returns:
            List of patterns where each has value computed by value_fn

        Example:
            >>> people = [Pattern.point("Alice"), Pattern.point("Bob")]
            >>> companies = [Pattern.point("TechCorp"), Pattern.point("StartupInc")]
            >>> relationships = Pattern.zip_with(people, companies,
            ...     lambda p, c: f"{p.value}_WORKS_AT_{c.value}")
        """
        ...

    def extract(self) -> Any:
        """
        Extract value at current position (comonad operation).

        Returns:
            The pattern's value (can be any type)
        """
        ...

    def extend(self, func: Callable[['Pattern'], Any]) -> 'Pattern':
        """
        Apply function to all contexts (comonad operation).

        Args:
            func: Function that takes a Pattern and returns a value

        Returns:
            New Pattern with func applied to all contexts
        """
        ...

    def depth_at(self) -> 'Pattern':
        """
        Decorate each position with its depth.

        Returns:
            Pattern where each value is replaced with its depth (int)
        """
        ...

    def size_at(self) -> 'Pattern':
        """
        Decorate each position with its subtree size.

        Returns:
            Pattern where each value is replaced with subtree size (int)
        """
        ...

    def indices_at(self) -> 'Pattern':
        """
        Decorate each position with path from root.

        Returns:
            Pattern where each value is replaced with path indices (List[int])
        """
        ...

    def validate(self, rules: 'ValidationRules') -> None:
        """
        Validate pattern structure against rules.

        Args:
            rules: ValidationRules instance

        Raises:
            ValidationError: If validation fails
        """
        ...

    def analyze_structure(self) -> 'StructureAnalysis':
        """
        Analyze pattern structure.

        Returns:
            StructureAnalysis instance with analysis results
        """
        ...

class ValidationRules:
    """Configuration for pattern validation."""

    def __init__(
        self,
        max_depth: Optional[int] = None,
        max_elements: Optional[int] = None
    ) -> None:
        """
        Create validation rules.

        Args:
            max_depth: Maximum allowed nesting depth (None for unlimited)
            max_elements: Maximum allowed elements per pattern (None for unlimited)
        """
        ...

    @property
    def max_depth(self) -> Optional[int]:
        """Get maximum depth constraint."""
        ...

    @property
    def max_elements(self) -> Optional[int]:
        """Get maximum elements constraint."""
        ...

class ValidationError(ValueError):
    """Error raised when pattern validation fails."""

    @property
    def message(self) -> str:
        """Get error message."""
        ...

    @property
    def rule(self) -> str:
        """Get name of violated rule."""
        ...

    @property
    def location(self) -> List[str]:
        """Get location in pattern where violation occurred."""
        ...

class StructureAnalysis:
    """Result of pattern structure analysis."""

    @property
    def summary(self) -> str:
        """Get human-readable summary."""
        ...

    @property
    def depth_distribution(self) -> List[int]:
        """Get count of nodes at each depth."""
        ...

    @property
    def element_counts(self) -> List[int]:
        """Get element counts at each level."""
        ...

    @property
    def nesting_patterns(self) -> List[str]:
        """Get description of nesting patterns."""
        ...

class SubjectBuilder:
    """
    Fluent Subject builder.

    Created via ``Subject.build(identity)``. Chain ``.label()`` and ``.property()``
    calls, then finalize with ``.done()``.

    Example::

        subject = Subject.build("alice").label("Person").property("name", "Alice").done()
    """

    def label(self, label: str) -> 'SubjectBuilder':
        """Add a label. Returns self for chaining."""
        ...

    def property(self, key: str, value: Union[Value, str, int, float, bool, list, dict]) -> 'SubjectBuilder':
        """Add a property. Accepts native Python types. Returns self for chaining."""
        ...

    def done(self) -> Subject:
        """Finalize the builder and return the constructed Subject."""
        ...


class StandardGraph:
    """
    Ergonomic graph builder and query interface.

    Zero configuration — create, add elements, and query without managing
    classifiers or policies.

    Example::

        g = StandardGraph()
        print(g.node_count)  # 0
    """

    def __init__(self) -> None:
        """Create an empty StandardGraph."""
        ...

    @staticmethod
    def from_patterns(patterns: List[Pattern]) -> 'StandardGraph':
        """Create from a list of Pattern instances."""
        ...

    # --- Element addition ---

    def add_node(self, subject: Subject) -> 'StandardGraph':
        """Add a node to the graph. Returns self for chaining."""
        ...

    def add_relationship(self, subject: Subject, source: Subject, target: Subject) -> 'StandardGraph':
        """Add a relationship to the graph. Returns self for chaining.
        Pass Subject objects for source and target; use Subject.from_id("id") when you only have a string."""
        ...

    def add_walk(self, subject: Subject, relationships: List[Subject]) -> 'StandardGraph':
        """Add a walk to the graph. Returns self for chaining.
        Pass a list of Subject objects; use Subject.from_id("id") for string-only references."""
        ...

    def add_annotation(self, subject: Subject, element: Subject) -> 'StandardGraph':
        """Add an annotation to the graph. Returns self for chaining.
        Pass the Subject for the annotated element; use Subject.from_id("id") for string-only references."""
        ...

    def add_pattern(self, pattern: Pattern) -> 'StandardGraph':
        """Add a single pattern (classified by shape). Returns self for chaining."""
        ...

    # --- Element access ---

    def node(self, id: str) -> Optional[Pattern]:
        """Get a node by identity. Returns None if not found."""
        ...

    def relationship(self, id: str) -> Optional[Pattern]:
        """Get a relationship by identity. Returns None if not found."""
        ...

    def walk(self, id: str) -> Optional[Pattern]:
        """Get a walk by identity. Returns None if not found."""
        ...

    def annotation(self, id: str) -> Optional[Pattern]:
        """Get an annotation by identity. Returns None if not found."""
        ...

    # --- Counts ---

    @property
    def node_count(self) -> int:
        """Number of nodes."""
        ...

    @property
    def relationship_count(self) -> int:
        """Number of relationships."""
        ...

    @property
    def walk_count(self) -> int:
        """Number of walks."""
        ...

    @property
    def annotation_count(self) -> int:
        """Number of annotations."""
        ...

    @property
    def is_empty(self) -> bool:
        """True if the graph has no elements."""
        ...

    @property
    def has_conflicts(self) -> bool:
        """True if any reconciliation conflicts exist."""
        ...

    # --- Iteration ---

    def nodes(self) -> List[Tuple[str, Pattern]]:
        """All nodes as list of (id, Pattern) tuples."""
        ...

    def relationships(self) -> List[Tuple[str, Pattern]]:
        """All relationships as list of (id, Pattern) tuples."""
        ...

    def walks(self) -> List[Tuple[str, Pattern]]:
        """All walks as list of (id, Pattern) tuples."""
        ...

    def annotations(self) -> List[Tuple[str, Pattern]]:
        """All annotations as list of (id, Pattern) tuples."""
        ...

    # --- Graph-native queries ---

    def source(self, rel_id: str) -> Optional[Pattern]:
        """Source node of a relationship. Returns None if not found."""
        ...

    def target(self, rel_id: str) -> Optional[Pattern]:
        """Target node of a relationship. Returns None if not found."""
        ...

    def neighbors(self, node_id: str) -> List[Pattern]:
        """All neighbor nodes of a node (both directions)."""
        ...

    def degree(self, node_id: str) -> int:
        """Number of incident relationships for a node."""
        ...

    def __repr__(self) -> str: ...
    def __len__(self) -> int: ...


__all__ = [
    'Value',
    'Subject',
    'SubjectBuilder',
    'Pattern',
    'ValidationRules',
    'ValidationError',
    'StructureAnalysis',
    'StandardGraph',
]