Reputation: 2536
Is there an established algorithm/library to create shorter, simpler strings based on words? I need to simplify a lot of brand name to generate our own part no, that we use in the warehouse.
Examples:
AECW....A E C WHITLOCK
BATI....BENATI
BDER....BOMBARDIER
PACC....PACCAR PARTS DIV
JAGR....JAEGER
JCB.....JCB
JNDR....JOHN DEERE
So, is there a way to generate them or my only option is to create a database table which contains all of them?
Another reason why I want them generated: I already have (and need) a table where all of the brand names are stored and I don't want to store the simplified ones If it is not necessary. Also, I would still need something that generates them for the first time.
Edit: Okay, I need to store them, but generating an abbreviation is still a question.
Upvotes: 1
Views: 443
Reputation: 23757
To generate abbreviations just remove vowels (PL/SQL code as example):
create function abbr(s varchar2) return varchar2 as
r varchar2(4000) := upper(s);
begin
for i in 5..regexp_count(r, '[A-Z]') loop
r := regexp_replace(r, '([A-Z])[AEIOU]', '\1', 1, 1);
end loop;
return substr(regexp_replace(r, '[^A-Z]'), 1, 4);
end;
A E C WHITLOCK AECW
BENATI BNTI
BOMBARDIER BMBR
PACCAR PARTS DIV PCCR
JAEGER JGER
JCB JCB
JOHN DEERE JHND
Upvotes: 2