@Test public void testIsDuplicate() throws IOException { URL dataUrl = QueryGeneratorTest.class.getResource("/data_enc.csv"); List<Triple> triples = TripleUtils.csvToTriples(dataUrl.getPath(), true); List<Triple> rdfTypeTriples = new ArrayList<>(); DuplicatesBuster buster = new DuplicatesBuster(); for(Triple triple: triples) { assertFalse(buster.isDuplicate(triple)); if(((Long) triple.getPredicate()) == 0) { rdfTypeTriples.add(triple); } } int duplicates = 0; for(Triple triple: triples) { boolean duplicate = buster.isDuplicate(triple); if(rdfTypeTriples.contains(triple)) { assertTrue(duplicate); } else { assertFalse(duplicate); } if(duplicate) { duplicates++; } } assertEquals(rdfTypeTriples.size(), duplicates); }
public boolean isDuplicate(Triple triple) { boolean duplicate = false; Long predicate = (Long) triple.getPredicate(); Long subject = (Long) triple.getSubject(); Long object = (Long) triple.getObject(); if(RDF_TYPE.equals(predicate)) { if(rdfTypeMap.containsKey(object)) { Set<Long> subjects = rdfTypeMap.get(object); if(subjects.contains(subject)) { duplicate = true; } else { subjects.add(subject); } } else { Set<Long> subjects = new HashSet<>(100000); subjects.add(subject); rdfTypeMap.putIfAbsent(object, subjects); } } return duplicate; }
DuplicatesBuster { public boolean isDuplicate(Triple triple) { boolean duplicate = false; Long predicate = (Long) triple.getPredicate(); Long subject = (Long) triple.getSubject(); Long object = (Long) triple.getObject(); if(RDF_TYPE.equals(predicate)) { if(rdfTypeMap.containsKey(object)) { Set<Long> subjects = rdfTypeMap.get(object); if(subjects.contains(subject)) { duplicate = true; } else { subjects.add(subject); } } else { Set<Long> subjects = new HashSet<>(100000); subjects.add(subject); rdfTypeMap.putIfAbsent(object, subjects); } } return duplicate; } }
DuplicatesBuster { public boolean isDuplicate(Triple triple) { boolean duplicate = false; Long predicate = (Long) triple.getPredicate(); Long subject = (Long) triple.getSubject(); Long object = (Long) triple.getObject(); if(RDF_TYPE.equals(predicate)) { if(rdfTypeMap.containsKey(object)) { Set<Long> subjects = rdfTypeMap.get(object); if(subjects.contains(subject)) { duplicate = true; } else { subjects.add(subject); } } else { Set<Long> subjects = new HashSet<>(100000); subjects.add(subject); rdfTypeMap.putIfAbsent(object, subjects); } } return duplicate; }  }
DuplicatesBuster { public boolean isDuplicate(Triple triple) { boolean duplicate = false; Long predicate = (Long) triple.getPredicate(); Long subject = (Long) triple.getSubject(); Long object = (Long) triple.getObject(); if(RDF_TYPE.equals(predicate)) { if(rdfTypeMap.containsKey(object)) { Set<Long> subjects = rdfTypeMap.get(object); if(subjects.contains(subject)) { duplicate = true; } else { subjects.add(subject); } } else { Set<Long> subjects = new HashSet<>(100000); subjects.add(subject); rdfTypeMap.putIfAbsent(object, subjects); } } return duplicate; }  boolean isDuplicate(Triple triple); }
DuplicatesBuster { public boolean isDuplicate(Triple triple) { boolean duplicate = false; Long predicate = (Long) triple.getPredicate(); Long subject = (Long) triple.getSubject(); Long object = (Long) triple.getObject(); if(RDF_TYPE.equals(predicate)) { if(rdfTypeMap.containsKey(object)) { Set<Long> subjects = rdfTypeMap.get(object); if(subjects.contains(subject)) { duplicate = true; } else { subjects.add(subject); } } else { Set<Long> subjects = new HashSet<>(100000); subjects.add(subject); rdfTypeMap.putIfAbsent(object, subjects); } } return duplicate; }  boolean isDuplicate(Triple triple);  }