1 | <?php
|
---|
2 | require_once RDFAPI_INCLUDE_DIR . 'model/Node.php';
|
---|
3 |
|
---|
4 | // ----------------------------------------------------------------------------------
|
---|
5 | // Class: Literal
|
---|
6 | // ----------------------------------------------------------------------------------
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * An RDF literal.
|
---|
10 | * The literal supports the xml:lang and rdf:datatype property.
|
---|
11 | * For XML datatypes see: http://www.w3.org/TR/xmlschema-2/
|
---|
12 | *
|
---|
13 | * @version $Id: Literal.php 497 2007-08-13 05:14:26Z cweiske $
|
---|
14 | * @author Chris Bizer <chris@bizer.de>
|
---|
15 | * @author Daniel Westphal <dawe@gmx.de>
|
---|
16 | *
|
---|
17 | * @package model
|
---|
18 | * @access public
|
---|
19 | *
|
---|
20 | */
|
---|
21 | class Literal extends Node {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Label of the literal
|
---|
25 | * @var string
|
---|
26 | * @access private
|
---|
27 | */
|
---|
28 | var $label;
|
---|
29 | /**
|
---|
30 | * Language of the literal
|
---|
31 | * @var string
|
---|
32 | * @access private
|
---|
33 | */
|
---|
34 | var $lang;
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Datatype of the literal
|
---|
38 | * @var string
|
---|
39 | * @access private
|
---|
40 | */
|
---|
41 | var $dtype;
|
---|
42 |
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Constructor
|
---|
46 | *
|
---|
47 | * @param string $str label of the literal
|
---|
48 | * @param string $language optional language identifier
|
---|
49 | * @param string $datatype optional datatype
|
---|
50 | *
|
---|
51 | */
|
---|
52 | function Literal($str, $language = NULL, $datatype = null)
|
---|
53 | {
|
---|
54 | $this->label = $str;
|
---|
55 |
|
---|
56 | if ($language != NULL) {
|
---|
57 | $this->lang = $language;
|
---|
58 | } else {
|
---|
59 | $this->lang = NULL;
|
---|
60 | }
|
---|
61 |
|
---|
62 | if ($datatype != null) {
|
---|
63 | $this->dtype = $datatype;
|
---|
64 | } else {
|
---|
65 | $this->dtype = NULL;
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Returns the string value of the literal.
|
---|
71 | *
|
---|
72 | * @access public
|
---|
73 | * @return string value of the literal
|
---|
74 | */
|
---|
75 | function getLabel() {
|
---|
76 |
|
---|
77 | return $this->label;
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Returns the language of the literal.
|
---|
82 | *
|
---|
83 | * @access public
|
---|
84 | * @return string language of the literal
|
---|
85 | */
|
---|
86 | function getLanguage() {
|
---|
87 |
|
---|
88 | return $this->lang;
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Sets the language of the literal.
|
---|
93 | *
|
---|
94 | * @access public
|
---|
95 | * @param string $lang
|
---|
96 | */
|
---|
97 | function setLanguage($lang) {
|
---|
98 |
|
---|
99 | $this->lang = $lang;
|
---|
100 | }
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Returns the datatype of the literal.
|
---|
104 | *
|
---|
105 | * @access public
|
---|
106 | * @return string datatype of the literal
|
---|
107 | */
|
---|
108 | function getDatatype() {
|
---|
109 |
|
---|
110 | return $this->dtype;
|
---|
111 | }
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Sets the datatype of the literal.
|
---|
115 | * Instead of datatype URI, you can also use an datatype shortcuts like STRING or INTEGER.
|
---|
116 | * The array $short_datatype with the possible shortcuts is definded in ../constants.php
|
---|
117 | *
|
---|
118 | * @access public
|
---|
119 | * @param string URI of XML datatype or datatype shortcut
|
---|
120 | *
|
---|
121 | */
|
---|
122 | function setDatatype($datatype) {
|
---|
123 | GLOBAL $short_datatype;
|
---|
124 | if (stristr($datatype,DATATYPE_SHORTCUT_PREFIX)) {
|
---|
125 | $this->dtype = $short_datatype[substr($datatype,strlen(DATATYPE_SHORTCUT_PREFIX)) ];}
|
---|
126 | else
|
---|
127 | $this->dtype = $datatype;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Checks if ihe literal equals another literal.
|
---|
132 | * Two literals are equal, if they have the same label and they
|
---|
133 | * have the same language/datatype or both have no language/datatype property set.
|
---|
134 | *
|
---|
135 | * @access public
|
---|
136 | * @param object literal $that
|
---|
137 | * @return boolean
|
---|
138 | */
|
---|
139 | function equals ($that) {
|
---|
140 |
|
---|
141 | if (($that == NULL) or !(is_a($that, 'Literal'))) {
|
---|
142 | return false;
|
---|
143 | }
|
---|
144 |
|
---|
145 | if ( ($this->label == $that->getLabel()) && ( ( ($this->lang == $that->getLanguage()) ||
|
---|
146 | ($this->lang == NULL && $that->getLanguage() == NULL) ) &&
|
---|
147 |
|
---|
148 | (
|
---|
149 | ($this->dtype == $that->getDatatype() ||
|
---|
150 | ($this->dtype == NULL && $that->getDatatype() == NULL)) ) ) )
|
---|
151 | {
|
---|
152 | return true;
|
---|
153 | }
|
---|
154 |
|
---|
155 | return false;
|
---|
156 | }
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * Dumps literal.
|
---|
160 | *
|
---|
161 | * @access public
|
---|
162 | * @return string
|
---|
163 | */
|
---|
164 | function toString() {
|
---|
165 | $dump = 'Literal("' . $this->label .'"';
|
---|
166 | if ($this->lang != NULL)
|
---|
167 | $dump .= ', lang="' . $this->lang .'"';
|
---|
168 | if ($this->dtype != NULL)
|
---|
169 | $dump .= ', datatype="' . $this->dtype .'"';
|
---|
170 | $dump .= ')';
|
---|
171 | return $dump;
|
---|
172 | }
|
---|
173 |
|
---|
174 |
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * Doing string magic in PHP5
|
---|
178 | * @return string String representation of this Literal
|
---|
179 | */
|
---|
180 | function __toString()
|
---|
181 | {
|
---|
182 | return $this->toString();
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|
186 | } // end: Literal
|
---|
187 |
|
---|
188 | ?> |
---|