Skip to content

Commit

Permalink
Fixed bug concerning same triples
Browse files Browse the repository at this point in the history
  • Loading branch information
D063520 committed Sep 27, 2018
1 parent 9b7d2c8 commit 3a0cd1e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 61 deletions.
20 changes: 19 additions & 1 deletion hdt-api/src/main/java/org/rdfhdt/hdt/triples/TripleID.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
package org.rdfhdt.hdt.triples;

import java.io.Serializable;
import java.util.Objects;

import org.rdfhdt.hdt.util.LongCompare;


Expand Down Expand Up @@ -157,8 +159,10 @@ public void clear() {
public String toString() {
return Long.toString(subject) + " " + predicate + " " + object;
}



public boolean equals(TripleID other) {
System.out.println(!( subject!=other.subject || predicate!=other.predicate || object!=other.object ));
return !( subject!=other.subject || predicate!=other.predicate || object!=other.object );
}

Expand Down Expand Up @@ -247,4 +251,18 @@ public static int size(){
return 48;
}

@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof TripleID)) {
return false;
}
TripleID other = (TripleID) o;
return !( subject!=other.subject || predicate!=other.predicate || object!=other.object );
}

@Override
public int hashCode() {
return (int) (subject * 13 + predicate * 17 + object * 31);
}
}
72 changes: 13 additions & 59 deletions hdt-java-core/src/test/java/org/rdfhdt/hdt/hdtCat/HdtCatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.rdfhdt.hdt.exceptions.ParserException;
import org.rdfhdt.hdt.hdt.HDT;
import org.rdfhdt.hdt.hdt.HDTManager;
import org.rdfhdt.hdt.hdtCat.utils.UtilDictionary;
import org.rdfhdt.hdt.hdtCat.utils.Utility;
import org.rdfhdt.hdt.listener.ProgressListener;
import org.rdfhdt.hdt.options.HDTSpecification;

Expand Down Expand Up @@ -37,8 +37,10 @@ public void help(String file1, String file2, String concat){
HDT hdtCatNew = HDTManager.catHDT(theDir.getAbsolutePath(), hdt1_location, hdt2_location, new HDTSpecification(), null);

//HDTCat hdtCatNew = new HDTCat(new HDTSpecification(),hdt1,hdt2,this);
UtilDictionary.printDictionary(hdtCatNew.getDictionary());
UtilDictionary.compareDictionary(hdtCatOld.getDictionary(), hdtCatNew.getDictionary());
Utility.printDictionary(hdtCatNew.getDictionary());
Utility.compareDictionary(hdtCatOld.getDictionary(), hdtCatNew.getDictionary());
Utility.printTriples(hdtCatNew);
Utility.compareTriples(hdtCatOld,hdtCatNew);

try {
Iterator it = hdtCatOld.search("", "", "");
Expand Down Expand Up @@ -149,62 +151,14 @@ public void cat10() {
help(file1,file2,concat);
}

// @Test
// public void cat13() {
// ClassLoader classLoader = getClass().getClassLoader();
// try {
// HDT hdt1 = HDTManager.mapHDT("/Users/Dennis/IdeaProjects/hdt-java/hdt-java-cli/lubm.1-4000Cat.hdt");
// System.out.println(hdt1.getDictionary().getNshared());
//
// IteratorTripleString it = hdt1.search("","","");
// int count = 0;
// while (it.hasNext()){
// it.next();
// count ++;
// if (count%1000==0){
// System.out.println(count);
// }
// }
// } catch (IOException e) {
// e.printStackTrace();
// } catch (NotFoundException e) {
// e.printStackTrace();
// }
// }


// @Test
// public void cat14() {
//
// ClassLoader classLoader = getClass().getClassLoader();
// File file1 = new File(classLoader.getResource("wikidata.nt").getFile());
// File file2 = new File(classLoader.getResource("example17.nt").getFile());
// File concat = new File(classLoader.getResource("example16+17.nt").getFile());
// HDT hdt1 = null;
// HDT hdt2 = null;
// try {
// hdt1 = HDTManager.generateHDT(file1.getAbsolutePath(), "uri", RDFNotation.NTRIPLES, new HDTSpecification(), this);
// hdt2 = HDTManager.generateHDT(file2.getAbsolutePath(), "uri", RDFNotation.NTRIPLES, new HDTSpecification(), this);
// HDT hdtCatOld = HDTManager.generateHDT(concat.getAbsolutePath(), "uri", RDFNotation.NTRIPLES, new HDTSpecification(), this);
// HDTCat hdtCatNew = new HDTCat(new HDTSpecification(),hdt1,hdt2,this);
//
// File concatSave = new File(classLoader.getResource("example4+5Save.nt").getFile());
// hdtCatNew.saveToHDT(concatSave.getAbsolutePath(),this);
//
// IteratorTripleString it = hdt1.search("","","");
// int count = 0;
// while (it.hasNext()){
// it.next();
// count ++;
// }
// } catch (IOException e) {
// e.printStackTrace();
// } catch (NotFoundException e) {
// e.printStackTrace();
// } catch (ParserException e) {
// e.printStackTrace();
// }
// }
@Test
public void cat11() {
ClassLoader classLoader = getClass().getClassLoader();
String file1 = classLoader.getResource("example1.nt").getFile();
String file2 = classLoader.getResource("example1.nt").getFile();
String concat = classLoader.getResource("example1.nt").getFile();
help(file1,file2,concat);
}

@Override
public void notifyProgress(float level, String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertFalse;

public class UtilDictionary {
public class Utility {

public static void printDictionary(Dictionary d){
Iterator i = d.getShared().getSortedEntries();
Expand Down

0 comments on commit 3a0cd1e

Please sign in to comment.