File tree Expand file tree Collapse file tree 7 files changed +35
-23
lines changed
sentences-compiler-plugin/src/main/kotlin/org/stypox/dicio/sentencesCompilerPlugin/gen
skill/src/main/java/org/dicio/skill/standard/construct Expand file tree Collapse file tree 7 files changed +35
-23
lines changed Original file line number Diff line number Diff line change @@ -31,23 +31,23 @@ fun generateConstruct(construct: Construct): CodeBlock {
3131
3232fun generateWord (word : Word ): CodeBlock {
3333 return CodeBlock .of(
34- " %T(%S, %L, %L, %Lf )" ,
34+ " %T(%S, %L, %L)" ,
3535 ClassName (" org.dicio.skill.standard.construct" , " WordConstruct" ),
3636 word.normalizedValue,
3737 /* isRegex = */ false ,
3838 word.isDiacriticsSensitive,
39- 1.0f // TODO allow specifying weight
39+ // TODO allow specifying weight
4040 )
4141}
4242
4343fun generateWordWithVariations (word : WordWithVariations ): CodeBlock {
4444 return CodeBlock .of(
45- " %T(%S, %L, %L, %Lf )" ,
45+ " %T(%S, %L, %L)" ,
4646 ClassName (" org.dicio.skill.standard.construct" , " WordConstruct" ),
4747 word.toJavaRegex(),
4848 /* isRegex = */ true ,
4949 word.isDiacriticsSensitive,
50- 1.0f // TODO allow specifying weight
50+ // TODO allow specifying weight
5151 )
5252}
5353
@@ -68,10 +68,10 @@ fun generateOptionalConstruct(): CodeBlock {
6868
6969fun generateCapturingGroup (capturingGroup : CapturingGroup ): CodeBlock {
7070 return CodeBlock .of(
71- " %T(%S, %Lf )" ,
71+ " %T(%S)" ,
7272 ClassName (" org.dicio.skill.standard.construct" , " CapturingConstruct" ),
7373 capturingGroup.name,
74- 0.0f // TODO allow specifying weight
74+ // TODO allow specifying weight
7575 )
7676}
7777
Original file line number Diff line number Diff line change @@ -7,7 +7,12 @@ import org.dicio.skill.standard.util.normalizeMemToEnd
77
88data class CapturingConstruct (
99 private val name : String ,
10- private val weight : Float
10+ // By default, don't assign extra points for having matched a capturing group: the fact that the
11+ // capturing group can match any part of the input already gives enough points from the words
12+ // that were actually matched. Also, if there is an optional word next to a capturing group that
13+ // matches with an input word, this will ensure that it is not included in the capturing group
14+ // but is instead matched.
15+ private val weight : Float = 0.0f ,
1116) : Construct {
1217 override fun matchToEnd (memToEnd : Array <StandardScore >, helper : MatchHelper ) {
1318 val cumulativeWeight = helper.cumulativeWeight
Original file line number Diff line number Diff line change @@ -10,11 +10,11 @@ import org.dicio.skill.standard.util.MatchHelper
1010 */
1111class DateTimeConstruct (
1212 name : String ,
13- weight : Float ,
14- bonusIfLargestPossible : Float ,
15- private val now : () -> LocalDateTime ,
16- private val shortScale : Boolean ,
17- private val preferMonthBeforeDay : Boolean ,
13+ weight : Float = DEFAULT_WEIGHT ,
14+ bonusIfLargestPossible : Float = DEFAULT_BONUS_IF_LARGEST_POSSIBLE ,
15+ private val now : () -> LocalDateTime = { LocalDateTime .now() } ,
16+ private val shortScale : Boolean = true ,
17+ private val preferMonthBeforeDay : Boolean = false ,
1818) : RangesConstruct<LocalDateTime>(name, weight, bonusIfLargestPossible) {
1919
2020 override fun parserParams (helper : MatchHelper ): ParserParams <LocalDateTime >? {
Original file line number Diff line number Diff line change @@ -10,9 +10,9 @@ import org.dicio.skill.standard.util.MatchHelper
1010 */
1111class DurationConstruct (
1212 name : String ,
13- weight : Float ,
14- bonusIfLargestPossible : Float ,
15- private val shortScale : Boolean ,
13+ weight : Float = DEFAULT_WEIGHT ,
14+ bonusIfLargestPossible : Float = DEFAULT_BONUS_IF_LARGEST_POSSIBLE ,
15+ private val shortScale : Boolean = true ,
1616) : RangesConstruct<Duration>(name, weight, bonusIfLargestPossible) {
1717
1818 override fun parserParams (helper : MatchHelper ): ParserParams <Duration >? {
Original file line number Diff line number Diff line change @@ -10,11 +10,11 @@ import org.dicio.skill.standard.util.MatchHelper
1010 */
1111class NumberConstruct (
1212 name : String ,
13- weight : Float ,
14- bonusIfLargestPossible : Float ,
15- private val shortScale : Boolean ,
16- private val preferOrdinal : Boolean ,
17- private val integerOnly : Boolean ,
13+ weight : Float = DEFAULT_WEIGHT ,
14+ bonusIfLargestPossible : Float = DEFAULT_BONUS_IF_LARGEST_POSSIBLE ,
15+ private val shortScale : Boolean = true ,
16+ private val preferOrdinal : Boolean = false ,
17+ private val integerOnly : Boolean = false ,
1818) : RangesConstruct<Number>(name, weight, bonusIfLargestPossible) {
1919
2020 override fun parserParams (helper : MatchHelper ): ParserParams <Number >? {
Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ import org.dicio.skill.standard.util.normalizeMemToEnd
1515 */
1616abstract class RangesConstruct <T >(
1717 private val name : String ,
18- private val weight : Float ,
19- private val bonusIfLargestPossible : Float ,
18+ private val weight : Float = DEFAULT_WEIGHT ,
19+ private val bonusIfLargestPossible : Float = DEFAULT_BONUS_IF_LARGEST_POSSIBLE ,
2020) : Construct {
2121
2222 /* *
@@ -75,4 +75,11 @@ abstract class RangesConstruct<T>(
7575 override fun toString (): String {
7676 return " .$name :${this ::class .simpleName?.removeSuffix(" Construct" )} ."
7777 }
78+
79+ companion object {
80+ // TODO these seem sensible default values after playing around a bit, but they haven't been
81+ // fine-tuned very well
82+ protected const val DEFAULT_WEIGHT = 1.0f
83+ protected const val DEFAULT_BONUS_IF_LARGEST_POSSIBLE = 0.5f
84+ }
7885}
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ data class WordConstruct(
99 private val text : String ,
1010 private val isRegex : Boolean ,
1111 private val isDiacriticsSensitive : Boolean ,
12- private val weight : Float ,
12+ private val weight : Float = 1.0f ,
1313) : Construct {
1414 private val compiledRegex = if (isRegex) Regex (text) else null
1515
You can’t perform that action at this time.
0 commit comments