SYNOPSIS

   # 1) bare bones
   my $tm = .....;  # get a map from somewhere (can be empty)
   Class::Trait->apply ($tm, "TM::Serializable::CSV");

   use Perl6::Slurp;
   $tm->deserialize (slurp 'myugly.csv');

   # 2) exploiting the timed sync in/out mechanism
   my $tm = new TM::.... (url => 'file:myugly.csv'); # get a RESOURCEABLE map from somewhere
   $tm->sync_in;

DESCRIPTION

This trait provides parsing and dumping from \s-1CSV\s0 formatted text streams.

INTERFACE

Methods

deserialize

$tm->deserialize ($text) This method consumes the text string passed in and interprets it as \s-1CSV\s0 formatted information. What topic map information is generated, depends on the header line (the first line):

  • If the header line contains a field called \*(C`association-type\*(C', then all rows will be interpreted as assertions. In that the remaining header fields (in that order) are interpreted as roles (role types). For all rows in the \s-1CSV\s0 stream, the position where the \*(C`association-type\*(C' field was is ignored. The other fields (in that order) are affiliated with the corresponding roles. Example: association-type,location,bio-unit is-born,gold-coast,rumsti is-born,vienna,ramsti Scoping cannot be controlled. Also all players and roles (obviously) are directly interpreted as identifiers. Subject identifiers and locators are not (yet) implemented.

  • If the header line contains a field called \*(C`id\*(C', then all further rows will be interpreted as topic characteristics, with each topic on one line. The column position where the \*(C`id\*(C' field in the header is will be interpreted as toplet identifier. All further columns will be interpreted according to the following:

    • If the header column is named \*(C`name\*(C', the values will be used as topic names.

    • Otherwise if the value looks like a \s-1URI\s0, an occurrence with that \s-1URI\s0 value will be be added to the topic.

    • Otherwise an occurrence with a string value will be added to the topic.

    Example: name,id,location,homepage "Rumsti",rumsti,gold-coast,http://rumsti.com "Ramsti",ramsti,vienna,http://ramsti.com

serialize

$tm->serialize [Since \s-1TM\s0 1.53] This method serializes a fragment of a topic map into \s-1CSV\s0. Which fragment can be controlled with the header line and options (see constructor).

This string contains a comma separated list (\s-1CSV\s0 parseable) of headings. If one of the headings is \*(C`association-type\*(C', then the generated \s-1CSV\s0 content will contain associations only. Nothing else is implemented yet. The other headings control which roles (and in which order) should be included in the \s-1CSV\s0 content. If a particular role type has more than one player, then all players are included. \s-1NOTE\s0: As this is inconsistent, this will have to change. If existing, then this controls which association type is to be taken. If existing and non-zero, the base \s-1URI\s0 of the map will remain in the identifiers. Otherwise it will be removed. If existing (and when selecting only associations), this specification will be interpreted in the sense of \*(C`asserts\*(C' (see \s-1TM\s0).

Example: $tm->serialize (header_line => 'association-type,location,bio-unit', type => 'is-born', baseuri => 0);

RELATED TO TM::Serializable::CSV…

\s-1TM\s0, TM::Serializable

AUTHOR INFORMATION

Copyright 2010 Robert Barta.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. http://www.perl.com/perl/misc/Artistic.html