my ($self, %args) = @_;
This idiom unpacks $self, then throw the rest of the arguments into %args.
]]>You can search on hierarchies in Lucene if your hierarchy can be represented as a path enumeration (a Dewey-Decimal-like style of encoding a path, like "001.014.003" for the 3rd grandchild of the 14th child of the 1st branch).
For example, a search phrase like:
hierarchy:001
would return only the direct children of the 1st branch, while:
hierarchy:001*
would return all descendants of the 1st branch.
To get only the children of a particular node, you specify only that node, like:
hierarchy:001.014.003
To get all of the descendants you specify everything that starts with that node:
hierarchy:001.014.003*
To get only the descendants after the children (grandchildren, etc.), you specify:
hierarchy:001.014.003.*
2019-05-21: I haven't tried it, but it looks like you could do this right in Perl with the now-quiescent Apache Lucy loose port of Lucene.
]]>(I say "will be" because rt.cpan.org does not yet have 2.2.0 as a valid version number for pmtools.)
]]>system "ls -l " . `$^X -S $Bin/pmpath $module`;
(note the additional "$^X").
As a side note, in Windows you may need to "use FindBin qw($Bin);" so your programs can actually find the Perl to run. (I had wondered if this use of FindBin was just cargo-cult programming carried over from old versions of Perl - now I know better.)
]]>Note that fulltext should be created dynamically from the fields for the particular document, rather than from a fixed set of named fields so you maximize the amount of text you can search against.
And yes, you are duplicating the text of the all of the other fields in this field :(.
]]>]]>"Looking at Perl code, it is easy to tell whether you are looking at the ravings of a lunatic. With Java, you can be several weeks into the project before you realize that you are dealing with the demented discourse of someone who should be trusted with nothing sharper than a spoon."
Run: "sudo docker run -v /home/mark/src/perllib/Set-Jaccard-SimilarityCoefficient/Set-Jaccard-SimilarityCoefficient-1.6.0:/Set-Jaccard-SimilarityCoefficient-1.6.0 -it ubuntu".
Because this is a plain-vanilla Ubuntu, I need to install some development tools (including missing pieces of Perl) by running: "apt-get update; apt-get install gcc make perl-modules-5.22". Followed by: "cpan -i App::cpanminus"
(If anyone points out in the comments how I could use the direct "curl" install for "cpanm" rather than using "cpan", I will update these directions.)
Run "cd /Set-Jaccard-SimilarityCoefficient" followed by: "perl Makefile.PL" to check for dependencies while we build the Makefile.
Finally, run: "cpanm Exception::Class ReadonlyX Set::Scalar Test::Most" to install the missing dependencies (which are noted in the "perl Makefile.PL" step due to my fixes for v1.6.0).
Note that this is applicable to finding the dependencies for any installation - I just picked Set::Jaccard::SimilarityCoefficient because I was working on it yesterday. I could just as well picked a Go program, a Ruby on Rails project, or even Pugs (the Perl 6 interpreter written in Haskell).
]]>Has all of the prerequisites in the Makefile.PL.
Uses the new (and internally simpler and more correct) ReadonlyX instead of the retired warhorse Readonly.
Has additional Kwalitee tests in t-kwalitee/.* (All Kwalitee tests pass.)
(This passes most of "perlcritic --theme pbp" except for the unknown word in POD and the POD before END checks.)
Enjoy!
]]>If you are never going to use the interface for anything other than mocking, then you are violating both DRY (Don't Repeat Yourself) and YAGNI (You Ain't Gonna Need It). Using interfaces requires synchronizing method signatures between the interface and its classes, thereby violating DRY. If the interface is only used for mocking that class, your are violating YAGNI. DRY and YAGNI reduce your code complexity, making it easier for you to understand your code later (and you always have to understand your code later).
It is said that you don't really know a tool until you know at least 3 ways to abuse it - forcing mocking to occur only when you use an interface has to be one of the ways to abuse interfaces. (Extra points to those who point out other examples of interface abuse.) I used to wonder why so much of Java code I looked at required interfaces that were never re-used - now I know.
]]>Now you would think that BETWEEN should give you easy-to-understand SQL for date ranges. Maybe in the hands of others BETWEEN does, but for me by the time I accounted for all of the cases the BETWEEN-based SQL date range overlap detection got more complicated than I thought it needed to be. So I drew up some diagrams, which eventually led me to the realization that this:
dateA.start <= dateB.end AND dateB.start <= dateA.end
is all that you need. No BETWEEN needed, simple to read, and should work in any useful dialect of SQL.
But there is an even simpler way to think about this (though the written expression is more complicated). In plain English, "there is no overlap if one range starts after the other one ends." In SQL that overlap detection looks like:
NOT (dateA.start > dateB.end) AND NOT (dateB.start > dateA.end)
So the above SQL formulation for range overlap detection:
dateA.start <= dateB.end AND dateB.start <= dateA.end
is simpler but is harder to reason about (IMHO).
As a (tiny) bonus, in ASCII art the no-overlap case always looks similar to:
| range A | | range B |
There are several overlap cases (drawing these is left as an exercise to the gentle reader).
]]>The answer is Stack Overflow. When I have a question, a web search often has 1 or more Stack Overflow answers at the top - answers that usually help me fix (or work around) the problem I have. It really is impressive how often Stack Overflow has just the answer I need and in just enough detail. (Disclosure: I answer questions on Stack Overflow on a semi-regular basis.)
Stack Overflow could be considered as a grimoire (in the "Wizard did not seem to be a career choice, so I chose programmer" sense). Many dusty, ill-lit corners of languages and systems have been brought to light by the helpful folks at Stack Overflow in both the answers and the comments. I don't know much about the beginner's questions on Stack Overflow or on the other Stack Exchange sites, but the questions I have day-to-day on programming are often answered in full on Stack Overflow. The breadth and depth of coverage is a quite an astonishing feat, especially having achieved this coverage in such a relatively short time.
But Stack Overflow is better than an old-fashioned spellbook. "You can't grep dead trees", as the saying goes, but with Stack Overflow you can search it through its built-in search, or using whichever search engine you are comfortable with. Stack Overflow questions are also tagged in multiple categories to make it easier to find just what you are looking for. This is crowd-sourced categorization, which means it is both useful and not nearly as powerful as it might be - but my impression from the librarians that I know is that complete categorization is a highly resource-intensive process (and IMHO not necessary for the categorization to be useful). If you need an answer on JavaScript external sorting, Perl statistical functions, C# command-line build incantations, or many other questions, the contributors at Stack Overflow are generous with their time and (almost always) gracious with their answers and comments.
A shout-out is also deserved by the other Stack Exchange sites -- Superuser, Ask Ubuntu, english.stackexchange.com, etc. etc.
Somewhere around our house is a picture of my cubicle circa 1995 - strewn with magazines and articles comprising a badly-organized and incomplete treasure trove of tricks, kludges, hints, clues, inklings, indications, etc. etc. necessary for quickly solving the problems whose solutions are not in the back of the programming book(s). Nowadays, my workspace is clean and uncluttered due in no small part to Stack Overflow and the other members of the Stack Exchange family of websites. This is not just a Good Thing - this is an advancement of the state of the art, and ask your local Ph.D. just how easy that is. Just as a little photography and a little materials science led to the Computer Revolution, a little amateur sociology, a little Information Retrieval, and a little programming led to the English-speaker's worldwide knowledgebases - Stack Overflow et.al. Kudos and laurels to the Stack Exchange team along with the many, many contributors.
]]>