Pages: [1]
  Print  
Author Topic: Creating attributes  (Read 1088 times)
Patrick
Newbie
*
Posts: 3


« on: March 26, 2009, 05:31:31 AM »

I am trying to create an attribute with existing variables containing hyphens.

ex: a-1

However, when I try to use the AttributeConstructor in conjunction with this variable name, it misinterprets this as the variable a (nonexistent) subtracted by 1.

I have worked around this by using the Attribute renaming facility, however this is proving cumbersome as 120 of my 154 variables contain hyphens.

Is there an easier way to encapsulate a variable name containing ambiguous characters such as the hyphen?

Thanks,

- Pat
Logged
Ingo Mierswa
Administrator
Hero Member
*****
Posts: 1226



WWW
« Reply #1 on: March 26, 2009, 09:56:42 AM »

Hello Pat,

in RM 4.4 there is a new operator called "ChangeAttributeNamesReplace" which can be used to replace all non-word characters (regular expression for replace_what is '\W') by an empty string or for example an underscore (replace_by could be "_"). If you apply this operator to all attributes (regular expression for the attribute names parameter would be ".*") then you end up with attribute names which can be used by the AttributeConstruction operator.

Hope that helps,
Ingo
Logged

Did you try our new Marketplace? Upload or download new Extensions, add comments, and organize your operators. Have a look at  http://marketplace.rapid-i.com
haddock
Hero Member
*****
Posts: 853



WWW
« Reply #2 on: March 26, 2009, 10:08:40 AM »

Just like this...

Code:
<operator name="Root" class="Process" expanded="yes">
    <operator name="ExampleSetGenerator" class="ExampleSetGenerator">
        <parameter key="number_examples" value="200"/>
        <parameter key="number_of_attributes" value="2"/>
        <parameter key="target_function" value="random"/>
    </operator>
    <operator name="ChangeAttributeName" class="ChangeAttributeName">
        <parameter key="new_name" value="X-1"/>
        <parameter key="old_name" value="att1"/>
    </operator>
    <operator name="ChangeAttributeNamesReplace" class="ChangeAttributeNamesReplace">
        <parameter key="apply_on_special" value="false"/>
        <parameter key="attributes" value="X.*"/>
        <parameter key="replace_by" value="_"/>
        <parameter key="replace_what" value="\-"/>
    </operator>
</operator>
Logged

Where is the wisdom we have lost in knowledge?
Where is the knowledge we have lost in information?

T.S.Eliot ~ Choruses from the Rock 1934
Pages: [1]
  Print  
 
Jump to: