Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7564715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:58:03+00:00 2026-05-30T13:58:03+00:00

A SubjectTeacherPeriod has a num_attribute_map , which is a map that maps certain attributes

  • 0

A SubjectTeacherPeriod has a num_attribute_map, which is a map that maps certain attributes (such as “boringness”) with their respective scores. I use the following code to sum attributes (such as “boringness”) over each day of the week.

But a certain line causes an error.

rule "insertAttributeDayTotal"
        //salience 1 // Do these rules first (optional, for performance)
    when
    $sum_regression_constraint : SumRegressionConstraint(
                    $class : class_,
                    $attribute : attribute//,
                    //$weight : weight;
                   )
    $day_of_week : DayOfWeek()
    $attribute_day_total : Number() from accumulate(
        SubjectTeacherPeriod(
            //period != null,
                period.class_ == $class,
            period.dayOfWeek == $day_of_week,
                $total : num_attribute_map[$attribute] //PROBLEM LINE
            ),
            sum($total)
        )

    then
    //System.out.println("BUCKET TOTAL "+$id+" "+$bucket_total.intValue());
        insertLogical(new AttributeDaySum($class, $attribute, $day_of_week, $attribute_day_total.intValue()));
end

The error is:

jesvin@Jesvin-Technovia:~/dev/drools/timetabler$ java -server in.co.technovia.timetabler.TimeTableApp
Exception in thread "main" java.lang.IllegalStateException: There are errors in the scoreDrl's:
Variables can not be used inside bindings. Variable [$attribute] is being used in binding 'num_attribute_map[$attribute]' : [Rule name='insertAttributeDayTotal']

Rule Compilation error : [Rule name='insertAttributeDayTotal']
    in/co/technovia/timetabler/domain/Rule_insertAttributeDayTotal_bb39fd28b3c8457cb8d86fc15b34a0e7.java (7:905) : Syntax error on token "null", invalid Type
    in/co/technovia/timetabler/domain/Rule_insertAttributeDayTotal_bb39fd28b3c8457cb8d86fc15b34a0e7.java (9:1050) : $total cannot be resolved

SubjectTeacherPeriod has the curious num_attribute_map so that I can define attributes at runtime. If I wanted a boringness (int) attribute for SubjectTeacherPeriod, I can do num_attribute_map.put("boringness",1) instead of adding a new attribute to SubjectTeacherPeriod.

A SumRegressionConstraint cares about a particular $attribute. That attribute’s value is stored in num_attribute_map of SubjectTeacherPeriod. I want to access num_attribute_map[$attribute] but this problem shows up.

What am I doing wrong?


Is there any other way to get dynamic attributes to work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:58:04+00:00Added an answer on May 30, 2026 at 1:58 pm

    At the moment, you can’t bind a variable to expressions, only to field names. So instead of binding it to:

    $total : num_attribute_map[$attribute]
    

    Bind it to:

    $total : num_attribute_map
    

    Then, you can use the expression on the function. If you are using the MVEL dialect:

    sum( $total[$attribute] )
    

    Or if you are using the java dialect:

    sum( $total.get($attribute) )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A line in my program which declares a Hashmap triggers an error. public class
In my code below, I am using the id property to distinguish between two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.