Iterator<String> concatenatedPredicateObjectMapsListItr = concatenatedPredicateObjectMapsList.iterator();
Iterator<String> predicatesItr = predicates.iterator();
Iterator<String> otherClassesItr = otherClasses.iterator();
String hNodeId = FetchHNodeIdFromAlignmentCommand.gethNodeId(AlignmentManager.Instance().constructAlignmentId(workspace.getId(), worksheetId), columnUri);
if (hNodeId == null) {
return new UpdateContainer(new AbstractUpdate() {
@Override
public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) {
pw.print(array.toString());
}
});
}
HNode hnode = factory.getHNode(hNodeId);
List<Table> dataTables = new ArrayList<Table>();
CloneTableUtils.getDatatable(worksheet.getDataTable(), factory.getHTable(hnode.getHTableId()), dataTables, selection);
KR2RMLBloomFilter uris = new KR2RMLBloomFilter(KR2RMLBloomFilter.defaultVectorSize, KR2RMLBloomFilter.defaultnbHash, Hash.JENKINS_HASH);
Set<String> uriSet = new HashSet<String>();
for(Table t : dataTables) {
for(Row r : t.getRows(0, t.getNumRows(), selection)) {
Node n = r.getNode(hNodeId);
if(n != null && n.getValue() != null && !n.getValue().isEmptyValue() && n.getValue().asString() != null && !n.getValue().asString().trim().isEmpty() ) {
String value = n.getValue().asString().trim().replace(" ", "");
String baseURI = worksheet.getMetadataContainer().getWorksheetProperties().getPropertyValue(Property.baseURI);
try {
URI uri = new URI(value);
if (!uri.isAbsolute() && baseURI != null) {
value = baseURI + value;
}
} catch (URISyntaxException e) {
}
builder = new StringBuilder();
value = builder.append("<").append(value).append(">").toString(); //String builder
uriSet.add(value);
uris.add(new Key(value.getBytes(UTF8_CHARSET)));
}
}
}
Set<String> maps = new HashSet<String>();
Map<String, String> bloomfilterMapping = new HashMap<String, String>();
try{
for (String concatenatedPredicateObjectMaps : concatenatedPredicateObjectMapsList) {
List<String> predicateObjectMaps = new ArrayList<String>(Arrays.asList(concatenatedPredicateObjectMaps.split(",")));
maps.addAll(predicateObjectMaps);
if (maps.size() > limit) {
bloomfilterMapping.putAll(util.getBloomFiltersForMaps(tripleStoreUrl, null, maps));
maps = new HashSet<String>();
}
}
if (maps.size() > 0)
bloomfilterMapping.putAll(util.getBloomFiltersForMaps(tripleStoreUrl, null, maps));
} catch (KarmaException e1) {
e1.printStackTrace();
}
while(concatenatedPredicateObjectMapsListItr.hasNext() && predicatesItr.hasNext() && otherClassesItr.hasNext())
{
String concatenatedPredicateObjectMaps = concatenatedPredicateObjectMapsListItr.next();
List<String> predicateObjectMaps = new ArrayList<String>(Arrays.asList(concatenatedPredicateObjectMaps.split(",")));
String predicate = predicatesItr.next();
String otherClass = otherClassesItr.next();
try {
KR2RMLBloomFilter intersectionBF = new KR2RMLBloomFilter(KR2RMLBloomFilter.defaultVectorSize, KR2RMLBloomFilter.defaultnbHash, Hash.JENKINS_HASH);
for (String triplemap : predicateObjectMaps) {
String serializedBloomFilter = bloomfilterMapping.get(triplemap);
if (serializedBloomFilter != null) {
KR2RMLBloomFilter bf = new KR2RMLBloomFilter();
bf.populateFromCompressedAndBase64EncodedString(serializedBloomFilter);
intersectionBF.or(bf);
}
}
System.out.println(predicate + " " + intersectionBF.estimateNumberOfHashedValues());
intersectionBF.and(uris);
int estimate = intersectionBF.estimateNumberOfHashedValues();
JSONObject obj = new JSONObject();
obj.put("predicate", predicate);
obj.put("otherClass", otherClass);
obj.put("estimate", estimate);
obj.put("incoming", "false");
// array.put(obj);
objects.add(obj);
} catch (Exception e) {
LOG.error("Unable to process bloom filter: " + e.getMessage());
}
}
Collections.sort(objects, new Comparator<JSONObject>() {
@Override
public int compare(JSONObject a, JSONObject b) {
return b.getInt("estimate") - a.getInt("estimate");
}
});
for (JSONObject obj : objects) {
array.put(obj);
}
return new UpdateContainer(new AbstractUpdate() {
@Override
public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) {
System.out.println(array.toString());
pw.print(array.toString());