Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for named graphs #196

Merged
merged 32 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f69df74
Implemented quad dictionaries for .nq files
QuentinJanuel May 31, 2023
728446d
temp triples can handle quads
QuentinJanuel Jun 1, 2023
3d9e29a
making sure graphs don't affect normal hdt
QuentinJanuel Jun 5, 2023
9a7d09d
FourQuadSectionDictionary needs to implement FourSectionDictionary, n…
QuentinJanuel Jun 15, 2023
7a024f5
quad patterns support (not implemented yet)
QuentinJanuel Jun 15, 2023
82cb465
fixed quadstring
QuentinJanuel Jun 22, 2023
3439c49
save triples (could be optimized)
QuentinJanuel Jun 22, 2023
a4f5bfb
search wip
QuentinJanuel Jun 26, 2023
d672ee9
Fixed search for triples (non quad)
QuentinJanuel Jun 29, 2023
c26b85e
number of graphs is now dynamic
QuentinJanuel Jun 29, 2023
f58cfa6
Adapt code for large files (RoaringBitmap)
QuentinJanuel Jul 11, 2023
bcc095a
roaring bitmap 64
QuentinJanuel Jul 13, 2023
f45facb
accelerated wildcard pattern a bit
QuentinJanuel Jul 13, 2023
1e612c3
BitmapQuadsIterator
QuentinJanuel Jul 17, 2023
8d31b3d
fixed roaring bitmap
QuentinJanuel Jul 20, 2023
c8b0c1e
let quads iterator variables be longs
QuentinJanuel Jul 20, 2023
b1ba3a6
support for ???G, S??G, SP?G & SPOG
QuentinJanuel Jul 20, 2023
0f1685b
?POG & ??OG (ZGFOQ)
QuentinJanuel Jul 28, 2023
5ccc86b
removed forgotten log
QuentinJanuel Jul 28, 2023
257aa30
?PO? & ??O? (ZFOQ)
QuentinJanuel Jul 28, 2023
76ee129
?P?G (YGFOQ)
QuentinJanuel Jul 31, 2023
41abd02
?P?? (YFOQ)
QuentinJanuel Aug 4, 2023
cbfeedc
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12416…
QuentinJanuel Aug 28, 2023
b9002a6
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12955…
QuentinJanuel Aug 28, 2023
fef55fb
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12955…
QuentinJanuel Aug 28, 2023
5233663
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12955…
QuentinJanuel Aug 28, 2023
59bba7c
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12955…
QuentinJanuel Aug 28, 2023
7ae491c
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12958…
QuentinJanuel Aug 28, 2023
eacd5bb
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12958…
QuentinJanuel Aug 28, 2023
f61bc58
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12959…
QuentinJanuel Aug 31, 2023
c675a01
cat tests for quads
QuentinJanuel Sep 4, 2023
3f4ba41
test quads iterators
QuentinJanuel Sep 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
BitmapQuadsIterator
  • Loading branch information
QuentinJanuel committed Jul 17, 2023
commit 1e612c372b5b6d7882f608f6c5b3f24783465d4b
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package org.rdfhdt.hdt.quads.impl;

import java.util.List;

import org.rdfhdt.hdt.compact.bitmap.Bitmap;
import org.rdfhdt.hdt.enums.TripleComponentOrder;
import org.rdfhdt.hdt.exceptions.NotImplementedException;
import org.rdfhdt.hdt.triples.TripleID;
import org.rdfhdt.hdt.triples.impl.BitmapTriples;
import org.rdfhdt.hdt.triples.impl.BitmapTriplesIterator;
import org.rdfhdt.hdt.triples.impl.TripleOrderConvert;

public class BitmapQuadsIterator extends BitmapTriplesIterator {

// resolves ????, S???, SP??, SPO? queries

private List<Bitmap> bitmapsGraph; // one bitmap per graph
private int numberOfGraphs;
private long posG; // the current graph bitmap
private int g; // g is variable

public BitmapQuadsIterator(BitmapTriples triples, TripleID pattern) {
super();
this.triples = triples;
this.returnTriple = new TripleID();
this.pattern = new TripleID();
this.bitmapsGraph = triples.getQuadInfoAG();
this.numberOfGraphs = bitmapsGraph.size();
newSearch(pattern);
}

@Override
public void goToStart() {
super.goToStart();
posG = 0;
while(!bitmapsGraph.get((int) posG).access(posZ)) {
posG++;
}
g = (int) posG + 1;
}

@Override
public long estimatedNumResults() {
long results = 0;
for(int i = 0; i < numberOfGraphs; i++) {
results += bitmapsGraph.get(i).rank1(maxZ - 1) - bitmapsGraph.get(i).rank1(minZ - 1);
}
return results;
}

/*
* Get the next solution
*/
@Override
public TripleID next() {
z = (int) adjZ.get(posZ); // get the next object (Z). We just retrieve it from the list of objects (AdjZ) from current position posZ
if(posZ>=nextZ) { // if, with the current position of the object (posZ), we have reached the next list of objects (starting in nexZ), then we should update the associated predicate (Y) and, potentially, also the associated subject (X)
posY = triples.bitmapZ.rank1(posZ-1); // move to the next position of predicates
y = (int) adjY.get(posY); // get the next predicate (Y). We just retrieve it from the list of predicates(AdjY) from current position posY
nextZ = adjZ.findNext(posZ)+1; // update nextZ, storing in which position (in adjZ) ends the list of objects associated with the current subject,predicate
if(posY>=nextY) { // if we have reached the next list of objects (starting in nexZ) we should update the associated predicate (Y) and, potentially, also the associated subject (X)
x = (int) triples.bitmapY.rank1(posY - 1) + 1; // get the next subject (X)
nextY = adjY.findNext(posY)+1; // update nextY, storing in which position (in AdjY) ends the list of predicates associated with the current subject
}
}

g = (int) posG + 1;

// set posG to the next graph of this triple
do {
posG++;
} while(posG+1 <= numberOfGraphs && !bitmapsGraph.get((int) posG).access(posZ));

if(posG == numberOfGraphs) { // there are no further graphs for this triple
posZ++;
if(posZ < maxZ) {
posG = 0;
while(!bitmapsGraph.get((int) posG).access(posZ)) {
posG++;
}
}
}

updateOutput(); // set the components (subject,predicate,object,graph) of the returned triple
return returnTriple; // return the triple as solution
}

/*
* Set the components (subject,predicate,object) of the returned triple
*/
@Override
protected void updateOutput() {
returnTriple.setAll(x, y, z, g);
TripleOrderConvert.swapComponentOrder(returnTriple, triples.order, TripleComponentOrder.SPO);
}

@Override
public boolean hasPrevious() {
throw new NotImplementedException();
}

@Override
public TripleID previous() {
throw new NotImplementedException();
}

@Override
public boolean canGoTo() {
throw new NotImplementedException();
}

@Override
public void goTo(long pos) {
throw new NotImplementedException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.rdfhdt.hdt.options.ControlInfo;
import org.rdfhdt.hdt.options.ControlInformation;
import org.rdfhdt.hdt.options.HDTOptions;
import org.rdfhdt.hdt.quads.impl.BitmapQuadsIterator;
import org.rdfhdt.hdt.triples.IteratorTripleID;
import org.rdfhdt.hdt.triples.TempTriples;
import org.rdfhdt.hdt.triples.TripleID;
Expand Down Expand Up @@ -294,12 +295,11 @@ public SuppliableIteratorTripleID search(TripleID pattern) {
}
}

SuppliableIteratorTripleID bitIt = new BitmapTriplesIterator(
SuppliableIteratorTripleID bitIt = new BitmapQuadsIterator(
this,
pattern,
true
pattern
);
if(patternString.equals("???") || patternString.equals("S??") || patternString.equals("SP?") || patternString.equals("SPO")) {
if(patternString.equals("????") || patternString.equals("S???") || patternString.equals("SP??") || patternString.equals("SPO?")) {
return bitIt;
} else {
return new SequentialSearchIteratorTripleID(pattern, bitIt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@
public class BitmapTriples implements TriplesPrivate {
protected static final Logger log = LoggerFactory.getLogger(BitmapTriples.class);

protected TripleComponentOrder order;
public TripleComponentOrder order;

protected Sequence seqY, seqZ, indexZ, predicateCount;
protected Bitmap bitmapY, bitmapZ, bitmapIndexZ;
public Bitmap bitmapY, bitmapZ, bitmapIndexZ;

protected AdjacencyList adjY, adjZ, adjIndex;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@

package org.rdfhdt.hdt.triples.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.rdfhdt.hdt.compact.bitmap.AdjacencyList;
import org.rdfhdt.hdt.compact.bitmap.Bitmap;
import org.rdfhdt.hdt.enums.ResultEstimationType;
import org.rdfhdt.hdt.enums.TripleComponentOrder;
import org.rdfhdt.hdt.iterator.SuppliableIteratorTripleID;
Expand All @@ -44,35 +39,26 @@
*/
public class BitmapTriplesIterator implements SuppliableIteratorTripleID {

private final BitmapTriples triples;
private final TripleID pattern, returnTriple;
private long lastPosition;
private long patX, patY, patZ;
protected BitmapTriples triples;
protected TripleID pattern, returnTriple;
protected long lastPosition;
protected long patX, patY, patZ;

protected AdjacencyList adjY, adjZ;
protected long posY, posZ, minY, minZ, maxY, maxZ;
protected long nextY, nextZ;
protected long x, y, z;

private AdjacencyList adjY, adjZ;
long posY, posZ, minY, minZ, maxY, maxZ, posG;
private long nextY, nextZ;
private long x, y, z, g;
private List<Long> currentGs;
private boolean isHDTQ;
protected BitmapTriplesIterator() {
}

public BitmapTriplesIterator(BitmapTriples triples, TripleID pattern) {
this.triples = triples;
this.returnTriple = new TripleID();
this.pattern = new TripleID();
this.currentGs = new ArrayList<Long>();
newSearch(pattern);
}

public BitmapTriplesIterator(
BitmapTriples triples,
TripleID pattern,
boolean isHDTQ
) {
this(triples, pattern);
this.isHDTQ = isHDTQ;
}

public BitmapTriplesIterator(BitmapTriples triples, long minZ, long maxZ) {
this.triples = triples;
this.returnTriple = new TripleID();
Expand Down Expand Up @@ -104,12 +90,9 @@ public void newSearch(TripleID pattern) {
goToStart();
}

private void updateOutput() {
protected void updateOutput() {
lastPosition = posZ;
if (isHDTQ)
returnTriple.setAll(x, y, z, g);
else
returnTriple.setAll(x, y, z);
returnTriple.setAll(x, y, z);
TripleOrderConvert.swapComponentOrder(
returnTriple,
triples.order,
Expand Down Expand Up @@ -166,44 +149,7 @@ private void findRange() {
*/
@Override
public boolean hasNext() {
return posZ < maxZ || currentGs.size() > 0;
}
class Indexed<T> {
public T value;
public int index;
public Indexed(T value, int index) {
this.value = value;
this.index = index;
}
}
public void updateCurrentGs() {
if (!isHDTQ) return;
if (!currentGs.isEmpty()) {
throw new RuntimeException("CurrentGs should not be updated if it is not empty");
}
List<Bitmap> quadInfo = triples.getQuadInfoAG();
// for (int i = 0; i < quadInfo.size(); i++) {
// Bitmap graph = quadInfo.get(i);
// if (graph.access((int)posG))
// currentGs.add((long) i + 1);
// }
currentGs = quadInfo
.stream()
.parallel()
.filter(graph -> graph.access((int)posG))
.map(graph -> quadInfo.indexOf(graph) + 1L)
.collect(Collectors.toList());
// currentGs = IntStream
// .range(0, quadInfo.size())
// .parallel()
// .mapToObj(i -> new Indexed<Bitmap>(quadInfo.get(i), i))
// .filter(ib -> ib.value.access((int)posG))
// .map(ib -> (long) ib.index + 1)
// .collect(Collectors.toList());
if (currentGs.isEmpty()) {
throw new RuntimeException("CurrentGs should not be empty");
}
posG++;
return posZ < maxZ;
}

/*
Expand All @@ -213,11 +159,6 @@ public void updateCurrentGs() {
*/
@Override
public TripleID next() {
if (isHDTQ && !currentGs.isEmpty()) {
g = currentGs.remove(0);
updateOutput();
return returnTriple;
}
z = adjZ.get(posZ);
if(posZ==nextZ) {
posY++;
Expand All @@ -232,11 +173,6 @@ public TripleID next() {
}
}

if (isHDTQ) {
updateCurrentGs();
g = currentGs.remove(0);
}

updateOutput();

posZ++;
Expand Down