2
2
from .._jpype_type_conversions import to_python_score
3
3
from _jpyinterpreter import unwrap_python_like_object , add_java_interface
4
4
from dataclasses import dataclass
5
+ from multipledispatch import dispatch
5
6
6
7
from typing import TypeVar , Generic , Union , TYPE_CHECKING , Any , cast , Optional , Type
7
8
@@ -456,7 +457,7 @@ def __init__(self, delegate: '_JavaConstraintAnalysis[Score_]'):
456
457
delegate .constraintRef ()
457
458
458
459
def __str__ (self ):
459
- return self .summary
460
+ return self .summarize
460
461
461
462
@property
462
463
def constraint_ref (self ) -> ConstraintRef :
@@ -485,7 +486,7 @@ def score(self) -> Score_:
485
486
return to_python_score (self ._delegate .score ())
486
487
487
488
@property
488
- def summary (self ) -> str :
489
+ def summarize (self ) -> str :
489
490
return self ._delegate .summarize ()
490
491
491
492
class ScoreAnalysis :
@@ -518,15 +519,19 @@ class ScoreAnalysis:
518
519
constraint_analyses : list[ConstraintAnalysis]
519
520
Individual ConstraintAnalysis instances that make up this ScoreAnalysis.
520
521
521
- summary : str
522
- Returns a diagnostic text
523
- that explains the solution through the `ConstraintMatch` API
524
- to identify which constraints cause that score quality .
522
+ summarize : str
523
+ Returns a diagnostic text that explains the solution through the `ConstraintAnalysis` API to identify which
524
+ Constraints cause that score quality.
525
+ The string is built fresh every time the method is called .
525
526
526
527
In case of an infeasible solution, this can help diagnose the cause of that.
528
+
527
529
Do not parse the return value, its format may change without warning.
528
- Instead, to provide this information in a UI or a service,
529
- use `constraint_analyses` and convert those into a domain-specific API.
530
+ Instead, provide this information in a UI or a service,
531
+ use `constraintAnalyses()`
532
+ and convert those into a domain-specific API.
533
+
534
+ is_solution_initialized : bool
530
535
531
536
Notes
532
537
-----
@@ -539,7 +544,7 @@ def __init__(self, delegate: '_JavaScoreAnalysis'):
539
544
self ._delegate = delegate
540
545
541
546
def __str__ (self ):
542
- return self .summary
547
+ return self .summarize
543
548
544
549
@property
545
550
def score (self ) -> 'Score' :
@@ -562,10 +567,81 @@ def constraint_analyses(self) -> list[ConstraintAnalysis]:
562
567
list ['_JavaConstraintAnalysis[Score]' ], self ._delegate .constraintAnalyses ())
563
568
]
564
569
570
+ @dispatch (str , str )
571
+ def constraint_analysis (self , constraint_package : str , constraint_name : str ) -> ConstraintAnalysis :
572
+ """
573
+ Performs a lookup on `constraint_map`.
574
+
575
+ Parameters
576
+ ----------
577
+ constraint_package : str
578
+ constraint_name : str
579
+
580
+ Returns
581
+ -------
582
+ ConstraintAnalysis
583
+ None if no constraint matches of such constraint are present
584
+ """
585
+ return ConstraintAnalysis (self ._delegate .getConstraintAnalysis (constraint_package , constraint_name ))
586
+
587
+ @dispatch (ConstraintRef )
588
+ def constraint_analysis (self , constraint_ref : ConstraintRef ) -> ConstraintAnalysis :
589
+ """
590
+ Performs a lookup on `constraint_map`.
591
+
592
+ Parameters
593
+ ----------
594
+ constraint_ref : ConstraintRef
595
+
596
+ Returns
597
+ -------
598
+ ConstraintAnalysis
599
+ None if no constraint matches of such constraint are present
600
+ """
601
+ return self .constraint_analysis (constraint_ref .package_name , constraint_ref .constraint_name )
602
+
565
603
@property
566
- def summary (self ) -> str :
604
+ def summarize (self ) -> str :
567
605
return self ._delegate .summarize ()
568
606
607
+ @property
608
+ def is_solution_initialized (self ) -> bool :
609
+ return self ._delegate .isSolutionInitialized ()
610
+
611
+
612
+ def diff (self , other : 'ScoreAnalysis' ) -> 'ScoreAnalysis' :
613
+ """
614
+ Compare this `ScoreAnalysis to another `ScoreAnalysis`
615
+ and retrieve the difference between them.
616
+ The comparison is in the direction of `this - other`.
617
+
618
+ Example: if `this` has a score of 100 and `other` has a score of 90,
619
+ the returned score will be 10.
620
+ If this and other were inverted, the score would have been -10.
621
+ The same applies to all other properties of `ScoreAnalysis`.
622
+
623
+ In order to properly diff `MatchAnalysis` against each other,
624
+ we rely on the user implementing `ConstraintJustification` equality correctly.
625
+ In other words, the diff will consider two justifications equal if the user says they are equal,
626
+ and it expects the hash code to be consistent with equals.
627
+
628
+ If one `ScoreAnalysis` provides `MatchAnalysis` and the other doesn't, exception is thrown.
629
+ Such `ScoreAnalysis` instances are mutually incompatible.
630
+
631
+ Parameters
632
+ ----------
633
+ other : ScoreAnalysis
634
+
635
+ Returns
636
+ -------
637
+ ScoreExplanation
638
+ The `ScoreAnalysis` corresponding to the diff.
639
+ """
640
+ return ScoreAnalysis (self ._delegate .diff (other ._delegate ))
641
+
642
+
643
+
644
+
569
645
570
646
__all__ = ['ScoreExplanation' ,
571
647
'ConstraintRef' , 'ConstraintMatch' , 'ConstraintMatchTotal' ,
0 commit comments