One of the major projects that we'll be undertaking in the near future is aimed at improving the findability of information on our site - you shouldn't need to know that you need a blog article dated 2nd Feb 2007 to find about
the difference between a comparator and comparable in Java, nor to look up on page /resources/Q907.html to find out about
object oriented design - there should be an easier way.
And what better way than to
actually use an Object Oriented approach where each of the "Pieces of Content" on the web site can be accessed through the same API (Application Programmer Interface)? Then - whether it's on
The Horse's Mouth Blog, in the
longer articles of the solution centre, part of a
course description or
somewhere in the Forum you should be able to find it by keyword or description, and further more have a ranked list of other pieces of content ("poc"s) that may also be relevant offered to you, irrespective of the particular subclass that they belong to.
On yesterday's
Perl for larger Projects course, which covers Object Orientation in Perl as one of its key subjects, I took my "poc" project as an example and came up with something of a concept test / spike solution for the first algorithms that we may use. Starting with a series of function calls, we moved on to an object oriented example, showing off most of the features of Perl's OO model - all the "usual OO stuff", plus autoloaders, exporters and the rest. I've added the full series of examples written on to our web site ... so you can look at the source of each stage if you wish; it made an excellent teaching tool:
1.
Use of a package
2.
Encapsulate code, and add strict checking
3.
Adding OO notations
4.
AUTOLOAD
5.
A list of objects
6.
Setters and Getters
7.
Inherited classes, and an Exporter
8. and 9.
The final demo - the test program to go with ...
the Perl module and the two classes
So where does the nuclear physics come in? Well - I've chosen to define an initial ranking for each piece of content, and a "halflife" - the number of days in which it decays to having just a half of its initial significance, as per the decay of a radioactive isotope. Here's the algorithm if you're interesed:
sub getrank {
my ($current) = @_;
my $now = time();
my $age_in_days = ($now - $current->{otime}) / 3600 / 24;
my $decaysteps = $age_in_days / $current->{halflife};
$decaysteps < 0 and $decaysteps = 0; # future content!
my $decayfactor = 0.5 ** $decaysteps;
my $rank = sprintf("%.2f",$current->{orank} * $decayfactor);
return $rank; }
but of course that's going to be encapsulated within the class and "Joe Public" visiting our site - our even our content providers - will be gloriously unaware of the mathematics!
No - the general visitor will be much more interested in the titles and ranking of the pages, as illustrated by running our test program:
Dorothy:plpw grahamellis$ perl poctest
The Vet who liked horse meat
rank is 15.00 down from 15
Copyright, Well House Consultants
MySQL left join - howto
rank is 73.82 down from 95
Copyright, Well House Consultants
Contacts at Well House Consultants
rank is 95.00 down from 95
Copyright, Well House Consultants
Perl for Deep Sea Divers
rank is 50.00 down from 50
Copyright, Well House Consultants
95.00 - Contacts at Well House Consultants
73.82 - MySQL left join - howto
50.00 - Perl for Deep Sea Divers
15.00 - The Vet who liked horse meat
Attributes supported - comment halflife orank otime author title
Dorothy:plpw grahamellis$ (written 2008-12-17 08:22:45)
Associated topics are indexed under
P218 - Perl - More Objects [2651] Calculation within objects - early, last minute, or cached? - (2010-02-26)
[2427] Operator overloading - redefining addition and other Perl tricks - (2009-09-27)
[1819] Calling base class constructors - (2008-10-03)
[1665] Factory method example - Perl - (2008-06-04)
[1664] Example of OO in Perl - (2008-06-03)
[1435] Object Oriented Programming in Perl - Course - (2007-11-18)
[1320] Perl for Larger Projects - Object Oriented Perl - (2007-08-25)
[1217] What are factory and singleton classes? - (2007-06-04)
[930] -> , >= and => in Perl - (2006-11-18)
[831] Comparison of Object Oriented Philosophy - Python, Java, C++, Perl - (2006-08-13)
[656] Think about your design even if you don't use full UML - (2006-03-24)
[592] NOT Gone phishing - (2006-02-05)
[588] Changing @INC - where Perl loads its modules - (2006-02-02)
[531] Packages in packages in Perl - (2005-12-16)
[246] When to bless a Perl variable - (2005-03-15)
[227] Bellringing and Programming and Objects and Perl - (2005-02-25)
Q110 - Object Orientation and General technical topics - Programming Algorithms [2617] Comparing floating point numbers - a word of caution and a solution - (2010-02-01)
[2586] And and Or illustrated by locks - (2010-01-17)
[2509] A life lesson from the accuracy of numbers in Excel and Lua - (2009-11-21)
[2259] Grouping rows for a summary report - MySQL and PHP - (2009-06-27)
[2189] Matching disparate referencing systems (MediaWiki, PHP, also Tcl) - (2009-05-19)
[1840] Validating Credit Card Numbers - (2008-10-14)
[1391] Ordnance Survey Grid Reference to Latitude / Longitude - (2007-10-14)
[1187] Updating a page strictly every minute (PHP, Perl) - (2007-05-14)
[1157] Speed Networking - a great evening and how we arranged it - (2007-04-21)
[642] How similar are two words - (2006-03-11)
[202] Searching for numbers - (2005-02-04)
Some other Articles
End of Training, 2008Small PrintWhisky - Setting and reading cookies from PerlCopyright of Training Notes and Web SiteNuclear Physics comes to our web siteBlame CulturePerl substitute - the e modifierVariable Types in PerlSummary - Apache httpd build on LinuxForwarding session and cookie requests from httpd to Tomcat