blib/lib/Lingua/Ogmios/Annotations/SemanticFeatures.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 9 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 108 SCAR 40.3
CC
7
Cov
0%
new
30.0
semantic_category
6.0
refid_semantic_unit
6.0
CRAP 56.0
1 package Lingua::Ogmios::Annotations::SemanticFeatures;
2  
3 use strict;
4 use warnings;
5  
6 use Lingua::Ogmios::Annotations::Element;
7 our @ISA = qw(Lingua::Ogmios::Annotations::Element);
8  
9
10 # <!-- =================================================== -->
11 # <!-- SEMANTIC_FEATURES_LEVEL -->
12 # <!-- =================================================== -->
13 # <!ELEMENT semantic_features_level
14 # (log_id?, comments*,
15 # semantic_features+) >
16
17 # <!-- semantic_features -->
18 # <!ELEMENT semantic_features
19 # (id, log_id?, semantic_category,
20 # refid_semantic_unit) >
21
22 # <!-- semantic_category -->
23
24 # <!ELEMENT semantic_category
25 # (list_refid_ontology_node)+ >
26  
27 # <!-- list_refid_ontology_node -->
28 # <!ELEMENT list_refid_ontology_node
29 # (refid_ontology_node)+ >
30  
31 # <!-- refid_ontology_node -->
32 # <!ELEMENT refid_ontology_node
33 # (#PCDATA) >
34  
35 sub new {
36 my ($class, $fields) = @_;
37  
38 if (!defined $fields->{'id'}) {
39 $fields->{'id'} = -1;
40 }
41 if ((!defined $fields->{'semantic_category'}) ||
42 (ref($fields->{'semantic_category'} ne "ARRAY")) ||
43 (ref($fields->{'semantic_category'}->[0] ne "ARRAY"))) { # semantic_category
44 die("semantic_category is not defined");
45 }
46 if (!defined $fields->{'refid_semantic_unit'}) { # refid_semantic_unit
47 die("refid_semantic_unit is not defined");
48 }
49  
50 my $semanticfeatures = $class->SUPER::new({
51 'id' => $fields->{'id'},
52 # 'form' => $fields->{'form'},
53 }
54 );
55 bless ($semanticfeatures,$class);
56  
57 $semanticfeatures->refid_semantic_unit($fields->{'refid_semantic_unit'});
58 $semanticfeatures->semantic_category('list_refid_ontology_node', $fields->{'semantic_category'});
59  
60 if (defined $fields->{'log_id'}) {
61 $semanticfeatures->setLogId($fields->{'log_id'});
62 }
63 return($semanticfeatures);
64 }
65  
66 sub semantic_category {
67 my $self = shift;
68 my $ref;
69 my $elt;
70 my $node;
71 my $position;
72 my $internal_field;
73  
74 if ((@_) && (scalar @_ == 2)) {
75 $self->{'semantic_category'} = {};
76 $self->{'semantic_category'}->{'reference'} = shift;
77 # warn "reference: " . $self->{'semantic_category'}->{'reference'} . "\n";
78 $self->{'semantic_category'}->{$self->{'semantic_category'}->{'reference'}} = [];
79  
80 # $position = index($self->{'semantic_category'}->{'reference'}, "list_");
81 # if ($position == 0) {
82 # $internal_field = substr($self->{'semantic_category'}->{'reference'}, $position + 5);
83 # } else {
84 # $internal_field = shift;
85 # }
86 $ref = shift;
87 foreach $elt (@$ref) {
88 my @tmp;
89 foreach $node (@$elt) {
90 push @tmp, $node;
91 # warn "node: $node (" . join(":", @tmp) . ")\n";
92 }
93 push @{$self->{'semantic_category'}->{$self->{'semantic_category'}->{'reference'}}}, \@tmp;
94 }
95 # foreach $elt (@$ref) {
96 # foreach $node (@$elt) {
97 # push @{$self->{$self->{'reference'}}}, $node;
98 # }
99 # }
100  
101 }
102 return($self->{'semantic_category'}->{$self->{'semantic_category'}->{'reference'}});
103 }
104  
105 sub first_node_first_semantic_category {
106 my $self = shift;
107  
108 return($self->{'semantic_category'}->{$self->{'semantic_category'}->{'reference'}}->[0]->[0]);
109 }
110  
111 sub refid_semantic_unit {
112 my $self = shift;
113  
114 if (@_) {
115 # my $old_refid = $self->{'refid_semantic_unit'};
116 $self->{'refid_semantic_unit'} = shift;
117 # if (defined $old_refid) {
118
119 # }
120 }
121 return($self->{'refid_semantic_unit'});
122 }
123  
124 sub reference {
125 my ($self) = @_;
126  
127 return($self->refid_semantic_unit);
128 }
129  
130 sub XMLout {
131 my ($self, $order) = @_;
132
133 return($self->SUPER::XMLout("semantic_features", $order));
134 }
135  
136 sub toString {
137 my $self = shift;
138  
139 my $semf;
140 my $semfString = "";
141
142  
143 # foreach $semf (@{$self->{'semantic_category'}->{$self->{'semantic_category'}->{'reference'}}}) {
144 foreach $semf (@{$self->semantic_category}) {
145 $semfString .= join('/', @$semf) . ":";
146 }
147 chop $semfString;
148 return($semfString);
149 }
150  
151 sub semantic_categorySize {
152 my $self = shift;
153  
154 return(scalar(@{$self->semantic_category}))
155 }
156  
157  
158 1;
159  
160  
161 __END__