Skip to content

Commit

Permalink
Fixing relations with same name and different schema
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ch4ls committed Nov 22, 2015
1 parent 1e450e7 commit e08f4d2
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 42 deletions.
14 changes: 7 additions & 7 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ finder = ModulesNoParser
[Authority]
finder = ModulesNoParser

[ReportVersions::Tiny]
exclude = Parse::RecDescent
exclude = DBD::Oracle
exclude = DBD::Pg
exclude = HTTP::Request::AsCGI
exclude = HTTP::Server::Simple::CGI
exclude = Net::HTTPServer
; [ReportVersions::Tiny]
; exclude = Parse::RecDescent
; exclude = DBD::Oracle
; exclude = DBD::Pg
; exclude = HTTP::Request::AsCGI
; exclude = HTTP::Server::Simple::CGI
; exclude = Net::HTTPServer

[ChangeStats::Git]
group=STATISTICS
Expand Down
16 changes: 10 additions & 6 deletions lib/PMLTQ/BtredEvaluator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,10 @@ sub new {
@query_nodes=PMLTQ::Common::FilterQueryNodes($query_tree); # same order as @orig_nodes
%orig2query = map { $orig_nodes[$_] => $query_nodes[$_] } 0..$#orig_nodes;
PMLTQ::Planner::name_all_query_nodes($query_tree); # need for planning
$roots = PMLTQ::Planner::plan(\@query_nodes,$query_tree);
$roots = PMLTQ::Planner::plan($self->{type_mapper},\@query_nodes,$query_tree);
for my $subquery (grep { $_->{'#name'} eq 'subtree' } $query_tree->root->descendants) {
my $subquery_roots = PMLTQ::Planner::plan(
$self->{type_mapper},
[PMLTQ::Common::FilterQueryNodes($subquery)],
$subquery->parent,
$subquery
Expand Down Expand Up @@ -801,7 +802,8 @@ sub create_iterator {
die "Invalid bounds for transitive relation '$label\{$min,$max}'\n";
}

$iterator = PMLTQ::Relation->create_iterator($start_node->{'node-type'}, $label, $conditions);
my $schema = $self->{type_mapper}->get_schema_for_type($start_node->{'node-type'});
$iterator = PMLTQ::Relation->create_iterator($schema->get_root_name, $start_node->{'node-type'}, $label, $conditions);
unless (defined $iterator) {
if (first { $_ eq $label }
@{$self->{type_mapper}->get_pmlrf_relations($start_node)}) {
Expand Down Expand Up @@ -2200,8 +2202,10 @@ sub serialize_element {
} else {
my $start_node = $node->parent;
$start_node = $start_node->parent while $start_node && $start_node->{'#name'} !~ /^(node|subquery)$/;
$expression =
$start_node && PMLTQ::Relation->test_code($start_node->{'node-type'},$label);
if ($start_node) {
my $schema = $self->{type_mapper}->get_schema_for_type($start_node->{'node-type'});
$expression = PMLTQ::Relation->test_code($schema->get_root_name,$start_node->{'node-type'},$label);
}
if (!defined $expression) {
if (first { $_ eq $label } @{$self->{type_mapper}->get_pmlrf_relations($node)}) {
return $self->serialize_element(
Expand Down Expand Up @@ -3180,12 +3184,12 @@ sub find_next_match {
}

sub plan_query {
my ($query_tree)=@_;
my ($type_mapper,$query_tree)=@_;
require PMLTQ::Planner;
$query_tree||=$TredMacro::root;
PMLTQ::Planner::name_all_query_nodes($query_tree);
my @query_nodes=PMLTQ::Common::FilterQueryNodes($query_tree);
PMLTQ::Planner::plan(\@query_nodes,$query_tree);
PMLTQ::Planner::plan($type_mapper,\@query_nodes,$query_tree);
}

1; # End of PMLTQ::BtredEvaluator
Expand Down
4 changes: 2 additions & 2 deletions lib/PMLTQ/Common.pm
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ my %type = (
);

sub reversed_relation {
my ($name,$node_type)=@_;
my ($schema_name,$node_type,$name)=@_;
if ($name=~s{^implementation:}{}) {
return PMLTQ::Relation->reversed_relation($node_type,$name);
return PMLTQ::Relation->reversed_relation($schema_name,$node_type,$name);
}
return $reversed_relations{$name};
}
Expand Down
20 changes: 10 additions & 10 deletions lib/PMLTQ/Planner.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ sub name_all_query_nodes {
return \%name2node;
}
sub weight {
my ($rel,$node_type)=@_;
my ($schema_name,$node_type,$rel)=@_;
my $name = $rel->name;
my $w;
if ($name eq 'user-defined') {
$w = PMLTQ::Relation->iterator_weight($node_type,$name) || $weight{'user-defined:'.$name};
$w = PMLTQ::Relation->iterator_weight($schema_name,$node_type,$name) || $weight{'user-defined:'.$name};
} else {
$w = $weight{$name};
}
Expand All @@ -79,13 +79,13 @@ sub weight {
return 5;
}
sub reversed_rel {
my ($ref,$start_type)=@_;
my ($schema_name,$start_type,$ref)=@_;
my ($rel)=SeqV($ref->{relation});
my $name = $rel->name;
if ($name eq 'user-defined') {
$name=$rel->value->{category}.':'.$rel->value->{label};
}
my $rname = PMLTQ::Common::reversed_relation($name,$start_type);
my $rname = PMLTQ::Common::reversed_relation($schema_name,$start_type,$name);
if (defined $rname) {
my $relv = $rel->value;
my $revv = Treex::PML::CloneValue($relv);
Expand All @@ -111,9 +111,9 @@ sub reversed_rel {
}

sub plan {
my ($query_nodes,$query_tree,$query_root)=@_;
die 'usage: plan(\@nodes,$query_tree,$query_node?)' unless
ref($query_nodes) eq 'ARRAY' and $query_tree;
my ($type_mapper,$query_nodes,$query_tree,$query_root)=@_;
die 'usage: plan($type_mapper,\@nodes,$query_tree,$query_node?)' unless
$type_mapper and ref($query_nodes) eq 'ARRAY' and $query_tree;
my %node2pos = map { $query_nodes->[$_] => $_ } 0..$#$query_nodes;
my %name2pos = map {
my $name = $query_nodes->[$_]->{name};
Expand Down Expand Up @@ -198,11 +198,11 @@ sub plan {
ref=>$ref,
real_start=>$edge_data->[0],
real_end=>$edge_data->[1],
weight=>weight($rel,$sn->{'node-type'}),
weight=>weight($type_mapper->get_schema_name_for($sn->{'node-type'}),$sn->{'node-type'},$rel),
} unless defined($root_pos) and $t==$root_pos;
}
unless ($no_reverse or (defined($root_pos) and $s==$root_pos)) {
my $reversed = reversed_rel($ref,$tn->{'node-type'});
my $reversed = reversed_rel($type_mapper->get_schema_name_for($tn->{'node-type'}),$tn->{'node-type'},$ref);
if (defined $reversed) {
push @edges,{
from => $t,
Expand All @@ -211,7 +211,7 @@ sub plan {
reverse_of_ref => $ref,
real_start=>$edge_data->[1],
real_end=>$edge_data->[0],
weight => weight($reversed,$tn->{'node-type'}),
weight => weight($type_mapper->get_schema_name_for($tn->{'node-type'}),$tn->{'node-type'},$reversed),
};
}
}
Expand Down
38 changes: 24 additions & 14 deletions lib/PMLTQ/Relation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use strict;
use warnings;
use Carp;
use File::Spec;
use File::Glob qw(:glob);
use PMLTQ::Loader;

my %user_defined;
Expand All @@ -21,14 +20,25 @@ sub import {
my $class=shift;
for my $def (@_) {
my $name = $def->{name};
$user_defined{ $def->{start_node_type}.':'.$name } = $def;
$start_to_target_type_map{ $def->{start_node_type} }{ $name } = $def->{target_node_type};
my $schema = $dev->{schema};
my $node_type = $dev->{start_node_type};

_relation($schema, $node_type, $name);
}
}

sub _relation {
my ($schema_name, $node_type, $name, $def) = @_;
if ($def) {
$user_defined{ $schema_name }{ $node_type }{ $name } = $def;
$start_to_target_type_map{ $schema_name }{ $node_type }{ $name } = $def->{target_node_type};
}
$user_defined{ $schema_name }{ $node_type }{ $name }
}

sub create_iterator {
my ($class,$node_type,$label) = (shift,shift,shift);
my $rel = $user_defined{ $node_type.':'.$label };
my ($class,$schema_name,$node_type,$label) = (shift,shift,shift,shift);
my $rel = _relation($schema_name, $node_type, $label);
if ($rel and exists($rel->{iterator_class})) {
$rel->{iterator_class}->new(@_);
} else {
Expand All @@ -37,33 +47,33 @@ sub create_iterator {
}

sub iterator_weight {
my ($class,$node_type,$label) = @_;
my $rel = $user_defined{$node_type.':'.$label};
my ($class,$schema_name,$node_type,$label) = @_;
my $rel = _relation($schema_name, $node_type, $label);
return unless $rel;
return $rel && $rel->{iterator_weight};
}

sub relations_for_node_type {
my ($class, $start_type)=@_;
my $map = $start_to_target_type_map{$start_type};
my ($class,$schema_name,$start_type)=@_;
my $map = $start_to_target_type_map{$schema_name}{$start_type};
return $map ? [sort keys %$map] : [];
}

sub target_type {
my ($class, $start_type,$label)=@_;
my $rel = $start_to_target_type_map{$start_type};
my ($class,$schema_name,$start_type,$label)=@_;
my $rel = $start_to_target_type_map{$schema_name}{$start_type};
return $rel && $rel->{$label};
}

sub reversed_relation {
my ($class, $start_type, $name)=@_;
my $rel = $user_defined{$start_type.':'.$name};
my ($class, $schema_name, $start_type, $name)=@_;
my $rel = _relation($schema_name, $start_type, $name);
return $rel && $rel->{reversed_relation};
}

sub test_code {
my ($class, $start_type, $name)=@_;
my $rel = $user_defined{$start_type.':'.$name};
my $rel = _relation($schema_name, $start_type, $name);
return $rel && $rel->{test_code};
return undef;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/PMLTQ/Relation/PDT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ sub AGetEParents { # node through
print STDERR
"GetEParents: Error - no coordination head $init_node->{AID}: ".ThisAddress($init_node)."\n";
return();
} elsif($node->{afun}eq'AuxS') {
} elsif($node->{afun} eq 'AuxS') {
print STDERR
"GetEParents: Error - no coordination head $node->{AID}: ".ThisAddress($node)."\n";
return();
Expand Down
1 change: 1 addition & 0 deletions lib/PMLTQ/Relation/PDT/AEChildIterator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;
use base qw(PMLTQ::Relation::SimpleListIterator);
use PMLTQ::Relation {
name => 'echild',
schema => 'adata',
reversed_relation => 'implementation:eparent',
start_node_type => 'a-node',
target_node_type => 'a-node',
Expand Down
1 change: 1 addition & 0 deletions lib/PMLTQ/Relation/PDT/AEParentIterator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;
use base qw(PMLTQ::Relation::SimpleListIterator);
use PMLTQ::Relation {
name => 'eparent',
schema => 'adata',
reversed_relation => 'implementation:echild',
start_node_type => 'a-node',
target_node_type => 'a-node',
Expand Down
1 change: 1 addition & 0 deletions lib/PMLTQ/Relation/PDT/ALexOrAuxRFIterator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;
use base qw(PMLTQ::Relation::SimpleListIterator);
use PMLTQ::Relation {
name => 'a/lex.rf|a/aux.rf',
schema => 'tdata',
start_node_type => 't-node',
target_node_type => 'a-node',
iterator_class => __PACKAGE__,
Expand Down
1 change: 1 addition & 0 deletions lib/PMLTQ/Relation/PDT/TEChildIterator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;
use base qw(PMLTQ::Relation::SimpleListIterator);
use PMLTQ::Relation {
name => 'echild',
schema => 'tdata',
reversed_relation => 'implementation:eparent',
start_node_type => 't-node',
target_node_type => 't-node',
Expand Down
1 change: 1 addition & 0 deletions lib/PMLTQ/Relation/PDT/TEParentIterator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;
use base qw(PMLTQ::Relation::SimpleListIterator);
use PMLTQ::Relation {
name => 'eparent',
schema => 'tdata',
reversed_relation => 'implementation:echild',
start_node_type => 't-node',
target_node_type => 't-node',
Expand Down
2 changes: 1 addition & 1 deletion lib/PMLTQ/Relation/Treex/AEChildCIterator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;
use base qw(PMLTQ::Relation::SimpleListIterator);
use PMLTQ::Relation {
name => 'echildC',
schema => 'treex_document',
reversed_relation => 'implementation:eparentC',
start_node_type => 'a-node',
target_node_type => 'a-node',
Expand All @@ -13,7 +14,6 @@ use PMLTQ::Relation {
test_code => q( grep($_ == $start, PMLTQ::Relation::Treex::AGetEParentsC($end)) ? 1 : 0 ),
};


sub get_node_list {
my ($self, $node) = @_;
my $type = $node->type->get_base_type_name;
Expand Down
1 change: 1 addition & 0 deletions lib/PMLTQ/Relation/Treex/AEChildIterator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;
use base qw(PMLTQ::Relation::SimpleListIterator);
use PMLTQ::Relation {
name => 'echild',
schema => 'treex_document',
reversed_relation => 'implementation:eparent',
start_node_type => 'a-node',
target_node_type => 'a-node',
Expand Down
1 change: 1 addition & 0 deletions lib/PMLTQ/Relation/Treex/AEParentCIterator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;
use base qw(PMLTQ::Relation::SimpleListIterator);
use PMLTQ::Relation {
name => 'eparentC',
schema => 'treex_document',
reversed_relation => 'implementation:echildC',
start_node_type => 'a-node',
target_node_type => 'a-node',
Expand Down
1 change: 1 addition & 0 deletions lib/PMLTQ/Relation/Treex/AEParentIterator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;
use base qw(PMLTQ::Relation::SimpleListIterator);
use PMLTQ::Relation {
name => 'eparent',
schema => 'treex_document',
reversed_relation => 'implementation:echild',
start_node_type => 'a-node',
target_node_type => 'a-node',
Expand Down
1 change: 1 addition & 0 deletions lib/PMLTQ/Relation/Treex/TEChildIterator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;
use base qw(PMLTQ::Relation::SimpleListIterator);
use PMLTQ::Relation {
name => 'echild',
schema => 'treex_document',
reversed_relation => 'implementation:eparent',
start_node_type => 't-node',
target_node_type => 't-node',
Expand Down
1 change: 1 addition & 0 deletions lib/PMLTQ/Relation/Treex/TEParentIterator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;
use base qw(PMLTQ::Relation::SimpleListIterator);
use PMLTQ::Relation {
name => 'eparent',
schema => 'treex_document',
reversed_relation => 'implementation:echild',
start_node_type => 't-node',
target_node_type => 't-node',
Expand Down
3 changes: 2 additions & 1 deletion lib/PMLTQ/TypeMapper.pm
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ sub get_user_defined_relations {
my ($self,$qnode_or_type)=@_;
if ($qnode_or_type) {
my $type = ref($qnode_or_type) ? PMLTQ::Common::GetQueryNodeType($qnode_or_type,$self) : $qnode_or_type;
return PMLTQ::Relation->relations_for_node_type($type);
my $schema = $self->get_schema_for_type($type);
return PMLTQ::Relation->relations_for_node_type($schema->get_root_name, type);
}
return [
map @{$self->get_user_defined_relations($_)}, grep $_, @{$self->get_node_types}
Expand Down

0 comments on commit e08f4d2

Please sign in to comment.