/** * Add to the output a serialization of a property assignment where an * SMWExpResource is the object. It is assumed that a suitable subject * block has already been openend. * * @param $expResourceProperty SMWExpNsResource the property to use * @param $expResource SMWExpResource the data value to use * @param $indent string specifying a prefix for indentation (usually a sequence of tabs) * @param $isClassTypeProp boolean whether the resource must be declared as a class */ protected function serializeExpResource(SMWExpNsResource $expResourceProperty, SMWExpResource $expResource, $indent, $isClassTypeProp) { $this->post_ns_buffer .= $indent . '<' . $expResourceProperty->getQName(); if (!$expResource->isBlankNode()) { if ($expResource instanceof SMWExpNsResource && $expResource->getNamespaceID() == 'wiki') { // very common case, reduce bandwidth $this->post_ns_buffer .= ' rdf:resource="&wiki;' . $expResource->getLocalName() . '"'; } else { $uriValue = $this->makeAttributeValueString($expResource->getUri()); $this->post_ns_buffer .= ' rdf:resource="' . $uriValue . '"'; } } $this->post_ns_buffer .= "/>\n"; if ($isClassTypeProp) { $this->requireDeclaration($expResource, SMW_SERIALIZER_DECL_CLASS); } }
/** * Return an array of ternary arrays (subject predicate object) of * SMWExpElements that represents the flattened version of this data. * * @return array of array of SMWExpElement */ public function getTripleList(Element $subject = null) { global $smwgBnodeCount; if (!isset($smwgBnodeCount)) { $smwgBnodeCount = 0; } if ($subject == null) { $subject = $this->m_subject; } $result = array(); foreach ($this->m_edges as $key => $edge) { foreach ($this->m_children[$key] as $childElement) { if ($childElement instanceof SMWExpData) { $childSubject = $childElement->getSubject(); } else { $childSubject = $childElement; } if ($childSubject instanceof SMWExpResource && $childSubject->isBlankNode()) { // bnode, rename ID to avoid unifying bnodes of different contexts // TODO: should we really rename bnodes of the form "_id" here? $childSubject = new SMWExpResource('_' . $smwgBnodeCount++, $childSubject->getDataItem()); } $result[] = array($subject, $edge, $childSubject); if ($childElement instanceof SMWExpData) { // recursively add child's triples $result = array_merge($result, $childElement->getTripleList($childSubject)); } } } return $result; }
protected function serializeExpResource(SMWExpResource $element) { if ($element instanceof SMWExpNsResource) { $this->requireNamespace($element->getNamespaceID(), $element->getNamespace()); } $this->post_ns_buffer .= self::getTurtleNameForExpElement($element); }
/** * Constructor. The given URI must not contain serialization-specific * abbreviations or escapings, such as XML entities. * * @param string $localName Local part of the abbreviated URI * @param string $namespace Namespace URI prefix of the abbreviated URI * @param string $namespaceId Namespace abbreviation of the abbreviated URI * @param SMWDataItem|null $dataItem * * @throws InvalidArgumentException */ public function __construct($localName, $namespace, $namespaceId, SMWDataItem $dataItem = null) { if (!is_string($localName)) { throw new InvalidArgumentException('$localName needs to be a string'); } if (!is_string($namespace)) { throw new InvalidArgumentException('$namespace needs to be a string'); } if (!is_string($namespaceId)) { throw new InvalidArgumentException('$namespaceId needs to be a string'); } parent::__construct($namespace . $localName, $dataItem); $this->namespace = $namespace; $this->namespaceId = $namespaceId; $this->localName = $localName; }
/** * Update the declaration "todo" and "done" lists to reflect the fact that * the given element has been declared to has the given type. * * @param $element SMWExpResource specifying the element to update * @param $typeflag integer specifying the type (e.g. SMW_SERIALIZER_DECL_CLASS) */ protected function declarationDone(SMWExpResource $element, $typeflag) { $name = $element->getUri(); $curdone = array_key_exists($name, $this->decl_done) ? $this->decl_done[$name] : 0; $this->decl_done[$name] = $curdone | $typeflag; if (array_key_exists($name, $this->decl_todo)) { $this->decl_todo[$name] = $this->decl_todo[$name] & ~$typeflag; if ($this->decl_todo[$name] == 0) { unset($this->decl_todo[$name]); } } }
/** * Constructor. The given URI must not contain serialization-specific * abbreviations or escapings, such as XML entities. * * @param $localname string local part of the abbreviated URI * @param $namespace string namespace URI prefix of the abbreviated URI * @param $namespaceid string namespace abbreviation of the abbreviated URI * @param $dataItem SMWDataItem or null */ public function __construct($localname, $namespace, $namespaceid, $dataItem = null) { parent::__construct($namespace . $localname, $dataItem); $this->m_namespace = $namespace; $this->m_namespaceid = $namespaceid; $this->m_localname = $localname; }