drj826 / SML

This is the Perl 5 implementation of the SML code library. SML is a minimalistic plain text descriptive markup language which is human readable, enables continuous integration of documentation, expresses and validates semantic relationships, is easy to edit, is easy to generate automatically, and publishes professional documentation from plain text manuscripts.
GNU General Public License v3.0
2 stars 2 forks source link

Simplify API for getting property values from a library object #74

Closed drj826 closed 8 years ago

drj826 commented 8 years ago

The current API for getting property values from a library object is horrible. For instance:

my $element = $library->get_first_property_value_element($division_id,$property_name);

Many templates use this call this way:

[%- INCLUDE element.tt element = library.get_first_property_value_element(division_id,'title') -%]

That's pretty terrible. The template system should probably not bother with individual elements. I would rather see:

[%- INCLUDE STRING.tt self = property_store.get_property_string(division_id,'title') -%]

drj826 commented 8 years ago

The current library methods that provide access to property data are:

my $text    = $library->get_first_property_value($division_id,$property_name)
my $element = $library->get_first_property_value_element($division_id,$property_name)
my $list    = $library->get_property_value_list($division_id,$property_name)
my $list    = $library->get_property_value_element_list($division_id,$property_name)
my $element = $library->get_property_value_element($division_id,$property_name,$property_value)
my $object  = $library->get_property_value_object($division_id,$property_name,$property_value)

For the majority of templating needs I think I should be able to get by with:

my $text   = $library->get_property_value($division_id,$property_name); # NEW
my $string = $library->get_property_value_string($division_id,$property_name); # NEW
my $list   = $library->get_property_value_list($division_id,$property_name);
my $list   = $library->get_property_value_string_list($division_id,$property_name); # NEW

Actually, there is no collision between the old API and the new API. I just need to add 3 new methods.

drj826 commented 8 years ago

I've decided to add two new classes: (1) ElementStore, and (2) PropertyStore. A library object will have one of each of these. The ElementStore object will store raw elements. The PropertyStore will store "assembled" property values in plain text and SML::String form. Properties in the PropertyStore may either be assembled from manuscript elements or be inferred by the Reasoner.

The ElementStore's 'add_element' method will update the PropertyStore's holdings whenever an element is added.

Templates should only access the PropertyStore and should never need to access raw elements.

drj826 commented 8 years ago

The purpose of the ElementStore is to de-duplicate element data. It will store element data in a three dimensional hash:

$hash->{$division_id}{$property_name}{$property_text} = $element;

Even if an SML manuscript contains a division with duplicate elements like this:

>>>DOCUMENT.my-doc
title:: My Document
author:: Don Johnson
author:: Don Johnson
.
.
.
<<<DOCUMENT

The duplicate element will be de-duplicated and the document author propery will only have one value.

drj826 commented 8 years ago

After playing with this for a while I don't see why this functionality shouldn't be provided by a SINGLE class (SML::PropertyStore). The PropertyStore class can have the 'add_element' method.

drj826 commented 8 years ago

Don't execute PropertyStore 'add_element' at Parser '_end_element' -- instead process all elements when you reach the end of an entity or the end of a document.

drj826 commented 8 years ago

Well I screwed that up good!

Before optimization: 3 min 23 seconds to publish the library After optimization: 3 hours 20 minutes

drj826 commented 8 years ago

class-diagram-property-store