My favorites | Sign in
Project Home
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
<?php

/*! @defgroup WsFramework Framework for the Web Services */
//@{

/*! @file \ws\framework\ProcessorXML.php
@brief This class handle the creationg and reading of a WSF Web Services internal XML data.

\n\n

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/


/*! @brief Manipulate structWSF internal XML resultset data resultsets

\n

@return returns NULL

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
class ProcessorXML
{
private $dom;

private $prefixes = array();

/*! @brief Constructor
@details Create a new DOM document for the XML document being processed

\n

@return returns NULL

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function __construct()
{
$this->dom = new DomDocument("1.0", "utf-8");
}

function __destruct(){}

/*! @brief Create a resultset root element

\n

@return returns the created resulotset element

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function createResultset()
{
$resultset = $this->dom->createElement("resultset");

return ($resultset);
}

/*! @brief Create a subject in the resultset

\n

@param[in] $type Type of the subject
@param[in] $uri Optional URI for the subject

@return returns the reference to the subject's element

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function createSubject($type, $uri = "")
{
$subject = $this->dom->createElement("subject");

// The TYPE attribute
$type_attr = $this->dom->createAttribute("type");
$type_attr_value = $this->dom->createTextNode($this->xmlEncode($type));

$subject->appendChild($type_attr);
$type_attr->appendChild($type_attr_value);

// The URI attribute
$uri_attr = $this->dom->createAttribute("uri");
$uri_attr_value = $this->dom->createTextNode($this->xmlEncode($uri));

$subject->appendChild($uri_attr);
$uri_attr->appendChild($uri_attr_value);

return $subject;
}

/*! @brief Create a prefix element for the resultset

\n

@param[in] $entity Entity prefix
@param[in] $uri Uri that goes with the entity prefix

@return returns the reference to the prefix element

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function createPrefix($entity, $uri)
{
$prefix = $this->dom->createElement("prefix");

// The TYPE attribute
$prefix_attr = $this->dom->createAttribute("entity");
$prefix_attr_value = $this->dom->createTextNode($entity);

$prefix->appendChild($prefix_attr);
$prefix_attr->appendChild($prefix_attr_value);

// The URI attribute
$uri_attr = $this->dom->createAttribute("uri");
$uri_attr_value = $this->dom->createTextNode($uri);

$prefix->appendChild($uri_attr);
$uri_attr->appendChild($uri_attr_value);

return $prefix;
}

/*! @brief Create a predicate for the resultset

\n

@param[in] $type Type of the predicate

@return returns the reference to the predicate's element

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function createPredicate($type)
{
$predicate = $this->dom->createElement("predicate");

// The TYPE attribute
$type_attr = $this->dom->createAttribute("type");
$type_attr_value = $this->dom->createTextNode($this->xmlEncode($type));

$predicate->appendChild($type_attr);
$type_attr->appendChild($type_attr_value);

return $predicate;
}

/*! @brief Create an object for the resultset

\n

@param[in] $type Type of the object
@param[in] $uri URI of the object
@param[in] $label Optional label to refer to the object

@return returns the reference to the predicate's element

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function createObject($type, $uri, $label = "")
{
$object = $this->dom->createElement("object");

// The TYPE attribute
if ($type != "")
{
$type_attr = $this->dom->createAttribute("type");
$type_attr_value = $this->dom->createTextNode($this->xmlEncode($type));

$object->appendChild($type_attr);
$type_attr->appendChild($type_attr_value);
}

// The URI attribute
$uri_attr = $this->dom->createAttribute("uri");
$uri_attr_value = $this->dom->createTextNode($this->xmlEncode($uri));

$object->appendChild($uri_attr);
$uri_attr->appendChild($uri_attr_value);

if ($label != "")
{
// The LABEL attribute
$label_attr = $this->dom->createAttribute("label");
$label_attr_value = $this->dom->createTextNode($this->xmlEncode($label));

$object->appendChild($label_attr);
$label_attr->appendChild($label_attr_value);
}

return $object;
}

/*! @brief Create an object that has a content (literal)
@details This kind of object are "literal objects"

\n

@param[in] $content Content of the literal.

@return returns the reference to the object's element

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function createObjectContent($content)
{
$objectContent = $this->dom->createElement("object", $this->xmlEncode($content));

// The TYPE attribute
$type_attr = $this->dom->createAttribute("type");
$type_attr_value = $this->dom->createTextNode("rdfs:Literal");

$objectContent->appendChild($type_attr);
$type_attr->appendChild($type_attr_value);

return $objectContent;
}


/*! @brief Create a reification statement for the resultset
@details This is the way to reify a statement in the resultset

\n

@param[in] $type Type of the reification statement
@param[in] $value Value of the reification statement

@return returns the reference to the refification statement's element

@return returns NULL

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function createReificationStatement($type, $value)
{
$reify = $this->dom->createElement("reify");

// The TYPE attribute
$type_attr = $this->dom->createAttribute("type");
$type_attr_value = $this->dom->createTextNode($this->xmlEncode($type));

$reify->appendChild($type_attr);
$type_attr->appendChild($type_attr_value);

// The VALUE attribute
$value_attr = $this->dom->createAttribute("value");
$value_attr_value = $this->dom->createTextNode($this->xmlEncode($value));

$reify->appendChild($value_attr);
$value_attr->appendChild($value_attr_value);

return $reify;
}

/*! @brief Save the resultset as a XML file

\n

@param[in] $resultset Resultset to be save as a xml document.

@return returns the XML document of the resultset

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function saveXML($resultset)
{
$this->dom->appendChild($resultset);

$this->dom->formatOutput = true;

return $this->dom->saveXML();
}

/*! @brief Load a XML document that is a resultset

\n

@param[in] $xml_doc XML document being loaded

@return returns a reference to the DOM structure of the loaded XML document

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function loadXML($xml_doc)
{
// Get all prefixes for this XML document.
$prefixPos = 0;

while (($prefixPos = strpos($xml_doc, "<prefix", $prefixPos)) !== FALSE)
{
$entityPosStart = strpos($xml_doc, 'entity="', $prefixPos);
$entityPosEnd = strpos($xml_doc, '"', $entityPosStart + 9);
$entity = substr($xml_doc, $entityPosStart + 8, ($entityPosEnd - $entityPosStart - 8));

$uriPosStart = strpos($xml_doc, 'uri="', $entityPosEnd);
$uriPosEnd = strpos($xml_doc, '"', $uriPosStart + 6);
$uri = substr($xml_doc, $uriPosStart + 5, ($uriPosEnd - $uriPosStart - 5));

$prefixPos = $uriPosEnd;

$this->prefixes[$entity] = $uri;
}

// Now lets resolve all prefixes in the XML file.

$replace = array();
$replaceFor = array();

foreach ($this->prefixes as $prefix => $uri)
{
array_push($replace, "type=\"$prefix:");
array_push($replaceFor, "type=\"$uri");
}

$xml_doc = str_ireplace($replace, $replaceFor, $xml_doc);

$this->dom->loadXML($xml_doc);
}

/*! @brief Create a resultset from a node reference of the current resultset.

\n

@param[in] $element Reference to the node from which to create the resultset

@return returns the new resultset being created

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function createResultsetFromElement(&$element)
{
if(get_class($element) != "DOMElement ")
{
$dom = new DomDocument("1.0", "utf-8");
$resultset = $dom->appendChild($dom->createElement("resultset"));

$domNode = $dom->importNode($element, true);
$resultset->appendChild($domNode);

$dom->formatOutput = true;

return ($dom);
}

return (NULL);
}
/*! @brief Append an element to the root element of the current XML document

\n

@param[in] $element Reference to the element to happen to the root element of this XML document.

@return returns NULL

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function appendElementToRoot(&$element)
{
$domNode = $this->dom->importNode($element, true);
$this->dom->documentElement->appendChild($domNode);
}

function importNode(&$targetElement, $importElement)
{
if(($targetElement != null && (get_class($targetElement) == "DOMNode" ||
get_class($targetElement) == "DOMElement")) &&
($importElement != null && (get_class($importElement) == "DOMNode" ||
get_class($importElement) == "DOMElement")))
{
$domNode = $this->dom->importNode($importElement, true);
$targetElement->appendChild($domNode);
}
}


/*! @brief Get a list of nodes of a given type

\n

@param[in] $type Type of the nodes you want

@return returns a DOMNodeList with a reference to all nodes of that type

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getSubjectsByType($type)
{
$type = $this->transformPrefix($type);

$xpath = new DOMXPath($this->dom);

$query = '//resultset/subject[attribute::type="' . $type . '"]';

$subjects = $xpath->query($query);

return ($subjects);
}

function transformPrefix($type)
{
if (strpos($type, ":") !== FALSE)
{
foreach ($this->prefixes as $entity => $uri)
{
if (stripos($type, $entity . ":") !== FALSE)
{
return (str_replace($entity . ":", $uri, $type));
}
}
}

return $type;
}


/*! @brief Get al subjects of a resultset

\n

@return returns a DOMNodeList with a reference to all subjects of the resultset

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getSubjects()
{
$xpath = new DOMXPath($this->dom);

$query = '//resultset/subject';

$subjects = $xpath->query($query);

return($subjects);
}

/*! @brief Get all prefixes for this document

\n

@return returns a DOMNodeList with a reference to all prefixes

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getPrefixes()
{
$xpath = new DOMXPath($this->dom);

$query = '//resultset/prefix';

$prefixes = $xpath->query($query);

return ($prefixes);
}

function getSubjectContent(&$subject){}


/*! @brief Send a XPath query to the resultset

\n

@param[in] $xpath The xpath query to send

@return returns a DOMNodeList with a reference to all ndoes that are in that path

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getXPath($xpath)
{
$xpath = $this->transformPrefix($xpath);

$xpath_path = new DOMXPath($this->dom);

$nodes = $xpath_path->query($xpath);

return ($nodes);
}


/*! @brief Get a list of predicate nodes of a given type

\n

@param[in] $subject Target subject to get its predicates from
@param[in] $type Type of the nodes you want

@return returns a DOMNodeList with a reference to all properties nodes of that type

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getPredicatesByType(&$subject, $type)
{
if($subject != null && (get_class($subject) == "DOMNode" ||
get_class($subject) == "DOMElement"))
{
$type = $this->transformPrefix($type);

$xpath = new DOMXPath($this->dom);

$query = './/predicate[attribute::type="' . $type . '"]';

$predicates = $xpath->query($query, $subject);

return($predicates);
}

return(new DOMNodeList());
}

/*! @brief Get all predicates for a given subject of the resultset

\n

@param[in] $subject Target subject

@return returns a DOMNodeList with a reference to all predicates of the resultset, for that subject

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getPredicates(&$subject)
{
if($subject != null && (get_class($subject) == "DOMNode" ||
get_class($subject) == "DOMElement"))
{
$xpath = new DOMXPath($this->dom);

$query = './/predicate';

$predicates = $xpath->query($query, $subject);

return ($predicates);
}

return(new DOMNodeList());
}

/*! @brief Get all objects for a given predicate of the resultset for a given type

\n

@param[in] $predicate Target predicate
@param[in] $type Target type

@return returns a DOMNodeList with a reference to all objects of the resultset, for that predicate, for that type

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getObjectsByType(&$predicate, $type)
{
if($predicate != null && (get_class($predicate) == "DOMNode" ||
get_class($predicate) == "DOMElement"))
{
$type = $this->transformPrefix($type);

$xpath = new DOMXPath($this->dom);

$query = './/object[attribute::type="' . $type . '"]';

$objects = $xpath->query($query, $predicate);

return ($objects);
}
else
{
return(new DOMNodeList());
}
}

/*! @brief Get all objects for a given predicate of the resultset

\n

@param[in] $predicate Target predicate

@return returns a DOMNodeList with a reference to all objects of the resultset, for that predicate

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getObjects(&$predicate)
{
if($predicate != null && (get_class($predicate) == "DOMNode" ||
get_class($predicate) == "DOMElement"))
{
$xpath = new DOMXPath($this->dom);

$query = './/object';

$objects = $xpath->query($query, $predicate);

return ($objects);
}

return(new DOMNodeList());
}

/*! @brief Get the reification statement of a triple by its reification type

\n

@param[in] $object the reference object node
@param[in] $type URI of the type of the reification statement

@return returns reification node

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getReificationStatementsByType(&$object, $type)
{
if($object != null && (get_class($object) == "DOMNode" ||
get_class($object) == "DOMElement"))
{
$type = $this->transformPrefix($type);

$xpath = new DOMXPath($this->dom);

$query = './/reify[attribute::type="' . $type . '"]';

$reifies = $xpath->query($query, $object);

return ($reifies);
}

return(new DOMNodeList());
}

/*! @brief Get the reification statement of a triple

\n

@param[in] $object the reference object node

@return returns reification node

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getReificationStatements(&$object)
{
if($object != null && (get_class($object) == "DOMNode" ||
get_class($object) == "DOMElement"))
{
$xpath = new DOMXPath($this->dom);

$query = './/reify';

$reifies = $xpath->query($query, $object);

return ($reifies);
}

return(new DOMNodeList());
}

/*! @brief Get URI of a node of the resulset

\n

@param[in] $node the reference node

@return returns the URI

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getURI(&$node)
{
if($node != null && (get_class($node) == "DOMNode" ||
get_class($node) == "DOMElement"))
{
if (isset($node->attributes))
{
return ($node->attributes->getNamedItem("uri")->nodeValue);
}
}

return "";
}

/*! @brief Get the Entity of a prefix element

\n

@param[in] $node the reference node

@return returns the Entity

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getEntity(&$node)
{
if($node != null && (get_class($node) == "DOMNode" ||
get_class($node) == "DOMElement"))
{
if(isset($node->attributes))
{
return ($node->attributes->getNamedItem("entity")->nodeValue);
}
}
return "";
}


/*! @brief Get Label of a node of the resulset

\n

@param[in] $node the reference node

@return returns the Label

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getLabel(&$node)
{
if($node != null && (get_class($node) == "DOMNode" ||
get_class($node) == "DOMElement"))
{
if (isset($node->attributes))
{
return ($node->attributes->getNamedItem("label")->nodeValue);
}
}

return "";
}

/*! @brief Get value of a node of the resulset

\n

@param[in] $node the reference node

@return returns the value

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getValue(&$node)
{
if($node != null && (get_class($node) == "DOMNode" ||
get_class($node) == "DOMElement"))
{
if (isset($node->attributes))
{
return ($node->attributes->getNamedItem("value")->nodeValue);
}
}

return "";
}

/*! @brief Get type of a node of the resulset

\n

@param[in] $node the reference node
@param[in] $prefixed Convert to prefixed form if a prefix exists for this type.

@return returns the type

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getType(&$node, $prefixed = TRUE)
{
if($node != null && (get_class($node) == "DOMNode" ||
get_class($node) == "DOMElement"))
{
if(isset($node->attributes))
{
if($prefixed === TRUE)
{
foreach($this->prefixes as $entity => $uri)
{
if(isset($node->attributes->getNamedItem("type")->nodeValue))
{
if(strpos($node->attributes->getNamedItem("type")->nodeValue, $uri) !== FALSE)
{
return(str_replace($uri, $entity . ":", $node->attributes->getNamedItem("type")->nodeValue));
}
}
}
}

if(isset($node->attributes->getNamedItem("type")->nodeValue))
{
return ($node->attributes->getNamedItem("type")->nodeValue);
}
}
}

return "";
}

/*! @brief Get content of a node of the resulset

\n

@param[in] $node the reference node

@return returns the content

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function getContent(&$node)
{
if($node != null && (get_class($node) == "DOMNode" ||
get_class($node) == "DOMElement"))
{
if(isset($node->attributes))
{
return($node->nodeValue);
}
}

return("");
}

/**
* Helper function that removes all child nodes of $node recursively
* (i.e. including child nodes of the child nodes and so forth).
*/
function removeChildren(&$node)
{
while ($node->firstChild)
{
while ($node->firstChild->firstChild)
{
$this->removeChildren($node->firstChild);
}

$node->removeChild($node->firstChild);
}
}

/*! @brief Remove all the predicates assertions for a given subject.

\n

@param[in] $subject Target subject for which to remove the predicate assertions
@param[in] $type URI of the predicate to remove.

@return returns Nothing

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function removePredicatesByType(&$subject, $type)
{
$type = $this->transformPrefix($type);

$xpath = new DOMXPath($this->dom);

$query = './/predicate[attribute::type="' . $type . '"]';

$predicates = $xpath->query($query, $subject);

foreach($predicates as $predicate)
{
$predicate->parentNode->removeChild($predicate);
}
}

/*! @brief Encode content to be included in XML files

\n

@param[in] $string The content string to be encoded

@return returns the encoded string

@author Frederick Giasson, Structured Dynamics LLC.

\n\n\n
*/
function xmlEncode($string)
{
// Replace all the possible entities by their character. That way, we won't "double encode"
// these entities. Otherwise, we can endup with things such as "&amp;amp;" which some
// XML parsers doesn't seem to like (and throws errors).
//$string = str_replace(array ("%5C", "&amp;", "&lt;", "&gt;"), array ("\\", "&", "<", ">"), $string);

return str_replace(array ("\\", "&", "<", ">"), array ("%5C", "&amp;", "&lt;", "&gt;"), $string);
}

function xmlDecode($string)
{
return str_replace(array ("%5C", "&amp;", "&lt;", "&gt;"), array ("\\", "&", "<", ">"), $string);
}

function saveRdfN3()
{
$rdf_part = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n\n";
$rdf_reification = "";

$subjects = $this->getSubjects();

foreach($subjects as $subject)
{
$subjectURI = $this->getURI($subject);
$subjectType = $this->getType($subject, FALSE);

$rdf_part .= "<$subjectURI> a <$subjectType> ;\n";

$predicates = $this->getPredicates($subject);

foreach($predicates as $predicate)
{
$objects = $this->getObjects($predicate);

foreach($objects as $object)
{
$objectType = $this->getType($object);
$predicateType = $this->getType($predicate, FALSE);

if($objectType == "rdfs:Literal")
{
$objectValue = $this->getContent($object);
$rdf_part .= " <$predicateType> \"" . $this->escapeN3($objectValue) . "\" ;\n";
}
else
{
$objectURI = $this->getURI($object);
$rdf_part .= " <$predicateType> <$objectURI> ;\n";
}


// Check for reified statements.
$reifies = $this->getReificationStatements($object);

foreach($reifies as $reify)
{
$reifyPredicate = $this->getType($reify, FALSE);

$rdf_reification .= "_:" . md5($this->getURI($subject) . $predicateType . $this->getURI($object))
. " a rdf:Statement ;\n";
$rdf_reification .= " rdf:subject <" . $this->getURI($subject) . "> ;\n";
$rdf_reification .= " rdf:predicate <" . $predicateType . "> ;\n";
$rdf_reification .= " rdf:object <" . $this->getURI($object) . "> ;\n";
$rdf_reification .= " <$reifyPredicate> \"" . $this->escapeN3($this->getValue($reify)) . "\" .\n\n";
}
}
}

if(strlen($rdf_part) > 0)
{
$rdf_part = substr($rdf_part, 0, strlen($rdf_part) - 2) . ". \n";
}
}

return($rdf_part.$rdf_reification);
}

private function escapeN3($literal)
{
$literal = str_replace("\\","\\\\", $literal);

return str_replace(array('"', "'"), array('\\"', "\\'"), $literal);
}
}

//@}

?>

Change log

r262 by f...@fgiasson.com on Oct 26, 2011   Diff
fixes a few "undefined" notices. These are
all undefined arrays keys issues. They had
no impact on the instance except if
notices were reported by PHP.
Go to: 
Project members, sign in to write a code review

Older revisions

r248 by f...@fgiasson.com on Sep 16, 2011   Diff
Improve the performance of the class
by using strpos() instead of
stripos(). Since this class is the
central data processor of any
structWSF endpoint, it is highly
...
r221 by f...@fgiasson.com on Aug 10, 2011   Diff
Apparently that the DOMNode->item()
method does some manipulations to the
HTML entities before populating the
DOMNode->nodeValue variable. This
means that if you use the
...
r220 by f...@fgiasson.com on Aug 3, 2011   Diff
XML-decode content with getContent.
All revisions of this file

File info

Size: 24831 bytes, 1020 lines
Powered by Google Project Hosting