kasei / attean

A Perl Semantic Web Framework
19 stars 10 forks source link

Fix as_string serialization of CONSTRUCT algebras #97

Closed kasei closed 8 years ago

kasei commented 8 years ago

They currently only serialize the pattern, not the construct template.

Attean::Algebra::Construct->algebra_as_string needs to be upgrade to include the triplesin the construct algebras. For example:

my $algebra = Attean->get_parser('SPARQL')->parse('CONSTRUCT { ?s ?p 2 } WHERE { ?s ?p 1 }');
say $algebra->as_string;

Currently returns:

-   Construct
-     BGP { ?s ?p "1"^^<http://www.w3.org/2001/XMLSchema#integer> . }

The first line comes from Attean::Algebra::Construct->algebra_as_string, while the second line gets appended by the as_string serialization for the members of @{ $algebra->children }. This should be returning something like this:

-   Construct
-     Triples:
-       ?s ?p "2"^^<http://www.w3.org/2001/XMLSchema#integer> .
-     Pattern:
-       BGP { ?s ?p "1"^^<http://www.w3.org/2001/XMLSchema#integer> . }

(Where Attean::Algebra::Construct->algebra_as_string is returning the first 3 lines.)

This could be done similarly to the (more complex) Attean::Algebra::Modify->algebra_as_string where quads from an update operation are serialized. In the Construct case, triples from @{ $algebra->triples } should be serialized under a "Triples:" heading.