store morphology as string rather than as L::F::Structure
Tara L Andrews [Fri, 15 Jun 2012 19:58:00 +0000 (21:58 +0200)]
lib/Text/Tradition/Collation/Reading/WordForm.pm
lib/Text/Tradition/Directory.pm
stemmaweb/lib/stemmaweb/Controller/Relation.pm

index 9d27181..968f205 100644 (file)
@@ -46,22 +46,15 @@ has 'language' => (
        required => 1,
        );
        
-# TODO do we need this?
-has 'form' => (
-       is => 'ro',
-       isa => 'Str',
-       # required => 1,
-       );
-       
 has 'lemma' => (
        is => 'ro',
        isa => 'Str',
        required => 1,
        );
        
-has 'morphology' => (
+has 'morphstr' => (
        is => 'ro',
-       isa => 'Lingua::Features::Structure',
+       isa => 'Str',
        required => 1,
        );
        
@@ -72,17 +65,34 @@ around BUILDARGS => sub {
        if( exists $args->{'JSON'} ) {
                my @data = split( / \/\/ /, $args->{'JSON'} );
                # print STDERR "Attempting to parse " . $data[2] . " into structure";
-               my $morph;
-               try {
-                       $morph = Lingua::Features::Structure->from_string( $data[2] );
-               } catch {
-                       throw("Could not parse string " . $data[2] . " into morphological structure");
-               }
                $args = { 'language' => $data[0], 'lemma' => $data[1],
-                       'morphology' => $morph };
+                       'morphstr' => $data[2] };
+       } elsif( exists $args->{'morphology'} ) {
+               # Backwards compat
+               my $mobj = delete $args->{'morphology'};
+               $args->{'morphstr'} = $mobj->to_string()
+                       if ref $mobj;
        }
        $class->$orig( $args );
 };
+
+=head2 morphology
+
+Returns a Lingua::Features::Structure object that corresponds to morphstr.
+
+=cut
+
+sub morphology {
+       my $self = shift;
+       return unless $self->morphstr;
+       my $struct;
+       try {
+               $struct = Lingua::Features::Structure->from_string( $self->morphstr );
+       } catch {
+               throw( "Morphology string " . $self->morphstr . " does not parse" );
+       }
+       return $struct;
+}
        
 =head2 to_string
 
@@ -101,7 +111,7 @@ sub to_string {
 sub TO_JSON {
        my $self = shift;
        return sprintf( "%s // %s // %s", $self->language, $self->lemma,
-               $self->morphology->to_string() );
+               $self->morphstr );
 }
        
 sub throw {
index 33c40ed..09aed7b 100644 (file)
@@ -163,8 +163,6 @@ has +typemap => (
           KiokuDB::TypeMap::Entry::Naive->new(),
         "Graph" => Text::Tradition::TypeMap::Entry->new(),
         "Graph::AdjacencyMap" => Text::Tradition::TypeMap::Entry->new(),
-               "Lingua::Features::Structure" => Text::Tradition::TypeMap::Entry->new,
-               "Lingua::Features::FeatureType" => Text::Tradition::TypeMap::Entry->new,
       }
     );
   },
index 8785d6f..22a1d07 100644 (file)
@@ -336,7 +336,7 @@ sub reading :Chained('text') :PathPart :Args(1) {
                                }
                        }               
                }
-               $m->save( $tradition );
+               $m->save( $rdg );
                $c->stash->{'result'} = $errmsg ? { 'error' => $errmsg }
                        : _reading_struct( $rdg );