classTextGeneralization
final class TextGeneralization
Collapses several patterns into the one shape that covers all of them.
Joining branches or iterations of a loop can produce more strings than a catalog should list. Generalization keeps the text the alternatives agree on and replaces the part they disagree on with a single gap, so the reported shape still matches every string the code can build.
Properties§
public Origin $originMethods§
public function __construct(public Origin $origin)Parameters
$origin | Origin | The origin recorded on gaps this generalization introduces |
public function merge(TextPattern $left, TextPattern $right): TextPatternThe narrowest pattern that covers both inputs.
Parameters
$left | TextPattern | |
$right | TextPattern |
Returns
Test cases 3
Called from 1
Calls 13
- method-call TextPattern::equals() line 33
- method-call TextGeneralization::mergeResolved() line 37
- method-call TextGeneralization::atoms() line 42
- method-call TextGeneralization::commonPrefixLength() line 44
- function-call
minline 45 - function-call
countline 45 - method-call TextGeneralization::commonSuffixLength() line 46
- function-call
array_mergeline 48 - method-call TextGeneralization::rebuild() line 49
- function-call
array_sliceline 49 - new TextHole line 50
- method-call TextGeneralization::gapType() line 50
- static-call TextPattern::fromSegments() line 54
public function mergeResolved(TextPattern $left, TextPattern $right): ?TextPatternThe narrowest pattern covering two fully resolved strings, or null when either has a gap.
Statements are long and are merged often, so the common case of two resolved strings is answered by comparing the strings themselves rather than by walking them character by character.
Parameters
$left | TextPattern | |
$right | TextPattern |
Returns
Called from 1
Calls 10
- method-call TextPattern::text() line 66
- method-call TextGeneralization::sharedPrefixLength() line 72
- function-call
minline 73 - function-call
strlenline 73 - function-call
strrevline 74 - static-call TextPattern::fromSegments() line 76
- new LiteralText line 77
- function-call
substrline 77 - new TextHole line 78
- static-call TypeShape::of() line 78
public function mergeAll(list<TextPattern> $patterns): TextPatternThe narrowest pattern that covers every input.
Parameters
$patterns | list<TextPattern> |
Returns
Test cases 2
Called from 1
Calls 3
- function-call
array_shiftline 98 - static-call TextPattern::empty() line 100
- method-call TextGeneralization::merge() line 104
public function atoms(TextPattern $pattern): list<string|TextHole>The pattern split into single characters and whole gaps, so the two sides align.
Parameters
$pattern | TextPattern |
Returns
list<string|TextHole>Test cases 1
Called from 2
Calls 1
- function-call
strlenline 126
public function commonPrefixLength(
list<string|TextHole> $left,
list<string|TextHole> $right,
): intHow many leading atoms the two sides share.
Returns
intTest cases 1
Called from 1
Calls 3
- function-call
minline 143 - function-call
countline 143 - method-call TextGeneralization::sameAtom() line 145
public function commonSuffixLength(
list<string|TextHole> $left,
list<string|TextHole> $right,
int $limit,
): intHow many trailing atoms the two sides share, without reaching into the prefix.
Parameters
Returns
intTest cases 1
Called from 1
Calls 2
- function-call
countline 161 - method-call TextGeneralization::sameAtom() line 166
Whether two atoms stand for the same thing.
Returns
boolTest cases 1
public function rebuild(list<string|TextHole> $atoms): list<TextSegment>Segments rebuilt from atoms.
Parameters
$atoms | list<string|TextHole> |
Returns
list<TextSegment>Test cases 1
Called from 2
Calls 1
- new LiteralText line 201
public function gapType(TextPattern $left, TextPattern $right): TypeShapeThe type recorded on the introduced gap.
Parameters
$left | TextPattern | |
$right | TextPattern |
Returns
Test cases 1
Called from 1
Calls 3
- method-call TextPattern::isExact() line 212
- static-call TypeShape::of() line 212
- static-call TypeShape::unknown() line 212
Test cases 33§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 13
TextGeneralizationTest::testAtomsSplitTextIntoCharactersAndKeepGapsWholecallsTextGeneralizationTest::testCommonPrefixLengthCountsSharedLeadingAtomscallsTextGeneralizationTest::testCommonSuffixLengthStopsAtTheGivenLimitcallsTextGeneralizationTest::testGapTypeIsAStringOnlyWhenBothSidesResolvedcallsTextGeneralizationTest::testMergeAllFoldsEveryAlternativecallsTextGeneralizationTest::testMergeAllOfNothingIsEmptycallsTextGeneralizationTest::testMergeCoversAGrowingSuffixcallsTextGeneralizationTest::testMergeKeepsWhatTheTwoSidesAgreeOncallsTextGeneralizationTest::testMergeResolvedAnswersOnlyForTwoResolvedStringscallsTextGeneralizationTest::testMergeReturnsTheSameShapeWhenBothSidesAgreecallsTextGeneralizationTest::testRebuildTurnsAtomsBackIntoSegmentscallsTextGeneralizationTest::testSameAtomComparesGapsByOrigincallsTextGeneralizationTest::testSharedPrefixLengthCountsTheLeadingBytesTwoStringsSharecalls
Other tests reaching this symbol 20
BuiltinCallModelTestcallsCallEvaluatorTestcallsCallbackEffectsTestcallsObjectEffectsTestcallsEntryFactoryTestcallsExpressionEvaluatorTestcallsReferenceEvaluatorTestcallsValueDomainTestcallsDomainTestcallsObjectMemoryTestcallsBuilderCallsTestcallsBuilderQueriesTestcallsCallbackModelTestcallsClausesTestcallsGrammarTestcallsModelMetadataTestcallsPredicatesTestcallsQueryStateTestcallsSelectCompilerTestcallsWriteCompilerTestcalls