diff options
author | mensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f> | 2008-01-25 07:24:38 +0000 |
---|---|---|
committer | mensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f> | 2008-01-25 07:24:38 +0000 |
commit | e740849d4c37dca5634e0ac39ffb6dfdb2aedf1e (patch) | |
tree | 959c130f4d200d456c73cd9e903e00a2ac1160cd /services | |
parent | 194ba8fbee8b4c131cecbb341d3b6bffbcb37627 (diff) | |
download | semanticscuttle-e740849d4c37dca5634e0ac39ffb6dfdb2aedf1e.tar.gz semanticscuttle-e740849d4c37dca5634e0ac39ffb6dfdb2aedf1e.tar.bz2 |
New feature: structured tags, add synonym links (in backend)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@28 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'services')
-rw-r--r-- | services/bookmarkservice.php | 11 | ||||
-rw-r--r-- | services/tag2tagservice.php | 36 |
2 files changed, 34 insertions, 13 deletions
diff --git a/services/bookmarkservice.php b/services/bookmarkservice.php index 93dd06a..68f3821 100644 --- a/services/bookmarkservice.php +++ b/services/bookmarkservice.php @@ -311,16 +311,13 @@ class BookmarkService { $query_4 .= ' AND ('; $allLinkedTags = $tag2tagservice->getAllLinkedTags($this->db->sql_escape($tags[$i]), '>', $user); - while (count($allLinkedTags)>1) { + + while (is_array($allLinkedTags) && count($allLinkedTags)>0) { $query_4 .= ' T'. $i .'.tag = "'. array_pop($allLinkedTags) .'"'; $query_4 .= ' OR'; } - if(is_array($allLinkedTags)) { - $query_4 .= ' T'. $i .'.tag = "'. array_pop($allLinkedTags) .'"'; - } else { - $query_4 .= ' T'. $i .'.tag = "'. $allLinkedTags .'"'; - } - + + $query_4 .= ' T'. $i .'.tag = "'. $this->db->sql_escape($tags[$i]) .'"'; $query_4 .= ') AND T'. $i .'.bId = B.bId'; //die($query_4); diff --git a/services/tag2tagservice.php b/services/tag2tagservice.php index 14d57b3..f46ef7c 100644 --- a/services/tag2tagservice.php +++ b/services/tag2tagservice.php @@ -37,7 +37,7 @@ class Tag2TagService { } // Return the target linked tags. If inverseRelation is true, return the source linked tags. - function getLinkedTags($tag, $relationType, $uId = null, $inverseRelation = false) { + function getLinkedTags($tag, $relationType, $uId = null, $inverseRelation = false, $stopList = array()) { // Set up the SQL query. if($inverseRelation) { $queriedTag = "tag1"; @@ -68,41 +68,65 @@ class Tag2TagService { $rowset = $this->db->sql_fetchrowset($dbresult); $output = array(); foreach($rowset as $row) { - $output[] = $row['tag']; + if(!in_array($row['tag'], $stopList)) { + $output[] = $row['tag']; + } + } + + //bijective case for '=' + if($relationType == '=' && $inverseRelation == false) { + //$stopList[] = $tag; + $bijectiveOutput = $this->getLinkedTags($tag, $relationType, $uId, true, $stopList); + $output = array_merge($output, $bijectiveOutput); + //$output = array_unique($output); // remove duplication } + return $output; } /* TODO: clean the outputs to obtain homogenous ones*/ function getAllLinkedTags($tag1, $relationType, $uId, $asFlatList=true, $stopList=array()) { + $asFlatList = true; //we disable the tree list parameter for the moment + if(in_array($tag1, $stopList)) { return $tag1; } - $linkedTags = $this->getLinkedTags($tag1, $relationType, $uId); + + $stopList2 = $stopList; + $stopList2[] = $tag1; + $linkedTags = $this->getLinkedTags($tag1, $relationType, $uId, false, $stopList2); + + if($relationType != '=') { + $linkedTags = array_merge($linkedTags, $this->getLinkedTags($tag1, '=', $uId, false, $stopList2)); + } + if(count($linkedTags) == 0) { return $tag1; } else { $output = array(); if($asFlatList == true) { - $output[$tag1] = $tag1; + //$output[$tag1] = $tag1; } else { $output = array('node'=>$tag1); } $stopList[] = $tag1; foreach($linkedTags as $linkedTag) { - $allLinkedTags = $this->getAllLinkedTags($linkedTag, $relationType, $uId, $asFlatList, $stopList); + $allLinkedTags = $this->getAllLinkedTags($linkedTag, $relationType, $uId, $asFlatList, $stopList); + if($asFlatList == true) { if(is_array($allLinkedTags)) { + $output[] = $linkedTag; $output = array_merge($output, $allLinkedTags); } else { - $output[$allLinkedTags] = $allLinkedTags; + $output[] = $allLinkedTags; } } else { $output[] = $allLinkedTags; } } } + //$output = array_unique($output); // remove duplication return $output; } |