Author: david
Date: Fri Oct 28 17:01:39 2011
New Revision: 10231
Log:
First stab at setting parent/child ids - no idea if it works. Refs issue 2005
Modified:
trunk/plugins/sfSkosPlugin/lib/sfSkosPlugin.class.php
Modified: trunk/plugins/sfSkosPlugin/lib/sfSkosPlugin.class.php
==============================================================================
--- trunk/plugins/sfSkosPlugin/lib/sfSkosPlugin.class.php Fri Oct 28
16:22:59 2011 (r10230)
+++ trunk/plugins/sfSkosPlugin/lib/sfSkosPlugin.class.php Fri Oct 28
17:01:39 2011 (r10231)
@@ -89,9 +89,14 @@
$skos->addTermRelations($concept);
}
- if (0 < $skos->xpath->query('./skos:broader | ./skos:narrower',
$concept)->length)
+ if (0 < $skos->xpath->query('./skos:broader')->length)
{
- $skos->buildHierarchy($concept);
+ $skos->setParent($concept);
+ }
+
+ if (0 < $skos->xpath->query('./skos:narrower')->length)
+ {
+ $skos->setChildren($concept);
}
}
@@ -183,7 +188,7 @@
$term->save();
// Hash to store concept to term mapping
- $this->concepts[$uri->nodeValue] = $term->id;
+ $this->terms[$uri->nodeValue] = $term;
return $this;
}
@@ -191,7 +196,7 @@
protected function addTermRelations($concept)
{
$subjectUri =
$concept->getAttributeNodeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'about');
- if (!($subjectUri instanceof DOMAttr) ||
!isset($this->concepts[$subjectUri->nodeValue]))
+ if (!($subjectUri instanceof DOMAttr) ||
!isset($this->terms[$subjectUri->nodeValue]))
{
continue;
}
@@ -199,7 +204,7 @@
foreach ($this->xpath->query('./skos:related', $concept) as $related)
{
$objectUri =
$related->getAttributeNodeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'resource');
- if (!($objectUri instanceof DomAttr) ||
!isset($this->concepts[$objectUri->nodeValue]))
+ if (!($objectUri instanceof DomAttr) ||
!isset($this->terms[$objectUri->nodeValue]))
{
continue;
}
@@ -217,8 +222,8 @@
$relation = new QubitRelation;
$relation->typeId = QubitTerm::TERM_RELATION_ASSOCIATIVE_ID;
- $relation->subjectId = $this->concepts[$subjectUri->nodeValue];
- $relation->objectId = $this->concepts[$objectUri->nodeValue];
+ $relation->subject = $this->terms[$subjectUri->nodeValue];
+ $relation->object = $this->terms[$objectUri->nodeValue];
$relation->save();
@@ -228,23 +233,68 @@
return $this;
}
- protected function buildHierarchy($concept)
+ protected function setParent($concept)
{
- return;
+ $uri =
$concept->getAttributeNodeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'about');
- // Find and add narrow terms
- // TODO: Merge broader/narrower relations for this term, as defining
- // inverse of relationship is not required by SKOS
- // http://www.w3.org/TR/2009/NOTE-skos-primer-20090818/#sechierarchy
- if ($uri instanceof DOMAttr)
+ if (!isset($this->terms[$uri->nodeValue]))
+ {
+ return;
+ }
+
+ // If term doesn't have default parentId, then assume it's already be set
+ if ($this->parent->id != $this->terms[$uri->nodeValue]->parentId)
+ {
+ return;
+ }
+
+ foreach($this->xpath->query('./skos:broader') as $broader)
+ {
+ if (!($broader instanceof DOMElement))
+ {
+ continue;
+ }
+
+ $parentUri =
$broader->getAttributeNodeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'resource');
+
+ if ($parentUri instanceof DOMAttr)
+ {
+ $this->terms[$uri->nodeValue]->parent =
$this->terms[$parentUri->nodeValue];
+ $this->terms[$uri->nodeValue]->save();
+ }
+
+ return; // Only allowed one parent
+ }
+ }
+
+ protected function setChildren($concept)
+ {
+ $uri =
$concept->getAttributeNodeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'about');
+
+ if (!isset($this->terms[$uri]))
{
- foreach
($this->xpath->query('./skos:Concept[skos:broader[@rdf:resource="'.$uri->nodeValue.'"]]')
as $narrower)
+ return;
+ }
+
+ foreach($this->xpath->query('./skos:narrower') as $narrower)
+ {
+ if (!($narrower instanceof DOMElement))
{
- if (!($narrower instanceof DOMElement))
+ continue;
+ }
+
+ $childUri =
$narrower->getAttributeNodeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'resource');
+
+ if ($childUri instanceof DOMAttr)
+ {
+ // Test if this child is already parented
+ if ($this->terms[$uri->nodeValue]->id ==
$this->terms[$childUri->nodeValue]->parentId)
{
continue;
}
- $this->addTerm($narrower, $term);
+
+ $this->terms[$childUri->nodeValue]->parent =
$this->terms[$uri->nodeValue];
+ $this->terms[$childUri->nodeValue]->save();
}
}
}
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.