replace values of numerical attribute in rapidminer by condition - rapidminer

how can I replace values of a numerical attribute in rapidminer by condition?
for example:
I have an age attribute and I want to set any data above 80 to 80.
thanks in advance.

Use the Generate Attributes operator and the if() function. For example, if your attribute is called age then you would set age as the attribute name and if(age > 80, 80, age) as the value.

Related

MySQL locate or remove string suffix from a known set

I want to write a MySQL stored procedure which will split a FQDN into host/authority/tld parts.
Let's say I have a list of known TLDs, and for the sake of illustration let's say it's the set
com
co.uk
uk
let's test it against these strings
input | output
----------------|-------
alpha.co.uk | alpha
mail.beta.uk | mail.beta
The output is the shortest substring of the input, starting from the beginning, such that CONCAT(output,'.',tld)=input for some tld which is a member of the given set.
Note that we need the shortest substring as the output, otherwise the output would be alpha.co in the first case, which is wrong.
I know how to write a MySQL function which tells me whether a given string is the suffix of another string, but here there are many possible such strings and any will do (provided no longer string is also a suffix of the input).
I know I could write a regex along the lines of co\.uk|uk|com but MySQL REGEX operator does not return the position of the match, just whether it matches or not.
Yes, I really do want a solution in SQL for this, not in the application language.
What's the best way to locate or remove the longest possible suffix, given a set of valid suffixes?
Here's one way to do that, relying on the fact that MIN() will yield the shortest of all the matches:
create table tld (tld varchar(100));
create table input (input varchar(100));
insert into tld values ('com'),('co.uk'),('uk');
insert into input values ('alpha.co.uk'),('mail.beta.com');
select
input.input as input,
min(substring(input.input, 1, length(input.input) - length(tld.tld) - 1)) as output
from input inner join tld
on input.input like concat('%.', tld.tld) group by input.input;
OR, if you only have a single value for input, then:
set #input = 'alpha.co.uk';
select min(substring(#input, 1, length(#input) - length(tld.tld) - 1)) as output
from tld
where #input like concat('%.', tld.tld);

How to use alphanumeric fields with BETWEEN clause in Mysql?

I have a table that contain a field names as mgrs, the value that stored in mgrs fields is like '42SWC227821555' may contain more charachters, and may contain lower case letters. So now i want to search records between two mgrs, so how can i do that? can i convert mgrs value to integer first and then use in between clause?
Instead of BETWEEN clause use STRCMP(expr1, expr2) function for string comparison operations:
WHERE STRCMP(mgrs, '42SWC227821555') >= 0 AND STRCMP(mgrs, '42SWC227821570') <= 0
You can use string expressions with BETWEEN comparison.
SELECT '42SWC2278215551' BETWEEN '42SWC227821555' AND '42SWd227821555'
-> 1
I will list some steps, instead of complete answer.
Remove all alphabets from you value, means you can have 1 more customized column using function listed on this link
Apply your filter on this column.

Set MySQL field according to substring comparison

I`m working on a data extraction from MySQL server and in several situations I'm using onquery substitutions. In example if I have a null field, it will assign an empty string for some fields, like:
ifnull(`negotiation_type`, "") AS negotiation_type
Now my need is to make similar test, but using substrings. I have a url field, and based on it`s value I want to set another field value, called property_type.
All the URLs will have the substring house or apartment, like:
http://www.example.com/?pics=true/tree-house-over-the-tree
http://www.example.com/?pics=true/blue-apartment-under-the-tere
And I`m wondering if composing the LOCATE function with any other mySQL function I will be able to make the property_type value assignment on SELECT.
Anyone have an idea?
Thanks
This one would do it I presume:
SELECT IF(LOCATE('HOUSE', `url`) > 0, 'HOUSE',IF(
LOCATE('APPARTEMENT', `url`) > 0, 'APPARTEMENT', 'OTHER')) AS property_type

Which is the best way to define the value of data being added to my database?

For example, I have a column > shopping_cart.status; and this column status should for each record contain one of three values > "incomplete" "complete" or "shipped". My question is, should it be my application that makes sure that these are the only values used, or do i need to build this into the domain of this attribute on the database side?
Use enums thats exactly what they are meant for.
An ENUM is a string object with a value chosen from a list of
permitted values that are enumerated explicitly in the column
specification at table creation time.
An enumeration value must be a quoted string literal; it may not be an
expression, even one that evaluates to a string value. For example,
you can create a table with an ENUM column like this:
CREATE TABLE shoppingcards (
shoppingcardstatus ENUM('incomplete', 'complete', 'shipped')
);
see: http://dev.mysql.com/doc/refman/5.0/en/enum.html

Select fields which contain only numeric values ACCESS

Can you please help me with these two points? :
(1) I working on Access and would like to wirte a query that returns those fields that contain only numberic values. e.g., 12, 45, 67. It shoud exclude any fields such as 12T, abc, TT34 because they contain characters in addition to the numbers.
(2) will it be possible to write a query to return data from fields with the following format: Num Num Char. such as : 19K or 30H or 22U
Thanks a lot!
You can use an expression such as:
WHERE Field Like "[0-9][0-9][a-z]"
Which will return two numbers followed by a letter, or
WHERE IsNumeric([Field])=True
Which will return numeric fields.