Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

RFC: A module to evaluate keywords expressions on tag lists.

by vitoco (Friar)
on Aug 31, 2009 at 15:43 UTC ( #792394=perlmeditation: print w/ replies, xml ) Need Help??

I needed a simple way to test if a list of keywords (tags) had the required words, but one moment later, conditional operators other than AND were required. I didn't find a public module that satisfied my needs. Some of this was discussed in AND and OR on Regular Expressions.

I took my subs and group them in a module, then changed into objects (my first attempt in OOP) and worked nice.

Examples of use:

# Simple query (same as: +xxx -ppp -jjj): my $query = "xxx-(ppp,jjj)"; use Keywords; my $kw = Keywords->new(ignorecase => 1); $kw->prepare($query); # Simple test: print "Match!" if $kw->test($list_of_tags); # @ids has some keys %table: @ok = grep {$kw->test($table{$_}[$col])} @ids; # Same as before: @ok = $kw->grep_keys(map {$_ => $table{$_}[$col]} @ids); # Hash only has keywords lists: @ok = $kw->grep_keys(%tags); # When ids are full keywords: @ok = $kw->grep(@ids);

Now, I want to share my efforts and decided to upload this to CPAN, but I need to define or append to a namespace. I thought on Search::Keywords, but Keywords::Match might be a better one.

Hints for a proper namespace?

Hints for extra features? I'm thinking on set/get parms, reparse, sentences (when tags have more than one word), UTF8 (un)support...

Thanks!

Comment on RFC: A module to evaluate keywords expressions on tag lists.
Download Code
Re: RFC: A module to evaluate keywords expressions on tag lists.
by ikegami (Pope) on Sep 03, 2009 at 18:33 UTC

    Neither is particularly compelling.

    Having a root namespace "Keywords::" means you can do lots of things with keywords. Is there that much you can do to keywords?

    Sounds like it would be better integrated into "Search::" or some other existing top-level namespace.

    I would actually prefer if the query parser provided a standard interface that supported multiple query languages. (The one you provided, Google's, etc)

    • Search::Query (Abstract interface)
    • Search::Query::Google
    • Search::Query::...

    I also have a feeling the matching functionality shouldn't be too heavily integrated.

      Is there that much you can do to keywords?

      I think not, but this module provides a query parser, a regexp builder and some tests methods. Not only the query language is relevant. Also it is the way that a list of keywords is being stored if you want to use some specific options, then a method to clean up the list string is provided. So it's not only a Search thing. That's made me doubt.

      I don't think that "Search::Query" is appropiate, for the same reason as above. May be "Regexp::Keywords"?

      BTW, "Search::Query::Google" made me think on a module to retrieve some results from Google (as "Google::Search")... "Search::Keywords::Google" is not much better, but I got the idea and agree on that.

      I also have a feeling the matching functionality shouldn't be too heavily integrated.

      Could you explain this?

        Could you explain this?

        If query building is separate from matching, then you'll be able to match against inputs other than a flat string.

        Specifically, only supporting flat strings prevents it from being extended to support "is:unread" or "title:foo"

        I'm not saying you should implement those features. I'm saying it would be great if the designed allowed someone to do so.

Re: RFC: A module to evaluate keywords expressions on tag lists.
by vitoco (Friar) on Sep 30, 2009 at 13:44 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://792394]
Approved by planetscape
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-10-23 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls