Navigation Menu

Skip to content

Commit

Permalink
Insert option disctinct
Browse files Browse the repository at this point in the history
  • Loading branch information
BorderCloud committed Oct 10, 2014
1 parent b4d1eae commit 08b3b9e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
16 changes: 12 additions & 4 deletions ParserCSV.php
Expand Up @@ -86,7 +86,7 @@ function sortTable($array){
return $result;
}

public static function compare($rs1,$rs2,$ordered=false) {
public static function compare($rs1,$rs2,$ordered=false,$distinct=false) {
$difference=array();
//A/ Check the variables lists in the header are the same.
if(count($rs1) ==0 && count($rs2) ==0){
Expand All @@ -102,9 +102,17 @@ public static function compare($rs1,$rs2,$ordered=false) {
//ref : http://blog.datagraph.org/2010/03/rdf-isomorphism

// 1.Compare graph sizes and all statements without blank nodes. If they do not match, fail.
//1.1 remove blank nodes
$clone1WithoutBlanknodes = $rs1;
$clone2WithoutBlanknodes = $rs2;
//1.1 remove blank nodes
$clone1WithoutBlanknodes = NULL;
$clone2WithoutBlanknodes = NULL;
if($distinct){
$clone1WithoutBlanknodes = $rs1;
$clone2WithoutBlanknodes = $rs2;
}else{
$clone1WithoutBlanknodes = ToolsBlankNode::removeDuplicate($rs1);
$clone2WithoutBlanknodes = ToolsBlankNode::removeDuplicate($rs2);
}

$bnodesInRs1=array();
$bnodesInRs2=array();
$patternBlankNode = '/^_:/';
Expand Down
14 changes: 11 additions & 3 deletions ParserSparqlResult.php
Expand Up @@ -151,7 +151,7 @@ function mySortResult($row1, $row2){
return $result;
}

public static function compare($rs1,$rs2,$ordered=false) {
public static function compare($rs1,$rs2,$ordered=false,$distinct=false) {
$difference=array();
//A/ Check the variables lists in the header are the same.
if(! isset($rs1['result']['variables']) && ! isset($rs2['result']['variables'])){
Expand All @@ -167,8 +167,16 @@ public static function compare($rs1,$rs2,$ordered=false) {

// 1.Compare graph sizes and all statements without blank nodes. If they do not match, fail.
//1.1 remove blank nodes
$clone1WithoutBlanknodes = $rs1['result']['rows'];
$clone2WithoutBlanknodes = $rs2['result']['rows'];
$clone1WithoutBlanknodes = NULL;
$clone2WithoutBlanknodes = NULL;
if($distinct){
$clone1WithoutBlanknodes = $rs1['result']['rows'];
$clone2WithoutBlanknodes = $rs2['result']['rows'];
}else{
$clone1WithoutBlanknodes = ToolsBlankNode::removeDuplicate($rs1['result']['rows']);
$clone2WithoutBlanknodes = ToolsBlankNode::removeDuplicate($rs2['result']['rows']);
}

$bnodesInRs1=array();
$bnodesInRs2=array();

Expand Down
14 changes: 11 additions & 3 deletions ParserTurtle.php
Expand Up @@ -170,10 +170,18 @@ static function getTriple($arrayTurtle, $s,$p){
return $result;
}

public static function compare($rs1,$rs2,$ordered=false) {
public static function compare($rs1,$rs2,$ordered=false,$distinct=false) {
$difference=array();
$rs1Triples = $rs1["triples"];
$rs2Triples = $rs2["triples"];
$rs1Triples = NULL;
$rs2Triples = NULL;

if($distinct){
$rs1Triples = $rs1["triples"];
$rs2Triples = $rs2["triples"];
}else{
$rs1Triples = ToolsBlankNode::removeDuplicate($rs1["triples"]);
$rs2Triples = ToolsBlankNode::removeDuplicate($rs2["triples"]);
}

//B/ Check the result set have the same number of rows.
if(count($rs1Triples) != count($rs2Triples)) {
Expand Down
19 changes: 19 additions & 0 deletions ToolsBlankNode.php
Expand Up @@ -6,6 +6,25 @@
*/
class ToolsBlankNode {

public static function removeDuplicate($set)
{
$find = false;
$result = array();
foreach ($set as $key1=>$value1) {
$find = false;
foreach ($result as $key2=>$value2) {
if(count(array_diff_assoc($value1,$value2)) == 0 ){
$find = true;
break;
}
}
if(! $find)
$result[] = $value1;

}
return $result;
}

public static function AllPermutations($set)
{
$solutions=array();
Expand Down

0 comments on commit 08b3b9e

Please sign in to comment.