/** * Calculated data matching ratios for all links in a relationship specified by rel_id. The computation is done in a background. * While computing the ratios distinct values from stories involved in the relationship might be cached in MSSQL server. The caching happens only if two stories are form * different locations (e.g. different DBMS and server). * * @param [type] $rel_ids colfusion relationship id for which to calculate links data matching rations. * @return [type] [description] */ public function calculateDataMatchingRatios($rel_ids) { //var_dump($rel_ids); if (!isset($rel_ids) || count($rel_ids) == 0) { return; } $relationshipDAO = new RelationshipDAO(); foreach ($rel_ids as $key => $rel_id) { $rel = $relationshipDAO->getRelationship($rel_id); //this might too expensive, I don't need all infor about relationships, just sids, tablemes and links foreach ($rel->links as $key => $link) { $from = new DataMatcherLinkOnePart(); $from->sid = $rel->fromDataset->sid; $from->tableName = $rel->fromTableName; $from->transformation = $link->fromPartEncoded; $to = new DataMatcherLinkOnePart(); $to->sid = $rel->toDataset->sid; $to->tableName = $rel->toTableName; $to->transformation = $link->toPartEncoded; //var_dump($from, $to); ExecutionManager::callChildProcessToCacheDistinctColumnValues($from, $to); } } }
private function getRelationshipDataMatchingRatio($rel_id) { $relationshipDAO = new RelationshipDAO(); $res = $relationshipDAO->getRelationshipAverageDataMatchingRatios($rel_id); return max($res->avgFrom, $res->avgTo); }
<?php require_once realpath(dirname(__FILE__)) . '/../config.php'; require_once realpath(dirname(__FILE__)) . '/../DAL/RelationshipDAO.php'; if (!$current_user->authenticated) { die('Please login to use this function.'); } $relId = $_POST['relId']; $userId = $current_user->user_id; $relationshipDAO = new RelationshipDAO(); echo json_encode($relationshipDAO->getComment($relId, $userId));
function testRelDAO() { $datasetFinder = new DatasetFinder(); //var_dump($datasetFinder->findDatasetInfoBySid(1495)); //var_dump($datasetFinder->findDatasetInfoBySid(1487)); $relDAO = new RelationshipDAO(); var_dump($relDAO->getRelationship(752)); //var_dump($relDAO->getComments(1454)); //var_dump($relDAO->getComment(1462, 20)); //var_dump($relDAO->updateComment(1462, 20, 0.7, 'Test update')); }
<?php require_once realpath(dirname(__FILE__)) . '/../config.php'; require_once realpath(dirname(__FILE__)) . '/../DAL/RelationshipDAO.php'; if (!$current_user->authenticated) { die('Please login to use this function.'); } $relId = $_POST['relId']; $userId = $current_user->user_id; $relationshipDAO = new RelationshipDAO(); $comments = $relationshipDAO->getComments($relId); for ($i = 0; $i < count($comments); $i++) { if ($comments[$i]->userId == $userId) { $yourComment = $comments[$i]; unset($comments[$i]); $comments = array_values($comments); break; } } $jsonResult = new stdClass(); $jsonResult->yourComment = $yourComment; $jsonResult->comments = $comments; echo json_encode($jsonResult);
public function GetCondisionsByRelationship($relationship) { $relstionshipDAO = new RelationshipDAO(); $links = $relstionshipDAO->GetLinksByRelId($relationship->relId, 1); $conditionsArr = array(); $dataMatchingCheckerDAO = new DataMatchingCheckerDAO(); foreach ($links as $key => $link) { if (isset($relationship->selectedLinks)) { //no selected property might be setup because, in case we just use all links $shouldBeIncluded = $this->isLinkSelected($link, $relationship->selectedLinks); if (!$shouldBeIncluded) { continue; } } $condition = " [{$relationship->sidFrom->tableName}{$relationship->sidFrom->sid}].[{$link->fromPart}] = [{$relationship->sidTo->tableName}{$relationship->sidTo->sid}].[{$link->toPart}] "; $encodeToDecodeMap = array($link->fromPartEncoded => $link->fromPart, $link->toPartEncoded => $link->toPart); $synonums = $dataMatchingCheckerDAO->getSynonymnsByCids($link->fromPartEncoded, $link->toPartEncoded); if (isset($synonums) && count($synonums) > 0) { $synCondArr = array(); foreach ($synonums as $key => $syn) { $synStr = " ( [{$relationship->sidFrom->tableName}{$relationship->sidFrom->sid}].[{$encodeToDecodeMap[$syn->linkFrom]}] = '{$syn->valueFrom}' AND [{$relationship->sidTo->tableName}{$relationship->sidTo->sid}].[{$encodeToDecodeMap[$syn->linkTo]}] = '{$syn->valueTo}' ) "; $synCondArr[] = $synStr; } $synCond = implode(" OR ", $synCondArr); $conditionsArr[] = "( {$condition} OR {$synCond} )"; } else { $conditionsArr[] = "( {$condition} )"; } } return implode(" and ", $conditionsArr); }
/** * Add neo4j relationship and nodes if needed by colfusion relationship id. * @param [type] $rel_id colfusion relationships id. */ public function addRelationshipByRelId($rel_id) { $relationshipDao = new RelationshipDAO(); $relationship = $relationshipDao->getRelationship($rel_id); //var_dump($relationship); $confidence = $relationshipDao->getRelationshipAverageConfidenceByRelId($rel_id); $this->addRelationship($relationship->fromDataset->sid, $relationship->toDataset->sid, $rel_id, 1 - $confidence); }
/** * Adds colfusion relationship between two stories. Also addes neo4j relationship and nodes if needed. And trigres backgroun computatio of datamatching ratios. * @param [type] $user_id id of the user who adds new relationships. * @param [type] $name name of the relationship. * @param [type] $description short textual description for new relationship. * @param [type] $from object containing info about From dataset sid and columns of the relationships from From dataset. TODO: create a class for that object. * @param [type] $to object containing info about To dataset sid and columns of the relationships from To dataset. TODO: the class class as for From should be used. * @param [type] $confidence confidence value for the relationship. * @param [type] $comment shor textual comment for the relationship. */ public function AddRelationship($user_id, $name, $description, $from, $to, $confidence, $comment) { // Add new relationshp in to colfusion $relationshipDao = new RelationshipDAO(); $rel_id = $relationshipDao->addRelationship($user_id, $name, $description, $from, $to, $confidence, $comment); // add newly created relationshiop to neo4j. $neo4JDAO = new Neo4JDAO(); $neo4JDAO->addRelationshipByRelId($rel_id); // triger background execution of data matching ration calcualtion. $dataMatcher = new DataMatcher(); $dataMatcher->calculateDataMatchingRatios(array($rel_id)); }
<?php require_once realpath(dirname(__FILE__)) . '/../config.php'; require_once realpath(dirname(__FILE__)) . '/../DAL/RelationshipDAO.php'; $relId = $_POST['relId']; $simThreshold = $_POST['simThreshold']; $userName = $current_user->user_login; $relationshipDAO = new RelationshipDAO(); try { $relationship = $relationshipDAO->getRelationship($relId, $simThreshold); $relationship->isOwned = $relationship->creator == $userName; $relationship->simThreshold = $simThreshold; echo json_encode($relationship); } catch (Exception $e) { die($e->getMessage()); }
<?php require_once realpath(dirname(__FILE__)) . '/../config.php'; require_once realpath(dirname(__FILE__)) . '/../DAL/RelationshipDAO.php'; require_once realpath(dirname(__FILE__)) . '/../DAL/Neo4JDAO.php'; require_once realpath(dirname(__FILE__)) . '/../DAL/NotificationDAO.php'; if (!$current_user->authenticated) { die('Please login to use this function.'); } $relId = $_POST['relId']; $userId = $current_user->user_id; $relationshipDAO = new RelationshipDAO(); $notificationDAO = new NotificationDAO(); $notificationDAO->addNTFtoDB($relId, "removeRelationship"); $jsonResult = new stdClass(); try { $relationshipDAO->deleteRelationship($relId, $userId); $n4jDao = new Neo4JDAO(); $n4jDao->deleteRelationshipByRelId($relId); $jsonResult->isSuccessful = true; } catch (Exception $e) { $jsonResult->isSuccessful = false; } echo json_encode($jsonResult);