muck about with serialization of lexeme wordforms; allow individual lexeme addressing
[scpubgit/stemmatology.git] / lib / Text / Tradition / Collation / Reading / WordForm.pm
index 46a9f80..4335857 100644 (file)
@@ -1,7 +1,8 @@
 package Text::Tradition::Collation::Reading::WordForm;
 
-use Moose;
 use Lingua::Features::Structure;
+use JSON ();
+use Moose;
 
 =head1 NAME
 
@@ -66,11 +67,13 @@ around BUILDARGS => sub {
        my $orig = shift;
        my $class = shift;
        my $args = @_ == 1 ? $_[0] : { @_ };
-       if( exists $args->{'serial'} ) {
-               my( $lang, $lemma, $morph ) = split( /\+\+/, delete $args->{'serial'} );
-               $args->{'language'} = $lang;
-               $args->{'lemma'} = $lemma;
-               $args->{'morphology'} = Lingua::Features::Structure->from_string( $morph );
+       if( exists $args->{'JSON'} ) {
+               $DB::single = 1;
+               my @data = split( / \/\/ /, $args->{'JSON'} );
+               print STDERR "Attempting to parse " . $data[2] . " into structure";
+               my $morph = Lingua::Features::Structure->from_string( $data[2] );
+               $args = { 'language' => $data[0], 'lemma' => $data[1],
+                       'morphology' => $morph };
        }
        $class->$orig( $args );
 };
@@ -84,7 +87,15 @@ in equivalence testing.
 
 sub to_string {
        my $self = shift;
-       return join( '++', $self->language, $self->lemma, $self->morphology->to_string );
+       return JSON->new->convert_blessed(1)->encode( $self );
+}
+
+# Rather than spitting it out as a JSON hash, encode it as a string so that
+# the XML serialization doesn't become insane.
+sub TO_JSON {
+       my $self = shift;
+       return sprintf( "%s // %s // %s", $self->language, $self->lemma,
+               $self->morphology->to_string() );
 }
        
 no Moose;