ufal / perl-pmltq

Query engine and query language for trees in PML format
3 stars 2 forks source link

PMLTQ::TypeMapper does not provide user defined relations #59

Open matyaskopp opened 5 years ago

matyaskopp commented 5 years ago

TrEd does not show implemented relations while local files are queried

choroba commented 5 years ago

The change introduced in 27b1ee93f1d9a625a8a121f015fedd166240b5b9 is not correct - the schema level in the hash was introduced for types of the same name in different schemas, but the code deduces the schema name from the type name. You need to propagate the schema to the subroutine from outside, you can't guess the schema if there are several types of the same name in different schemas.

matyaskopp commented 5 years ago

@choroba thanks for comment.

I am not sure that I understand what you mean. If my changes are not correct neither this piece of code is correct: https://github.com/ufal/perl-pmltq/blob/27b1ee93f1d9a625a8a121f015fedd166240b5b9/lib/PMLTQ/TypeMapper.pm#L222-L223 (1) Am I right?

call stack: https://github.com/ufal/perl-pmltq/blob/27b1ee93f1d9a625a8a121f015fedd166240b5b9/lib/PMLTQ/TypeMapper.pm#L259 https://github.com/ufal/perl-pmltq/blob/27b1ee93f1d9a625a8a121f015fedd166240b5b9/lib/PMLTQ/TypeMapper.pm#L66 https://github.com/ufal/perl-pmltq/blob/27b1ee93f1d9a625a8a121f015fedd166240b5b9/lib/PMLTQ/TypeMapper.pm#L56 https://github.com/ufal/perl-pmltq/blob/27b1ee93f1d9a625a8a121f015fedd166240b5b9/lib/PMLTQ/TypeMapper.pm#L107

(2) So if $self->{fsfile} is correctly opened guessing schema is based on pml file that is the best way how it can be done.

related commit https://github.com/ufal/perl-pmltq/commit/e08f4d29629aef5eca60671a2a58af0b30a34532#diff-5ecae3e8fb680874e3f810bd2eaf694b

matyaskopp commented 5 years ago

I have added some tests: https://github.com/ufal/perl-pmltq/commit/d554dd5049031a5cfbf65462ece2f2b9665334e7

choroba commented 5 years ago

e08f4d29629aef5eca60671a2a58af0b30a34532 introduced the change to distinguish nodes with the same name but different schema. It would be best to have an example of such a situation - in our schemas, node types have different names in different schemas. Also, I'm not sure how nodes from different schemas could be targets of one relation.

matyaskopp commented 5 years ago

Ok, I understand your point.

Basically there are two ways how schema can be reached:

  1. Looking for schema name with file name /*/head/schema/@href
  2. Looking for schema name with matching root element /*/name()

(1) is stricter. Different versions of schema should strictly use version in schema file name to avoid bad schema guessing. If the names are same first schema in the schema list is used. (2) is not so strict so it can happen that two different schemas has same name.

In PMLTQ::TypeMapper we don't search for the exact schema. We want to know schema name to determine which relations are available. So both ways give us the same result. https://github.com/ufal/perl-pmltq/blob/d554dd5049031a5cfbf65462ece2f2b9665334e7/lib/PMLTQ/Relation/PDT/AEChildIterator.pm#L10

It can happen that nonsense relation is listed but we are not able to avoid it. If we want to do this right we should define something like treebank family and determine relations for te pair (family, schema name)