Permalink
Browse files

Added accessors to Arc that return an arc's related anchors, nodes,

and members.
  • Loading branch information...
1 parent 1a56c5f commit 28f85feacc56d0e73b2787aeae7d586effe69774 @rcaputo committed Sep 25, 2007
Showing with 65 additions and 2 deletions.
  1. +63 −0 trunk/ThirdLobe/Arc.pm
  2. +2 −2 trunk/ThirdLobe/Database.pm
View
@@ -35,6 +35,69 @@ sub sub_seq { return shift()->{sub_seq} }
sub prd_seq { return shift()->{prd_seq} }
sub obj_seq { return shift()->{obj_seq} }
+sub sub_arc {
+ my $self = shift;
+ return $self->{sub_arc} if defined $self->{sub_arc};
+ return $self->{sub_arc} = $self->{db}->arc_from_seq($self->sub_seq());
+}
+
+sub prd_arc {
+ my $self = shift;
+ return $self->{prd_arc} if defined $self->{prd_arc};
+ return $self->{prd_arc} = $self->{db}->arc_from_seq($self->prd_seq());
+}
+
+sub obj_arc {
+ my $self = shift;
+ return $self->{obj_arc} if defined $self->{obj_arc};
+ return $self->{obj_arc} = $self->{db}->arc_from_seq($self->obj_seq());
+}
+
+sub sub_node {
+ my $self = shift;
+ return $self->{sub_node} if defined $self->{sub_node};
+ return $self->{sub_node} = $self->{db}->node_from_anchor( $self->sub_arc() );
+}
+
+sub prd_node {
+ my $self = shift;
+ return $self->{prd_node} if defined $self->{prd_node};
+ return $self->{prd_node} = $self->{db}->node_from_anchor( $self->prd_arc() );
+}
+
+sub obj_node {
+ my $self = shift;
+ return $self->{obj_node} if defined $self->{obj_node};
+ return $self->{obj_node} = $self->{db}->node_from_anchor( $self->obj_arc() );
+}
+
+sub subject {
+ my $self = shift;
+ return $self->{sub_text} if defined $self->{sub_text};
+
+ my $sub_node = $self->sub_node();
+ return $self->{sub_text} = $sub_node->val() if defined $sub_node;
+ return $self->{sub_text} = $self->{sub_arc};
+}
+
+sub predicate {
+ my $self = shift;
+ return $self->{prd_text} if defined $self->{prd_text};
+
+ my $prd_node = $self->prd_node();
+ return $self->{prd_text} = $prd_node->val() if defined $prd_node;
+ return $self->{prd_text} = $self->{prd_arc};
+}
+
+sub object {
+ my $self = shift;
+ return $self->{obj_text} if defined $self->{obj_text};
+
+ my $obj_node = $self->obj_node();
+ return $self->{obj_text} = $obj_node->val() if defined $obj_node;
+ return $self->{obj_text} = $self->{obj_arc};
+}
+
=head1 BUGS
ThirdLobe::Arc objects are independent of each other, even if two or
@@ -263,7 +263,7 @@ sub arc_from_arcs {
# The (0,0,0,0) arc doesn't officially exist.
next unless $row->{seq};
- push @arcs, ThirdLobe::Arc->new($row);
+ push @arcs, ThirdLobe::Arc->new({ db => $self, %$row });
}
$sth->finish();
@@ -356,7 +356,7 @@ sub arc_from_seq {
# TODO - Error checking. Return undef on failure.
my $row = $sth->fetchrow_hashref();
- my $arc = ThirdLobe::Arc->new($row);
+ my $arc = ThirdLobe::Arc->new({ db => $self, %$row });
$sth->finish();
return $arc;

0 comments on commit 28f85fe

Please sign in to comment.