Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Search and Replace with a Large Dictionary

by RMGir (Prior)
on Oct 08, 2008 at 21:18 UTC ( [id://716098]=note: print w/replies, xml ) Need Help??


in reply to Search and Replace with a Large Dictionary

Well, you could try something fancy, but first I'd make sure that a "dumb" approach isn't fast enough.
#!/usr/bin/perl -w use strict; my %fieldDescs=( 'ManagedSystem.Product', 'Product Code', 'ManagedSystem.Status', 'Status', # and many more, in actuality loaded from your database ); my %keywords=( EQ => 'is equal to', OFFLINE => "'OFFLINE'", IF => 'if', VALUE => 'the value of', # And your other keywords ); my $text="*IF *VALUE ManagedSystem.Product *EQ NT *AND *VALUE ManagedS +ystem.Status *EQ '*OFFLINE'"; # Substitute *FOO for the equivalent from %keywords, if it exists $text=~s/\*(\w+)\b/(exists $keywords{$1})?$keywords{$1}:$1/eg; # Substitute any word for its description from fieldDescs, if the word +s exists there $text=~s/\b([A-Za-z_\.0-9]+)\b/(exists $fieldDescs{$1})?$fieldDescs{$1 +}:$1/eg; print "New text is\n\t$text\n";
It's not algorithmically very advanced, and it will be somewhat slow, but it's mostly proportional to the number of words in your formulas, not the words in your Attribute names... It's worth a try.

Mike

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://716098]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-19 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found