Author: david
Date: Fri Oct 28 16:22:59 2011
New Revision: 10230

Log:
Use hash for existing term lookups.  Fix duplication of related term 
relationships

Modified:
   trunk/plugins/sfSkosPlugin/lib/sfSkosPlugin.class.php
   
trunk/plugins/sfSkosPlugin/modules/sfSkosPlugin/actions/importAction.class.php
   trunk/plugins/sfSkosPlugin/modules/sfSkosPlugin/templates/importSuccess.php

Modified: trunk/plugins/sfSkosPlugin/lib/sfSkosPlugin.class.php
==============================================================================
--- trunk/plugins/sfSkosPlugin/lib/sfSkosPlugin.class.php       Fri Oct 28 
16:01:52 2011        (r10229)
+++ trunk/plugins/sfSkosPlugin/lib/sfSkosPlugin.class.php       Fri Oct 28 
16:22:59 2011        (r10230)
@@ -20,8 +20,7 @@
 class sfSkosPlugin
 {
   public
-    $terms = array(),
-    $length = 0;
+    $concepts = array();
 
   public static function parse($doc, $options = array())
   {
@@ -183,8 +182,8 @@
     // Save the term
     $term->save();
 
-    $this->terms[] = $term;
-    $this->length++;
+    // Hash to store concept to term mapping
+    $this->concepts[$uri->nodeValue] = $term->id;
 
     return $this;
   }
@@ -192,7 +191,7 @@
   protected function addTermRelations($concept)
   {
     $subjectUri = 
$concept->getAttributeNodeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 
'about');
-    if (!($subjectUri instanceof DOMAttr) || null === $subject = 
self::getTermBySourceNote($subjectUri->nodeValue))
+    if (!($subjectUri instanceof DOMAttr) || 
!isset($this->concepts[$subjectUri->nodeValue]))
     {
       continue;
     }
@@ -200,15 +199,17 @@
     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) || null === $obj = 
self::getTermBySourceNote($objectUri->nodeValue))
+      if (!($objectUri instanceof DomAttr) || 
!isset($this->concepts[$objectUri->nodeValue]))
       {
         continue;
       }
 
-      // Don't duplicate reciprocal relationship
-      foreach ($relations as $r)
+      // Don't duplicate relationship
+      foreach ($this->relations as $r)
       {
-        if ($r['subject'] == $objectUri->nodeValue && $r['object'] == 
$subjectUri->nodeValue)
+        if (
+          $r['subject'] == $objectUri->nodeValue && $r['object'] == 
$subjectUri->nodeValue ||
+          $r['subject'] == $subjectUri->nodeValue && $r['object'] == 
$objectUri->nodeValue)
         {
           continue 2;
         }
@@ -216,12 +217,12 @@
 
       $relation = new QubitRelation;
       $relation->typeId = QubitTerm::TERM_RELATION_ASSOCIATIVE_ID;
-      $relation->subject = $subject;
-      $relation->object = $obj;
+      $relation->subjectId = $this->concepts[$subjectUri->nodeValue];
+      $relation->objectId = $this->concepts[$objectUri->nodeValue];
 
       $relation->save();
 
-      $relations[] = array('subject' => $subjectUri->nodeValue, 'object' => 
$objectUri->nodeValue);
+      $this->relations[] = array('subject' => $subjectUri->nodeValue, 'object' 
=> $objectUri->nodeValue);
     }
 
     return $this;

Modified: 
trunk/plugins/sfSkosPlugin/modules/sfSkosPlugin/actions/importAction.class.php
==============================================================================
--- 
trunk/plugins/sfSkosPlugin/modules/sfSkosPlugin/actions/importAction.class.php  
    Fri Oct 28 16:01:52 2011        (r10229)
+++ 
trunk/plugins/sfSkosPlugin/modules/sfSkosPlugin/actions/importAction.class.php  
    Fri Oct 28 16:22:59 2011        (r10230)
@@ -73,14 +73,6 @@
 
           $this->skos = sfSkosPlugin::parse($doc, array('taxonomy' => 
$this->taxonomy, 'parent' => $this->parent));
 
-          $this->topLevelTerms = array();
-          foreach ($this->skos->terms as $term)
-          {
-            if ($term->parent == $this->parent)
-            {
-              $this->topLevelTerms[] = $term;
-            }
-          }
         }
       }
     }

Modified: 
trunk/plugins/sfSkosPlugin/modules/sfSkosPlugin/templates/importSuccess.php
==============================================================================
--- trunk/plugins/sfSkosPlugin/modules/sfSkosPlugin/templates/importSuccess.php 
Fri Oct 28 16:01:52 2011        (r10229)
+++ trunk/plugins/sfSkosPlugin/modules/sfSkosPlugin/templates/importSuccess.php 
Fri Oct 28 16:22:59 2011        (r10230)
@@ -1,18 +1,9 @@
-<h1><?php echo __('Import complete') ?></h1>
-
-<h1 class="label"><?php echo __('The following top-level terms were imported') 
?></h2>
+<h1><?php echo __('Import successful') ?></h1>
 
 <?php echo $form->renderFormTag(url_for(array('module' => 'sfSkosPlugin', 
'action' => 'import'))) ?>
 
-  <ul>
-    <?php for ($i = 0; $i < ($termsPerPage <= count($topLevelTerms) ? 
$termsPerPage : count($topLevelTerms)); $i++): ?>
-      <?php $term = $topLevelTerms[$i] ?>
-      <li><?php echo link_to($term->__toString(), url_for(array($term, 
'module' => 'term'))) ?></li>
-    <?php endfor; ?>
-  </ul>
-
   <div>
-    <?php echo __('A total of %1% terms were imported in %2%s', array('%1%' => 
$skos->length, '%2%' => $timer->elapsed())) ?>
+    <?php echo __('%1% terms imported in %2%s', array('%1%' => 
count($skos->concepts), '%2%' => $timer->elapsed())) ?>
   </div>
 
   <div class="actions section">

-- 
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.

Reply via email to